mirror of
https://github.com/jech/galene.git
synced 2024-12-27 17:55:47 +01:00
Implement update-user.
This commit is contained in:
parent
b634e494fd
commit
31dc84d904
1 changed files with 47 additions and 0 deletions
|
@ -70,6 +70,10 @@ var commands = map[string]command{
|
|||
command: deleteUserCmd,
|
||||
description: "delete a user",
|
||||
},
|
||||
"update-user": {
|
||||
command: updateUserCmd,
|
||||
description: "change a user's permissions",
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -574,6 +578,49 @@ func createUserCmd(cmdname string, args []string) {
|
|||
}
|
||||
}
|
||||
|
||||
func updateUserCmd(cmdname string, args []string) {
|
||||
var groupname string
|
||||
var permissions string
|
||||
cmd := flag.NewFlagSet(cmdname, flag.ExitOnError)
|
||||
setUsage(cmd, cmdname,
|
||||
"%v [option...] %v [option...] username\n",
|
||||
os.Args[0], cmdname,
|
||||
)
|
||||
cmd.StringVar(&groupname, "group", "", "group `name`")
|
||||
cmd.StringVar(&permissions, "permissions", "", "permissions")
|
||||
cmd.Parse(args)
|
||||
|
||||
if cmd.NArg() != 1 {
|
||||
cmd.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if permissions == "" {
|
||||
log.Fatalf("Nothing to do!")
|
||||
}
|
||||
perms, err := parsePermissions(permissions)
|
||||
if err != nil {
|
||||
log.Fatalf("Parse permissions: %v", err)
|
||||
}
|
||||
|
||||
url, err := url.JoinPath(
|
||||
serverURL, "/galene-api/v0/.groups", groupname,
|
||||
".users", cmd.Args()[0],
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("Build URL: %v", err)
|
||||
}
|
||||
|
||||
err = updateJSON(url, func(m map[string]any) map[string]any {
|
||||
m["permissions"] = perms
|
||||
return m
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Create user: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func deleteUserCmd(cmdname string, args []string) {
|
||||
var groupname string
|
||||
cmd := flag.NewFlagSet(cmdname, flag.ExitOnError)
|
||||
|
|
Loading…
Reference in a new issue