summaryrefslogtreecommitdiffstats
path: root/cmd/mattermost/commands/roles.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-05-17 12:40:40 -0700
committerGitHub <noreply@github.com>2018-05-17 12:40:40 -0700
commit11cbb597471127c1b29e78e6cad0a1a4d93ea24c (patch)
tree0eceb950872c7234348f0b41d4492073908840d0 /cmd/mattermost/commands/roles.go
parent1f6c271b3bedd6656ae7155714423b1b39a669c1 (diff)
downloadchat-11cbb597471127c1b29e78e6cad0a1a4d93ea24c.tar.gz
chat-11cbb597471127c1b29e78e6cad0a1a4d93ea24c.tar.bz2
chat-11cbb597471127c1b29e78e6cad0a1a4d93ea24c.zip
Renaming platform binary to mattermost. (#8801)
Diffstat (limited to 'cmd/mattermost/commands/roles.go')
-rw-r--r--cmd/mattermost/commands/roles.go89
1 files changed, 89 insertions, 0 deletions
diff --git a/cmd/mattermost/commands/roles.go b/cmd/mattermost/commands/roles.go
new file mode 100644
index 000000000..b8fdcdba2
--- /dev/null
+++ b/cmd/mattermost/commands/roles.go
@@ -0,0 +1,89 @@
+// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package commands
+
+import (
+ "errors"
+
+ "github.com/spf13/cobra"
+)
+
+var RolesCmd = &cobra.Command{
+ Use: "roles",
+ Short: "Management of user roles",
+}
+
+var MakeSystemAdminCmd = &cobra.Command{
+ Use: "system_admin [users]",
+ Short: "Set a user as system admin",
+ Long: "Make some users system admins",
+ Example: " roles system_admin user1",
+ RunE: makeSystemAdminCmdF,
+}
+
+var MakeMemberCmd = &cobra.Command{
+ Use: "member [users]",
+ Short: "Remove system admin privileges",
+ Long: "Remove system admin privileges from some users.",
+ Example: " roles member user1",
+ RunE: makeMemberCmdF,
+}
+
+func init() {
+ RolesCmd.AddCommand(
+ MakeSystemAdminCmd,
+ MakeMemberCmd,
+ )
+ RootCmd.AddCommand(RolesCmd)
+}
+
+func makeSystemAdminCmdF(command *cobra.Command, args []string) error {
+ a, err := InitDBCommandContextCobra(command)
+ if err != nil {
+ return err
+ }
+ defer a.Shutdown()
+
+ if len(args) < 1 {
+ return errors.New("Enter at least one user.")
+ }
+
+ users := getUsersFromUserArgs(a, args)
+ for i, user := range users {
+ if user == nil {
+ return errors.New("Unable to find user '" + args[i] + "'")
+ }
+
+ if _, err := a.UpdateUserRoles(user.Id, "system_admin system_user", true); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+func makeMemberCmdF(command *cobra.Command, args []string) error {
+ a, err := InitDBCommandContextCobra(command)
+ if err != nil {
+ return err
+ }
+ defer a.Shutdown()
+
+ if len(args) < 1 {
+ return errors.New("Enter at least one user.")
+ }
+
+ users := getUsersFromUserArgs(a, args)
+ for i, user := range users {
+ if user == nil {
+ return errors.New("Unable to find user '" + args[i] + "'")
+ }
+
+ if _, err := a.UpdateUserRoles(user.Id, "system_user", true); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}