Fix license upload when already set by env variable (#30974)

* Fix license upload when already set by env variable

* Add tooltip

* Fix tests and texts

* Fix snapshots

* Add disabled styles to secondary button

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Daniel Espino García
2025-06-13 13:07:20 +02:00
коммит произвёл GitHub
родитель 43018759e5
Коммит 0376bc7cc1
7 изменённых файлов: 48 добавлений и 11 удалений

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

@@ -310,6 +310,7 @@ exports[`components/admin_console/license_settings/LicenseSettings should match
handleChange={[Function]}
handleRemove={[Function]}
isDisabled={false}
isLicenseSetByEnvVar={false}
isTrialLicense={false}
license={
Object {
@@ -461,6 +462,7 @@ exports[`components/admin_console/license_settings/LicenseSettings should match
handleChange={[Function]}
handleRemove={[Function]}
isDisabled={false}
isLicenseSetByEnvVar={false}
isTrialLicense={false}
license={
Object {
@@ -600,6 +602,7 @@ exports[`components/admin_console/license_settings/LicenseSettings should match
handleChange={[Function]}
handleRemove={[Function]}
isDisabled={false}
isLicenseSetByEnvVar={false}
isTrialLicense={false}
license={
Object {
@@ -739,6 +742,7 @@ exports[`components/admin_console/license_settings/LicenseSettings should match
handleChange={[Function]}
handleRemove={[Function]}
isDisabled={false}
isLicenseSetByEnvVar={false}
isTrialLicense={false}
license={
Object {
@@ -878,6 +882,7 @@ exports[`components/admin_console/license_settings/LicenseSettings should match
handleChange={[Function]}
handleRemove={[Function]}
isDisabled={true}
isLicenseSetByEnvVar={false}
isTrialLicense={false}
license={
Object {
@@ -1017,6 +1022,7 @@ exports[`components/admin_console/license_settings/LicenseSettings should match
handleChange={[Function]}
handleRemove={[Function]}
isDisabled={false}
isLicenseSetByEnvVar={false}
isTrialLicense={false}
license={
Object {
@@ -1146,6 +1152,7 @@ exports[`components/admin_console/license_settings/LicenseSettings should match
handleChange={[Function]}
handleRemove={[Function]}
isDisabled={false}
isLicenseSetByEnvVar={false}
isTrialLicense={true}
license={
Object {
@@ -1846,6 +1853,7 @@ exports[`components/admin_console/license_settings/LicenseSettings should match
handleChange={[Function]}
handleRemove={[Function]}
isDisabled={false}
isLicenseSetByEnvVar={false}
isTrialLicense={false}
license={
Object {
@@ -1987,6 +1995,7 @@ exports[`components/admin_console/license_settings/LicenseSettings should match
handleChange={[Function]}
handleRemove={[Function]}
isDisabled={false}
isLicenseSetByEnvVar={false}
isTrialLicense={false}
license={
Object {

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

@@ -94,6 +94,7 @@ describe('components/admin_console/license_settings/enterprise_edition/enterpris
handleChange: jest.fn(),
fileInputRef: React.createRef(),
statsActiveUsers: 1,
isLicenseSetByEnvVar: false,
};
test('should format the Users field', () => {

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

@@ -4,7 +4,7 @@
import classNames from 'classnames';
import React, {useEffect, useState} from 'react';
import type {RefObject} from 'react';
import {FormattedDate, FormattedMessage, FormattedNumber, FormattedTime, defineMessages, useIntl} from 'react-intl';
import {FormattedDate, FormattedMessage, FormattedNumber, FormattedTime, defineMessage, defineMessages, useIntl} from 'react-intl';
import type {ClientLicense} from '@mattermost/types/config';
@@ -13,6 +13,7 @@ import {Client4} from 'mattermost-redux/client';
import useOpenPricingModal from 'components/common/hooks/useOpenPricingModal';
import useOpenSalesLink from 'components/common/hooks/useOpenSalesLink';
import Tag from 'components/widgets/tag/tag';
import WithTooltip from 'components/with_tooltip';
import {FileTypes} from 'utils/constants';
import {calculateOverageUserActivated} from 'utils/overage_team';
@@ -35,6 +36,7 @@ export interface EnterpriseEditionProps {
fileInputRef: RefObject<HTMLInputElement>;
handleChange: () => void;
statsActiveUsers: number;
isLicenseSetByEnvVar: boolean;
}
export const messages = defineMessages({
@@ -52,6 +54,7 @@ const EnterpriseEditionLeftPanel = ({
fileInputRef,
handleChange,
statsActiveUsers,
isLicenseSetByEnvVar,
}: EnterpriseEditionProps) => {
const {formatMessage} = useIntl();
const [unsanitizedLicense, setUnsanitizedLicense] = useState(license);
@@ -148,6 +151,7 @@ const EnterpriseEditionLeftPanel = ({
handleChange,
statsActiveUsers,
expirationDays,
isLicenseSetByEnvVar,
)
}
</div>
@@ -245,6 +249,7 @@ const renderLicenseContent = (
handleChange: () => void,
statsActiveUsers: number,
expirationDays: number,
isLicenseSetByEnvVar: boolean,
) => {
// Note: DO NOT LOCALISE THESE STRINGS. Legally we can not since the license is in English.
@@ -284,7 +289,7 @@ const renderLicenseContent = (
<div className='licenseElements'>
{licenseValues.map(renderLicenseValues(statsActiveUsers, parseInt(license.Users, 10), expirationDays))}
<hr/>
{renderAddNewLicenseButton(fileInputRef, handleChange)}
{renderAddNewLicenseButton(fileInputRef, handleChange, isLicenseSetByEnvVar)}
{renderRemoveButton(handleRemove, isDisabled, removing)}
</div>
);
@@ -293,18 +298,28 @@ const renderLicenseContent = (
const renderAddNewLicenseButton = (
fileInputRef: RefObject<HTMLInputElement>,
handleChange: () => void,
isLicenseSetByEnvVar: boolean,
) => {
return (
<>
<button
className='btn btn-tertiary add-new-licence-btn'
onClick={() => fileInputRef.current?.click()}
<WithTooltip
title={defineMessage({
id: 'admin.license.setByEnvVar',
defaultMessage: 'License location is set by environment variable',
})}
disabled={!isLicenseSetByEnvVar}
>
<FormattedMessage
id='admin.license.keyAddNew'
defaultMessage='Add a new license'
/>
</button>
<button
className={'btn btn-secondary'}
onClick={() => fileInputRef.current?.click()}
disabled={isLicenseSetByEnvVar}
>
<FormattedMessage
id='admin.license.keyAddNew'
defaultMessage='Add a new license'
/>
</button>
</WithTooltip>
<input
ref={fileInputRef}
type='file'

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

@@ -42,6 +42,7 @@ describe('components/admin_console/license_settings/LicenseSettings', () => {
upgradedFromTE: false,
enterpriseReady: true,
totalUsers: 10,
environmentConfig: {},
isMySql: false,
actions: {
getLicenseConfig: jest.fn(),

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

@@ -5,7 +5,7 @@ import React from 'react';
import {FormattedMessage, defineMessages} from 'react-intl';
import type {StatusOK} from '@mattermost/types/client4';
import type {ClientLicense} from '@mattermost/types/config';
import type {ClientLicense, EnvironmentConfig} from '@mattermost/types/config';
import type {ServerError} from '@mattermost/types/errors';
import type {ServerLimits} from '@mattermost/types/limits';
import type {GetFilteredUsersStatsOpts, UsersStats} from '@mattermost/types/users';
@@ -45,6 +45,7 @@ type Props = {
totalUsers: number;
isDisabled: boolean;
prevTrialLicense: ClientLicense;
environmentConfig: Partial<EnvironmentConfig>;
isMySql: boolean;
actions: {
getLicenseConfig: () => void;
@@ -321,6 +322,7 @@ export default class LicenseSettings extends React.PureComponent<Props, State> {
fileInputRef={this.fileInputRef}
handleChange={this.handleChange}
statsActiveUsers={this.props.totalUsers || 0}
isLicenseSetByEnvVar={Boolean(this.props.environmentConfig?.ServiceSettings?.LicenseFileLocation)}
/>
);

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

@@ -1560,6 +1560,7 @@
"admin.license.renewalCard.reviewNumbers": "Review your numbers below to ensure you renew for the right number of users.",
"admin.license.renewalCard.usersNumbers_active": "Active Users: ",
"admin.license.renewalCard.usersNumbers_licensed": "Licensed Users: ",
"admin.license.setByEnvVar": "License location is set by environment variable",
"admin.license.title": "Edition and License",
"admin.license.Trial": "Trial",
"admin.license.trial-request.accept-terms": "By clicking <strong>Start trial</strong>, I agree to the <linkEvaluation>Mattermost Software and Services License Agreement</linkEvaluation>, <linkPrivacy>Privacy Policy</linkPrivacy>, and receiving product emails.",

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

@@ -269,6 +269,14 @@ button {
}
}
&:disabled,
&:disabled:hover,
&:disabled:active {
border-color: rgba(var(--center-channel-color-rgb), 0.32);
background: transparent;
color: rgba(var(--center-channel-color-rgb), 0.32) !important;
}
&:hover {
background-color: rgb(var(--button-bg-rgb), 0.08);
}