[Gekidou] Show alert message when server is unsupported (#6764)

* Show alert message when server is unsupported

* set server min required version to 5.26.2
This commit is contained in:
Elias Nahum
2022-11-18 12:18:11 +02:00
committed by GitHub
parent 6dd7fc9fc5
commit 2a6bb1ddc1
15 changed files with 199 additions and 151 deletions

View File

@@ -8,16 +8,21 @@ import CompassIcon from '@components/compass_icon';
import {Screens, Sso, SupportedServer, Launch} from '@constants';
import {dismissBottomSheet, showModal} from '@screens/navigation';
import {getErrorMessage} from '@utils/client_error';
import {isMinimumServerVersion} from '@utils/helpers';
import {changeOpacity} from '@utils/theme';
import {tryOpenURL} from '@utils/url';
import type ServersModel from '@typings/database/models/app/servers';
export function unsupportedServer(isSystemAdmin: boolean, intl: IntlShape) {
export function isSupportedServer(currentVersion: string) {
return isMinimumServerVersion(currentVersion, SupportedServer.MAJOR_VERSION, SupportedServer.MIN_VERSION, SupportedServer.PATCH_VERSION);
}
export function unsupportedServer(serverDisplayName: string, isSystemAdmin: boolean, intl: IntlShape, onPress?: () => void) {
if (isSystemAdmin) {
return unsupportedServerAdminAlert(intl);
return unsupportedServerAdminAlert(serverDisplayName, intl, onPress);
}
return unsupportedServerAlert(intl);
return unsupportedServerAlert(serverDisplayName, intl, onPress);
}
export function semverFromServerVersion(value: string) {
@@ -179,21 +184,22 @@ export function alertServerAlreadyConnected(intl: IntlShape) {
);
}
function unsupportedServerAdminAlert(intl: IntlShape) {
function unsupportedServerAdminAlert(serverDisplayName: string, intl: IntlShape, onPress?: () => void) {
const title = intl.formatMessage({id: 'mobile.server_upgrade.title', defaultMessage: 'Server upgrade required'});
const message = intl.formatMessage({
id: 'mobile.server_upgrade.alert_description',
defaultMessage: 'This server version is unsupported and users will be exposed to compatibility issues that cause crashes or severe bugs breaking core functionality of the app. Upgrading to server version {serverVersion} or later is required.',
}, {serverVersion: SupportedServer.FULL_VERSION});
id: 'server_upgrade.alert_description',
defaultMessage: 'Your server, {serverDisplayName}, is running an unsupported server version. Users will be exposed to compatibility issues that cause crashes or severe bugs breaking core functionality of the app. Upgrading to server version {supportedServerVersion} or later is required.',
}, {serverDisplayName, supportedServerVersion: SupportedServer.FULL_VERSION});
const cancel: AlertButton = {
text: intl.formatMessage({id: 'mobile.server_upgrade.dismiss', defaultMessage: 'Dismiss'}),
text: intl.formatMessage({id: 'server_upgrade.dismiss', defaultMessage: 'Dismiss'}),
style: 'default',
onPress,
};
const learnMore: AlertButton = {
text: intl.formatMessage({id: 'mobile.server_upgrade.learn_more', defaultMessage: 'Learn More'}),
text: intl.formatMessage({id: 'server_upgrade.learn_more', defaultMessage: 'Learn More'}),
style: 'cancel',
onPress: () => {
const url = 'https://docs.mattermost.com/administration/release-lifecycle.html';
@@ -213,17 +219,18 @@ function unsupportedServerAdminAlert(intl: IntlShape) {
Alert.alert(title, message, buttons, options);
}
function unsupportedServerAlert(intl: IntlShape) {
const title = intl.formatMessage({id: 'mobile.unsupported_server.title', defaultMessage: 'Unsupported server version'});
function unsupportedServerAlert(serverDisplayName: string, intl: IntlShape, onPress?: () => void) {
const title = intl.formatMessage({id: 'unsupported_server.title', defaultMessage: 'Unsupported server version'});
const message = intl.formatMessage({
id: 'mobile.unsupported_server.message',
defaultMessage: 'Attachments, link previews, reactions and embed data may not be displayed correctly. If this issue persists contact your System Administrator to upgrade your Mattermost server.',
});
id: 'unsupported_server.message',
defaultMessage: 'Your server, {serverDisplayName}, is running an unsupported server version. You may experience compatibility issues that cause crashes or severe bugs breaking core functionality of the app. Please contact your System Administrator to upgrade your Mattermost server.',
}, {serverDisplayName});
const okButton: AlertButton = {
text: intl.formatMessage({id: 'mobile.unsupported_server.ok', defaultMessage: 'OK'}),
text: intl.formatMessage({id: 'mobile.server_upgrade.button', defaultMessage: 'OK'}),
style: 'default',
onPress,
};
const buttons: AlertButton[] = [okButton];

View File

@@ -12,13 +12,13 @@ describe('Unsupported Server Alert', () => {
it('should show the alert for sysadmin', () => {
const alert = jest.spyOn(Alert, 'alert');
unsupportedServer(true, intl);
unsupportedServer('Default Server', true, intl);
expect(alert?.mock?.calls?.[0]?.[2]?.length).toBe(2);
});
it('should show the alert for team admin / user', () => {
const alert = jest.spyOn(Alert, 'alert');
unsupportedServer(false, intl);
unsupportedServer('Default Server', false, intl);
expect(alert?.mock?.calls?.[0]?.[2]?.length).toBe(1);
});
});