* feat: Replace 5% grace period with configurable ExtraUsers field - Rename ExtraSeats to ExtraUsers in license Features struct - Remove fixed 5% grace period and minimum 1 extra user logic - Add configurable ExtraUsers field that allows exact control over additional seats - Update calculateGraceLimit() to use extraUsers parameter directly - When ExtraUsers is nil, defaults to 0 (hard cap with no overage) - Special case maintained: zero user licenses always return 0 grace limit - Update all tests to use new ExtraUsers functionality Closes #31628 Co-authored-by: Jesse Hallam <lieut-data@users.noreply.github.com> * feat: eliminate calculateGraceLimit function, use inline baseLimit + extraUsers - Remove calculateGraceLimit function and replace with inline calculation - Allow extraUsers even when baseLimit is 0 (behavioral change) - Update tests to reflect new behavior - Remove TestCalculateGraceLimit since function no longer exists Co-authored-by: Jesse Hallam <lieut-data@users.noreply.github.com> * feat: move ExtraUsers field to top level License struct Move ExtraUsers field from Features struct to the top level License struct for better organization and direct access. Update all references in limits.go and limits_test.go to use the new field location. Co-authored-by: Jesse Hallam <lieut-data@users.noreply.github.com> * feat: use model.NewPointer for creating integer pointers in tests Replace inline function declarations with model.NewPointer calls for cleaner code. Co-authored-by: Jesse Hallam <lieut-data@users.noreply.github.com> * feat: reorder ExtraUsers field to be after IsSeatCountEnforced Co-authored-by: Jesse Hallam <lieut-data@users.noreply.github.com> * fix: format Go files with gofmt - Remove extra blank line in limits.go - Align struct fields in limits_test.go table test Co-authored-by: Jesse Hallam <lieut-data@users.noreply.github.com> * Fix user limits tests and document ExtraUsers field - Fix TestCreateUserOrGuestSeatCountEnforcement to use ExtraUsers instead of old grace period - Add documentation to ExtraUsers field explaining it as a grace mechanism - Update test comments to reflect hard limit terminology 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Jesse Hallam <lieut-data@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
60 строки
1.7 KiB
Go
60 строки
1.7 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package app
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
)
|
|
|
|
const (
|
|
maxUsersLimit = 2_500
|
|
maxUsersHardLimit = 5_000
|
|
)
|
|
|
|
func (a *App) GetServerLimits() (*model.ServerLimits, *model.AppError) {
|
|
limits := &model.ServerLimits{}
|
|
license := a.License()
|
|
|
|
if license == nil && maxUsersLimit > 0 {
|
|
// Enforce hard-coded limits for unlicensed servers (no grace period).
|
|
limits.MaxUsersLimit = maxUsersLimit
|
|
limits.MaxUsersHardLimit = maxUsersHardLimit
|
|
} else if license != nil && license.IsSeatCountEnforced && license.Features != nil && license.Features.Users != nil {
|
|
// Enforce license limits as required by the license with configurable extra users.
|
|
licenseUserLimit := int64(*license.Features.Users)
|
|
limits.MaxUsersLimit = licenseUserLimit
|
|
|
|
// Use ExtraUsers if configured, otherwise default to 0 (no extra users)
|
|
extraUsers := 0
|
|
if license.ExtraUsers != nil {
|
|
extraUsers = *license.ExtraUsers
|
|
}
|
|
|
|
limits.MaxUsersHardLimit = licenseUserLimit + int64(extraUsers)
|
|
}
|
|
|
|
activeUserCount, appErr := a.Srv().Store().User().Count(model.UserCountOptions{})
|
|
if appErr != nil {
|
|
return nil, model.NewAppError("GetServerLimits", "app.limits.get_app_limits.user_count.store_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
|
|
}
|
|
limits.ActiveUserCount = activeUserCount
|
|
|
|
return limits, nil
|
|
}
|
|
|
|
func (a *App) isAtUserLimit() (bool, *model.AppError) {
|
|
userLimits, appErr := a.GetServerLimits()
|
|
if appErr != nil {
|
|
return false, appErr
|
|
}
|
|
|
|
if userLimits.MaxUsersHardLimit == 0 {
|
|
return false, nil
|
|
}
|
|
|
|
return userLimits.ActiveUserCount >= userLimits.MaxUsersHardLimit, appErr
|
|
}
|