From c7419e10ed8a31ec02dbbef7c0c5799725035a94 Mon Sep 17 00:00:00 2001 From: Wessie Date: Fri, 20 Dec 2024 20:28:22 +0100 Subject: [PATCH] cmd/hanyuu: fix add-user not checking for user existence correctly also made users created through this command get DEV permission instead of ADMIN permission since it gives more access. --- cmd/hanyuu/database.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/hanyuu/database.go b/cmd/hanyuu/database.go index e02da97..bbf7623 100644 --- a/cmd/hanyuu/database.go +++ b/cmd/hanyuu/database.go @@ -169,10 +169,11 @@ func (d databaseCmd) addUser(ctx context.Context, cfg config.Config) error { u := db.User(ctx) // only allow adding a user this way if it doesn't exist yet - _, err = u.Get(name) - if err != nil && !errors.Is(errors.UserUnknown, err) { - fmt.Println("user already exists") - return err + if user, err := u.Get(name); user != nil { + if err != nil { + return errors.E(err, "failed to check for existing user") + } + return errors.E("user already exists") } hash, err := radio.GenerateHashFromPassword(passwd) @@ -184,7 +185,7 @@ func (d databaseCmd) addUser(ctx context.Context, cfg config.Config) error { Password: string(hash), UserPermissions: radio.UserPermissions{ radio.PermActive: struct{}{}, - radio.PermAdmin: struct{}{}, + radio.PermDev: struct{}{}, }, } @@ -193,6 +194,6 @@ func (d databaseCmd) addUser(ctx context.Context, cfg config.Config) error { return err } - fmt.Println("successfully added user") + fmt.Printf("successfully added user %s\n", name) return nil }