summaryrefslogtreecommitdiffstats
path: root/app/permissions.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2018-04-18 10:18:07 +0100
committerGitHub <noreply@github.com>2018-04-18 10:18:07 +0100
commitb13a228b0451098ea32933a36fe64566e366583d (patch)
tree569aa0c6c5f273b806b4c3e0c59801204916492c /app/permissions.go
parenta1882d4004ce624dad1b8624804e974f209efe8d (diff)
downloadchat-b13a228b0451098ea32933a36fe64566e366583d.tar.gz
chat-b13a228b0451098ea32933a36fe64566e366583d.tar.bz2
chat-b13a228b0451098ea32933a36fe64566e366583d.zip
MM-10121: CLI command to reset permissions system to default state. (#8637)
* MM-10121: CLI command to reset permissions system to default state. * Review comment.
Diffstat (limited to 'app/permissions.go')
-rw-r--r--app/permissions.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/permissions.go b/app/permissions.go
new file mode 100644
index 000000000..be975e03d
--- /dev/null
+++ b/app/permissions.go
@@ -0,0 +1,25 @@
+// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package app
+
+import (
+ "github.com/mattermost/mattermost-server/model"
+)
+
+func (a *App) ResetPermissionsSystem() *model.AppError {
+ // Purge all roles from the database.
+ if result := <-a.Srv.Store.Role().PermanentDeleteAll(); result.Err != nil {
+ return result.Err
+ }
+
+ // Remove the "System" table entry that marks the advanced permissions migration as done.
+ if result := <-a.Srv.Store.System().PermanentDeleteByName(ADVANCED_PERMISSIONS_MIGRATION_KEY); result.Err != nil {
+ return result.Err
+ }
+
+ // Now that the permissions system has been reset, re-run the migration to reinitialise it.
+ a.DoAdvancedPermissionsMigration()
+
+ return nil
+}