[ADF-3191] Not able to login only to BPM or ECM (#3478)

* disable random test

* host setting component reset JS-API

* reload api after user prefrence change

* remove replicate reset

* missing semicolon

* deprecate provider property

* remove trailing space

* check new value before to set
This commit is contained in:
Eugenio Romano 2018-06-13 16:05:35 +01:00 committed by GitHub
parent d41e3d5b9c
commit afdedf02d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 68 additions and 139 deletions

View File

@ -29,7 +29,6 @@
<adf-login <adf-login
#alfrescologin #alfrescologin
[providers]="providers"
[fieldsValidation]="customValidation" [fieldsValidation]="customValidation"
[disableCsrf]="disableCsrf" [disableCsrf]="disableCsrf"
[showLoginActions]="showFooter" [showLoginActions]="showFooter"

View File

@ -18,7 +18,7 @@
import { Component, OnInit, ViewChild } from '@angular/core'; import { Component, OnInit, ViewChild } from '@angular/core';
import { Validators } from '@angular/forms'; import { Validators } from '@angular/forms';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { LogService, UserPreferencesService } from '@alfresco/adf-core'; import { LogService } from '@alfresco/adf-core';
@Component({ @Component({
selector: 'app-login', selector: 'app-login',
@ -30,7 +30,6 @@ export class LoginComponent implements OnInit {
@ViewChild('alfrescologin') @ViewChild('alfrescologin')
alfrescologin: any; alfrescologin: any;
providers = 'ECM';
customValidation: any; customValidation: any;
disableCsrf = false; disableCsrf = false;
@ -38,7 +37,6 @@ export class LoginComponent implements OnInit {
customMinLength = 2; customMinLength = 2;
constructor(private router: Router, constructor(private router: Router,
private userPreference: UserPreferencesService,
private logService: LogService) { private logService: LogService) {
this.customValidation = { this.customValidation = {
username: ['', Validators.compose([Validators.required, Validators.minLength(this.customMinLength)])], username: ['', Validators.compose([Validators.required, Validators.minLength(this.customMinLength)])],
@ -50,12 +48,6 @@ export class LoginComponent implements OnInit {
this.alfrescologin.addCustomValidationError('username', 'required', 'LOGIN.MESSAGES.USERNAME-REQUIRED'); this.alfrescologin.addCustomValidationError('username', 'required', 'LOGIN.MESSAGES.USERNAME-REQUIRED');
this.alfrescologin.addCustomValidationError('username', 'minlength', 'LOGIN.MESSAGES.USERNAME-MIN', {minLength: this.customMinLength}); this.alfrescologin.addCustomValidationError('username', 'minlength', 'LOGIN.MESSAGES.USERNAME-MIN', {minLength: this.customMinLength});
this.alfrescologin.addCustomValidationError('password', 'required', 'LOGIN.MESSAGES.PASSWORD-REQUIRED'); this.alfrescologin.addCustomValidationError('password', 'required', 'LOGIN.MESSAGES.PASSWORD-REQUIRED');
this.initProviders();
}
initProviders() {
this.providers = this.userPreference.providers;
} }
onLogin($event) { onLogin($event) {

View File

@ -1 +1 @@
<adf-host-settings (cancel)="onCancel()" (success)="onSuccess()" (error)="onError($event)"></adf-host-settings> <adf-host-settings (cancel)="onCancel()" (success)="onSuccess()" (error)="onError($event)"></adf-host-settings>

View File

@ -34,7 +34,6 @@ Authenticates to Alfresco Content Services and Alfresco Process Services.
```html ```html
<adf-login <adf-login
providers="ECM"
successRoute="/home"> successRoute="/home">
</adf-login> </adf-login>
``` ```
@ -73,7 +72,6 @@ Authenticates to Alfresco Content Services and Alfresco Process Services.
```html ```html
<adf-login <adf-login
providers="ALL"
(success)="mySuccessMethod($event)" (success)="mySuccessMethod($event)"
(error)="myErrorMethod($event)"> (error)="myErrorMethod($event)">
</adf-login> </adf-login>

View File

@ -138,13 +138,13 @@ module.exports = function (config) {
{type: 'html'}, {type: 'html'},
{type: 'lcov'} {type: 'lcov'}
] ]
},
client: {
jasmine: {
random: true
}
} }
// client: {
// jasmine: {
// random: true
// }
// }
}; };
config.set(_config); config.set(_config);

View File

@ -562,19 +562,6 @@ describe('LoginComponent', () => {
expect(element.querySelector('#password').type).toEqual('password'); 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(() => { it('should emit only the username and not the password as part of the executeSubmit', async(() => {
component.executeSubmit.subscribe((res) => { component.executeSubmit.subscribe((res) => {
fixture.detectChanges(); fixture.detectChanges();

View File

@ -16,21 +16,14 @@
*/ */
import { import {
Component, Component, ElementRef, EventEmitter, Input, OnInit,
ElementRef, Output, TemplateRef, ViewEncapsulation
EventEmitter,
Input,
OnInit,
Output,
TemplateRef,
ViewEncapsulation
} from '@angular/core'; } from '@angular/core';
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { AuthenticationService } from '../../services/authentication.service'; import { AuthenticationService } from '../../services/authentication.service';
import { LogService } from '../../services/log.service'; import { LogService } from '../../services/log.service';
import { SettingsService } from '../../services/settings.service';
import { TranslationService } from '../../services/translation.service'; import { TranslationService } from '../../services/translation.service';
import { UserPreferencesService } from '../../services/user-preferences.service'; import { UserPreferencesService } from '../../services/user-preferences.service';
@ -90,8 +83,9 @@ export class LoginComponent implements OnInit {
@Input() @Input()
copyrightText: string = '\u00A9 2016 Alfresco Software, Inc. All Rights Reserved.'; copyrightText: string = '\u00A9 2016 Alfresco Software, Inc. All Rights Reserved.';
/** Possible valid values are ECM, BPM or ALL. By default, this component /** Possible valid values are ECM, BPM or ALL.
* will log in only to ECM. If you want to log in in both systems then use ALL. * deprecated in 2.4.0 use the providers property in the the app.config.json
* @deprecated 2.4.0
*/ */
@Input() @Input()
providers: string; providers: string;
@ -140,12 +134,10 @@ export class LoginComponent implements OnInit {
* Constructor * Constructor
* @param _fb * @param _fb
* @param authService * @param authService
* @param settingsService
* @param translate * @param translate
*/ */
constructor(private _fb: FormBuilder, constructor(private _fb: FormBuilder,
private authService: AuthenticationService, private authService: AuthenticationService,
private settingsService: SettingsService,
private translateService: TranslationService, private translateService: TranslationService,
private logService: LogService, private logService: LogService,
private elementRef: ElementRef, private elementRef: ElementRef,
@ -177,14 +169,10 @@ export class LoginComponent implements OnInit {
* @param event * @param event
*/ */
onSubmit(values: any) { onSubmit(values: any) {
if (this.disableCsrf !== null && this.disableCsrf !== undefined) {
if (!this.checkRequiredParams()) { this.userPreferences.disableCSRF = this.disableCsrf;
return false;
} }
this.settingsService.setProviders(this.providers);
this.settingsService.csrfDisabled = this.disableCsrf;
this.disableError(); this.disableError();
const args = new LoginSubmitEvent({ controls: { username: this.form.controls.username } }); const args = new LoginSubmitEvent({ controls: { username: this.form.controls.username } });
this.executeSubmit.emit(args); 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 * Add a custom form error for a field
* @param field * @param field

View File

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

View File

@ -25,7 +25,8 @@ import * as alfrescoApi from 'alfresco-js-api';
import { AppConfigService } from '../app-config/app-config.service'; import { AppConfigService } from '../app-config/app-config.service';
import { StorageService } from './storage.service'; import { StorageService } from './storage.service';
import { Subject } from 'rxjs/Subject'; 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 */ /* tslint:disable:adf-file-name */
@ -96,8 +97,17 @@ export class AlfrescoApiService {
} }
constructor(protected appConfig: AppConfigService, constructor(protected appConfig: AppConfigService,
protected userPreference: UserPreferencesService, protected userPreferencesService: UserPreferencesService,
protected storage: StorageService) { 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() { async load() {
@ -112,18 +122,18 @@ export class AlfrescoApiService {
protected initAlfrescoApi() { protected initAlfrescoApi() {
let oauth; let oauth;
if (this.userPreference.oauthConfig) { if (this.userPreferencesService.oauthConfig) {
oauth = Object.assign({}, this.userPreference.oauthConfig); oauth = Object.assign({}, this.userPreferencesService.oauthConfig);
oauth.redirectUri = window.location.origin + (oauth.redirectUri || '/'); oauth.redirectUri = window.location.origin + (oauth.redirectUri || '/');
oauth.redirectUriLogout = window.location.origin + (oauth.redirectUriLogout || '/'); oauth.redirectUriLogout = window.location.origin + (oauth.redirectUriLogout || '/');
} }
const config = { const config = {
provider: this.userPreference.providers, provider: this.userPreferencesService.providers,
ticketEcm: this.storage.getItem('ticket-ECM'), ticketEcm: this.storage.getItem('ticket-ECM'),
ticketBpm: this.storage.getItem('ticket-BPM'), ticketBpm: this.storage.getItem('ticket-BPM'),
hostEcm: this.userPreference.ecmHost, hostEcm: this.userPreferencesService.ecmHost,
hostBpm: this.userPreference.bpmHost, hostBpm: this.userPreferencesService.bpmHost,
authType: this.userPreference.authType, authType: this.userPreferencesService.authType,
contextRootBpm: this.appConfig.get<string>('contextRootBpm'), contextRootBpm: this.appConfig.get<string>('contextRootBpm'),
contextRoot: this.appConfig.get<string>('contextRootEcm'), contextRoot: this.appConfig.get<string>('contextRootEcm'),
disableCsrf: this.storage.getItem('DISABLE_CSRF') === 'true', disableCsrf: this.storage.getItem('DISABLE_CSRF') === 'true',

View File

@ -66,12 +66,12 @@ export class SettingsService {
/** @deprecated in 1.7.0 */ /** @deprecated in 1.7.0 */
public getProviders(): string { public getProviders(): string {
this.logService.log(`SettingsService.getProviders is deprecated. Use UserPreferencesService.authType instead.`); this.logService.log(`SettingsService.getProviders is deprecated. Use UserPreferencesService.authType instead.`);
return this.preferences.authType; return this.preferences.providers;
} }
/** @deprecated in 1.7.0 */ /** @deprecated in 1.7.0 */
public setProviders(providers: string) { public setProviders(providers: string) {
this.logService.log(`SettingsService.getProviders is deprecated. Use UserPreferencesService.authType instead.`); this.logService.log(`SettingsService.getProviders is deprecated. Use UserPreferencesService.authType instead.`);
this.preferences.authType = providers; this.preferences.providers = providers;
} }
} }

View File

@ -28,7 +28,12 @@ export enum UserPreferenceValues {
PaginationSize = 'PAGINATION_SIZE', PaginationSize = 'PAGINATION_SIZE',
DisableCSRF = 'DISABLE_CSRF', DisableCSRF = 'DISABLE_CSRF',
Locale = 'LOCALE', Locale = 'LOCALE',
SupportedPageSizes = 'supportedPageSizes' SupportedPageSizes = 'supportedPageSizes',
oauthConfig = 'oauthConfig',
ecmHost = 'ecmHost',
bpmHost = 'bpmHost',
providers = 'providers',
authType = 'authType'
} }
@Injectable() @Injectable()
@ -199,7 +204,9 @@ export class UserPreferencesService {
} }
set providers(providers: string) { set providers(providers: string) {
this.storage.setItem('providers', providers); if (providers !== this.providers) {
this.storage.setItem('providers', providers);
}
} }
get bpmHost(): string { get bpmHost(): string {
@ -211,7 +218,9 @@ export class UserPreferencesService {
} }
set bpmHost(bpmHost: string) { set bpmHost(bpmHost: string) {
this.storage.setItem('bpmHost', bpmHost); if (bpmHost !== this.bpmHost) {
this.storage.setItem('bpmHost', bpmHost);
}
} }
get ecmHost(): string { get ecmHost(): string {
@ -223,7 +232,9 @@ export class UserPreferencesService {
} }
set ecmHost(ecmHost: string) { set ecmHost(ecmHost: string) {
this.storage.setItem('ecmHost', ecmHost); if (ecmHost !== this.ecmHost) {
this.storage.setItem('ecmHost', ecmHost);
}
} }
get oauthConfig(): OauthConfigModel { get oauthConfig(): OauthConfigModel {
@ -235,7 +246,9 @@ export class UserPreferencesService {
} }
set oauthConfig(oauthConfig: OauthConfigModel) { 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 { get authType(): string {
@ -247,7 +260,9 @@ export class UserPreferencesService {
} }
set authType(authType: string) { set authType(authType: string) {
this.storage.setItem('authType', authType); if (authType !== this.authType) {
this.storage.setItem('authType', authType);
}
} }
} }

View File

@ -62,7 +62,7 @@ export class HostSettingsComponent implements OnInit {
bpmHostChange = new EventEmitter<string>(); bpmHostChange = new EventEmitter<string>();
constructor(private formBuilder: FormBuilder, constructor(private formBuilder: FormBuilder,
private userPreference: UserPreferencesService) { private userPreferencesService: UserPreferencesService) {
} }
ngOnInit() { ngOnInit() {
@ -70,16 +70,16 @@ export class HostSettingsComponent implements OnInit {
this.showSelectProviders = false; this.showSelectProviders = false;
} }
let providerSelected = this.userPreference.providers; let providerSelected = this.userPreferencesService.providers;
this.form = this.formBuilder.group({ this.form = this.formBuilder.group({
providersControl: [providerSelected, Validators.required], providersControl: [providerSelected, Validators.required],
authType: this.userPreference.authType authType: this.userPreferencesService.authType
}); });
this.addFormGroups(); this.addFormGroups();
if (this.userPreference.authType === 'OAUTH') { if (this.userPreferencesService.authType === 'OAUTH') {
this.addOAuthFormGroup(); this.addOAuthFormGroup();
} }
@ -127,7 +127,7 @@ export class HostSettingsComponent implements OnInit {
} }
private createOAuthFormGroup(): AbstractControl { 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({ return this.formBuilder.group({
host: [oAuthConfig.host, [Validators.required, Validators.pattern(this.HOST_REGEX)]], host: [oAuthConfig.host, [Validators.required, Validators.pattern(this.HOST_REGEX)]],
clientId: [oAuthConfig.clientId, Validators.required], clientId: [oAuthConfig.clientId, Validators.required],
@ -140,11 +140,11 @@ export class HostSettingsComponent implements OnInit {
} }
private createBPMFormControl(): AbstractControl { 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 { 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() { onCancel() {
@ -152,7 +152,7 @@ export class HostSettingsComponent implements OnInit {
} }
onSubmit(values: any) { onSubmit(values: any) {
this.userPreference.providers = values.providersControl; this.userPreferencesService.providers = values.providersControl;
if (this.isBPM()) { if (this.isBPM()) {
this.saveBPMValues(values); this.saveBPMValues(values);
@ -167,21 +167,21 @@ export class HostSettingsComponent implements OnInit {
this.saveOAuthValues(values); this.saveOAuthValues(values);
} }
this.userPreference.authType = values.authType; this.userPreferencesService.authType = values.authType;
this.success.emit(true); this.success.emit(true);
} }
private saveOAuthValues(values: any) { private saveOAuthValues(values: any) {
this.userPreference.oauthConfig = values.oauthConfig; this.userPreferencesService.oauthConfig = values.oauthConfig;
} }
private saveBPMValues(values: any) { private saveBPMValues(values: any) {
this.userPreference.bpmHost = values.bpmHost; this.userPreferencesService.bpmHost = values.bpmHost;
} }
private saveECMValues(values: any) { private saveECMValues(values: any) {
this.userPreference.ecmHost = values.ecmHost; this.userPreferencesService.ecmHost = values.ecmHost;
} }
isBPM(): boolean { isBPM(): boolean {