Alerting: Migration to remove scope from permission alert.notifications.receivers:create (#95805)

add migration to remove scope from receivers:create permission
This commit is contained in:
Yuri Tseretyan
2024-11-06 11:31:40 -05:00
committed by GitHub
parent f41f0eac80
commit af513964c8
2 changed files with 33 additions and 0 deletions
@@ -85,3 +85,34 @@ func (m *alertingMigrator) migrateNotificationActions() error {
return nil
}
type receiverCreateScopeMigration struct {
migrator.MigrationBase
}
var _ migrator.CodeMigration = new(alertingMigrator)
func (m *receiverCreateScopeMigration) SQL(migrator.Dialect) string {
return "code migration"
}
func (m *receiverCreateScopeMigration) Exec(sess *xorm.Session, mg *migrator.Migrator) error {
result, err := sess.Exec(`UPDATE permission
SET scope = '',
kind = '',
attribute='',
identifier=''
WHERE action = 'alert.notifications.receivers:create'
AND (scope <> '' OR kind <> '' OR attribute <> '' OR identifier <> '');`)
if result != nil {
aff, _ := result.RowsAffected()
if aff > 0 {
mg.Logger.Info("Removed scope from permission 'alert.notifications.receivers:create'", "affectedRows", aff)
}
}
return err
}
func AddReceiverCreateScopeMigration(mg *migrator.Migrator) {
mg.AddMigration("remove scope from alert.notifications.receivers:create", &receiverCreateScopeMigration{})
}