[ACA-4715] reduce env variables and provide defaults (#3311)

* use default "sessionTimeForOpenAppDialogDisplay"

* improve iPhone prefix url api

* improve android prefix url api

* session timeout

* app store url defaults

* enable mobile redirect by default

* enable AOS by default

* enable content plugins by default

* enable folder rules by default

* remove obsolete AI flag

* remove obsolete APA flag

* auto download defaults

* cleanup auth vars
This commit is contained in:
Denys Vuika 2023-07-05 15:21:45 +01:00 committed by GitHub
parent 4aee82c867
commit 46ed7a8360
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 62 additions and 156 deletions

View File

@ -26,20 +26,9 @@ runs:
{ {
echo "APP_CONFIG_ECM_HOST={protocol}//{hostname}{:port}" echo "APP_CONFIG_ECM_HOST={protocol}//{hostname}{:port}"
echo "APP_CONFIG_PLUGIN_FOLDER_RULES=true"
echo "APP_CONFIG_PLUGIN_AOS=true"
echo "APP_CONFIG_PLUGIN_CONTENT_SERVICE=true"
echo "APP_CONFIG_ENABLE_MOBILE_APP_SWITCH=false"
echo "APP_CONFIG_PROVIDER=ECM" echo "APP_CONFIG_PROVIDER=ECM"
echo "APP_CONFIG_AUTH_TYPE=BASIC" echo "APP_CONFIG_AUTH_TYPE=BASIC"
echo "APP_CONFIG_OAUTH2_HOST=http://localhost:4200/auth/realms/alfresco" echo "APP_CONFIG_OAUTH2_HOST=http://localhost:4200/auth/realms/alfresco"
echo "APP_CONFIG_OAUTH2_CLIENTID=alfresco"
echo "APP_CONFIG_SESSION_TIME_FOR_OPEN_APP_DIALOG_DISPLAY_IN_HOURS=12"
echo "APP_CONFIG_OAUTH2_IMPLICIT_FLOW=true"
echo "APP_CONFIG_OAUTH2_SILENT_LOGIN=true"
echo "APP_CONFIG_OAUTH2_REDIRECT_LOGOUT=/"
echo "APP_CONFIG_OAUTH2_REDIRECT_LOGIN=/"
echo "APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI={protocol}//{hostname}{:port}/assets/silent-refresh.html"
} >> .env } >> .env
npm start > /dev/null &\ npm start > /dev/null &\

View File

@ -27,20 +27,9 @@ runs:
{ {
echo "APP_CONFIG_ECM_HOST={protocol}//{hostname}{:port}" echo "APP_CONFIG_ECM_HOST={protocol}//{hostname}{:port}"
echo "APP_CONFIG_PLUGIN_FOLDER_RULES=true"
echo "APP_CONFIG_PLUGIN_AOS=true"
echo "APP_CONFIG_PLUGIN_CONTENT_SERVICE=true"
echo "APP_CONFIG_ENABLE_MOBILE_APP_SWITCH=false"
echo "APP_CONFIG_PROVIDER=ECM" echo "APP_CONFIG_PROVIDER=ECM"
echo "APP_CONFIG_AUTH_TYPE=BASIC" echo "APP_CONFIG_AUTH_TYPE=BASIC"
echo "APP_CONFIG_OAUTH2_HOST=http://localhost:4200/auth/realms/alfresco" echo "APP_CONFIG_OAUTH2_HOST=http://localhost:4200/auth/realms/alfresco"
echo "APP_CONFIG_OAUTH2_CLIENTID=alfresco"
echo "APP_CONFIG_SESSION_TIME_FOR_OPEN_APP_DIALOG_DISPLAY_IN_HOURS=12"
echo "APP_CONFIG_OAUTH2_IMPLICIT_FLOW=true"
echo "APP_CONFIG_OAUTH2_SILENT_LOGIN=true"
echo "APP_CONFIG_OAUTH2_REDIRECT_LOGOUT=/"
echo "APP_CONFIG_OAUTH2_REDIRECT_LOGIN=/"
echo "APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI={protocol}//{hostname}{:port}/assets/silent-refresh.html"
} >> .env } >> .env
npm start > /dev/null &\ npm start > /dev/null &\

View File

@ -29,23 +29,6 @@ env:
APP_CONFIG_AUTH_TYPE: BASIC APP_CONFIG_AUTH_TYPE: BASIC
APP_CONFIG_OAUTH2_HOST: http://localhost:4200/auth/realms/alfresco APP_CONFIG_OAUTH2_HOST: http://localhost:4200/auth/realms/alfresco
PLAYWRIGHT_E2E_HOST: ${{ secrets.PLAYWRIGHT_E2E_HOST }} PLAYWRIGHT_E2E_HOST: ${{ secrets.PLAYWRIGHT_E2E_HOST }}
APP_CONFIG_OAUTH2_CLIENTID: alfresco
APP_CONFIG_PLUGIN_AOS: true
APP_CONFIG_PLUGIN_CONTENT_SERVICE: true
APP_CONFIG_PLUGIN_FOLDER_RULES: true
APP_CONFIG_ENABLE_MOBILE_APP_SWITCH: true
APP_CONFIG_SESSION_TIME_FOR_OPEN_APP_DIALOG_DISPLAY_IN_HOURS: "12"
APP_CONFIG_OAUTH2_IMPLICIT_FLOW: true
APP_CONFIG_OAUTH2_SILENT_LOGIN: true
APP_CONFIG_OAUTH2_REDIRECT_LOGOUT: /
APP_CONFIG_OAUTH2_REDIRECT_LOGIN: /
APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI: "{protocol}//{hostname}{:port}/assets/silent-refresh.html"
APP_CONFIG_ENABLE_DOWNLOAD_PROMPT: true
APP_CONFIG_ENABLE_DOWNLOAD_PROMPT_REMINDERS: true
APP_CONFIG_DOWNLOAD_PROMPT_DELAY: 50
APP_CONFIG_DOWNLOAD_PROMPT_REMINDER_DELAY: 30
APP_CONFIG_ENABLE_FILE_AUTO_DOWNLOAD: true
APP_CONFIG_FILE_AUTO_DOWNLOAD_SIZE_THRESHOLD_IN_MB: 15
GH_BUILD_NUMBER: ${{ github.run_id }} GH_BUILD_NUMBER: ${{ github.run_id }}
MAXINSTANCES: 2 MAXINSTANCES: 2
RETRY_COUNT: 2 RETRY_COUNT: 2

View File

@ -23,17 +23,6 @@ env:
APP_CONFIG_AUTH_TYPE: BASIC APP_CONFIG_AUTH_TYPE: BASIC
APP_CONFIG_OAUTH2_HOST: http://localhost:4200/auth/realms/alfresco APP_CONFIG_OAUTH2_HOST: http://localhost:4200/auth/realms/alfresco
PLAYWRIGHT_E2E_HOST: ${{ secrets.PLAYWRIGHT_E2E_HOST }} PLAYWRIGHT_E2E_HOST: ${{ secrets.PLAYWRIGHT_E2E_HOST }}
APP_CONFIG_OAUTH2_CLIENTID: alfresco
APP_CONFIG_PLUGIN_AOS: true
APP_CONFIG_PLUGIN_CONTENT_SERVICE: true
APP_CONFIG_PLUGIN_FOLDER_RULES: true
APP_CONFIG_ENABLE_MOBILE_APP_SWITCH: true
APP_CONFIG_SESSION_TIME_FOR_OPEN_APP_DIALOG_DISPLAY_IN_HOURS: "12"
APP_CONFIG_OAUTH2_IMPLICIT_FLOW: true
APP_CONFIG_OAUTH2_SILENT_LOGIN: true
APP_CONFIG_OAUTH2_REDIRECT_LOGOUT: /
APP_CONFIG_OAUTH2_REDIRECT_LOGIN: /
APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI: "{protocol}//{hostname}{:port}/assets/silent-refresh.html"
NPM_REGISTRY_ADDRESS: ${{ secrets.NPM_REGISTRY_ADDRESS }} NPM_REGISTRY_ADDRESS: ${{ secrets.NPM_REGISTRY_ADDRESS }}

View File

@ -27,24 +27,6 @@ ENV APP_CONFIG_OAUTH2_HOST="{protocol}//{hostname}{:port}/auth/realms/alfresco"
ENV APP_CONFIG_BPM_HOST="{protocol}//{hostname}{:port}" ENV APP_CONFIG_BPM_HOST="{protocol}//{hostname}{:port}"
ENV APP_CONFIG_ECM_HOST="{protocol}//{hostname}{:port}" ENV APP_CONFIG_ECM_HOST="{protocol}//{hostname}{:port}"
ENV APP_CONFIG_OAUTH2_CLIENTID="alfresco"
ENV APP_CONFIG_OAUTH2_IMPLICIT_FLOW=true
ENV APP_CONFIG_OAUTH2_SILENT_LOGIN=true
ENV APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI="{protocol}//{hostname}{:port}/assets/silent-refresh.html"
ENV APP_CONFIG_OAUTH2_REDIRECT_LOGIN="/"
ENV APP_CONFIG_OAUTH2_REDIRECT_LOGOUT="/"
ENV APP_CONFIG_PLUGIN_AOS=true
ENV APP_CONFIG_PLUGIN_FOLDER_RULES=true
ENV APP_CONFIG_PLUGIN_CONTENT_SERVICE=true
ENV APP_CONFIG_ENABLE_MOBILE_APP_SWITCH=true
ENV APP_CONFIG_SESSION_TIME_FOR_OPEN_APP_DIALOG_DISPLAY_IN_HOURS="12"
ENV APP_CONFIG_ENABLE_DOWNLOAD_PROMPT=true
ENV APP_CONFIG_ENABLE_DOWNLOAD_PROMPT_REMINDERS=true
ENV APP_CONFIG_DOWNLOAD_PROMPT_DELAY=50
ENV APP_CONFIG_DOWNLOAD_PROMPT_REMINDER_DELAY=30
ENV APP_CONFIG_ENABLE_FILE_AUTO_DOWNLOAD=true
ENV APP_CONFIG_FILE_AUTO_DOWNLOAD_SIZE_THRESHOLD_IN_MB=15
COPY docker/default.conf.template /etc/nginx/templates/ COPY docker/default.conf.template /etc/nginx/templates/
COPY dist/$PROJECT_NAME /usr/share/nginx/html/ COPY dist/$PROJECT_NAME /usr/share/nginx/html/

View File

@ -26,32 +26,9 @@ Create an `.env` file in the project root folder with the following content
```yml ```yml
APP_CONFIG_ECM_HOST="<URL>" APP_CONFIG_ECM_HOST="<URL>"
APP_CONFIG_PLUGIN_AOS=false
APP_CONFIG_PLUGIN_CONTENT_SERVICE=true
APP_CONFIG_PLUGIN_FOLDER_RULES=true
APP_CONFIG_ENABLE_MOBILE_APP_SWITCH=false
APP_CONFIG_PROVIDER=ECM APP_CONFIG_PROVIDER=ECM
APP_CONFIG_AUTH_TYPE=BASIC APP_CONFIG_AUTH_TYPE=BASIC
APP_CONFIG_OAUTH2_HOST=http://localhost:4200/auth/realms/alfresco APP_CONFIG_OAUTH2_HOST=http://localhost:4200/auth/realms/alfresco
APP_CONFIG_OAUTH2_CLIENTID=alfresco
APP_CONFIG_PLUGIN_AOS=true
APP_CONFIG_PLUGIN_CONTENT_SERVICE=true
APP_CONFIG_PLUGIN_FOLDER_RULES=true
APP_CONFIG_ENABLE_MOBILE_APP_SWITCH=true
APP_CONFIG_SESSION_TIME_FOR_OPEN_APP_DIALOG_DISPLAY_IN_HOURS="12"
APP_CONFIG_OAUTH2_IMPLICIT_FLOW=true
APP_CONFIG_OAUTH2_SILENT_LOGIN=true
APP_CONFIG_OAUTH2_REDIRECT_LOGOUT=/
APP_CONFIG_OAUTH2_REDIRECT_LOGIN=/
APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI="{protocol}//{hostname}{:port}/assets/silent-refresh.html"
# Download Prompt configurations
APP_CONFIG_ENABLE_DOWNLOAD_PROMPT=true
APP_CONFIG_ENABLE_DOWNLOAD_PROMPT_REMINDERS=true
APP_CONFIG_DOWNLOAD_PROMPT_DELAY=<time>
APP_CONFIG_DOWNLOAD_PROMPT_REMINDER_DELAY=<time>
APP_CONFIG_ENABLE_FILE_AUTO_DOWNLOAD=true
APP_CONFIG_FILE_AUTO_DOWNLOAD_SIZE_THRESHOLD_IN_MB=<file-size>
``` ```
Where `<URL>` is the address of the ACS. Where `<URL>` is the address of the ACS.

View File

@ -7,29 +7,24 @@
"authType": "${APP_CONFIG_AUTH_TYPE}", "authType": "${APP_CONFIG_AUTH_TYPE}",
"loginRoute": "login", "loginRoute": "login",
"mobileAppSwitch": { "mobileAppSwitch": {
"enabled" : ${APP_CONFIG_ENABLE_MOBILE_APP_SWITCH}, "enabled": true
"iphoneUrl": "iosamw://",
"androidUrlPart1": "intent:///",
"androidUrlPart2": "#Intent;scheme=androidamw;package=com.alfresco.content.app;end",
"sessionTimeForOpenAppDialogDisplay": "${APP_CONFIG_SESSION_TIME_FOR_OPEN_APP_DIALOG_DISPLAY_IN_HOURS}",
"appStoreUrl": "https://apps.apple.com/us/app/alfresco-mobile-workspace/id1514434480"
}, },
"plugins": { "plugins": {
"aosPlugin": ${APP_CONFIG_PLUGIN_AOS}, "aosPlugin": true,
"contentService": ${APP_CONFIG_PLUGIN_CONTENT_SERVICE}, "contentService": true,
"folderRules": ${APP_CONFIG_PLUGIN_FOLDER_RULES} "folderRules": true
}, },
"oauth2": { "oauth2": {
"host": "${APP_CONFIG_OAUTH2_HOST}", "host": "${APP_CONFIG_OAUTH2_HOST}",
"clientId": "${APP_CONFIG_OAUTH2_CLIENTID}", "clientId": "alfresco",
"scope": "openid", "scope": "openid",
"secret": "", "secret": "",
"implicitFlow": ${APP_CONFIG_OAUTH2_IMPLICIT_FLOW}, "implicitFlow": true,
"silentLogin": ${APP_CONFIG_OAUTH2_SILENT_LOGIN}, "silentLogin": true,
"publicUrls": ["**/preview/s/*", "**/settings", "**/blank"], "publicUrls": ["**/preview/s/*", "**/settings", "**/blank"],
"redirectSilentIframeUri": "${APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI}", "redirectSilentIframeUri": "{protocol}//{hostname}{:port}/assets/silent-refresh.html",
"redirectUri": "${APP_CONFIG_OAUTH2_REDIRECT_LOGIN}", "redirectUri": "/",
"redirectUriLogout": "${APP_CONFIG_OAUTH2_REDIRECT_LOGOUT}" "redirectUriLogout": "/"
}, },
"locale": "en", "locale": "en",
"application": { "application": {
@ -1128,11 +1123,11 @@
"ai": ["ai:products", "ai:dates", "ai:places", "ai:events", "ai:organizations", "ai:people", "ai:things", "ai:quantities", "ai:creativeWorks", "ai:labels", "ai:textLines"] "ai": ["ai:products", "ai:dates", "ai:places", "ai:events", "ai:organizations", "ai:people", "ai:things", "ai:quantities", "ai:creativeWorks", "ai:labels", "ai:textLines"]
}, },
"viewer": { "viewer": {
"enableDownloadPrompt": ${APP_CONFIG_ENABLE_DOWNLOAD_PROMPT}, "enableDownloadPrompt": true,
"enableDownloadPromptReminder": ${APP_CONFIG_ENABLE_DOWNLOAD_PROMPT_REMINDERS}, "enableDownloadPromptReminder": true,
"downloadPromptDelay": ${APP_CONFIG_DOWNLOAD_PROMPT_DELAY}, "downloadPromptDelay": 50,
"downloadPromptReminderDelay": ${APP_CONFIG_DOWNLOAD_PROMPT_REMINDER_DELAY}, "downloadPromptReminderDelay": 30,
"enableFileAutoDownload": ${APP_CONFIG_ENABLE_FILE_AUTO_DOWNLOAD}, "enableFileAutoDownload": true,
"fileAutoDownloadSizeThresholdInMB": ${APP_CONFIG_FILE_AUTO_DOWNLOAD_SIZE_THRESHOLD_IN_MB} "fileAutoDownloadSizeThresholdInMB": 15
} }
} }

