Fix auto-promotion of the first user

This commit is contained in:
Denis Arh
2019-06-19 19:20:03 +02:00
parent 1960fd7a51
commit 10f124a008
2 changed files with 7 additions and 7 deletions
+1 -1
View File
@@ -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
}
+6 -6
View File
@@ -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
}