User limit enforcement (#26511)
* Added hard limits when creating user * Added check to user activation * Added missing check for licensed servers * Fix i18n * Fixed style order * Added a separate hard limit along with existing 10k user soft limit * For CI * Fixing flaky test, hopefully * Added tests
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2c2dbba72c
Коммит
b02d634916
@@ -230,6 +230,15 @@ func (a *App) CreateGuest(c request.CTX, user *model.User) (*model.User, *model.
|
||||
}
|
||||
|
||||
func (a *App) createUserOrGuest(c request.CTX, user *model.User, guest bool) (*model.User, *model.AppError) {
|
||||
exceeded, limitErr := a.isHardUserLimitExceeded()
|
||||
if limitErr != nil {
|
||||
return nil, limitErr
|
||||
}
|
||||
|
||||
if exceeded {
|
||||
return nil, model.NewAppError("createUserOrGuest", "api.user.create_user.user_limits.exceeded", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if err := a.isUniqueToGroupNames(user.Username); err != nil {
|
||||
err.Where = "createUserOrGuest"
|
||||
return nil, err
|
||||
@@ -324,11 +333,11 @@ func (a *App) createUserOrGuest(c request.CTX, user *model.User, guest bool) (*m
|
||||
}(ruser.Id)
|
||||
}
|
||||
|
||||
userLimits, appErr := a.GetUserLimits()
|
||||
if appErr != nil {
|
||||
userLimits, limitErr := a.GetUserLimits()
|
||||
if limitErr != nil {
|
||||
// we don't want to break the create user flow just because of this.
|
||||
// So, we log the error, not return
|
||||
mlog.Error("Error fetching user limits in createUserOrGuest", mlog.Err(appErr))
|
||||
mlog.Error("Error fetching user limits in createUserOrGuest", mlog.Err(limitErr))
|
||||
} else {
|
||||
if userLimits.ActiveUserCount > userLimits.MaxUsersLimit {
|
||||
mlog.Warn("ERROR_SAFETY_LIMITS_EXCEEDED: Created user exceeds the total activated users limit.", mlog.Int("user_limit", userLimits.MaxUsersLimit))
|
||||
@@ -1003,6 +1012,17 @@ func (a *App) invalidateUserChannelMembersCaches(c request.CTX, userID string) *
|
||||
}
|
||||
|
||||
func (a *App) UpdateActive(c request.CTX, user *model.User, active bool) (*model.User, *model.AppError) {
|
||||
if active {
|
||||
exceeded, appErr := a.isHardUserLimitExceeded()
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
if exceeded {
|
||||
return nil, model.NewAppError("UpdateActive", "app.user.update_active.user_limit.exceeded", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
user.UpdateAt = model.GetMillis()
|
||||
if active {
|
||||
user.DeleteAt = 0
|
||||
|
||||
Ссылка в новой задаче
Block a user