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
This commit is contained in:
Antonio Felix 2022-02-08 13:18:28 +00:00 committed by GitHub
parent 9b8ae32aad
commit fce8857585
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 198 additions and 4 deletions

View File

@ -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=/

View File

@ -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="<url>"
APP_CONFIG_ECM_HOST="<url>"
APP_CONFIG_OAUTH2_HOST="<url>"
APP_CONFIG_IDENTITY_HOST="<url>"
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

View File

@ -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}",

View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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);
});
});

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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';
}
}

View File

@ -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.

View File

@ -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
});
}
}
}

View File

@ -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: {