From 11cbb597471127c1b29e78e6cad0a1a4d93ea24c Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Thu, 17 May 2018 12:40:40 -0700 Subject: Renaming platform binary to mattermost. (#8801) --- cmd/mattermost/commands/permissions.go | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 cmd/mattermost/commands/permissions.go (limited to 'cmd/mattermost/commands/permissions.go') diff --git a/cmd/mattermost/commands/permissions.go b/cmd/mattermost/commands/permissions.go new file mode 100644 index 000000000..52cae0ecb --- /dev/null +++ b/cmd/mattermost/commands/permissions.go @@ -0,0 +1,64 @@ +// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package commands + +import ( + "errors" + "fmt" + + "github.com/spf13/cobra" +) + +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, + ) + RootCmd.AddCommand(PermissionsCmd) +} + +func resetPermissionsCmdF(command *cobra.Command, args []string) error { + a, err := InitDBCommandContextCobra(command) + if err != nil { + return err + } + + confirmFlag, _ := command.Flags().GetBool("confirm") + if !confirmFlag { + var confirm string + 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.") + } + 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()) + } + + CommandPrettyPrintln("Permissions system successfully reset") + + return nil +} -- cgit v1.2.3-1-g7c22