[ADF-3191] Fix userprefrence oauth2 (#3488)

* remove user preference setting save

* fix host setting test

* remove userPreferences test

* fix title service test

* remove unused imports

* restore input align

* fix service import in test tag rating
This commit is contained in:
Eugenio Romano
2018-06-15 08:32:16 +01:00
committed by GitHub
parent af2cde0791
commit 8966e22487
43 changed files with 417 additions and 528 deletions

View File

@@ -19,13 +19,13 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HostSettingsComponent } from './host-settings.component';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
import { UserPreferencesService } from '../services/user-preferences.service';
import { AppConfigService } from '../app-config/app-config.service';
describe('HostSettingsComponent', () => {
let fixture: ComponentFixture<HostSettingsComponent>;
let component: HostSettingsComponent;
let userPreferences: UserPreferencesService;
let appConfigService: AppConfigService;
let element: any;
setupTestBed({
@@ -35,7 +35,7 @@ describe('HostSettingsComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(HostSettingsComponent);
component = fixture.componentInstance;
userPreferences = TestBed.get(UserPreferencesService);
appConfigService = TestBed.get(AppConfigService);
element = fixture.nativeElement;
});
@@ -46,9 +46,9 @@ describe('HostSettingsComponent', () => {
describe('Providers', () => {
beforeEach(() => {
userPreferences.providers = 'ECM';
userPreferences.authType = 'OAUTH';
userPreferences.oauthConfig = {
appConfigService.config.providers = 'ECM';
appConfigService.config.authType = 'OAUTH';
appConfigService.config.oauth2 = {
host: 'http://localhost:6543',
redirectUri: '/',
silentLogin: false,
@@ -57,6 +57,8 @@ describe('HostSettingsComponent', () => {
scope: 'openid',
secret: ''
};
appConfigService.load();
fixture.detectChanges();
});
@@ -64,7 +66,7 @@ describe('HostSettingsComponent', () => {
fixture.destroy();
});
it('should not show the providers select box if you hav eine porovider', (done) => {
it('should not show the providers select box if you have any provider', (done) => {
component.providers = ['BPM'];
component.ngOnInit();
@@ -76,7 +78,7 @@ describe('HostSettingsComponent', () => {
});
});
it('should show the providers select box if you hav eine porovider', (done) => {
it('should show the providers select box if you have any provider', (done) => {
component.providers = ['BPM', 'ECM'];
component.ngOnInit();
@@ -96,7 +98,8 @@ describe('HostSettingsComponent', () => {
let bpmUrlInput;
beforeEach(() => {
userPreferences.providers = 'BPM';
appConfigService.config.providers = 'BPM';
appConfigService.load();
fixture.detectChanges();
bpmUrlInput = element.querySelector('#bpmHost');
ecmUrlInput = element.querySelector('#ecmHost');
@@ -148,7 +151,8 @@ describe('HostSettingsComponent', () => {
let bpmUrlInput;
beforeEach(() => {
userPreferences.providers = 'ECM';
appConfigService.config.providers = 'ECM';
appConfigService.load();
fixture.detectChanges();
bpmUrlInput = element.querySelector('#bpmHost');
ecmUrlInput = element.querySelector('#ecmHost');
@@ -195,7 +199,8 @@ describe('HostSettingsComponent', () => {
let bpmUrlInput;
beforeEach(() => {
userPreferences.providers = 'ALL';
appConfigService.config.providers = 'ALL';
appConfigService.load();
fixture.detectChanges();
bpmUrlInput = element.querySelector('#bpmHost');
ecmUrlInput = element.querySelector('#ecmHost');
@@ -269,9 +274,9 @@ describe('HostSettingsComponent', () => {
let clientIdInput;
beforeEach(() => {
userPreferences.providers = 'ALL';
userPreferences.authType = 'OAUTH';
userPreferences.oauthConfig = {
appConfigService.config.providers = 'ALL';
appConfigService.config.authType = 'OAUTH';
appConfigService.config.oauth2 = {
host: 'http://localhost:6543',
redirectUri: '/',
silentLogin: false,
@@ -280,6 +285,7 @@ describe('HostSettingsComponent', () => {
scope: 'openid',
secret: ''
};
appConfigService.load();
fixture.detectChanges();
bpmUrlInput = element.querySelector('#bpmHost');
ecmUrlInput = element.querySelector('#ecmHost');

View File

@@ -17,7 +17,10 @@
import { Component, EventEmitter, Output, ViewEncapsulation, OnInit, Input } from '@angular/core';
import { Validators, FormGroup, FormBuilder, AbstractControl, FormControl } from '@angular/forms';
import { UserPreferencesService } from '../services/user-preferences.service';
import { AppConfigService, AppConfigValues } from '../app-config/app-config.service';
import { StorageService } from '../services/storage.service';
import { AlfrescoApiService } from '../services/alfresco-api.service';
import { OauthConfigModel } from '../models/oauth-config.model';
@Component({
selector: 'adf-host-settings',
@@ -62,7 +65,9 @@ export class HostSettingsComponent implements OnInit {
bpmHostChange = new EventEmitter<string>();
constructor(private formBuilder: FormBuilder,
private userPreferencesService: UserPreferencesService) {
private storageService: StorageService,
private alfrescoApiService: AlfrescoApiService,
private appConfig: AppConfigService) {
}
ngOnInit() {
@@ -70,16 +75,16 @@ export class HostSettingsComponent implements OnInit {
this.showSelectProviders = false;
}
let providerSelected = this.userPreferencesService.providers;
let providerSelected = this.appConfig.get<string>(AppConfigValues.PROVIDERS);
this.form = this.formBuilder.group({
providersControl: [providerSelected, Validators.required],
authType: this.userPreferencesService.authType
authType: this.appConfig.get<string>(AppConfigValues.AUTHTYPE)
});
this.addFormGroups();
if (this.userPreferencesService.authType === 'OAUTH') {
if (this.appConfig.get<string>(AppConfigValues.AUTHTYPE) === 'OAUTH') {
this.addOAuthFormGroup();
}
@@ -127,24 +132,25 @@ export class HostSettingsComponent implements OnInit {
}
private createOAuthFormGroup(): AbstractControl {
const oAuthConfig: any = this.userPreferencesService.oauthConfig ? this.userPreferencesService.oauthConfig : {};
let oauth = <OauthConfigModel> this.appConfig.get(AppConfigValues.OAUTHCONFIG, {});
return this.formBuilder.group({
host: [oAuthConfig.host, [Validators.required, Validators.pattern(this.HOST_REGEX)]],
clientId: [oAuthConfig.clientId, Validators.required],
redirectUri: [oAuthConfig.redirectUri, Validators.required],
scope: [oAuthConfig.scope, Validators.required],
secret: oAuthConfig.secret,
silentLogin: oAuthConfig.silentLogin,
implicitFlow: oAuthConfig.implicitFlow
host: [oauth.host, [Validators.required, Validators.pattern(this.HOST_REGEX)]],
clientId: [oauth.clientId, Validators.required],
redirectUri: [oauth.redirectUri, Validators.required],
scope: [oauth.scope, Validators.required],
secret: oauth.secret,
silentLogin: oauth.silentLogin,
implicitFlow: oauth.implicitFlow
});
}
private createBPMFormControl(): AbstractControl {
return new FormControl(this.userPreferencesService.bpmHost, [Validators.required, Validators.pattern(this.HOST_REGEX)]);
return new FormControl(this.appConfig.get<string>(AppConfigValues.BPMHOST), [Validators.required, Validators.pattern(this.HOST_REGEX)]);
}
private createECMFormControl(): AbstractControl {
return new FormControl(this.userPreferencesService.ecmHost, [Validators.required, Validators.pattern(this.HOST_REGEX)]);
return new FormControl(this.appConfig.get<string>(AppConfigValues.ECMHOST), [Validators.required, Validators.pattern(this.HOST_REGEX)]);
}
onCancel() {
@@ -152,7 +158,7 @@ export class HostSettingsComponent implements OnInit {
}
onSubmit(values: any) {
this.userPreferencesService.providers = values.providersControl;
this.storageService.setItem(AppConfigValues.PROVIDERS, values.providersControl);
if (this.isBPM()) {
this.saveBPMValues(values);
@@ -167,21 +173,22 @@ export class HostSettingsComponent implements OnInit {
this.saveOAuthValues(values);
}
this.userPreferencesService.authType = values.authType;
this.storageService.setItem(AppConfigValues.AUTHTYPE, values.authType);
this.alfrescoApiService.reset();
this.success.emit(true);
}
private saveOAuthValues(values: any) {
this.userPreferencesService.oauthConfig = values.oauthConfig;
this.storageService.setItem(AppConfigValues.OAUTHCONFIG, JSON.stringify(values.oauthConfig));
}
private saveBPMValues(values: any) {
this.userPreferencesService.bpmHost = values.bpmHost;
this.storageService.setItem(AppConfigValues.BPMHOST, values.bpmHost);
}
private saveECMValues(values: any) {
this.userPreferencesService.ecmHost = values.ecmHost;
this.storageService.setItem(AppConfigValues.ECMHOST, values.ecmHost);
}
isBPM(): boolean {