diff --git a/server/channels/app/user.go b/server/channels/app/user.go index 9201e49de0..986de0bcbd 100644 --- a/server/channels/app/user.go +++ b/server/channels/app/user.go @@ -318,6 +318,17 @@ func (a *App) createUserOrGuest(c request.CTX, user *model.User, guest bool) (*m }(ruser.Id) } + userLimits, appErr := a.GetUserLimits() + if appErr != 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)) + } else { + if userLimits.ActiveUserCount > userLimits.MaxUsersLimit { + mlog.Warn("ERROR_USER_LIMITS_EXCEEDED: Created user exceeds the total activated users limit.", mlog.Int("user_limit", userLimits.MaxUsersLimit)) + } + } + return ruser, nil } @@ -1013,6 +1024,17 @@ func (a *App) UpdateActive(c request.CTX, user *model.User, active bool) (*model }) } + if active { + userLimits, appErr := a.GetUserLimits() + if appErr != nil { + mlog.Error("Error fetching user limits in UpdateActive", mlog.Err(appErr)) + } else { + if userLimits.ActiveUserCount > userLimits.MaxUsersLimit { + mlog.Warn("ERROR_USER_LIMITS_EXCEEDED: Activated user exceeds the total active user limit.", mlog.Int("user_limit", userLimits.MaxUsersLimit)) + } + } + } + return ruser, nil }