mirror of
https://github.com/thomiceli/opengist.git
synced 2024-12-22 20:42:40 +00:00
Add/Remove admins (#337)
This commit is contained in:
parent
fa8217e27f
commit
605c8b892a
2 changed files with 39 additions and 0 deletions
11
docs/administration/manage-admins.md
Normal file
11
docs/administration/manage-admins.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Manage admins
|
||||||
|
|
||||||
|
You can add and remove Opengist admins from the CLI.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./opengist admin toggle-admin <username>
|
||||||
|
```
|
||||||
|
```bash
|
||||||
|
$ ./opengist admin toggle-admin thomas
|
||||||
|
User thomas admin set to true
|
||||||
|
```
|
|
@ -12,6 +12,7 @@ var CmdAdmin = cli.Command{
|
||||||
Usage: "Admin commands",
|
Usage: "Admin commands",
|
||||||
Subcommands: []*cli.Command{
|
Subcommands: []*cli.Command{
|
||||||
&CmdAdminResetPassword,
|
&CmdAdminResetPassword,
|
||||||
|
&CmdAdminToggleAdmin,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,3 +49,30 @@ var CmdAdminResetPassword = cli.Command{
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var CmdAdminToggleAdmin = cli.Command{
|
||||||
|
Name: "toggle-admin",
|
||||||
|
Usage: "Toggle the admin status for a given user",
|
||||||
|
ArgsUsage: "[username]",
|
||||||
|
Action: func(ctx *cli.Context) error {
|
||||||
|
initialize(ctx)
|
||||||
|
if ctx.NArg() < 1 {
|
||||||
|
return fmt.Errorf("username is required")
|
||||||
|
}
|
||||||
|
username := ctx.Args().Get(0)
|
||||||
|
|
||||||
|
user, err := db.GetUserByUsername(username)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Cannot get user %s: %s\n", username, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
user.IsAdmin = !user.IsAdmin
|
||||||
|
if err = user.Update(); err != nil {
|
||||||
|
fmt.Printf("Cannot update user %s: %s\n", username, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("User %s admin set to %t\n", username, user.IsAdmin)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue