2022-04-05 21:07:51 +00:00
|
|
|
package migrator
|
|
|
|
|
|
|
|
import (
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
|
|
|
"github.com/portainer/portainer/api/internal/authorization"
|
2022-09-16 16:18:44 +00:00
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
2022-04-05 21:07:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (m *Migrator) migrateDBVersionToDB36() error {
|
2022-09-16 16:18:44 +00:00
|
|
|
log.Info().Msg("updating user authorizations")
|
2022-04-05 21:07:51 +00:00
|
|
|
|
2022-09-16 16:18:44 +00:00
|
|
|
return m.migrateUsersToDB36()
|
2022-04-05 21:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Migrator) migrateUsersToDB36() error {
|
2022-09-28 17:56:32 +00:00
|
|
|
log.Info().Msg("updating user authorizations")
|
|
|
|
|
2023-06-22 21:28:07 +00:00
|
|
|
users, err := m.userService.ReadAll()
|
2022-04-05 21:07:51 +00:00
|
|
|
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
|
2023-06-22 21:28:07 +00:00
|
|
|
err = m.userService.Update(user.ID, &user)
|
2022-04-05 21:07:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|