Files
Steve Munene 178a62c08f MG-370 - Add fine grained access control to reports (#403)
* add access control to rules engine

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>

* fix build

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>

* remove unused variable

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>

* fix report database

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>

* fix variable naming

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>

* fix entity type

Signed-off-by: Arvindh <arvindh91@gmail.com>

* update authorize method

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>

* fix generate report

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>

* revert env changes

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>

* fix linter

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>

* fix failing linter

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>

* update generate permission

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>

* revert go mod file

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>

* revert go mod file

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>

---------

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Co-authored-by: Arvindh <arvindh91@gmail.com>
2026-03-05 13:59:22 +01:00

70 lines
2.1 KiB
Go

// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0
package postgres
import (
dpostgres "github.com/absmach/supermq/domains/postgres"
"github.com/absmach/supermq/pkg/errors"
repoerr "github.com/absmach/supermq/pkg/errors/repository"
rolesPostgres "github.com/absmach/supermq/pkg/roles/repo/postgres"
_ "github.com/jackc/pgx/v5/stdlib" // required for SQL access
migrate "github.com/rubenv/sql-migrate"
)
func Migration() (*migrate.MemoryMigrationSource, error) {
rolesMigration, err := rolesPostgres.Migration(rolesTableNamePrefix, entityTableName, entityIDColumnName)
if err != nil {
return &migrate.MemoryMigrationSource{}, errors.Wrap(repoerr.ErrRoleMigration, err)
}
reportsMigration := &migrate.MemoryMigrationSource{
Migrations: []*migrate.Migration{
{
Id: "reports_01",
Up: []string{
`CREATE TABLE IF NOT EXISTS report_config (
id VARCHAR(36) PRIMARY KEY,
name VARCHAR(1024),
description TEXT,
domain_id VARCHAR(36) NOT NULL,
status SMALLINT NOT NULL DEFAULT 0 CHECK (status >= 0),
created_at TIMESTAMP,
created_by VARCHAR(254),
updated_at TIMESTAMP,
updated_by VARCHAR(254),
due TIMESTAMPTZ,
recurring SMALLINT,
recurring_period SMALLINT,
start_datetime TIMESTAMP,
config JSONB,
email JSONB,
metrics JSONB
);`,
},
Down: []string{
`DROP TABLE IF EXISTS report_config;`,
},
},
{
Id: "reports_02",
Up: []string{
`ALTER TABLE report_config ADD COLUMN report_template TEXT;`,
},
Down: []string{
`ALTER TABLE report_config DROP COLUMN report_template;`,
},
},
},
}
reportsMigration.Migrations = append(reportsMigration.Migrations, rolesMigration.Migrations...)
domainsMigration, err := dpostgres.Migration()
if err != nil {
return &migrate.MemoryMigrationSource{}, errors.Wrap(repoerr.ErrRoleMigration, err)
}
reportsMigration.Migrations = append(reportsMigration.Migrations, domainsMigration.Migrations...)
return reportsMigration, nil
}