summaryrefslogtreecommitdiffstats
path: root/app/app.go
diff options
context:
space:
mode:
Diffstat (limited to 'app/app.go')
-rw-r--r--app/app.go106
1 files changed, 96 insertions, 10 deletions
diff --git a/app/app.go b/app/app.go
index 6de75855c..bda56ca1a 100644
--- a/app/app.go
+++ b/app/app.go
@@ -20,6 +20,7 @@ import (
"github.com/mattermost/mattermost-server/einterfaces"
ejobs "github.com/mattermost/mattermost-server/einterfaces/jobs"
"github.com/mattermost/mattermost-server/jobs"
+ tjobs "github.com/mattermost/mattermost-server/jobs/interfaces"
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/plugin/pluginenv"
@@ -29,6 +30,7 @@ import (
)
const ADVANCED_PERMISSIONS_MIGRATION_KEY = "AdvancedPermissionsMigrationComplete"
+const EMOJIS_PERMISSIONS_MIGRATION_KEY = "EmojisPermissionsMigrationComplete"
type App struct {
goroutineCount int32
@@ -56,7 +58,6 @@ type App struct {
Compliance einterfaces.ComplianceInterface
DataRetention einterfaces.DataRetentionInterface
Elasticsearch einterfaces.ElasticsearchInterface
- Emoji einterfaces.EmojiInterface
Ldap einterfaces.LdapInterface
MessageExport einterfaces.MessageExportInterface
Metrics einterfaces.MetricsInterface
@@ -93,6 +94,8 @@ type App struct {
clientConfig map[string]string
clientConfigHash string
diagnosticId string
+
+ phase2PermissionsMigrationComplete bool
}
var appCount = 0
@@ -285,12 +288,6 @@ func RegisterElasticsearchInterface(f func(*App) einterfaces.ElasticsearchInterf
elasticsearchInterface = f
}
-var emojiInterface func(*App) einterfaces.EmojiInterface
-
-func RegisterEmojiInterface(f func(*App) einterfaces.EmojiInterface) {
- emojiInterface = f
-}
-
var jobsDataRetentionJobInterface func(*App) ejobs.DataRetentionJobInterface
func RegisterJobsDataRetentionJobInterface(f func(*App) ejobs.DataRetentionJobInterface) {
@@ -321,6 +318,12 @@ func RegisterJobsLdapSyncInterface(f func(*App) ejobs.LdapSyncInterface) {
jobsLdapSyncInterface = f
}
+var jobsMigrationsInterface func(*App) tjobs.MigrationsJobInterface
+
+func RegisterJobsMigrationsJobInterface(f func(*App) tjobs.MigrationsJobInterface) {
+ jobsMigrationsInterface = f
+}
+
var ldapInterface func(*App) einterfaces.LdapInterface
func RegisterLdapInterface(f func(*App) einterfaces.LdapInterface) {
@@ -367,9 +370,6 @@ func (a *App) initEnterprise() {
if elasticsearchInterface != nil {
a.Elasticsearch = elasticsearchInterface(a)
}
- if emojiInterface != nil {
- a.Emoji = emojiInterface(a)
- }
if ldapInterface != nil {
a.Ldap = ldapInterface(a)
a.AddConfigListener(func(_, cfg *model.Config) {
@@ -415,6 +415,9 @@ func (a *App) initJobs() {
if jobsLdapSyncInterface != nil {
a.Jobs.LdapSync = jobsLdapSyncInterface(a)
}
+ if jobsMigrationsInterface != nil {
+ a.Jobs.Migrations = jobsMigrationsInterface(a)
+ }
}
func (a *App) DiagnosticId() string {
@@ -580,3 +583,86 @@ func (a *App) DoAdvancedPermissionsMigration() {
mlog.Critical(fmt.Sprint(result.Err))
}
}
+
+func (a *App) SetPhase2PermissionsMigrationStatus(isComplete bool) error {
+ if !isComplete {
+ res := <-a.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
+ if res.Err != nil {
+ return res.Err
+ }
+ }
+ a.phase2PermissionsMigrationComplete = isComplete
+ return nil
+}
+
+func (a *App) DoEmojisPermissionsMigration() {
+ // If the migration is already marked as completed, don't do it again.
+ if result := <-a.Srv.Store.System().GetByName(EMOJIS_PERMISSIONS_MIGRATION_KEY); result.Err == nil {
+ return
+ }
+
+ var role *model.Role = nil
+ var systemAdminRole *model.Role = nil
+ var err *model.AppError = nil
+
+ mlog.Info("Migrating emojis config to database.")
+ switch *a.Config().ServiceSettings.RestrictCustomEmojiCreation {
+ case model.RESTRICT_EMOJI_CREATION_ALL:
+ role, err = a.GetRoleByName(model.SYSTEM_USER_ROLE_ID)
+ if err != nil {
+ mlog.Critical("Failed to migrate emojis creation permissions from mattermost config.")
+ mlog.Critical(err.Error())
+ return
+ }
+ break
+ case model.RESTRICT_EMOJI_CREATION_ADMIN:
+ role, err = a.GetRoleByName(model.TEAM_ADMIN_ROLE_ID)
+ if err != nil {
+ mlog.Critical("Failed to migrate emojis creation permissions from mattermost config.")
+ mlog.Critical(err.Error())
+ return
+ }
+ break
+ case model.RESTRICT_EMOJI_CREATION_SYSTEM_ADMIN:
+ role = nil
+ break
+ default:
+ mlog.Critical("Failed to migrate emojis creation permissions from mattermost config.")
+ mlog.Critical("Invalid restrict emoji creation setting")
+ return
+ }
+
+ if role != nil {
+ role.Permissions = append(role.Permissions, model.PERMISSION_MANAGE_EMOJIS.Id)
+ if result := <-a.Srv.Store.Role().Save(role); result.Err != nil {
+ mlog.Critical("Failed to migrate emojis creation permissions from mattermost config.")
+ mlog.Critical(result.Err.Error())
+ return
+ }
+ }
+
+ systemAdminRole, err = a.GetRoleByName(model.SYSTEM_ADMIN_ROLE_ID)
+ if err != nil {
+ mlog.Critical("Failed to migrate emojis creation permissions from mattermost config.")
+ mlog.Critical(err.Error())
+ return
+ }
+
+ systemAdminRole.Permissions = append(systemAdminRole.Permissions, model.PERMISSION_MANAGE_EMOJIS.Id)
+ systemAdminRole.Permissions = append(systemAdminRole.Permissions, model.PERMISSION_MANAGE_OTHERS_EMOJIS.Id)
+ if result := <-a.Srv.Store.Role().Save(systemAdminRole); result.Err != nil {
+ mlog.Critical("Failed to migrate emojis creation permissions from mattermost config.")
+ mlog.Critical(result.Err.Error())
+ return
+ }
+
+ system := model.System{
+ Name: EMOJIS_PERMISSIONS_MIGRATION_KEY,
+ Value: "true",
+ }
+
+ if result := <-a.Srv.Store.System().Save(&system); result.Err != nil {
+ mlog.Critical("Failed to mark emojis permissions migration as completed.")
+ mlog.Critical(fmt.Sprint(result.Err))
+ }
+}