MM-44351: Creates new Custom Group Admin system role. (#20573)
* MM-44351: Creates new Custom Group Admin system role. * MM-44351: Adds missing test mock. * MM-44351: Adds missing mocks.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
abd5384d9b
Коммит
1f34e8ba2e
@@ -15,6 +15,7 @@ import (
|
||||
const EmojisPermissionsMigrationKey = "EmojisPermissionsMigrationComplete"
|
||||
const GuestRolesCreationMigrationKey = "GuestRolesCreationMigrationComplete"
|
||||
const SystemConsoleRolesCreationMigrationKey = "SystemConsoleRolesCreationMigrationComplete"
|
||||
const CustomGroupAdminRoleCreationMigrationKey = "CustomGroupAdminRoleCreationMigrationComplete"
|
||||
const ContentExtractionConfigDefaultTrueMigrationKey = "ContentExtractionConfigDefaultTrueMigrationComplete"
|
||||
const PlaybookRolesCreationMigrationKey = "PlaybookRolesCreationMigrationComplete"
|
||||
const FirstAdminSetupCompleteKey = model.SystemFirstAdminSetupComplete
|
||||
@@ -290,6 +291,36 @@ func (s *Server) doSystemConsoleRolesCreationMigration() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) doCustomGroupAdminRoleCreationMigration() {
|
||||
// If the migration is already marked as completed, don't do it again.
|
||||
if _, err := s.Store.System().GetByName(CustomGroupAdminRoleCreationMigrationKey); err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
roles := model.MakeDefaultRoles()
|
||||
|
||||
allSucceeded := true
|
||||
if _, err := s.Store.Role().GetByName(context.Background(), model.SystemCustomGroupAdminRoleId); err != nil {
|
||||
if _, err := s.Store.Role().Save(roles[model.SystemCustomGroupAdminRoleId]); err != nil {
|
||||
mlog.Critical("Failed to create new role.", mlog.Err(err), mlog.String("role", model.SystemCustomGroupAdminRoleId))
|
||||
allSucceeded = false
|
||||
}
|
||||
}
|
||||
|
||||
if !allSucceeded {
|
||||
return
|
||||
}
|
||||
|
||||
system := model.System{
|
||||
Name: CustomGroupAdminRoleCreationMigrationKey,
|
||||
Value: "true",
|
||||
}
|
||||
|
||||
if err := s.Store.System().Save(&system); err != nil {
|
||||
mlog.Critical("Failed to mark custom group admin role creation migration as completed.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) doContentExtractionConfigDefaultTrueMigration() {
|
||||
// If the migration is already marked as completed, don't do it again.
|
||||
if _, err := s.Store.System().GetByName(ContentExtractionConfigDefaultTrueMigrationKey); err == nil {
|
||||
@@ -516,6 +547,7 @@ func (s *Server) doAppMigrations() {
|
||||
s.doEmojisPermissionsMigration()
|
||||
s.doGuestRolesCreationMigration()
|
||||
s.doSystemConsoleRolesCreationMigration()
|
||||
s.doCustomGroupAdminRoleCreationMigration()
|
||||
// This migration always must be the last, because can be based on previous
|
||||
// migrations. For example, it needs the guest roles migration.
|
||||
err := s.doPermissionsMigrations()
|
||||
|
||||
Ссылка в новой задаче
Block a user