From fce88575857bb84c57d9719861d5e1d35c524d26 Mon Sep 17 00:00:00 2001 From: Antonio Felix Date: Tue, 8 Feb 2022 13:18:28 +0000 Subject: [PATCH] MNT-22687- Add new aosPlugin variable to hide or show the AOS plugin (#2382) * MNT-22687- Add new aosPlugin variable to hide or show the AOS plugin * MNT-22687 - Added a new interface to extend the RuleContext from ADF * MNT-22687 - Removed carriage return and added whitespaces * MNT-22687 - Removed carriage returns * MNT-22687 - Fixed PR Comments Completed documentation, removed environment variable from the package.json, added plugins section in the app.config.json.tpl * MNT-22687 - Created a new service to deal with the new functionality. Reverted the old approach. * MNT-22687 - Reverted missing file * MNT-22687 - Reverted missing file * MNT-22687 - Removed variable replacement * MNT-22687 - Included environment variables in the README.md file --- .travis.yml | 1 + README.md | 21 +++++ app/src/app.config.json.tpl | 3 + docker/run.sh | 1 + .../alfresco-office-extension.service.spec.ts | 88 +++++++++++++++++++ .../alfresco-office-extension.service.ts | 64 ++++++++++++++ projects/adf-office-services-ext/README.md | 8 ++ .../src/lib/aos-extension.module.ts | 15 +++- scripts/app-config-replace.js | 1 + 9 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 projects/aca-shared/src/lib/services/alfresco-office-extension.service.spec.ts create mode 100644 projects/aca-shared/src/lib/services/alfresco-office-extension.service.ts diff --git a/.travis.yml b/.travis.yml index db29dc277..7b12ce497 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,6 +49,7 @@ env: - APP_CONFIG_AUTH_TYPE=BASIC - APP_CONFIG_OAUTH2_HOST=http://localhost:4200/auth/realms/alfresco - APP_CONFIG_OAUTH2_CLIENTID=alfresco + - APP_CONFIG_PLUGIN_AOS=true - APP_CONFIG_OAUTH2_IMPLICIT_FLOW=true - APP_CONFIG_OAUTH2_SILENT_LOGIN=true - APP_CONFIG_OAUTH2_REDIRECT_LOGOUT=/ diff --git a/README.md b/README.md index 772860671..be4d79d56 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,24 @@ Please refer to the [Public documentation](https://alfresco-content-app.netlify. | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | | master | [![Build Status](https://travis-ci.com/Alfresco/alfresco-content-app.svg?branch=master)](https://travis-ci.com/Alfresco/alfresco-content-app) | | develop | [![Build Status](https://travis-ci.org/Alfresco/alfresco-content-app.svg?branch=develop)](https://travis-ci.com/Alfresco/alfresco-content-app) | + +## Setting up environment variables + +We need to set some environment variable to be able to run the local dev server. In the project root folder, create an `.env` file (this is gitignored) with the following data: + +```bash +# App config settings +APP_CONFIG_BPM_HOST="" +APP_CONFIG_ECM_HOST="" +APP_CONFIG_OAUTH2_HOST="" +APP_CONFIG_IDENTITY_HOST="" +APP_CONFIG_PROVIDER="ALL" +APP_CONFIG_AUTH_TYPE="OAUTH" +APP_CONFIG_OAUTH2_CLIENTID="alfresco" +APP_CONFIG_OAUTH2_IMPLICIT_FLOW=true +APP_CONFIG_OAUTH2_SILENT_LOGIN=true +APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI="{protocol}//{hostname}{:port}/assets/silent-refresh.html" +APP_CONFIG_OAUTH2_REDIRECT_LOGIN=/ +APP_CONFIG_OAUTH2_REDIRECT_LOGOUT=/ +# CONTENT - ALFRESCO OFFICE SERVICES PLUGIN RELATED +APP_CONFIG_PLUGIN_AOS=true diff --git a/app/src/app.config.json.tpl b/app/src/app.config.json.tpl index 46e385ba4..110c1ebda 100644 --- a/app/src/app.config.json.tpl +++ b/app/src/app.config.json.tpl @@ -6,6 +6,9 @@ "providers": "${APP_CONFIG_PROVIDER}", "authType": "${APP_CONFIG_AUTH_TYPE}", "loginRoute": "login", + "plugins":{ + "aosPlugin" : ${APP_CONFIG_PLUGIN_AOS} + }, "oauth2": { "host": "${APP_CONFIG_OAUTH2_HOST}", "clientId": "${APP_CONFIG_OAUTH2_CLIENTID}", diff --git a/docker/run.sh b/docker/run.sh index 7d0c9174b..d13f61fd3 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -23,4 +23,5 @@ docker run --rm -it \ --env APP_CONFIG_ECM_HOST=$APP_CONFIG_ECM_HOST \ --env APP_BASE_SHARE_URL=$APP_BASE_SHARE_URL \ --env APP_EXTENSIONS_IGNORE_REFS=$APP_EXTENSIONS_IGNORE_REFS \ + --env APP_CONFIG_PLUGIN_AOS=${APP_CONFIG_PLUGIN_AOS} \ --user 1000:1000 --publish $HOST_PORT:$CONTAINER_PORT $DOCKER_IMAGE_REPO diff --git a/projects/aca-shared/src/lib/services/alfresco-office-extension.service.spec.ts b/projects/aca-shared/src/lib/services/alfresco-office-extension.service.spec.ts new file mode 100644 index 000000000..e50dcffba --- /dev/null +++ b/projects/aca-shared/src/lib/services/alfresco-office-extension.service.spec.ts @@ -0,0 +1,88 @@ +/*! + * @license + * Alfresco Example Content Application + * + * Copyright (C) 2005 - 2020 Alfresco Software Limited + * + * This file is part of the Alfresco Example Content Application. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * The Alfresco Example Content Application is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The Alfresco Example Content Application is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +import { TestBed } from '@angular/core/testing'; +import { AppConfigService } from '@alfresco/adf-core'; +import { AlfrescoOfficeExtensionService } from './alfresco-office-extension.service'; +import { provideMockStore } from '@ngrx/store/testing'; +import { initialState, LibTestingModule } from '../testing/lib-testing-module'; + +describe('AlfrescoOfficeExtensionService', () => { + let appConfig: AppConfigService; + let service: AlfrescoOfficeExtensionService; + const mock = () => { + let storage: { [key: string]: any } = {}; + return { + getItem: (key: string) => (key in storage ? storage[key] : null), + setItem: (key: string, value: any) => (storage[key] = value || ''), + removeItem: (key: string) => delete storage[key], + clear: () => (storage = {}) + }; + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [LibTestingModule], + providers: [provideMockStore({ initialState })] + }); + + service = TestBed.inject(AlfrescoOfficeExtensionService); + + appConfig = TestBed.inject(AppConfigService); + appConfig.config = Object.assign(appConfig.config, { + aosPlugin: true + }); + + Object.defineProperty(window, 'localStorage', { value: mock() }); + }); + + it('Should initialize the localStorage with the item aosPlugin true if not present', () => { + expect(localStorage.getItem('aosPlugin')).toBeNull('The localStorage aosPlugin is not null'); + service.enablePlugin(); + expect(localStorage.getItem('aosPlugin')).toBe('true'); + expect(service.isAosPluginEnabled()).toBe(true); + }); + + it('Should not change the item aosPlugin value if false', () => { + localStorage.setItem('aosPlugin', 'false'); + service.enablePlugin(); + expect(localStorage.getItem('aosPlugin')).toBe('false'); + expect(service.isAosPluginEnabled()).toBe(false); + }); + + it('Should not change the item aosPlugin value if true', () => { + localStorage.setItem('aosPlugin', 'true'); + service.enablePlugin(); + expect(localStorage.getItem('aosPlugin')).toBe('true'); + expect(service.isAosPluginEnabled()).toBe(true); + }); + + it('Should change the item aosPlugin disabled', () => { + localStorage.setItem('aosPlugin', 'true'); + service.disablePlugin(); + expect(localStorage.getItem('aosPlugin')).toBeNull(); + expect(service.isAosPluginEnabled()).toBe(false); + }); +}); diff --git a/projects/aca-shared/src/lib/services/alfresco-office-extension.service.ts b/projects/aca-shared/src/lib/services/alfresco-office-extension.service.ts new file mode 100644 index 000000000..7e0b99091 --- /dev/null +++ b/projects/aca-shared/src/lib/services/alfresco-office-extension.service.ts @@ -0,0 +1,64 @@ +/*! + * @license + * Alfresco Example Content Application + * + * Copyright (C) 2005 - 2020 Alfresco Software Limited + * + * This file is part of the Alfresco Example Content Application. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * The Alfresco Example Content Application is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The Alfresco Example Content Application is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +import { Injectable } from '@angular/core'; +import { AppConfigService } from '@alfresco/adf-core'; +import { map, take } from 'rxjs/operators'; + +@Injectable({ + providedIn: 'root' +}) +export class AlfrescoOfficeExtensionService { + constructor(private appConfigService: AppConfigService) { + this.appConfigService.onLoad + .pipe( + take(1), + map((appConfig) => { + return appConfig.plugins && appConfig.plugins.aosPlugin; + }) + ) + .subscribe((aosPlugin) => { + if (aosPlugin) { + this.enablePlugin(); + } else { + this.disablePlugin(); + } + }); + } + + enablePlugin() { + if (localStorage && localStorage.getItem('aosPlugin') === null) { + localStorage.setItem('aosPlugin', 'true'); + } + } + + disablePlugin() { + localStorage.removeItem('aosPlugin'); + } + + isAosPluginEnabled() { + return localStorage && localStorage.getItem('aosPlugin') === 'true'; + } +} diff --git a/projects/adf-office-services-ext/README.md b/projects/adf-office-services-ext/README.md index f8f8cb161..f455644a4 100644 --- a/projects/adf-office-services-ext/README.md +++ b/projects/adf-office-services-ext/README.md @@ -70,3 +70,11 @@ Update `app.extensions.json` and append a reference to the plugin definition: "$references": ["aos.plugin.json"] } ``` + +## Disable and Enable the extension after it is installed + +There's an environment that can disable or enable the installed extension. + +In the `app.config.json` file there's a `aosPlugin` boolean variable where you can toggle the value `false` or `true` if you want to hide or show the extension. + +The extension is enabled by default. diff --git a/projects/adf-office-services-ext/src/lib/aos-extension.module.ts b/projects/adf-office-services-ext/src/lib/aos-extension.module.ts index cba5b36d6..26fae1e54 100644 --- a/projects/adf-office-services-ext/src/lib/aos-extension.module.ts +++ b/projects/adf-office-services-ext/src/lib/aos-extension.module.ts @@ -28,6 +28,7 @@ import { NgModule } from '@angular/core'; import { EffectsModule } from '@ngrx/effects'; import { AosEffects } from './effects/aos.effects'; import { TranslationService } from '@alfresco/adf-core'; +import { AlfrescoOfficeExtensionService } from 'projects/aca-shared/src/lib/services/alfresco-office-extension.service'; import { canOpenWithOffice } from './evaluators'; @NgModule({ @@ -35,10 +36,16 @@ import { canOpenWithOffice } from './evaluators'; providers: [provideExtensionConfig(['aos.plugin.json'])] }) export class AosExtensionModule { - constructor(extensions: ExtensionService, translation: TranslationService) { + constructor(extensions: ExtensionService, translation: TranslationService, aosService: AlfrescoOfficeExtensionService) { translation.addTranslationFolder('adf-office-services-ext', 'assets/adf-office-services-ext'); - extensions.setEvaluators({ - 'aos.canOpenWithOffice': canOpenWithOffice - }); + if (!aosService.isAosPluginEnabled()) { + extensions.setEvaluators({ + 'aos.canOpenWithOffice': () => false + }); + } else { + extensions.setEvaluators({ + 'aos.canOpenWithOffice': canOpenWithOffice + }); + } } } diff --git a/scripts/app-config-replace.js b/scripts/app-config-replace.js index 886c098ac..652d20b51 100755 --- a/scripts/app-config-replace.js +++ b/scripts/app-config-replace.js @@ -9,6 +9,7 @@ const APP_CONFIG_BPM_HOST = process.env.APP_CONFIG_BPM_HOST; const APP_CONFIG_OAUTH2_HOST = process.env.APP_CONFIG_OAUTH2_HOST || 'oauth-host-default-replaced-value'; const APP_CONFIG_IDENTITY_HOST = process.env.APP_CONFIG_IDENTITY_HOST || 'identity-host-default-replaced-value'; const APP_CONFIG_NOTIFICATION_LAST = parseInt(process.env.APP_CONFIG_NOTIFICATION_LAST, 10) || 2000; +const APP_CONFIG_PLUGIN_AOS = process.env.APP_CONFIG_PLUGIN_AOS || true; const options = { apiHost: {