[MM-36198] - Activating a user in System Console does not respect cloud user limits (#17719)
* [MM-36198] - Activating a user in System Console does not respect cloud user limits * feedback impl * improve error check
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a2700684f1
Коммит
5ce5ea93f4
46
app/cloud.go
46
app/cloud.go
@@ -79,6 +79,52 @@ func (a *App) SendAdminUpgradeRequestEmail(username string, subscription *model.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) GetSubscriptionStats() (*model.SubscriptionStats, *model.AppError) {
|
||||
if a.Srv().License() == nil || !*a.Srv().License().Features.Cloud {
|
||||
return nil, model.NewAppError("app.GetSubscriptionStats", "api.cloud.license_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
subscription, appErr := a.Cloud().GetSubscription("")
|
||||
if appErr != nil {
|
||||
return nil, model.NewAppError("app.GetSubscriptionStats", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
count, err := a.Srv().Store.User().Count(model.UserCountOptions{})
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("app.GetSubscriptionStats", "app.user.get_total_users_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
cloudUserLimit := *a.Config().ExperimentalSettings.CloudUserLimit
|
||||
|
||||
s := cloudUserLimit - count
|
||||
|
||||
return &model.SubscriptionStats{
|
||||
RemainingSeats: int(s),
|
||||
IsPaidTier: subscription.IsPaidTier,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *App) CheckCloudAccountAtLimit() (bool, *model.AppError) {
|
||||
if a.Srv().License() == nil || (a.Srv().License() != nil && !*a.Srv().License().Features.Cloud) {
|
||||
// Not cloud instance, so no at limit checks
|
||||
return false, nil
|
||||
}
|
||||
|
||||
stats, err := a.GetSubscriptionStats()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if stats.IsPaidTier == "true" {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if stats.RemainingSeats < 1 {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (a *App) CheckAndSendUserLimitWarningEmails(c *request.Context) *model.AppError {
|
||||
if a.Srv().License() == nil || (a.Srv().License() != nil && !*a.Srv().License().Features.Cloud) {
|
||||
// Not cloud instance, do nothing
|
||||
|
||||
Ссылка в новой задаче
Block a user