View File

@ -9,22 +9,12 @@ eval ALL_ARGUMENTS=("BASE_PATH"
"APP_CONFIG_BPM_HOST" "APP_CONFIG_BPM_HOST"
"APP_CONFIG_ECM_HOST" "APP_CONFIG_ECM_HOST"
"APP_CONFIG_AUTH_TYPE" "APP_CONFIG_AUTH_TYPE"
"APP_CONFIG_OAUTH2_CLIENTID"
"APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI"
"APP_CONFIG_OAUTH2_IMPLICIT_FLOW"
"APP_CONFIG_OAUTH2_SILENT_LOGIN"
"APP_CONFIG_OAUTH2_REDIRECT_LOGIN"
"APP_CONFIG_OAUTH2_REDIRECT_LOGOUT"
"APP_CONFIG_PROVIDER" "APP_CONFIG_PROVIDER"
"APP_CONFIG_APPS_DEPLOYED"
"APP_CONFIG_PLUGIN_MICROSOFT_ONLINE" "APP_CONFIG_PLUGIN_MICROSOFT_ONLINE"
"APP_CONFIG_MICROSOFT_ONLINE_AUTHORITY" "APP_CONFIG_MICROSOFT_ONLINE_AUTHORITY"
"APP_CONFIG_MICROSOFT_ONLINE_CLIENTID" "APP_CONFIG_MICROSOFT_ONLINE_CLIENTID"
"APP_CONFIG_MICROSOFT_ONLINE_OOI_URL" "APP_CONFIG_MICROSOFT_ONLINE_OOI_URL"
"APP_CONFIG_MICROSOFT_ONLINE_REDIRECT" "APP_CONFIG_MICROSOFT_ONLINE_REDIRECT"
"APP_CONFIG_PLUGIN_AOS",
"APP_CONFIG_PLUGIN_FOLDER_RULES",
"APP_CONFIG_PLUGIN_AI_SERVICE"
) )
ALL_ARGUMENTS_LENGTH=${#ALL_ARGUMENTS[@]} ALL_ARGUMENTS_LENGTH=${#ALL_ARGUMENTS[@]}
DOCKER_ARGS="" DOCKER_ARGS=""

View File

@ -35,9 +35,6 @@ You need to set some environment variables to be able to run the local dev serve
```yml ```yml
# App config settings # App config settings
APP_CONFIG_ECM_HOST="<URL>" APP_CONFIG_ECM_HOST="<URL>"
APP_CONFIG_PLUGIN_AOS=false
APP_CONFIG_PLUGIN_CONTENT_SERVICE=true
APP_CONFIG_PLUGIN_FOLDER_RULES=true
``` ```
## Proxy settings ## Proxy settings

View File

@ -7,7 +7,7 @@
"postinstall": "ngcc", "postinstall": "ngcc",
"ng": "ng", "ng": "ng",
"validate-app-config": "ajv validate -s ./node_modules/@alfresco/adf-core/app.config.schema.json -d ./app/.tmp/app.config.json --errors=text --verbose", "validate-app-config": "ajv validate -s ./node_modules/@alfresco/adf-core/app.config.schema.json -d ./app/.tmp/app.config.json --errors=text --verbose",
"assemble-app-config": "envsub --env-file ./.env --env APP_CONFIG_ECM_HOST={protocol}//{hostname}{:port} --env APP_CONFIG_PROVIDER=ECM --env APP_CONFIG_AUTH_TYPE=BASIC --env APP_CONFIG_OAUTH2_HOST=http://localhost:4200/auth/realms/alfresco --env APP_CONFIG_OAUTH2_CLIENTID=alfresco --env APP_CONFIG_OAUTH2_IMPLICIT_FLOW=true --env APP_CONFIG_OAUTH2_SILENT_LOGIN=true --env APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI={protocol}//{hostname}{:port}/assets/silent-refresh.html --env APP_CONFIG_OAUTH2_REDIRECT_LOGIN=/ --env APP_CONFIG_OAUTH2_REDIRECT_LOGOUT=/logout --all ./app/src/app.config.json.tpl ./app/.tmp/app.config.json", "assemble-app-config": "envsub --env-file ./.env --env APP_CONFIG_ECM_HOST={protocol}//{hostname}{:port} --env APP_CONFIG_PROVIDER=ECM --env APP_CONFIG_AUTH_TYPE=BASIC --env APP_CONFIG_OAUTH2_HOST=http://localhost:4200/auth/realms/alfresco --all ./app/src/app.config.json.tpl ./app/.tmp/app.config.json",
"prestart": "mkdir -p ./app/.tmp && npm run assemble-app-config && npm run validate-app-config", "prestart": "mkdir -p ./app/.tmp && npm run assemble-app-config && npm run validate-app-config",
"start": "nx serve content-ce", "start": "nx serve content-ce",
"start:prod": "npm run validate-app-config && node --max-old-space-size=8192 nx serve content-ce --configuration production", "start:prod": "npm run validate-app-config && node --max-old-space-size=8192 nx serve content-ce --configuration production",

View File

@ -0,0 +1,16 @@
# Open in Mobile Application
Configuring via `app.config.json`:
```json
{
"mobileAppSwitch": {
"enabled": true,
"iphoneUrl": "iosamw://",
"androidUrlPart1": "intent:///",
"androidUrlPart2": "#Intent;scheme=androidamw;package=com.alfresco.content.app;end",
"sessionTimeout": 12,
"appStoreUrl": "https://apps.apple.com/us/app/alfresco-mobile-workspace/id1514434480"
}
}
```

View File

@ -45,11 +45,7 @@ describe('AcaMobileAppSwitcherService', () => {
}); });
appConfig = TestBed.inject(AppConfigService); appConfig = TestBed.inject(AppConfigService);
appConfig.config.mobileAppSwitch = { appConfig.config.mobileAppSwitch = {
enabled: true, enabled: true
iphoneUrl: 'iosamw://',
androidUrlPart1: 'intent:///',
androidUrlPart2: '#Intent;scheme=androidamw;package=com.alfresco.content.app;end',
sessionTimeForOpenAppDialogDisplay: 12
}; };
service = TestBed.inject(AcaMobileAppSwitcherService); service = TestBed.inject(AcaMobileAppSwitcherService);
sessionStorage.clear(); sessionStorage.clear();
@ -58,15 +54,14 @@ describe('AcaMobileAppSwitcherService', () => {
it('should set the redirectUrl to `iphoneUrl`', () => { it('should set the redirectUrl to `iphoneUrl`', () => {
spyOnProperty(window.navigator, 'userAgent').and.returnValue('iphone'); spyOnProperty(window.navigator, 'userAgent').and.returnValue('iphone');
const url: string = window.location.href; const url: string = window.location.href;
const iphoneUrl: string = appConfig.config.mobileAppSwitch.iphoneUrl + url; const iphoneUrl = service.getIPhoneRedirectUrl(url);
service.identifyBrowserAndSetRedirectURL(); service.identifyBrowserAndSetRedirectURL();
expect(service.redirectUrl).toEqual(iphoneUrl); expect(service.redirectUrl).toEqual(iphoneUrl);
}); });
it('should set the redirectUrl to `androidUrl`', () => { it('should set the redirectUrl to `androidUrl`', () => {
spyOnProperty(window.navigator, 'userAgent').and.returnValue('android'); spyOnProperty(window.navigator, 'userAgent').and.returnValue('android');
const url: string = window.location.href; const androidUrl = service.getAndroidRedirectUrl(window.location.href);
const androidUrl: string = appConfig.config.mobileAppSwitch.androidUrlPart1 + url + appConfig.config.mobileAppSwitch.androidUrlPart2;
service.identifyBrowserAndSetRedirectURL(); service.identifyBrowserAndSetRedirectURL();
expect(service.redirectUrl).toEqual(androidUrl); expect(service.redirectUrl).toEqual(androidUrl);
}); });
@ -86,15 +81,13 @@ describe('AcaMobileAppSwitcherService', () => {
}); });
it('should check if `openInApp` dialog box is getting opened with `iphone` url', () => { it('should check if `openInApp` dialog box is getting opened with `iphone` url', () => {
const url: string = window.location.href; service.redirectUrl = service.getIPhoneRedirectUrl(window.location.href);
service.redirectUrl = appConfig.config.mobileAppSwitch.iphoneUrl + url;
service.identifyBrowserAndSetRedirectURL(); service.identifyBrowserAndSetRedirectURL();
expect(mockDialogRef.open).toHaveBeenCalled(); expect(mockDialogRef.open).toHaveBeenCalled();
}); });
it('should check if `openInApp` dialog box is getting opened with `android` url', () => { it('should check if `openInApp` dialog box is getting opened with `android` url', () => {
const url: string = window.location.href; service.redirectUrl = service.getAndroidRedirectUrl(window.location.href);
service.redirectUrl = appConfig.config.mobileAppSwitch.androidUrlPart1 + url + appConfig.config.mobileAppSwitch.androidUrlPart2;
service.identifyBrowserAndSetRedirectURL(); service.identifyBrowserAndSetRedirectURL();
expect(mockDialogRef.open).toHaveBeenCalled(); expect(mockDialogRef.open).toHaveBeenCalled();
}); });

