mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
* 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
* 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
* 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.
* feat: use model.NewPointer for creating integer pointers in tests
Replace inline function declarations with model.NewPointer calls for cleaner code.
* feat: reorder ExtraUsers field to be after IsSeatCountEnforced
* 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 <[email protected]>
* 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
---------
(cherry picked from commit 221c5dd2c6)
Co-authored-by: Jesse Hallam <[email protected]>
Co-authored-by: Jesse Hallam <[email protected]>
Co-authored-by: Hanzo Dev <[email protected]>
60 lines
1.7 KiB
Go
60 lines
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
|
|
}
|