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 17:31:40 +01:00 committed by GitHub
parent f41f0eac80
commit af513964c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 0 deletions

View File

@ -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{})
}

View File

@ -138,6 +138,8 @@ func (oss *OSSMigrations) AddMigration(mg *Migrator) {
accesscontrol.AddActionSetPermissionsMigrator(mg)
externalsession.AddMigration(mg)
accesscontrol.AddReceiverCreateScopeMigration(mg)
}
func addStarMigrations(mg *Migrator) {