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>
Этот коммит содержится в:
Jesse Hallam
2025-06-13 17:12:05 -03:00
коммит произвёл GitHub
родитель f89326574f
Коммит 0082e3e94d
8 изменённых файлов: 978 добавлений и 204 удалений

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

@@ -147,7 +147,9 @@ export class SystemUserDetail extends PureComponent<Props, State> {
} catch (err) {
console.error('SystemUserDetails-handleActivateUser', err); // eslint-disable-line no-console
this.setState({error: this.props.intl.formatMessage({id: 'admin.user_item.userActivateFailed', defaultMessage: 'Failed to activate user'})});
// Show the actual server error message instead of generic message
const errorMessage = (err as Error).message || this.props.intl.formatMessage({id: 'admin.user_item.userActivateFailed', defaultMessage: 'Failed to activate user'});
this.setState({error: errorMessage});
}
};
@@ -166,7 +168,9 @@ export class SystemUserDetail extends PureComponent<Props, State> {
} catch (err) {
console.error('SystemUserDetails-handleDeactivateMember', err); // eslint-disable-line no-console
this.setState({error: this.props.intl.formatMessage({id: 'admin.user_item.userDeactivateFailed', defaultMessage: 'Failed to deactivate user'})});
// Show the actual server error message instead of generic message
const errorMessage = (err as Error).message || this.props.intl.formatMessage({id: 'admin.user_item.userDeactivateFailed', defaultMessage: 'Failed to deactivate user'});
this.setState({error: errorMessage});
}
this.toggleCloseModalDeactivateMember();