[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
@@ -113,31 +113,13 @@ func changeSubscription(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getSubscriptionStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if c.App.Srv().License() == nil || !*c.App.Srv().License().Features.Cloud {
|
||||
c.Err = model.NewAppError("Api4.getSubscriptionStats", "api.cloud.license_error", nil, "", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
subscription, appErr := c.App.Cloud().GetSubscription("")
|
||||
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getSubscriptionStats", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
count, err := c.App.Srv().Store.User().Count(model.UserCountOptions{})
|
||||
s, err := c.App.GetSubscriptionStats()
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getSubscriptionStats", "app.user.get_total_users_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
cloudUserLimit := *c.App.Config().ExperimentalSettings.CloudUserLimit
|
||||
|
||||
s := cloudUserLimit - count
|
||||
|
||||
stats, _ := json.Marshal(model.SubscriptionStats{
|
||||
RemainingSeats: int(s),
|
||||
IsPaidTier: subscription.IsPaidTier,
|
||||
})
|
||||
stats, _ := json.Marshal(s)
|
||||
|
||||
w.Write([]byte(string(stats)))
|
||||
}
|
||||
|
||||
12
api4/user.go
12
api4/user.go
@@ -1377,6 +1377,18 @@ func updateUserActive(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// if non cloud instances, isOverLimit is false and no error
|
||||
isAtLimit, err := c.App.CheckCloudAccountAtLimit()
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("updateUserActive", "api.user.update_active.cloud_at_limit_check_error", nil, "userId="+c.Params.UserId, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if active && isAtLimit {
|
||||
c.Err = model.NewAppError("updateUserActive", "api.user.update_active.cloud_at_or_over_limit_check_overcapacity", nil, "userId="+c.Params.UserId, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = c.App.UpdateActive(c.AppContext, user, active); err != nil {
|
||||
c.Err = err
|
||||
}
|
||||
|
||||
@@ -2104,6 +2104,48 @@ func assertWebsocketEventUserUpdatedWithEmail(t *testing.T, client *model.WebSoc
|
||||
}
|
||||
|
||||
func TestUpdateUserActive(t *testing.T) {
|
||||
t.Run("not activating more users when cloud license users at limit", func(t *testing.T) {
|
||||
// create 5 active users
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
cloudMock := &mocks.CloudInterface{}
|
||||
cloudMock.Mock.On(
|
||||
"GetSubscription", mock.Anything,
|
||||
).Return(&model.Subscription{
|
||||
ID: "MySubscriptionID",
|
||||
CustomerID: "MyCustomer",
|
||||
ProductID: "SomeProductId",
|
||||
AddOns: []string{},
|
||||
StartAt: 1000000000,
|
||||
EndAt: 2000000000,
|
||||
CreateAt: 1000000000,
|
||||
Seats: 100,
|
||||
DNS: "some.dns.server",
|
||||
IsPaidTier: "false",
|
||||
}, nil)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
th.App.Srv().Cloud = cloudMock
|
||||
|
||||
user := th.BasicUser
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.TeamSettings.EnableUserDeactivation = true
|
||||
*cfg.ExperimentalSettings.CloudUserLimit = 4
|
||||
})
|
||||
|
||||
// deactivate 5th user, now we have 4 active users and are at limit
|
||||
pass, resp := th.SystemAdminClient.UpdateUserActive(user.Id, false)
|
||||
CheckNoError(t, resp)
|
||||
require.True(t, pass)
|
||||
|
||||
// try and reactivate 5th user, not allowed because it exceeds the set cloud user limit
|
||||
pass, resp = th.SystemAdminClient.UpdateUserActive(user.Id, true)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
require.False(t, pass)
|
||||
require.Equal(t, resp.Error.Message, "Unable to activate more users as the cloud account is over capacity.")
|
||||
})
|
||||
t.Run("basic tests", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user