add missed migration for DB version 36 (#6678)

pull/6728/head
Prabhat Khera 3 years ago committed by GitHub
parent 7e28b3ca3f
commit e1df46b92b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -183,6 +183,12 @@ func (m *Migrator) Migrate() error {
}
}
if m.currentDBVersion < 36 {
migrateLog.Info("Migrating to DB 36")
if err := m.migrateDBVersionToDB36(); err != nil {
return migrationError(err, "migrateDBVersionToDB36")
}
}
err = m.versionService.StoreDBVersion(portainer.DBVersion)
if err != nil {
return migrationError(err, "StoreDBVersion")

@ -0,0 +1,36 @@
package migrator
import (
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/internal/authorization"
)
func (m *Migrator) migrateDBVersionToDB36() error {
migrateLog.Info("Updating user authorizations")
if err := m.migrateUsersToDB36(); err != nil {
return err
}
return nil
}
func (m *Migrator) migrateUsersToDB36() error {
users, err := m.userService.Users()
if err != nil {
return err
}
for _, user := range users {
currentAuthorizations := authorization.DefaultPortainerAuthorizations()
currentAuthorizations[portainer.OperationPortainerUserListToken] = true
currentAuthorizations[portainer.OperationPortainerUserCreateToken] = true
currentAuthorizations[portainer.OperationPortainerUserRevokeToken] = true
user.PortainerAuthorizations = currentAuthorizations
err = m.userService.UpdateUser(user.ID, &user)
if err != nil {
return err
}
}
return nil
}

@ -424,6 +424,9 @@ func DefaultPortainerAuthorizations() portainer.Authorizations {
portainer.OperationPortainerUserList: true,
portainer.OperationPortainerUserInspect: true,
portainer.OperationPortainerUserMemberships: true,
portainer.OperationPortainerUserListToken: true,
portainer.OperationPortainerUserCreateToken: true,
portainer.OperationPortainerUserRevokeToken: true,
}
}

@ -1792,6 +1792,9 @@ const (
OperationPortainerUserInspect Authorization = "PortainerUserInspect"
OperationPortainerUserMemberships Authorization = "PortainerUserMemberships"
OperationPortainerUserCreate Authorization = "PortainerUserCreate"
OperationPortainerUserListToken Authorization = "PortainerUserListToken"
OperationPortainerUserCreateToken Authorization = "PortainerUserCreateToken"
OperationPortainerUserRevokeToken Authorization = "PortainerUserRevokeToken"
OperationPortainerUserUpdate Authorization = "PortainerUserUpdate"
OperationPortainerUserUpdatePassword Authorization = "PortainerUserUpdatePassword"
OperationPortainerUserDelete Authorization = "PortainerUserDelete"

Loading…
Cancel
Save