-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into meteor3/tracing
- Loading branch information
Showing
43 changed files
with
972 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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/meteor": major | ||
"@rocket.chat/i18n": major | ||
"@rocket.chat/license": major | ||
--- | ||
|
||
Adds restrictions to air-gapped environments without a license |
This file contains 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 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 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 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
5 changes: 5 additions & 0 deletions
5
apps/meteor/app/license/server/airGappedRestrictionsWrapper.ts
This file contains 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,5 @@ | ||
import { makeFunction } from '@rocket.chat/patch-injection'; | ||
|
||
export const applyAirGappedRestrictionsValidation = makeFunction(async <T>(fn: () => Promise<T>): Promise<T> => { | ||
return fn(); | ||
}); |
This file contains 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 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,52 @@ | ||
import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
import { renderHook } from '@testing-library/react'; | ||
|
||
import { useAirGappedRestriction } from './useAirGappedRestriction'; | ||
|
||
// [restricted, warning, remainingDays] | ||
describe('useAirGappedRestriction hook', () => { | ||
it('should return [false, false, -1] if setting value is not a number', () => { | ||
const { result } = renderHook(() => useAirGappedRestriction(), { | ||
legacyRoot: true, | ||
wrapper: mockAppRoot().withSetting('Cloud_Workspace_AirGapped_Restrictions_Remaining_Days', -1).build(), | ||
}); | ||
|
||
expect(result.current).toEqual([false, false, -1]); | ||
}); | ||
|
||
it('should return [false, false, -1] if user has a license (remaining days is a negative value)', () => { | ||
const { result } = renderHook(() => useAirGappedRestriction(), { | ||
legacyRoot: true, | ||
wrapper: mockAppRoot().withSetting('Cloud_Workspace_AirGapped_Restrictions_Remaining_Days', -1).build(), | ||
}); | ||
|
||
expect(result.current).toEqual([false, false, -1]); | ||
}); | ||
|
||
it('should return [false, false, 8] if not on warning or restriction phase', () => { | ||
const { result } = renderHook(() => useAirGappedRestriction(), { | ||
legacyRoot: true, | ||
wrapper: mockAppRoot().withSetting('Cloud_Workspace_AirGapped_Restrictions_Remaining_Days', 8).build(), | ||
}); | ||
|
||
expect(result.current).toEqual([false, false, 8]); | ||
}); | ||
|
||
it('should return [true, false, 7] if on warning phase', () => { | ||
const { result } = renderHook(() => useAirGappedRestriction(), { | ||
legacyRoot: true, | ||
wrapper: mockAppRoot().withSetting('Cloud_Workspace_AirGapped_Restrictions_Remaining_Days', 7).build(), | ||
}); | ||
|
||
expect(result.current).toEqual([false, true, 7]); | ||
}); | ||
|
||
it('should return [true, false, 0] if on restriction phase', () => { | ||
const { result } = renderHook(() => useAirGappedRestriction(), { | ||
legacyRoot: true, | ||
wrapper: mockAppRoot().withSetting('Cloud_Workspace_AirGapped_Restrictions_Remaining_Days', 0).build(), | ||
}); | ||
|
||
expect(result.current).toEqual([true, false, 0]); | ||
}); | ||
}); |
This file contains 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,19 @@ | ||
import { useSetting } from '@rocket.chat/ui-contexts'; | ||
|
||
export const useAirGappedRestriction = (): [isRestrictionPhase: boolean, isWarningPhase: boolean, remainingDays: number] => { | ||
const airGappedRestrictionRemainingDays = useSetting('Cloud_Workspace_AirGapped_Restrictions_Remaining_Days'); | ||
|
||
if (typeof airGappedRestrictionRemainingDays !== 'number') { | ||
return [false, false, -1]; | ||
} | ||
|
||
// If this value is negative, the user has a license with valid module | ||
if (airGappedRestrictionRemainingDays < 0) { | ||
return [false, false, airGappedRestrictionRemainingDays]; | ||
} | ||
|
||
const isRestrictionPhase = airGappedRestrictionRemainingDays === 0; | ||
const isWarningPhase = !isRestrictionPhase && airGappedRestrictionRemainingDays <= 7; | ||
|
||
return [isRestrictionPhase, isWarningPhase, airGappedRestrictionRemainingDays]; | ||
}; |
This file contains 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
19 changes: 19 additions & 0 deletions
19
.../meteor/client/sidebar/sections/AirGappedRestrictionBanner/AirGappedRestrictionBanner.tsx
This file contains 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,19 @@ | ||
import { SidebarBanner } from '@rocket.chat/fuselage'; | ||
import { ExternalLink } from '@rocket.chat/ui-client'; | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import AirGappedRestrictionWarning from './AirGappedRestrictionWarning'; | ||
|
||
const AirGappedRestrictionSection = ({ isRestricted, remainingDays }: { isRestricted: boolean; remainingDays: number }) => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<SidebarBanner | ||
text={<AirGappedRestrictionWarning isRestricted={isRestricted} remainingDays={remainingDays} />} | ||
description={<ExternalLink to='https://go.rocket.chat/i/airgapped-restriction'>{t('Learn_more')}</ExternalLink>} | ||
/> | ||
); | ||
}; | ||
|
||
export default AirGappedRestrictionSection; |
27 changes: 27 additions & 0 deletions
27
...meteor/client/sidebar/sections/AirGappedRestrictionBanner/AirGappedRestrictionWarning.tsx
This file contains 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 } from '@rocket.chat/fuselage'; | ||
import React from 'react'; | ||
import { Trans } from 'react-i18next'; | ||
|
||
const AirGappedRestrictionWarning = ({ isRestricted, remainingDays }: { isRestricted: boolean; remainingDays: number }) => { | ||
if (isRestricted) { | ||
return ( | ||
<Trans i18nKey='Airgapped_workspace_restriction'> | ||
This air-gapped workspace is in read-only mode.{' '} | ||
<Box fontScale='p2' is='span'> | ||
Connect it to internet or upgraded to a premium plan to restore full functionality. | ||
</Box> | ||
</Trans> | ||
); | ||
} | ||
|
||
return ( | ||
<Trans i18nKey='Airgapped_workspace_warning2' values={{ remainingDays }}> | ||
This air-gapped workspace will enter read-only mode in <>{{ remainingDays }}</> days.{' '} | ||
<Box fontScale='p2' is='span'> | ||
Connect it to internet or upgrade to a premium plan to prevent this. | ||
</Box> | ||
</Trans> | ||
); | ||
}; | ||
|
||
export default AirGappedRestrictionWarning; |
Oops, something went wrong.