diff --git a/demo-shell/src/app/components/login/login.component.html b/demo-shell/src/app/components/login/login.component.html index 9b62c9e918..c35993cc39 100644 --- a/demo-shell/src/app/components/login/login.component.html +++ b/demo-shell/src/app/components/login/login.component.html @@ -29,7 +29,6 @@ + diff --git a/docs/core/login.component.md b/docs/core/login.component.md index 4e021d8ded..713a2d1cd7 100644 --- a/docs/core/login.component.md +++ b/docs/core/login.component.md @@ -34,7 +34,6 @@ Authenticates to Alfresco Content Services and Alfresco Process Services. ```html ``` @@ -73,7 +72,6 @@ Authenticates to Alfresco Content Services and Alfresco Process Services. ```html diff --git a/lib/config/karma.conf-all.js b/lib/config/karma.conf-all.js index a60a518884..b2d9c92d2a 100644 --- a/lib/config/karma.conf-all.js +++ b/lib/config/karma.conf-all.js @@ -138,13 +138,13 @@ module.exports = function (config) { {type: 'html'}, {type: 'lcov'} ] - }, - - client: { - jasmine: { - random: true - } } + + // client: { + // jasmine: { + // random: true + // } + // } }; config.set(_config); diff --git a/lib/core/login/components/login.component.spec.ts b/lib/core/login/components/login.component.spec.ts index 94f2da4bbe..e72419a9cb 100644 --- a/lib/core/login/components/login.component.spec.ts +++ b/lib/core/login/components/login.component.spec.ts @@ -562,19 +562,6 @@ describe('LoginComponent', () => { expect(element.querySelector('#password').type).toEqual('password'); }); - it('should emit error event when the providers is undefined', async(() => { - component.error.subscribe((error) => { - fixture.detectChanges(); - - expect(component.isError).toBe(true); - expect(getLoginErrorElement()).toBeDefined(); - expect(getLoginErrorMessage()).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-PROVIDERS'); - expect(error).toEqual(new LoginErrorEvent('LOGIN.MESSAGES.LOGIN-ERROR-PROVIDERS')); - }); - - loginWithCredentials('fake-username', 'fake-password', null); - })); - it('should emit only the username and not the password as part of the executeSubmit', async(() => { component.executeSubmit.subscribe((res) => { fixture.detectChanges(); diff --git a/lib/core/login/components/login.component.ts b/lib/core/login/components/login.component.ts index 8ed9ae5f44..57aeea26d9 100644 --- a/lib/core/login/components/login.component.ts +++ b/lib/core/login/components/login.component.ts @@ -16,21 +16,14 @@ */ import { - Component, - ElementRef, - EventEmitter, - Input, - OnInit, - Output, - TemplateRef, - ViewEncapsulation + Component, ElementRef, EventEmitter, Input, OnInit, + Output, TemplateRef, ViewEncapsulation } from '@angular/core'; import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Router } from '@angular/router'; import { AuthenticationService } from '../../services/authentication.service'; import { LogService } from '../../services/log.service'; -import { SettingsService } from '../../services/settings.service'; import { TranslationService } from '../../services/translation.service'; import { UserPreferencesService } from '../../services/user-preferences.service'; @@ -90,8 +83,9 @@ export class LoginComponent implements OnInit { @Input() copyrightText: string = '\u00A9 2016 Alfresco Software, Inc. All Rights Reserved.'; - /** Possible valid values are ECM, BPM or ALL. By default, this component - * will log in only to ECM. If you want to log in in both systems then use ALL. + /** Possible valid values are ECM, BPM or ALL. + * deprecated in 2.4.0 use the providers property in the the app.config.json + * @deprecated 2.4.0 */ @Input() providers: string; @@ -140,12 +134,10 @@ export class LoginComponent implements OnInit { * Constructor * @param _fb * @param authService - * @param settingsService * @param translate */ constructor(private _fb: FormBuilder, private authService: AuthenticationService, - private settingsService: SettingsService, private translateService: TranslationService, private logService: LogService, private elementRef: ElementRef, @@ -177,14 +169,10 @@ export class LoginComponent implements OnInit { * @param event */ onSubmit(values: any) { - - if (!this.checkRequiredParams()) { - return false; + if (this.disableCsrf !== null && this.disableCsrf !== undefined) { + this.userPreferences.disableCSRF = this.disableCsrf; } - this.settingsService.setProviders(this.providers); - this.settingsService.csrfDisabled = this.disableCsrf; - this.disableError(); const args = new LoginSubmitEvent({ controls: { username: this.form.controls.username } }); this.executeSubmit.emit(args); @@ -272,25 +260,6 @@ export class LoginComponent implements OnInit { } } - /** - * Check the require parameter - */ - private checkRequiredParams(): boolean { - - let isAllParamPresent: boolean = true; - - if (this.providers === undefined || this.providers === null || this.providers === '') { - this.errorMsg = 'LOGIN.MESSAGES.LOGIN-ERROR-PROVIDERS'; - this.enableError(); - let messageProviders: any; - messageProviders = this.translateService.get(this.errorMsg); - this.error.emit(new LoginErrorEvent(messageProviders.value)); - isAllParamPresent = false; - } - - return isAllParamPresent; - } - /** * Add a custom form error for a field * @param field diff --git a/lib/core/services/alfresco-api.service.spec.ts b/lib/core/services/alfresco-api.service.spec.ts deleted file mode 100644 index 2af16b29fb..0000000000 --- a/lib/core/services/alfresco-api.service.spec.ts +++ /dev/null @@ -1,41 +0,0 @@ -/*! - * @license - * Copyright 2016 Alfresco Software, Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { AlfrescoApiService } from './alfresco-api.service'; - -/* tslint:disable:adf-file-name */ - -describe('AlfrescoApiService', () => { - - let service: AlfrescoApiService; - - beforeEach(() => { - service = new AlfrescoApiService(null, null, null); - }); - - it('should rase nodeChanged event with node payload', (done) => { - const node: any = {}; - - service.nodeUpdated.subscribe(result => { - expect(result).toEqual(node); - done(); - }); - - service.nodeUpdated.next(node); - }); - -}); diff --git a/lib/core/services/alfresco-api.service.ts b/lib/core/services/alfresco-api.service.ts index 5b28e82db3..153a250358 100644 --- a/lib/core/services/alfresco-api.service.ts +++ b/lib/core/services/alfresco-api.service.ts @@ -25,7 +25,8 @@ import * as alfrescoApi from 'alfresco-js-api'; import { AppConfigService } from '../app-config/app-config.service'; import { StorageService } from './storage.service'; import { Subject } from 'rxjs/Subject'; -import { UserPreferencesService } from './user-preferences.service'; +import { UserPreferencesService, UserPreferenceValues } from './user-preferences.service'; +import { merge } from 'rxjs/observable/merge'; /* tslint:disable:adf-file-name */ @@ -96,8 +97,17 @@ export class AlfrescoApiService { } constructor(protected appConfig: AppConfigService, - protected userPreference: UserPreferencesService, + protected userPreferencesService: UserPreferencesService, protected storage: StorageService) { + + merge(this.userPreferencesService.select(UserPreferenceValues.oauthConfig), + this.userPreferencesService.select(UserPreferenceValues.ecmHost), + this.userPreferencesService.select(UserPreferenceValues.bpmHost), + this.userPreferencesService.select(UserPreferenceValues.authType), + this.userPreferencesService.select(UserPreferenceValues.providers)).subscribe(() => { + this.reset(); + }); + } async load() { @@ -112,18 +122,18 @@ export class AlfrescoApiService { protected initAlfrescoApi() { let oauth; - if (this.userPreference.oauthConfig) { - oauth = Object.assign({}, this.userPreference.oauthConfig); + if (this.userPreferencesService.oauthConfig) { + oauth = Object.assign({}, this.userPreferencesService.oauthConfig); oauth.redirectUri = window.location.origin + (oauth.redirectUri || '/'); oauth.redirectUriLogout = window.location.origin + (oauth.redirectUriLogout || '/'); } const config = { - provider: this.userPreference.providers, + provider: this.userPreferencesService.providers, ticketEcm: this.storage.getItem('ticket-ECM'), ticketBpm: this.storage.getItem('ticket-BPM'), - hostEcm: this.userPreference.ecmHost, - hostBpm: this.userPreference.bpmHost, - authType: this.userPreference.authType, + hostEcm: this.userPreferencesService.ecmHost, + hostBpm: this.userPreferencesService.bpmHost, + authType: this.userPreferencesService.authType, contextRootBpm: this.appConfig.get('contextRootBpm'), contextRoot: this.appConfig.get('contextRootEcm'), disableCsrf: this.storage.getItem('DISABLE_CSRF') === 'true', diff --git a/lib/core/services/settings.service.ts b/lib/core/services/settings.service.ts index 800cf5227c..1b9030527d 100644 --- a/lib/core/services/settings.service.ts +++ b/lib/core/services/settings.service.ts @@ -66,12 +66,12 @@ export class SettingsService { /** @deprecated in 1.7.0 */ public getProviders(): string { this.logService.log(`SettingsService.getProviders is deprecated. Use UserPreferencesService.authType instead.`); - return this.preferences.authType; + return this.preferences.providers; } /** @deprecated in 1.7.0 */ public setProviders(providers: string) { this.logService.log(`SettingsService.getProviders is deprecated. Use UserPreferencesService.authType instead.`); - this.preferences.authType = providers; + this.preferences.providers = providers; } } diff --git a/lib/core/services/user-preferences.service.ts b/lib/core/services/user-preferences.service.ts index 583a8a17a3..7634244607 100644 --- a/lib/core/services/user-preferences.service.ts +++ b/lib/core/services/user-preferences.service.ts @@ -28,7 +28,12 @@ export enum UserPreferenceValues { PaginationSize = 'PAGINATION_SIZE', DisableCSRF = 'DISABLE_CSRF', Locale = 'LOCALE', - SupportedPageSizes = 'supportedPageSizes' + SupportedPageSizes = 'supportedPageSizes', + oauthConfig = 'oauthConfig', + ecmHost = 'ecmHost', + bpmHost = 'bpmHost', + providers = 'providers', + authType = 'authType' } @Injectable() @@ -199,7 +204,9 @@ export class UserPreferencesService { } set providers(providers: string) { - this.storage.setItem('providers', providers); + if (providers !== this.providers) { + this.storage.setItem('providers', providers); + } } get bpmHost(): string { @@ -211,7 +218,9 @@ export class UserPreferencesService { } set bpmHost(bpmHost: string) { - this.storage.setItem('bpmHost', bpmHost); + if (bpmHost !== this.bpmHost) { + this.storage.setItem('bpmHost', bpmHost); + } } get ecmHost(): string { @@ -223,7 +232,9 @@ export class UserPreferencesService { } set ecmHost(ecmHost: string) { - this.storage.setItem('ecmHost', ecmHost); + if (ecmHost !== this.ecmHost) { + this.storage.setItem('ecmHost', ecmHost); + } } get oauthConfig(): OauthConfigModel { @@ -235,7 +246,9 @@ export class UserPreferencesService { } set oauthConfig(oauthConfig: OauthConfigModel) { - this.storage.setItem('oauthConfig', JSON.stringify(oauthConfig)); + if (JSON.stringify(oauthConfig) !== JSON.stringify(this.oauthConfig)) { + this.storage.setItem('oauthConfig', JSON.stringify(oauthConfig)); + } } get authType(): string { @@ -247,7 +260,9 @@ export class UserPreferencesService { } set authType(authType: string) { - this.storage.setItem('authType', authType); + if (authType !== this.authType) { + this.storage.setItem('authType', authType); + } } } diff --git a/lib/core/settings/host-settings.component.ts b/lib/core/settings/host-settings.component.ts index c30e56ee9d..f9018dbe72 100644 --- a/lib/core/settings/host-settings.component.ts +++ b/lib/core/settings/host-settings.component.ts @@ -62,7 +62,7 @@ export class HostSettingsComponent implements OnInit { bpmHostChange = new EventEmitter(); constructor(private formBuilder: FormBuilder, - private userPreference: UserPreferencesService) { + private userPreferencesService: UserPreferencesService) { } ngOnInit() { @@ -70,16 +70,16 @@ export class HostSettingsComponent implements OnInit { this.showSelectProviders = false; } - let providerSelected = this.userPreference.providers; + let providerSelected = this.userPreferencesService.providers; this.form = this.formBuilder.group({ providersControl: [providerSelected, Validators.required], - authType: this.userPreference.authType + authType: this.userPreferencesService.authType }); this.addFormGroups(); - if (this.userPreference.authType === 'OAUTH') { + if (this.userPreferencesService.authType === 'OAUTH') { this.addOAuthFormGroup(); } @@ -127,7 +127,7 @@ export class HostSettingsComponent implements OnInit { } private createOAuthFormGroup(): AbstractControl { - const oAuthConfig: any = this.userPreference.oauthConfig ? this.userPreference.oauthConfig : {}; + const oAuthConfig: any = this.userPreferencesService.oauthConfig ? this.userPreferencesService.oauthConfig : {}; return this.formBuilder.group({ host: [oAuthConfig.host, [Validators.required, Validators.pattern(this.HOST_REGEX)]], clientId: [oAuthConfig.clientId, Validators.required], @@ -140,11 +140,11 @@ export class HostSettingsComponent implements OnInit { } private createBPMFormControl(): AbstractControl { - return new FormControl(this.userPreference.bpmHost, [Validators.required, Validators.pattern(this.HOST_REGEX)]); + return new FormControl(this.userPreferencesService.bpmHost, [Validators.required, Validators.pattern(this.HOST_REGEX)]); } private createECMFormControl(): AbstractControl { - return new FormControl(this.userPreference.ecmHost, [Validators.required, Validators.pattern(this.HOST_REGEX)]); + return new FormControl(this.userPreferencesService.ecmHost, [Validators.required, Validators.pattern(this.HOST_REGEX)]); } onCancel() { @@ -152,7 +152,7 @@ export class HostSettingsComponent implements OnInit { } onSubmit(values: any) { - this.userPreference.providers = values.providersControl; + this.userPreferencesService.providers = values.providersControl; if (this.isBPM()) { this.saveBPMValues(values); @@ -167,21 +167,21 @@ export class HostSettingsComponent implements OnInit { this.saveOAuthValues(values); } - this.userPreference.authType = values.authType; + this.userPreferencesService.authType = values.authType; this.success.emit(true); } private saveOAuthValues(values: any) { - this.userPreference.oauthConfig = values.oauthConfig; + this.userPreferencesService.oauthConfig = values.oauthConfig; } private saveBPMValues(values: any) { - this.userPreference.bpmHost = values.bpmHost; + this.userPreferencesService.bpmHost = values.bpmHost; } private saveECMValues(values: any) { - this.userPreference.ecmHost = values.ecmHost; + this.userPreferencesService.ecmHost = values.ecmHost; } isBPM(): boolean {