-
Notifications
You must be signed in to change notification settings - Fork 13.8k
feat: Improve manual license management #40916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
58ce502
feat: add licenses.validate endpoint to preview a license before appl…
rodrigok 93bc1b7
chore: lint
dougfabris 6463727
refactor: simplify licenses.validate to success/reasons contract
ggazzo 65e0e5f
Merge branch 'develop' into worktree-majestic-wibbling-jellyfish
dougfabris fcaeed1
refactor: report malformed license via the same validate failure shape
ggazzo 59f2352
wip
dougfabris 80364b1
feat: hide enterprise setting page
dougfabris a0c6663
feat: invalid license error messages
dougfabris 0c2ad64
chore: split useWorkspaceInfo to display hashed URL
dougfabris 38a9064
feat: implement modal, hooks, translations and tests
dougfabris f3725e0
chore: remove comment
dougfabris 9aa156e
fix: unify open handle function
dougfabris 17274a1
feat: invalidate license when applying or removing
dougfabris 5661888
feat: add license details in `PlanCardTrial`
dougfabris 40be9c4
chore: changeset
dougfabris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@rocket.chat/license': minor | ||
| '@rocket.chat/rest-typings': minor | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Adds a new `licenses.validate` REST endpoint that validates a Rocket.Chat license (V2 or V3 JWT) against the current workspace without applying it, so a license can be previewed before it is applied from the UI. A valid license responds with success; an invalid one responds with the validation behaviors that rejected it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@rocket.chat/i18n': minor | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Adds a manage license flow to the subscription admin page, allowing license verification before applying it and an option to remove the license. Note: From this point license management should be made in subscription page instead of the Enterprise settings page. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
apps/meteor/client/views/admin/settings/groups/EnterpriseGroupPage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { Box } from '@rocket.chat/fuselage'; | ||
| import { PageScrollableContentWithShadow } from '@rocket.chat/ui-client'; | ||
| import { useRouter } from '@rocket.chat/ui-contexts'; | ||
| import { useCallback } from 'react'; | ||
| import type { MouseEvent } from 'react'; | ||
| import { Trans } from 'react-i18next'; | ||
|
|
||
| import SettingsGroupPage from '../SettingsGroupPage'; | ||
|
|
||
| type EnterpriseGroupPageProps = { | ||
| _id: string; | ||
| i18nLabel: string; | ||
| currentTab?: string; | ||
| hasReset?: boolean; | ||
| onClickBack?: () => void; | ||
| }; | ||
|
|
||
| const useRedirectToRouteLink = (onClick: (event: MouseEvent<HTMLAnchorElement>) => void) => { | ||
| const handleClick = useCallback( | ||
| (event: MouseEvent<HTMLAnchorElement>) => { | ||
| event.preventDefault(); | ||
| onClick(event); | ||
| }, | ||
| [onClick], | ||
| ); | ||
|
|
||
| return { href: '#', onClick: handleClick }; | ||
| }; | ||
|
|
||
| const EnterpriseGroupPage = ({ _id, i18nLabel, onClickBack, ...props }: EnterpriseGroupPageProps) => { | ||
| const { navigate } = useRouter(); | ||
| const redirectProps = useRedirectToRouteLink(() => navigate('/admin/subscription')); | ||
|
|
||
| return ( | ||
| <SettingsGroupPage isCustom _id={_id} i18nLabel={i18nLabel} onClickBack={onClickBack} {...props}> | ||
| <PageScrollableContentWithShadow> | ||
| <Box marginBlock='none' marginInline='auto' width='full' maxWidth='x580'> | ||
| <Trans | ||
| i18nKey='Workspace_license_is_now_managed_from_the_subscription_page' | ||
| components={{ a: <Box is='a' fontScale='p2' color='info' {...redirectProps} /> }} | ||
| /> | ||
| </Box> | ||
| </PageScrollableContentWithShadow> | ||
| </SettingsGroupPage> | ||
| ); | ||
| }; | ||
|
|
||
| export default EnterpriseGroupPage; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ws/admin/subscription/components/cards/PlanCard/ManageLicenseModal/LicenseFilePreview.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { Box, IconButton } from '@rocket.chat/fuselage'; | ||
| import { FilePreviewIcon } from '@rocket.chat/ui-client'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| import { getFileExtension } from '../../../../../../../../lib/utils/getFileExtension'; | ||
| import { formatBytes } from '../../../../../../../lib/utils/formatBytes'; | ||
|
|
||
| const LicenseFilePreview = ({ selectedFile, handleRemoveFile }: { selectedFile: File; handleRemoveFile: () => void }) => { | ||
| const { t } = useTranslation(); | ||
|
|
||
| return ( | ||
| <Box display='flex' alignItems='center' padding={4} mbe={8} borderRadius={4} borderWidth={1} borderColor='extra-light'> | ||
| <FilePreviewIcon format={getFileExtension(selectedFile.name)} /> | ||
| <Box flexGrow={1} withTruncatedText mis={8} display='flex' flexDirection='column'> | ||
| <Box fontScale='p2' color='info' withTruncatedText> | ||
| {selectedFile.name} | ||
| </Box> | ||
| <Box fontScale='c1' color='hint' textTransform='uppercase'> | ||
| {`${formatBytes(selectedFile.size, 2)} - ${getFileExtension(selectedFile.name)}`} | ||
| </Box> | ||
| </Box> | ||
| <IconButton icon='cross' tiny title={t('Remove_file')} onClick={handleRemoveFile} /> | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| export default LicenseFilePreview; |
36 changes: 36 additions & 0 deletions
36
...t/views/admin/subscription/components/cards/PlanCard/ManageLicenseModal/LicenseStatus.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { Callout, Skeleton } from '@rocket.chat/fuselage'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| type LicenseStatusProps = { | ||
| isValidating: boolean; | ||
| isValid: boolean; | ||
| invalidMessage: string; | ||
| }; | ||
|
|
||
| const LicenseStatus = ({ isValidating, isValid, invalidMessage }: LicenseStatusProps) => { | ||
| const { t } = useTranslation(); | ||
|
|
||
| if (isValidating) { | ||
| return ( | ||
| <Callout icon='reload' type='info' title={`${t('Validating_license')}...`}> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Move the ellipsis into the translation string. Concatenating 🌐 Proposed fix- <Callout icon='reload' type='info' title={`${t('Validating_license')}...`}>
+ <Callout icon='reload' type='info' title={t('Validating_license_ellipsis')}>🤖 Prompt for AI Agents |
||
| <Skeleton width='x320' /> | ||
| </Callout> | ||
| ); | ||
| } | ||
|
|
||
| if (isValid) { | ||
| return ( | ||
| <Callout type='success' title={t('Valid_license')}> | ||
| {t('This_license_is_valid_and_ready_to_apply')} | ||
| </Callout> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Callout type='danger' title={t('Invalid_license')}> | ||
| {invalidMessage} | ||
| </Callout> | ||
| ); | ||
| }; | ||
|
|
||
| export default LicenseStatus; | ||
123 changes: 123 additions & 0 deletions
123
...min/subscription/components/cards/PlanCard/ManageLicenseModal/ManageLicenseModal.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import type { BehaviorWithContext } from '@rocket.chat/core-typings'; | ||
| import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
| import { act, render, screen, waitFor } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
|
|
||
| import ManageLicenseModal from './ManageLicenseModal'; | ||
| import createDeferredMockFn from '../../../../../../../../tests/mocks/utils/createDeferredMockFn'; | ||
|
|
||
| // Long enough to pass isPlausibleLicense (>= 100 chars) so validation actually runs. | ||
| const LICENSE = 'a'.repeat(120); | ||
| const OTHER_LICENSE = 'b'.repeat(120); | ||
|
|
||
| const reasons = (...pairs: [string, string][]): BehaviorWithContext[] => | ||
| pairs.map(([behavior, reason]) => ({ behavior, reason }) as BehaviorWithContext); | ||
|
|
||
| // The endpoint is typed `void`; the REST client resolves it as `null`, so mocks must return null. | ||
| const validationSuccess = () => null; | ||
| const validationFailure = (fails: BehaviorWithContext[]) => () => Promise.reject({ reasons: fails }); | ||
|
|
||
| // getByLabelText matches by label association regardless of visibility, so it reaches the display:none input. | ||
| const fileInput = () => screen.getByLabelText('Upload_license_file'); | ||
|
|
||
| it('should render the title, description and a disabled apply button', () => { | ||
| render(<ManageLicenseModal enterpriseLicense='' onCancel={jest.fn()} />, { wrapper: mockAppRoot().build() }); | ||
|
|
||
| expect(screen.getByRole('heading', { name: 'Manage_license' })).toBeInTheDocument(); | ||
| expect(screen.getByText('Manage_license_description')).toBeInTheDocument(); | ||
| expect(screen.getByRole('button', { name: 'Apply_license' })).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('should show a success status for a valid license', async () => { | ||
| render(<ManageLicenseModal enterpriseLicense={LICENSE} onCancel={jest.fn()} />, { | ||
| wrapper: mockAppRoot().withEndpoint('POST', '/v1/licenses.validate', validationSuccess).build(), | ||
| }); | ||
|
|
||
| expect(await screen.findByText('Valid_license')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should map a validation failure to a specific message', async () => { | ||
| render(<ManageLicenseModal enterpriseLicense={LICENSE} onCancel={jest.fn()} />, { | ||
| wrapper: mockAppRoot() | ||
| .withEndpoint('POST', '/v1/licenses.validate', validationFailure(reasons(['invalidate_license', 'period']))) | ||
| .build(), | ||
| }); | ||
|
|
||
| expect(await screen.findByText('License_error_expired')).toBeInTheDocument(); | ||
| expect(screen.getByText('Invalid_license')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should show a generic message when validation fails for a non-license reason', async () => { | ||
| render(<ManageLicenseModal enterpriseLicense={LICENSE} onCancel={jest.fn()} />, { | ||
| wrapper: mockAppRoot() | ||
| .withEndpoint('POST', '/v1/licenses.validate', () => Promise.reject(new Error('network down'))) | ||
| .build(), | ||
| }); | ||
|
|
||
| expect(await screen.findByText('License_error_generic')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should show a validating status while the request is in flight', async () => { | ||
| const { fn, resolve } = createDeferredMockFn<null>(); | ||
|
|
||
| render(<ManageLicenseModal enterpriseLicense={LICENSE} onCancel={jest.fn()} />, { | ||
| wrapper: mockAppRoot().withEndpoint('POST', '/v1/licenses.validate', fn).build(), | ||
| }); | ||
|
|
||
| expect(await screen.findByText('Validating_license...')).toBeInTheDocument(); | ||
|
|
||
| act(() => resolve(null)); | ||
|
|
||
| expect(await screen.findByText('Valid_license')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should populate the preview and validate an uploaded .txt file', async () => { | ||
| render(<ManageLicenseModal enterpriseLicense='' onCancel={jest.fn()} />, { | ||
| wrapper: mockAppRoot().withEndpoint('POST', '/v1/licenses.validate', validationSuccess).build(), | ||
| }); | ||
|
|
||
| await userEvent.upload(fileInput(), new File([LICENSE], 'license.txt', { type: 'text/plain' })); | ||
|
|
||
| expect(await screen.findByText('license.txt')).toBeInTheDocument(); | ||
| expect(await screen.findByText('Valid_license')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should reject an uploaded non-txt file with an error status', async () => { | ||
| render(<ManageLicenseModal enterpriseLicense='' onCancel={jest.fn()} />, { | ||
| wrapper: mockAppRoot().build(), | ||
| }); | ||
|
|
||
| // Bypass the input's `accept` filter so the guard in handleFile is what rejects the file. | ||
| const user = userEvent.setup({ applyAccept: false }); | ||
| await user.upload(fileInput(), new File(['nope'], 'license.png', { type: 'image/png' })); | ||
|
|
||
| expect(await screen.findByText('Only_txt_license_files_are_supported')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should apply a valid license and close the modal', async () => { | ||
| const onCancel = jest.fn(); | ||
|
|
||
| render(<ManageLicenseModal enterpriseLicense='' onCancel={onCancel} />, { | ||
| wrapper: mockAppRoot().withEndpoint('POST', '/v1/licenses.validate', validationSuccess).build(), | ||
| }); | ||
|
|
||
| await userEvent.upload(fileInput(), new File([OTHER_LICENSE], 'license.txt', { type: 'text/plain' })); | ||
|
|
||
| const applyButton = screen.getByRole('button', { name: 'Apply_license' }); | ||
| await waitFor(() => expect(applyButton).toBeEnabled()); | ||
|
|
||
| await userEvent.click(applyButton); | ||
|
|
||
| await waitFor(() => expect(onCancel).toHaveBeenCalled()); | ||
| }); | ||
|
|
||
| it('should ask for confirmation before removing the current license', async () => { | ||
| render(<ManageLicenseModal enterpriseLicense={LICENSE} onCancel={jest.fn()} />, { | ||
| wrapper: mockAppRoot().withEndpoint('POST', '/v1/licenses.validate', validationSuccess).build(), | ||
| }); | ||
|
|
||
| // The remove action only shows when the entered license is the applied one. | ||
| await userEvent.click(await screen.findByRole('button', { name: 'Remove_license' })); | ||
|
|
||
| expect(screen.getByRole('heading', { name: 'Remove_license_key' })).toBeInTheDocument(); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.