mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[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:
parent
d41e3d5b9c
commit
afdedf02d1
@ -29,7 +29,6 @@
|
||||
|
||||
<adf-login
|
||||
#alfrescologin
|
||||
[providers]="providers"
|
||||
[fieldsValidation]="customValidation"
|
||||
[disableCsrf]="disableCsrf"
|
||||
[showLoginActions]="showFooter"
|
||||
|
@ -18,7 +18,7 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { Validators } from '@angular/forms';
|
||||
import { Router } from '@angular/router';
|
||||
import { LogService, UserPreferencesService } from '@alfresco/adf-core';
|
||||
import { LogService } from '@alfresco/adf-core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
@ -30,7 +30,6 @@ export class LoginComponent implements OnInit {
|
||||
@ViewChild('alfrescologin')
|
||||
alfrescologin: any;
|
||||
|
||||
providers = 'ECM';
|
||||
customValidation: any;
|
||||
|
||||
disableCsrf = false;
|
||||
@ -38,7 +37,6 @@ export class LoginComponent implements OnInit {
|
||||
customMinLength = 2;
|
||||
|
||||
constructor(private router: Router,
|
||||
private userPreference: UserPreferencesService,
|
||||
private logService: LogService) {
|
||||
this.customValidation = {
|
||||
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', 'minlength', 'LOGIN.MESSAGES.USERNAME-MIN', {minLength: this.customMinLength});
|
||||
this.alfrescologin.addCustomValidationError('password', 'required', 'LOGIN.MESSAGES.PASSWORD-REQUIRED');
|
||||
|
||||
this.initProviders();
|
||||
}
|
||||
|
||||
initProviders() {
|
||||
this.providers = this.userPreference.providers;
|
||||
}
|
||||
|
||||
onLogin($event) {
|
||||
|
@ -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>
|
||||
|
@ -34,7 +34,6 @@ Authenticates to Alfresco Content Services and Alfresco Process Services.
|
||||
|
||||
```html
|
||||
<adf-login
|
||||
providers="ECM"
|
||||
successRoute="/home">
|
||||
</adf-login>
|
||||
```
|
||||
@ -73,7 +72,6 @@ Authenticates to Alfresco Content Services and Alfresco Process Services.
|
||||
|
||||
```html
|
||||
<adf-login
|
||||
providers="ALL"
|
||||
(success)="mySuccessMethod($event)"
|
||||
(error)="myErrorMethod($event)">
|
||||
</adf-login>
|
||||
|
@ -138,13 +138,13 @@ module.exports = function (config) {
|
||||
{type: 'html'},
|
||||
{type: 'lcov'}
|
||||
]
|
||||
},
|
||||
|
||||
client: {
|
||||
jasmine: {
|
||||
random: true
|
||||
}
|
||||
}
|
||||
|
||||
// client: {
|
||||
// jasmine: {
|
||||
// random: true
|
||||
// }
|
||||
// }
|
||||
};
|
||||
|
||||
config.set(_config);
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
@ -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<string>('contextRootBpm'),
|
||||
contextRoot: this.appConfig.get<string>('contextRootEcm'),
|
||||
disableCsrf: this.storage.getItem('DISABLE_CSRF') === 'true',
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ export class HostSettingsComponent implements OnInit {
|
||||
bpmHostChange = new EventEmitter<string>();
|
||||
|
||||
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user