Skip to content

Commit

Permalink
cmd/hanyuu: fix add-user not checking for user existence correctly
Browse files Browse the repository at this point in the history
also made users created through this command get DEV permission instead
of ADMIN permission since it gives more access.
  • Loading branch information
Wessie committed Dec 20, 2024
1 parent dd312a6 commit c7419e1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions cmd/hanyuu/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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{}{},
},
}

Expand All @@ -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
}

0 comments on commit c7419e1

Please sign in to comment.