mattermost/server/channels/app/limits.go

113 lines
3.4 KiB
Go
Raw Permalink Normal View History

// 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 = 200
maxUsersHardLimit = 250
)
enforce License.IsSeatCountEnforced if set (#31354) * enforce License.IsSeatCountEnforced if set If a license sets `IsSeatCountEnforced`, enforce the user limit therein as a hard cap. Fixes: https://mattermost.atlassian.net/browse/CLD-9260 * remove duplicate tests * Improve user limit error messages and display - Add separate error messages for licensed vs unlicensed servers - Licensed servers: "Server exceeds maximum licensed users. ERROR_LICENSED_USERS_LIMITS" - Unlicensed servers: "Server exceeds safe user limit. ERROR_SAFETY_LIMITS_EXCEEDED" - Remove redundant "Contact administrator" text from activation errors shown to admins - Fix system console to display actual server error messages instead of generic "Failed to activate user" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add license nil check and test coverage - Add license != nil check in GetServerLimits to prevent panic - Add test case to verify graceful handling of license being set to nil - Ensures fallback to hard-coded limits when license becomes nil Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix user limits tests to expect license-specific error IDs Update test expectations to use the new license-specific error IDs: - app.user.update_active.license_user_limit.exceeded for licensed server user activation - api.user.create_user.license_user_limits.exceeded for licensed server user creation Also update frontend to show actual server error messages instead of generic ones in system console. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove redundant license nil test The test couldn't meaningfully verify nil license behavior since it relied on hard-coded constants that can't be modified in the test. Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix whitespace issue in limits_test.go Remove unnecessary trailing newline to pass style checks. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * updated i18n * s/ERROR_LICENSED_USERS_LIMITS/ERROR_LICENSED_USERS_LIMIT_EXCEEDED/, expand warning log * Add 5% grace period for licensed user limits - Add calculateGraceLimit() function with 5% or +1 minimum grace - Apply grace period only to licensed servers with seat count enforcement - Handle zero user licenses by returning zero grace limit - Add comprehensive test coverage for grace period scenarios - Unlicensed servers maintain existing hard-coded limits without grace 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestCreateUserOrGuestSeatCountEnforcement to account for 5% grace period The test was failing because it expected user creation to fail at exactly the license limit, but the implementation now includes a 5% grace period before enforcement kicks in. Changes: - Update test cases to create users up to the grace limit (6 for a 5-user license) - Add comments explaining the grace period calculation - Both regular user and guest user creation tests now properly validate enforcement at the grace limit rather than the base license limit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestUpdateActiveWithUserLimits to account for 5% grace period Update test expectations to match the new grace period behavior: - At base limit (100) but below grace limit (105): should succeed - At grace limit (105): should fail - Above grace limit (106): should fail This aligns the tests with the license enforcement implementation that includes a 5% grace period above the licensed user count. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> Co-authored-by: Mattermost Build <build@mattermost.com>
2025-06-13 16:12:05 -04:00
func (a *App) GetServerLimits() (*model.ServerLimits, *model.AppError) {
limits := &model.ServerLimits{}
license := a.License()
enforce License.IsSeatCountEnforced if set (#31354) * enforce License.IsSeatCountEnforced if set If a license sets `IsSeatCountEnforced`, enforce the user limit therein as a hard cap. Fixes: https://mattermost.atlassian.net/browse/CLD-9260 * remove duplicate tests * Improve user limit error messages and display - Add separate error messages for licensed vs unlicensed servers - Licensed servers: "Server exceeds maximum licensed users. ERROR_LICENSED_USERS_LIMITS" - Unlicensed servers: "Server exceeds safe user limit. ERROR_SAFETY_LIMITS_EXCEEDED" - Remove redundant "Contact administrator" text from activation errors shown to admins - Fix system console to display actual server error messages instead of generic "Failed to activate user" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add license nil check and test coverage - Add license != nil check in GetServerLimits to prevent panic - Add test case to verify graceful handling of license being set to nil - Ensures fallback to hard-coded limits when license becomes nil Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix user limits tests to expect license-specific error IDs Update test expectations to use the new license-specific error IDs: - app.user.update_active.license_user_limit.exceeded for licensed server user activation - api.user.create_user.license_user_limits.exceeded for licensed server user creation Also update frontend to show actual server error messages instead of generic ones in system console. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove redundant license nil test The test couldn't meaningfully verify nil license behavior since it relied on hard-coded constants that can't be modified in the test. Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix whitespace issue in limits_test.go Remove unnecessary trailing newline to pass style checks. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * updated i18n * s/ERROR_LICENSED_USERS_LIMITS/ERROR_LICENSED_USERS_LIMIT_EXCEEDED/, expand warning log * Add 5% grace period for licensed user limits - Add calculateGraceLimit() function with 5% or +1 minimum grace - Apply grace period only to licensed servers with seat count enforcement - Handle zero user licenses by returning zero grace limit - Add comprehensive test coverage for grace period scenarios - Unlicensed servers maintain existing hard-coded limits without grace 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestCreateUserOrGuestSeatCountEnforcement to account for 5% grace period The test was failing because it expected user creation to fail at exactly the license limit, but the implementation now includes a 5% grace period before enforcement kicks in. Changes: - Update test cases to create users up to the grace limit (6 for a 5-user license) - Add comments explaining the grace period calculation - Both regular user and guest user creation tests now properly validate enforcement at the grace limit rather than the base license limit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestUpdateActiveWithUserLimits to account for 5% grace period Update test expectations to match the new grace period behavior: - At base limit (100) but below grace limit (105): should succeed - At grace limit (105): should fail - Above grace limit (106): should fail This aligns the tests with the license enforcement implementation that includes a 5% grace period above the licensed user count. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> Co-authored-by: Mattermost Build <build@mattermost.com>
2025-06-13 16:12:05 -04:00
if license == nil && maxUsersLimit > 0 {
// Enforce hard-coded limits for unlicensed servers (no grace period).
limits.MaxUsersLimit = maxUsersLimit
limits.MaxUsersHardLimit = maxUsersHardLimit
enforce License.IsSeatCountEnforced if set (#31354) * enforce License.IsSeatCountEnforced if set If a license sets `IsSeatCountEnforced`, enforce the user limit therein as a hard cap. Fixes: https://mattermost.atlassian.net/browse/CLD-9260 * remove duplicate tests * Improve user limit error messages and display - Add separate error messages for licensed vs unlicensed servers - Licensed servers: "Server exceeds maximum licensed users. ERROR_LICENSED_USERS_LIMITS" - Unlicensed servers: "Server exceeds safe user limit. ERROR_SAFETY_LIMITS_EXCEEDED" - Remove redundant "Contact administrator" text from activation errors shown to admins - Fix system console to display actual server error messages instead of generic "Failed to activate user" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add license nil check and test coverage - Add license != nil check in GetServerLimits to prevent panic - Add test case to verify graceful handling of license being set to nil - Ensures fallback to hard-coded limits when license becomes nil Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix user limits tests to expect license-specific error IDs Update test expectations to use the new license-specific error IDs: - app.user.update_active.license_user_limit.exceeded for licensed server user activation - api.user.create_user.license_user_limits.exceeded for licensed server user creation Also update frontend to show actual server error messages instead of generic ones in system console. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove redundant license nil test The test couldn't meaningfully verify nil license behavior since it relied on hard-coded constants that can't be modified in the test. Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix whitespace issue in limits_test.go Remove unnecessary trailing newline to pass style checks. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * updated i18n * s/ERROR_LICENSED_USERS_LIMITS/ERROR_LICENSED_USERS_LIMIT_EXCEEDED/, expand warning log * Add 5% grace period for licensed user limits - Add calculateGraceLimit() function with 5% or +1 minimum grace - Apply grace period only to licensed servers with seat count enforcement - Handle zero user licenses by returning zero grace limit - Add comprehensive test coverage for grace period scenarios - Unlicensed servers maintain existing hard-coded limits without grace 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestCreateUserOrGuestSeatCountEnforcement to account for 5% grace period The test was failing because it expected user creation to fail at exactly the license limit, but the implementation now includes a 5% grace period before enforcement kicks in. Changes: - Update test cases to create users up to the grace limit (6 for a 5-user license) - Add comments explaining the grace period calculation - Both regular user and guest user creation tests now properly validate enforcement at the grace limit rather than the base license limit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestUpdateActiveWithUserLimits to account for 5% grace period Update test expectations to match the new grace period behavior: - At base limit (100) but below grace limit (105): should succeed - At grace limit (105): should fail - Above grace limit (106): should fail This aligns the tests with the license enforcement implementation that includes a 5% grace period above the licensed user count. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> Co-authored-by: Mattermost Build <build@mattermost.com>
2025-06-13 16:12:05 -04:00
} else if license != nil && license.IsSeatCountEnforced && license.Features != nil && license.Features.Users != nil {
feat: Replace 5% grace period with configurable ExtraUsers field (#31629) * 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 &lt;lieut-data@users.noreply.github.com&gt; * 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>
2025-06-17 15:56:52 -04:00
// Enforce license limits as required by the license with configurable extra users.
enforce License.IsSeatCountEnforced if set (#31354) * enforce License.IsSeatCountEnforced if set If a license sets `IsSeatCountEnforced`, enforce the user limit therein as a hard cap. Fixes: https://mattermost.atlassian.net/browse/CLD-9260 * remove duplicate tests * Improve user limit error messages and display - Add separate error messages for licensed vs unlicensed servers - Licensed servers: "Server exceeds maximum licensed users. ERROR_LICENSED_USERS_LIMITS" - Unlicensed servers: "Server exceeds safe user limit. ERROR_SAFETY_LIMITS_EXCEEDED" - Remove redundant "Contact administrator" text from activation errors shown to admins - Fix system console to display actual server error messages instead of generic "Failed to activate user" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add license nil check and test coverage - Add license != nil check in GetServerLimits to prevent panic - Add test case to verify graceful handling of license being set to nil - Ensures fallback to hard-coded limits when license becomes nil Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix user limits tests to expect license-specific error IDs Update test expectations to use the new license-specific error IDs: - app.user.update_active.license_user_limit.exceeded for licensed server user activation - api.user.create_user.license_user_limits.exceeded for licensed server user creation Also update frontend to show actual server error messages instead of generic ones in system console. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove redundant license nil test The test couldn't meaningfully verify nil license behavior since it relied on hard-coded constants that can't be modified in the test. Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix whitespace issue in limits_test.go Remove unnecessary trailing newline to pass style checks. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * updated i18n * s/ERROR_LICENSED_USERS_LIMITS/ERROR_LICENSED_USERS_LIMIT_EXCEEDED/, expand warning log * Add 5% grace period for licensed user limits - Add calculateGraceLimit() function with 5% or +1 minimum grace - Apply grace period only to licensed servers with seat count enforcement - Handle zero user licenses by returning zero grace limit - Add comprehensive test coverage for grace period scenarios - Unlicensed servers maintain existing hard-coded limits without grace 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestCreateUserOrGuestSeatCountEnforcement to account for 5% grace period The test was failing because it expected user creation to fail at exactly the license limit, but the implementation now includes a 5% grace period before enforcement kicks in. Changes: - Update test cases to create users up to the grace limit (6 for a 5-user license) - Add comments explaining the grace period calculation - Both regular user and guest user creation tests now properly validate enforcement at the grace limit rather than the base license limit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestUpdateActiveWithUserLimits to account for 5% grace period Update test expectations to match the new grace period behavior: - At base limit (100) but below grace limit (105): should succeed - At grace limit (105): should fail - Above grace limit (106): should fail This aligns the tests with the license enforcement implementation that includes a 5% grace period above the licensed user count. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> Co-authored-by: Mattermost Build <build@mattermost.com>
2025-06-13 16:12:05 -04:00
licenseUserLimit := int64(*license.Features.Users)
limits.MaxUsersLimit = licenseUserLimit
feat: Replace 5% grace period with configurable ExtraUsers field (#31629) * 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 &lt;lieut-data@users.noreply.github.com&gt; * 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>
2025-06-17 15:56:52 -04:00
// 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)
}
// Check if license has post history limits and get the calculated timestamp
if license != nil && license.Limits != nil && license.Limits.PostHistory > 0 {
limits.PostHistoryLimit = license.Limits.PostHistory
// Get the calculated timestamp of the last accessible post
lastAccessibleTime, appErr := a.GetLastAccessiblePostTime()
if appErr != nil {
return nil, appErr
}
limits.LastAccessiblePostTime = lastAccessibleTime
}
enforce License.IsSeatCountEnforced if set (#31354) * enforce License.IsSeatCountEnforced if set If a license sets `IsSeatCountEnforced`, enforce the user limit therein as a hard cap. Fixes: https://mattermost.atlassian.net/browse/CLD-9260 * remove duplicate tests * Improve user limit error messages and display - Add separate error messages for licensed vs unlicensed servers - Licensed servers: "Server exceeds maximum licensed users. ERROR_LICENSED_USERS_LIMITS" - Unlicensed servers: "Server exceeds safe user limit. ERROR_SAFETY_LIMITS_EXCEEDED" - Remove redundant "Contact administrator" text from activation errors shown to admins - Fix system console to display actual server error messages instead of generic "Failed to activate user" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add license nil check and test coverage - Add license != nil check in GetServerLimits to prevent panic - Add test case to verify graceful handling of license being set to nil - Ensures fallback to hard-coded limits when license becomes nil Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix user limits tests to expect license-specific error IDs Update test expectations to use the new license-specific error IDs: - app.user.update_active.license_user_limit.exceeded for licensed server user activation - api.user.create_user.license_user_limits.exceeded for licensed server user creation Also update frontend to show actual server error messages instead of generic ones in system console. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove redundant license nil test The test couldn't meaningfully verify nil license behavior since it relied on hard-coded constants that can't be modified in the test. Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix whitespace issue in limits_test.go Remove unnecessary trailing newline to pass style checks. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * updated i18n * s/ERROR_LICENSED_USERS_LIMITS/ERROR_LICENSED_USERS_LIMIT_EXCEEDED/, expand warning log * Add 5% grace period for licensed user limits - Add calculateGraceLimit() function with 5% or +1 minimum grace - Apply grace period only to licensed servers with seat count enforcement - Handle zero user licenses by returning zero grace limit - Add comprehensive test coverage for grace period scenarios - Unlicensed servers maintain existing hard-coded limits without grace 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestCreateUserOrGuestSeatCountEnforcement to account for 5% grace period The test was failing because it expected user creation to fail at exactly the license limit, but the implementation now includes a 5% grace period before enforcement kicks in. Changes: - Update test cases to create users up to the grace limit (6 for a 5-user license) - Add comments explaining the grace period calculation - Both regular user and guest user creation tests now properly validate enforcement at the grace limit rather than the base license limit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestUpdateActiveWithUserLimits to account for 5% grace period Update test expectations to match the new grace period behavior: - At base limit (100) but below grace limit (105): should succeed - At grace limit (105): should fail - Above grace limit (106): should fail This aligns the tests with the license enforcement implementation that includes a 5% grace period above the licensed user count. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> Co-authored-by: Mattermost Build <build@mattermost.com>
2025-06-13 16:12:05 -04:00
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)
}
Add single-channel guest tracking and reporting (#35451) * Add single-channel guest tracking and reporting - Add AnalyticsGetSingleChannelGuestCount store method to count guests in exactly one channel - Exclude single-channel guests from active user seat count in GetServerLimits - Add single-channel guest count to standard analytics response - Add Single-channel Guests card to System Statistics page with overage warning - Add Single-channel guests row to Edition and License page with overage styling - Add dismissible admin-only banner when single-channel guest limit is exceeded - Gate feature behind non-Entry SKU and guest accounts enabled checks - Re-fetch server limits on config changes for reactive UI updates - Fix label alignment in license details panel Made-with: Cursor * Refine single-channel guest tracking - Remove license GuestAccounts feature check from shouldTrackSingleChannelGuests (only config matters) - Re-add getServerLimits calls on page mount for fresh data - Remove config-change reactivity code (componentDidUpdate, useEffect) - Add server i18n translations for error strings - Sync webapp i18n via extract - Add inline comments for business logic - Restore struct field comments in ServerLimits model - Add Playwright E2E tests for single-channel guest feature - Fix label alignment in license details panel Made-with: Cursor * Guests over limit fixes and PR feedback * Fix linter issues and code quality improvements - Use max() builtin to clamp adjusted user count instead of if-statement (modernize linter) - Change banner type from ADVISOR to CRITICAL for proper red color styling Made-with: Cursor * Fix overage warnings incorrectly counting single-channel guests Single-channel guests are free and should not trigger license seat overage warnings. Update all overage checks to use serverLimits.activeUserCount (seat-adjusted, excluding SCG) instead of the raw total_users_count or TOTAL_USERS analytics stat. - UserSeatAlertBanner on License page: use serverLimits.activeUserCount - UserSeatAlertBanner on Site Statistics page: use serverLimits.activeUserCount - ActivatedUserCard display and overage check: use serverLimits.activeUserCount - OverageUsersBanner: use serverLimits.activeUserCount Made-with: Cursor * Use license.Users as fallback for singleChannelGuestLimit before limits load This prevents the SingleChannelGuestsCard from showing a false overage state before serverLimits has been fetched, while still rendering the card immediately on page load. Made-with: Cursor * Fix invite modal overage banner incorrectly counting single-channel guests Made-with: Cursor * Fix invitation modal tests missing limits entity in mock state Made-with: Cursor * Fix tests * Add E2E test for single-channel guest exceeded limit scenario Made-with: Cursor * Fix TypeScript errors in single channel guests E2E test Made-with: Cursor * Fix channel name validation error caused by unawaited async getRandomId() Made-with: Cursor * Add contextual tooltips to stat cards when guest accounts are enabled Made-with: Cursor * Code review feedback: query builder, readability, tooltips, and alignment fixes Made-with: Cursor * Fix license page tooltip alignment, width, and SaveLicense SCG exclusion Made-with: Cursor * Fix banner dismiss, license spacing, and add dismiss test Made-with: Cursor * Exclude DM/GM channels from single-channel guest count and fix E2E tests Filter the AnalyticsGetSingleChannelGuestCount query to only count memberships in public/private channels, excluding DMs and GMs. Update store tests with DM-only, GM-only, and mixed membership cases. Fix E2E overage test to mock the server limits API instead of skipping, and correct banner locator to use data-testid. Made-with: Cursor
2026-03-10 10:31:10 -04:00
if a.shouldTrackSingleChannelGuests() {
singleChannelGuestCount, err := a.Srv().Store().User().AnalyticsGetSingleChannelGuestCount()
if err != nil {
return nil, model.NewAppError("GetServerLimits", "app.limits.get_app_limits.single_channel_guest_count.store_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
// Single-channel guests are free and excluded from the primary seat count.
limits.ActiveUserCount = max(activeUserCount-singleChannelGuestCount, 0)
limits.SingleChannelGuestCount = singleChannelGuestCount
// Guests are allowed up to a 1:1 ratio with licensed seats.
if license != nil && license.Features != nil && license.Features.Users != nil {
limits.SingleChannelGuestLimit = int64(*license.Features.Users)
}
} else {
limits.ActiveUserCount = activeUserCount
}
enforce License.IsSeatCountEnforced if set (#31354) * enforce License.IsSeatCountEnforced if set If a license sets `IsSeatCountEnforced`, enforce the user limit therein as a hard cap. Fixes: https://mattermost.atlassian.net/browse/CLD-9260 * remove duplicate tests * Improve user limit error messages and display - Add separate error messages for licensed vs unlicensed servers - Licensed servers: "Server exceeds maximum licensed users. ERROR_LICENSED_USERS_LIMITS" - Unlicensed servers: "Server exceeds safe user limit. ERROR_SAFETY_LIMITS_EXCEEDED" - Remove redundant "Contact administrator" text from activation errors shown to admins - Fix system console to display actual server error messages instead of generic "Failed to activate user" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add license nil check and test coverage - Add license != nil check in GetServerLimits to prevent panic - Add test case to verify graceful handling of license being set to nil - Ensures fallback to hard-coded limits when license becomes nil Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix user limits tests to expect license-specific error IDs Update test expectations to use the new license-specific error IDs: - app.user.update_active.license_user_limit.exceeded for licensed server user activation - api.user.create_user.license_user_limits.exceeded for licensed server user creation Also update frontend to show actual server error messages instead of generic ones in system console. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove redundant license nil test The test couldn't meaningfully verify nil license behavior since it relied on hard-coded constants that can't be modified in the test. Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix whitespace issue in limits_test.go Remove unnecessary trailing newline to pass style checks. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * updated i18n * s/ERROR_LICENSED_USERS_LIMITS/ERROR_LICENSED_USERS_LIMIT_EXCEEDED/, expand warning log * Add 5% grace period for licensed user limits - Add calculateGraceLimit() function with 5% or +1 minimum grace - Apply grace period only to licensed servers with seat count enforcement - Handle zero user licenses by returning zero grace limit - Add comprehensive test coverage for grace period scenarios - Unlicensed servers maintain existing hard-coded limits without grace 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestCreateUserOrGuestSeatCountEnforcement to account for 5% grace period The test was failing because it expected user creation to fail at exactly the license limit, but the implementation now includes a 5% grace period before enforcement kicks in. Changes: - Update test cases to create users up to the grace limit (6 for a 5-user license) - Add comments explaining the grace period calculation - Both regular user and guest user creation tests now properly validate enforcement at the grace limit rather than the base license limit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestUpdateActiveWithUserLimits to account for 5% grace period Update test expectations to match the new grace period behavior: - At base limit (100) but below grace limit (105): should succeed - At grace limit (105): should fail - Above grace limit (106): should fail This aligns the tests with the license enforcement implementation that includes a 5% grace period above the licensed user count. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> Co-authored-by: Mattermost Build <build@mattermost.com>
2025-06-13 16:12:05 -04:00
return limits, nil
}
Add single-channel guest tracking and reporting (#35451) * Add single-channel guest tracking and reporting - Add AnalyticsGetSingleChannelGuestCount store method to count guests in exactly one channel - Exclude single-channel guests from active user seat count in GetServerLimits - Add single-channel guest count to standard analytics response - Add Single-channel Guests card to System Statistics page with overage warning - Add Single-channel guests row to Edition and License page with overage styling - Add dismissible admin-only banner when single-channel guest limit is exceeded - Gate feature behind non-Entry SKU and guest accounts enabled checks - Re-fetch server limits on config changes for reactive UI updates - Fix label alignment in license details panel Made-with: Cursor * Refine single-channel guest tracking - Remove license GuestAccounts feature check from shouldTrackSingleChannelGuests (only config matters) - Re-add getServerLimits calls on page mount for fresh data - Remove config-change reactivity code (componentDidUpdate, useEffect) - Add server i18n translations for error strings - Sync webapp i18n via extract - Add inline comments for business logic - Restore struct field comments in ServerLimits model - Add Playwright E2E tests for single-channel guest feature - Fix label alignment in license details panel Made-with: Cursor * Guests over limit fixes and PR feedback * Fix linter issues and code quality improvements - Use max() builtin to clamp adjusted user count instead of if-statement (modernize linter) - Change banner type from ADVISOR to CRITICAL for proper red color styling Made-with: Cursor * Fix overage warnings incorrectly counting single-channel guests Single-channel guests are free and should not trigger license seat overage warnings. Update all overage checks to use serverLimits.activeUserCount (seat-adjusted, excluding SCG) instead of the raw total_users_count or TOTAL_USERS analytics stat. - UserSeatAlertBanner on License page: use serverLimits.activeUserCount - UserSeatAlertBanner on Site Statistics page: use serverLimits.activeUserCount - ActivatedUserCard display and overage check: use serverLimits.activeUserCount - OverageUsersBanner: use serverLimits.activeUserCount Made-with: Cursor * Use license.Users as fallback for singleChannelGuestLimit before limits load This prevents the SingleChannelGuestsCard from showing a false overage state before serverLimits has been fetched, while still rendering the card immediately on page load. Made-with: Cursor * Fix invite modal overage banner incorrectly counting single-channel guests Made-with: Cursor * Fix invitation modal tests missing limits entity in mock state Made-with: Cursor * Fix tests * Add E2E test for single-channel guest exceeded limit scenario Made-with: Cursor * Fix TypeScript errors in single channel guests E2E test Made-with: Cursor * Fix channel name validation error caused by unawaited async getRandomId() Made-with: Cursor * Add contextual tooltips to stat cards when guest accounts are enabled Made-with: Cursor * Code review feedback: query builder, readability, tooltips, and alignment fixes Made-with: Cursor * Fix license page tooltip alignment, width, and SaveLicense SCG exclusion Made-with: Cursor * Fix banner dismiss, license spacing, and add dismiss test Made-with: Cursor * Exclude DM/GM channels from single-channel guest count and fix E2E tests Filter the AnalyticsGetSingleChannelGuestCount query to only count memberships in public/private channels, excluding DMs and GMs. Update store tests with DM-only, GM-only, and mixed membership cases. Fix E2E overage test to mock the server limits API instead of skipping, and correct banner locator to use data-testid. Made-with: Cursor
2026-03-10 10:31:10 -04:00
func (a *App) shouldTrackSingleChannelGuests() bool {
license := a.License()
if license == nil {
return false
}
if license.IsMattermostEntry() {
return false
}
cfg := a.Config()
if cfg == nil || cfg.GuestAccountsSettings.Enable == nil {
return false
}
return *cfg.GuestAccountsSettings.Enable
}
func (a *App) GetPostHistoryLimit() int64 {
license := a.License()
if license == nil || license.Limits == nil || license.Limits.PostHistory == 0 {
// No limits applicable
return 0
}
return license.Limits.PostHistory
}
enforce License.IsSeatCountEnforced if set (#31354) * enforce License.IsSeatCountEnforced if set If a license sets `IsSeatCountEnforced`, enforce the user limit therein as a hard cap. Fixes: https://mattermost.atlassian.net/browse/CLD-9260 * remove duplicate tests * Improve user limit error messages and display - Add separate error messages for licensed vs unlicensed servers - Licensed servers: "Server exceeds maximum licensed users. ERROR_LICENSED_USERS_LIMITS" - Unlicensed servers: "Server exceeds safe user limit. ERROR_SAFETY_LIMITS_EXCEEDED" - Remove redundant "Contact administrator" text from activation errors shown to admins - Fix system console to display actual server error messages instead of generic "Failed to activate user" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add license nil check and test coverage - Add license != nil check in GetServerLimits to prevent panic - Add test case to verify graceful handling of license being set to nil - Ensures fallback to hard-coded limits when license becomes nil Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix user limits tests to expect license-specific error IDs Update test expectations to use the new license-specific error IDs: - app.user.update_active.license_user_limit.exceeded for licensed server user activation - api.user.create_user.license_user_limits.exceeded for licensed server user creation Also update frontend to show actual server error messages instead of generic ones in system console. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove redundant license nil test The test couldn't meaningfully verify nil license behavior since it relied on hard-coded constants that can't be modified in the test. Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix whitespace issue in limits_test.go Remove unnecessary trailing newline to pass style checks. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * updated i18n * s/ERROR_LICENSED_USERS_LIMITS/ERROR_LICENSED_USERS_LIMIT_EXCEEDED/, expand warning log * Add 5% grace period for licensed user limits - Add calculateGraceLimit() function with 5% or +1 minimum grace - Apply grace period only to licensed servers with seat count enforcement - Handle zero user licenses by returning zero grace limit - Add comprehensive test coverage for grace period scenarios - Unlicensed servers maintain existing hard-coded limits without grace 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestCreateUserOrGuestSeatCountEnforcement to account for 5% grace period The test was failing because it expected user creation to fail at exactly the license limit, but the implementation now includes a 5% grace period before enforcement kicks in. Changes: - Update test cases to create users up to the grace limit (6 for a 5-user license) - Add comments explaining the grace period calculation - Both regular user and guest user creation tests now properly validate enforcement at the grace limit rather than the base license limit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestUpdateActiveWithUserLimits to account for 5% grace period Update test expectations to match the new grace period behavior: - At base limit (100) but below grace limit (105): should succeed - At grace limit (105): should fail - Above grace limit (106): should fail This aligns the tests with the license enforcement implementation that includes a 5% grace period above the licensed user count. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> Co-authored-by: Mattermost Build <build@mattermost.com>
2025-06-13 16:12:05 -04:00
func (a *App) isAtUserLimit() (bool, *model.AppError) {
userLimits, appErr := a.GetServerLimits()
if appErr != nil {
return false, appErr
}
enforce License.IsSeatCountEnforced if set (#31354) * enforce License.IsSeatCountEnforced if set If a license sets `IsSeatCountEnforced`, enforce the user limit therein as a hard cap. Fixes: https://mattermost.atlassian.net/browse/CLD-9260 * remove duplicate tests * Improve user limit error messages and display - Add separate error messages for licensed vs unlicensed servers - Licensed servers: "Server exceeds maximum licensed users. ERROR_LICENSED_USERS_LIMITS" - Unlicensed servers: "Server exceeds safe user limit. ERROR_SAFETY_LIMITS_EXCEEDED" - Remove redundant "Contact administrator" text from activation errors shown to admins - Fix system console to display actual server error messages instead of generic "Failed to activate user" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add license nil check and test coverage - Add license != nil check in GetServerLimits to prevent panic - Add test case to verify graceful handling of license being set to nil - Ensures fallback to hard-coded limits when license becomes nil Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix user limits tests to expect license-specific error IDs Update test expectations to use the new license-specific error IDs: - app.user.update_active.license_user_limit.exceeded for licensed server user activation - api.user.create_user.license_user_limits.exceeded for licensed server user creation Also update frontend to show actual server error messages instead of generic ones in system console. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove redundant license nil test The test couldn't meaningfully verify nil license behavior since it relied on hard-coded constants that can't be modified in the test. Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> * Fix whitespace issue in limits_test.go Remove unnecessary trailing newline to pass style checks. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * updated i18n * s/ERROR_LICENSED_USERS_LIMITS/ERROR_LICENSED_USERS_LIMIT_EXCEEDED/, expand warning log * Add 5% grace period for licensed user limits - Add calculateGraceLimit() function with 5% or +1 minimum grace - Apply grace period only to licensed servers with seat count enforcement - Handle zero user licenses by returning zero grace limit - Add comprehensive test coverage for grace period scenarios - Unlicensed servers maintain existing hard-coded limits without grace 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestCreateUserOrGuestSeatCountEnforcement to account for 5% grace period The test was failing because it expected user creation to fail at exactly the license limit, but the implementation now includes a 5% grace period before enforcement kicks in. Changes: - Update test cases to create users up to the grace limit (6 for a 5-user license) - Add comments explaining the grace period calculation - Both regular user and guest user creation tests now properly validate enforcement at the grace limit rather than the base license limit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TestUpdateActiveWithUserLimits to account for 5% grace period Update test expectations to match the new grace period behavior: - At base limit (100) but below grace limit (105): should succeed - At grace limit (105): should fail - Above grace limit (106): should fail This aligns the tests with the license enforcement implementation that includes a 5% grace period above the licensed user count. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: lieut-data <lieut-data@users.noreply.github.com> Co-authored-by: Mattermost Build <build@mattermost.com>
2025-06-13 16:12:05 -04:00
if userLimits.MaxUsersHardLimit == 0 {
return false, nil
}
return userLimits.ActiveUserCount >= userLimits.MaxUsersHardLimit, appErr
}