Replace db count query in user signup process (#18072)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d3973557fc
Коммит
bd65e8daf9
@@ -10,6 +10,7 @@ var (
|
||||
VerifyUserError = errors.New("could not update verify email field")
|
||||
UserCountError = errors.New("could not get the total number of the users.")
|
||||
UserCreationDisabledError = errors.New("user creation is not allowed")
|
||||
UserStoreIsEmptyError = errors.New("could not check if the user store is empty")
|
||||
|
||||
GetTokenError = errors.New("could not get token")
|
||||
GetSessionError = errors.New("could not get session")
|
||||
|
||||
@@ -13,6 +13,8 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mfa"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
"github.com/mattermost/mattermost-server/v6/store"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type UserCreateOptions struct {
|
||||
@@ -41,11 +43,9 @@ func (us *UserService) CreateUser(user *model.User, opts UserCreateOptions) (*mo
|
||||
|
||||
// Below is a special case where the first user in the entire
|
||||
// system is granted the system_admin role
|
||||
count, err := us.store.Count(model.UserCountOptions{IncludeDeleted: true})
|
||||
if err != nil {
|
||||
return nil, UserCountError
|
||||
}
|
||||
if count <= 0 {
|
||||
if ok, err := us.store.IsEmpty(); err != nil {
|
||||
return nil, errors.Wrap(UserStoreIsEmptyError, err.Error())
|
||||
} else if ok {
|
||||
user.Roles = model.SystemAdminRoleId + " " + model.SystemUserRoleId
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user