* Add migration to remove datasources:drilldown * remove role assignments as well * rename to datasources:drilldown * remove the role assignments * made it simple instead * Update pkg/services/sqlstore/migrations/accesscontrol/datasource_drilldown_removal.go Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com> * Update pkg/services/sqlstore/migrations/accesscontrol/datasource_drilldown_removal.go Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com> --------- Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package accesscontrol
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"xorm.io/xorm"
|
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
|
)
|
|
|
|
const (
|
|
datasourceDrilldownRemoval = "remove the datasources:drilldown action"
|
|
)
|
|
|
|
func AddDatasourceDrilldownRemovalMigration(mg *migrator.Migrator) {
|
|
mg.AddMigration(datasourceDrilldownRemoval, &datasourceDrilldownRemovalMigrator{})
|
|
}
|
|
|
|
type datasourceDrilldownRemovalMigrator struct {
|
|
migrator.MigrationBase
|
|
}
|
|
|
|
func (m *datasourceDrilldownRemovalMigrator) SQL(dialect migrator.Dialect) string {
|
|
return CodeMigrationSQL
|
|
}
|
|
|
|
func (m *datasourceDrilldownRemovalMigrator) Exec(sess *xorm.Session, mg *migrator.Migrator) error {
|
|
result, err := sess.Exec("DELETE FROM permission WHERE action = ?", "datasources:drilldown")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
rowsAffected, err := result.RowsAffected()
|
|
if err != nil {
|
|
mg.Logger.Error("Failed to get rows affected by the datasources:drilldown removal", "error", err)
|
|
} else {
|
|
mg.Logger.Info(fmt.Sprintf("Removed %d datasources:drilldown permissions", rowsAffected))
|
|
}
|
|
|
|
return nil
|
|
}
|