summaryrefslogtreecommitdiffstats
path: root/cmd
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 /cmd
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 'cmd')
-rw-r--r--cmd/commands/permissions.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/cmd/commands/permissions.go b/cmd/commands/permissions.go
new file mode 100644
index 000000000..33c255a31
--- /dev/null
+++ b/cmd/commands/permissions.go
@@ -0,0 +1,66 @@
+// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package commands
+
+import (
+ "errors"
+ "fmt"
+
+ "github.com/spf13/cobra"
+
+ "github.com/mattermost/mattermost-server/cmd"
+)
+
+var PermissionsCmd = &cobra.Command{
+ Use: "permissions",
+ Short: "Management of the Permissions system",
+}
+
+var ResetPermissionsCmd = &cobra.Command{
+ Use: "reset",
+ Short: "Reset the permissions system to its default state",
+ Long: "Reset the permissions system to its default state",
+ Example: " permissions reset",
+ RunE: resetPermissionsCmdF,
+}
+
+func init() {
+ ResetPermissionsCmd.Flags().Bool("confirm", false, "Confirm you really want to reset the permissions system and a database backup has been performed.")
+
+ PermissionsCmd.AddCommand(
+ ResetPermissionsCmd,
+ )
+ cmd.RootCmd.AddCommand(PermissionsCmd)
+}
+
+func resetPermissionsCmdF(command *cobra.Command, args []string) error {
+ a, err := cmd.InitDBCommandContextCobra(command)
+ if err != nil {
+ return err
+ }
+
+ confirmFlag, _ := command.Flags().GetBool("confirm")
+ if !confirmFlag {
+ var confirm string
+ cmd.CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
+ fmt.Scanln(&confirm)
+
+ if confirm != "YES" {
+ return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
+ }
+ cmd.CommandPrettyPrintln("Are you sure you want to reset the permissions system? All data related to the permissions system will be permanently deleted and all users will revert to having the default permissions. (YES/NO): ")
+ fmt.Scanln(&confirm)
+ if confirm != "YES" {
+ return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
+ }
+ }
+
+ if err := a.ResetPermissionsSystem(); err != nil {
+ return errors.New(err.Error())
+ }
+
+ cmd.CommandPrettyPrintln("Permissions system successfully reset")
+
+ return nil
+}