Fix auto-promotion of the first user
This commit is contained in:
@@ -145,7 +145,7 @@ func (r *user) Find(filter *types.UserFilter) ([]*types.User, error) {
|
||||
|
||||
func (r user) Total() (count uint) {
|
||||
query := fmt.Sprintf("SELECT COUNT(*) FROM %s WHERE %s", r.users, sqlUserScope)
|
||||
_ = r.db().Select(&count, query)
|
||||
_ = r.db().Get(&count, query)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -816,13 +816,13 @@ func (svc auth) createUserToken(user *types.User, kind string) (token string, er
|
||||
func (svc auth) autoPromote(u *types.User) (err error) {
|
||||
if svc.users.Total() == 0 && u.ID > 0 {
|
||||
err = svc.roles.MemberAddByID(permissions.AdminRoleID, u.ID)
|
||||
}
|
||||
|
||||
svc.log(
|
||||
zap.String("email", u.Email),
|
||||
zap.Uint64("userID", u.ID),
|
||||
zap.Error(err),
|
||||
).Info("auto-promoted user to administrator role")
|
||||
svc.log(
|
||||
zap.String("email", u.Email),
|
||||
zap.Uint64("userID", u.ID),
|
||||
zap.Error(err),
|
||||
).Info("auto-promoted user to administrator role")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user