diff --git a/.travis.yml b/.travis.yml index 8c2026d6b..26265fa1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,6 +50,7 @@ env: - APP_CONFIG_OAUTH2_HOST=http://localhost:4200/auth/realms/alfresco - APP_CONFIG_OAUTH2_CLIENTID=alfresco - APP_CONFIG_PLUGIN_AOS=true + - APP_CONFIG_CONTENT_SERVICE=true - APP_CONFIG_OAUTH2_IMPLICIT_FLOW=true - APP_CONFIG_OAUTH2_SILENT_LOGIN=true - APP_CONFIG_OAUTH2_REDIRECT_LOGOUT=/ diff --git a/Dockerfile b/Dockerfile index 37042d6fb..d12ae6456 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,6 +34,7 @@ ENV APP_CONFIG_OAUTH2_REDIRECT_SILENT_IFRAME_URI="{protocol}//{hostname}{:port}/ ENV APP_CONFIG_OAUTH2_REDIRECT_LOGIN="/" ENV APP_CONFIG_OAUTH2_REDIRECT_LOGOUT="/" ENV APP_CONFIG_PLUGIN_AOS=true +ENV APP_CONFIG_CONTENT_SERVICE=true COPY docker/default.conf.template /etc/nginx/templates/ COPY docker/docker-entrypoint.d/* /docker-entrypoint.d/ diff --git a/README.md b/README.md index be4d79d56..3619e1464 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,5 @@ APP_CONFIG_OAUTH2_REDIRECT_LOGIN=/ APP_CONFIG_OAUTH2_REDIRECT_LOGOUT=/ # CONTENT - ALFRESCO OFFICE SERVICES PLUGIN RELATED APP_CONFIG_PLUGIN_AOS=true +# ALFRESCO CONTENT SERVICE RELATED +APP_CONFIG_CONTENT_SERVICE=true diff --git a/app/src/app.config.json.tpl b/app/src/app.config.json.tpl index 15f196209..707f7d95e 100644 --- a/app/src/app.config.json.tpl +++ b/app/src/app.config.json.tpl @@ -7,7 +7,8 @@ "authType": "${APP_CONFIG_AUTH_TYPE}", "loginRoute": "login", "plugins":{ - "aosPlugin" : ${APP_CONFIG_PLUGIN_AOS} + "aosPlugin" : ${APP_CONFIG_PLUGIN_AOS}, + "contentService": ${APP_CONFIG_CONTENT_SERVICE} }, "oauth2": { "host": "${APP_CONFIG_OAUTH2_HOST}", diff --git a/app/src/app/extensions/core.extensions.module.ts b/app/src/app/extensions/core.extensions.module.ts index 0c1174087..9ab36596b 100644 --- a/app/src/app/extensions/core.extensions.module.ts +++ b/app/src/app/extensions/core.extensions.module.ts @@ -54,6 +54,7 @@ import { LanguagePickerComponent } from '../components/common/language-picker/la import { LogoutComponent } from '../components/common/logout/logout.component'; import { AppExtensionService, ExtensionsDataLoaderGuard } from '@alfresco/aca-shared'; import { PreviewComponent } from '../components/preview/preview.component'; +import { ContentServiceExtensionService } from '../services/content-service-extension.service'; // eslint-disable-next-line prefer-arrow/prefer-arrow-functions export function setupExtensions(service: AppExtensionService): () => void { @@ -71,7 +72,7 @@ export class CoreExtensionsModule { { provide: APP_INITIALIZER, useFactory: setupExtensions, - deps: [AppExtensionService], + deps: [AppExtensionService, ContentServiceExtensionService], multi: true } ] @@ -181,7 +182,8 @@ export class CoreExtensionsModule { 'repository.isQuickShareEnabled': rules.hasQuickShareEnabled, 'user.isAdmin': rules.isAdmin, - 'app.canShowLogout': rules.canShowLogout + 'app.canShowLogout': rules.canShowLogout, + 'app.isContentServiceEnabled': rules.isContentServiceEnabled }); } } diff --git a/app/src/app/services/content-service-extension.service.spec.ts b/app/src/app/services/content-service-extension.service.spec.ts new file mode 100644 index 000000000..c0f86fe1b --- /dev/null +++ b/app/src/app/services/content-service-extension.service.spec.ts @@ -0,0 +1,56 @@ +/* + * Copyright © 2005 - 2021 Alfresco Software, Ltd. All rights reserved. + * + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +import { ContentServiceExtensionService } from './content-service-extension.service'; +import { AppConfigService, AppConfigServiceMock, setupTestBed } from '@alfresco/adf-core'; +import { TestBed } from '@angular/core/testing'; +import { of } from 'rxjs'; +import { HttpClientModule } from '@angular/common/http'; + +describe('ContentServiceExtensionService', () => { + let service: ContentServiceExtensionService; + let appConfig: AppConfigService; + + setupTestBed({ + imports: [HttpClientModule], + providers: [{ provide: AppConfigService, useClass: AppConfigServiceMock }] + }); + + beforeEach(() => { + service = TestBed.inject(ContentServiceExtensionService); + appConfig = TestBed.inject(AppConfigService); + appConfig.config = Object.assign(appConfig.config, { + plugins: { + contentService: true + } + }); + + appConfig.load(); + appConfig.onLoad = of(appConfig.config); + }); + + it('should set the content service to true when it is false in local storage and enabled in the app config', () => { + localStorage.setItem('contentService', 'false'); + service.updateContentServiceAvailability(); + + expect(localStorage.getItem('contentService')).toEqual('true'); + }); + + it('should set the content service to false in local storage when it is false in the app config', () => { + appConfig.config.plugins.contentService = false; + appConfig.load(); + appConfig.onLoad = of(appConfig.config); + service.updateContentServiceAvailability(); + + expect(localStorage.getItem('contentService')).toEqual('false'); + }); + + afterEach(() => { + localStorage.clear(); + }); +}); diff --git a/app/src/app/services/content-service-extension.service.ts b/app/src/app/services/content-service-extension.service.ts new file mode 100644 index 000000000..e25c95783 --- /dev/null +++ b/app/src/app/services/content-service-extension.service.ts @@ -0,0 +1,42 @@ +/* + * Copyright © 2005 - 2021 Alfresco Software, Ltd. All rights reserved. + * + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + */ + +import { Injectable } from '@angular/core'; +import { AppConfigService } from '@alfresco/adf-core'; +import { take } from 'rxjs/operators'; + +@Injectable({ + providedIn: 'root' +}) +export class ContentServiceExtensionService { + constructor(private appConfigService: AppConfigService) { + this.updateContentServiceAvailability(); + } + + updateContentServiceAvailability() { + this.appConfigService.onLoad.pipe(take(1)).subscribe((config) => { + if (config.plugins && config.plugins.contentService === false) { + this.disableContentServices(); + } else { + this.enableContentServices(); + } + }); + } + + private disableContentServices() { + if (localStorage) { + localStorage.setItem('contentService', 'false'); + } + } + + private enableContentServices() { + if (localStorage && localStorage.getItem('contentService') === 'false') { + localStorage.setItem('contentService', 'true'); + } + } +} diff --git a/app/src/assets/app.extensions.json b/app/src/assets/app.extensions.json index 18add811a..08dfa2329 100644 --- a/app/src/assets/app.extensions.json +++ b/app/src/assets/app.extensions.json @@ -241,6 +241,9 @@ "icon": "library_books", "title": "APP.BROWSE.LIBRARIES.SIDENAV_LINK.LABEL", "description": "APP.BROWSE.LIBRARIES.SIDENAV_LINK.TOOLTIP", + "rules": { + "visible": "app.isContentServiceEnabled" + }, "children": [ { "id": "app.navbar.libraries.favorite", @@ -262,6 +265,9 @@ }, { "id": "app.navbar.secondary", + "rules": { + "visible": "app.isContentServiceEnabled" + }, "items": [ { "id": "app.navbar.shared", diff --git a/karma.conf.js b/karma.conf.js index 7929239c8..9be6a95d5 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -72,7 +72,6 @@ module.exports = function(config) { } }, singleRun: true, - captureTimeout: 180000, browserDisconnectTimeout: 180000, browserDisconnectTolerance: 3, diff --git a/projects/aca-shared/rules/src/app.rules.spec.ts b/projects/aca-shared/rules/src/app.rules.spec.ts index 5b4296dc4..b0f2599b9 100644 --- a/projects/aca-shared/rules/src/app.rules.spec.ts +++ b/projects/aca-shared/rules/src/app.rules.spec.ts @@ -530,4 +530,21 @@ describe('app.evaluators', () => { expect(app.isLibraryManager(context)).toBe(false); }); }); + + describe('isContentServiceEnabled', () => { + it('should return true when local storage has contentService set to true', () => { + localStorage.setItem('contentService', 'true'); + expect(app.isContentServiceEnabled()).toBe(true); + }); + + it('should return false when local storage has contentService set to false', () => { + localStorage.setItem('contentService', 'false'); + expect(app.isContentServiceEnabled()).toBe(false); + }); + + it('should return true when contentService is not defined in local storage', () => { + localStorage.clear(); + expect(app.isContentServiceEnabled()).toBe(true); + }); + }); }); diff --git a/projects/aca-shared/rules/src/app.rules.ts b/projects/aca-shared/rules/src/app.rules.ts index 4db77ae9f..51fd8f63c 100644 --- a/projects/aca-shared/rules/src/app.rules.ts +++ b/projects/aca-shared/rules/src/app.rules.ts @@ -32,6 +32,12 @@ export interface AcaRuleContext extends RuleContext { withCredentials: boolean; } +/** + * Checks if the content plugin is enabled. + * JSON ref: `app.isContentServiceEnabled` + */ +export const isContentServiceEnabled = (): boolean => localStorage && localStorage.getItem('contentService') !== 'false'; + /** * Checks if user can copy selected node. * JSON ref: `app.canCopyNode`