[MM-44475] Team Unarchive: Do not allow to unarchive if workspace has reached the limit of teams (#20281)

* Prevent cloud limited installations from restoring teams when at or above the teams limit

* Code clean up

* fix i18n

* Actually fix i18n

* updates for govet

* Update model/client4.go

Co-authored-by: Vishal <vish9812@gmail.com>

* [MM-44397] Restrict team creation based on subscription limits (#20282)

* restrict team creation based on limits

* Update api4/team.go

Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>

* Fix tests

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>

* Add additional field to teamsusage

* Fix

* remove useless test

* Fix error for team creation

* Remove apostrophe

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Vishal <vish9812@gmail.com>
Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>
Этот коммит содержится в:
Nick Misasi
2022-05-31 15:06:54 -04:00
коммит произвёл GitHub
родитель 287edba57a
Коммит cffe921e62
10 изменённых файлов: 299 добавлений и 16 удалений

Просмотреть файл

@@ -95,6 +95,29 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
// Freemium enabled, on a cloud license. We must check limits before allowing to create
if c.App.Config().FeatureFlags != nil && c.App.Config().FeatureFlags.CloudFree && (c.App.Channels().License() != nil && c.App.Channels().License().Features != nil && *c.App.Channels().License().Features.Cloud) {
limits, err := c.App.Cloud().GetCloudLimits(c.AppContext.Session().UserId)
if err != nil {
c.Err = model.NewAppError("Api4.createTeam", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
return
}
// If there are no limits for teams, for active teams, or the limit for active teams is less than 0, do nothing
if !(limits == nil || limits.Teams == nil || limits.Teams.Active == nil || *limits.Teams.Active <= 0) {
teamsUsage, appErr := c.App.GetTeamsUsage()
if appErr != nil {
c.Err = appErr
return
}
// if the number of active teams is greater than or equal to the limit, return 400
if teamsUsage.Active >= int64(*limits.Teams.Active) {
c.Err = model.NewAppError("Api4.createTeam", "api.cloud.teams_limit_reached.create", nil, "", http.StatusBadRequest)
return
}
}
}
rteam, err := c.App.CreateTeamWithUser(c.AppContext, &team, c.AppContext.Session().UserId)
if err != nil {
c.Err = err
@@ -258,6 +281,28 @@ func restoreTeam(c *Context, w http.ResponseWriter, r *http.Request) {
c.SetPermissionError(model.PermissionManageTeam)
return
}
// Freemium enabled, on a cloud license. We must check limits before allowing to restore
if c.App.Config().FeatureFlags != nil && c.App.Config().FeatureFlags.CloudFree && (c.App.Channels().License() != nil && c.App.Channels().License().Features != nil && *c.App.Channels().License().Features.Cloud) {
limits, err := c.App.Cloud().GetCloudLimits(c.AppContext.Session().UserId)
if err != nil {
c.Err = model.NewAppError("Api4.restoreTeam", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
return
}
// If there are no limits for teams, for active teams, or the limit for active teams is less than 0, do nothing
if !(limits == nil || limits.Teams == nil || limits.Teams.Active == nil || *limits.Teams.Active <= 0) {
teamsUsage, appErr := c.App.GetTeamsUsage()
if appErr != nil {
c.Err = appErr
return
}
// if the number of active teams is greater than or equal to the limit, return 400
if teamsUsage.Active >= int64(*limits.Teams.Active) {
c.Err = model.NewAppError("Api4.restoreTeam", "api.cloud.teams_limit_reached.restore", nil, "", http.StatusBadRequest)
return
}
}
}
err := c.App.RestoreTeam(c.Params.TeamId)
if err != nil {