Access: Add migration to remove datasources:drilldown (#102188)
* 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>
This commit is contained in:
co-authored by
Gabriel MABILLE
parent
c79c768421
commit
fc9e5110d7
@@ -0,0 +1,40 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user