View File

@ -23,29 +23,37 @@
*/ */
import { AppConfigService } from '@alfresco/adf-core'; import { AppConfigService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core'; import { inject, Injectable } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog'; import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { OpenInAppComponent } from '../components/open-in-app/open-in-app.component'; import { OpenInAppComponent } from '../components/open-in-app/open-in-app.component';
export interface MobileAppSwitchConfigurationOptions {
enabled: string;
iphoneUrl: string;
androidUrlPart1: string;
androidUrlPart2: string;
sessionTimeForOpenAppDialogDisplay: string;
appStoreUrl: string;
}
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class AcaMobileAppSwitcherService { export class AcaMobileAppSwitcherService {
private mobileAppSwitchConfig: MobileAppSwitchConfigurationOptions;
public redirectUrl: string; public redirectUrl: string;
public appStoreUrl: string;
private dialogRef: MatDialogRef<OpenInAppComponent>; private dialogRef: MatDialogRef<OpenInAppComponent>;
private config = inject(AppConfigService);
private dialog = inject(MatDialog);
constructor(private config: AppConfigService, private dialog: MatDialog) { get appStoreUrl(): string {
this.mobileAppSwitchConfig = this.config.get<MobileAppSwitchConfigurationOptions>('mobileAppSwitch'); const defaultValue = 'https://apps.apple.com/us/app/alfresco-mobile-workspace/id1514434480';
return this.config.get<string>('mobileAppSwitch.appStoreUrl', defaultValue);
}
get sessionTimeout(): number {
return this.config.get<number>('mobileAppSwitch.sessionTimeout', 12);
}
getIPhoneRedirectUrl(url: string): string {
const prefix = this.config.get<string>('mobileAppSwitch.iphoneUrl', 'iosamw://');
return prefix + url;
}
getAndroidRedirectUrl(url: string): string {
const prefix = this.config.get<string>('mobileAppSwitch.androidUrlPart1', 'intent:///');
const suffix = this.config.get<string>('mobileAppSwitch.androidUrlPart2', '#Intent;scheme=androidamw;package=com.alfresco.content.app;end');
return prefix + url + suffix;
} }
resolveExistenceOfDialog(): void { resolveExistenceOfDialog(): void {
@ -68,9 +76,8 @@ export class AcaMobileAppSwitcherService {
const currentTime: number = new Date().getTime(); const currentTime: number = new Date().getTime();
const sessionConvertedTime: number = parseFloat(sessionTime); const sessionConvertedTime: number = parseFloat(sessionTime);
const timeDifference: number = (currentTime - sessionConvertedTime) / (1000 * 60 * 60); const timeDifference: number = (currentTime - sessionConvertedTime) / (1000 * 60 * 60);
const sessionTimeForOpenAppDialogDisplay: number = parseFloat(this.mobileAppSwitchConfig.sessionTimeForOpenAppDialogDisplay);
if (timeDifference > sessionTimeForOpenAppDialogDisplay) { if (timeDifference > this.sessionTimeout) {
this.clearSessionExpireTime(); this.clearSessionExpireTime();
this.identifyBrowserAndSetRedirectURL(); this.identifyBrowserAndSetRedirectURL();
} }
@ -87,10 +94,9 @@ export class AcaMobileAppSwitcherService {
const currentUrl: string = this.getCurrentUrl(); const currentUrl: string = this.getCurrentUrl();
if (isIOS === true) { if (isIOS === true) {
this.redirectUrl = this.mobileAppSwitchConfig.iphoneUrl + currentUrl; this.redirectUrl = this.getIPhoneRedirectUrl(currentUrl);
this.appStoreUrl = this.mobileAppSwitchConfig.appStoreUrl;
} else if (isAndroid === true) { } else if (isAndroid === true) {
this.redirectUrl = this.mobileAppSwitchConfig.androidUrlPart1 + currentUrl + this.mobileAppSwitchConfig.androidUrlPart2; this.redirectUrl = this.getAndroidRedirectUrl(currentUrl);
} }
if (this.redirectUrl !== undefined && this.redirectUrl !== null) { if (this.redirectUrl !== undefined && this.redirectUrl !== null) {