[ADF-1047] preserve login providers between page reloads (#2078)

* preserve csrf and auth type settings between reloads

* update unit tests

* fix prefs issues

* fix tests
This commit is contained in:
Denys Vuika
2017-07-13 09:14:43 +01:00
committed by Eugenio Romano
parent 8e2b022b6b
commit 8fef3b6781
12 changed files with 109 additions and 75 deletions

View File

@@ -18,7 +18,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AlfrescoApi } from 'alfresco-js-api'; import { AlfrescoApi } from 'alfresco-js-api';
import * as alfrescoApi from 'alfresco-js-api'; import * as alfrescoApi from 'alfresco-js-api';
import { AlfrescoSettingsService } from './alfresco-settings.service';
import { AppConfigService } from './app-config.service'; import { AppConfigService } from './app-config.service';
import { StorageService } from './storage.service'; import { StorageService } from './storage.service';
@@ -26,42 +25,26 @@ import { StorageService } from './storage.service';
export class AlfrescoApiService { export class AlfrescoApiService {
private alfrescoApi: AlfrescoApi; private alfrescoApi: AlfrescoApi;
private provider: string;
private disableCsrf: boolean;
public getInstance(): AlfrescoApi { public getInstance(): AlfrescoApi {
return this.alfrescoApi; return this.alfrescoApi;
} }
constructor(private appConfig: AppConfigService, constructor(private appConfig: AppConfigService,
private settingsService: AlfrescoSettingsService,
private storage: StorageService) { private storage: StorageService) {
this.provider = this.settingsService.getProviders(); this.reset();
this.disableCsrf = false;
this.init();
settingsService.csrfSubject.subscribe((disableCsrf) => {
this.disableCsrf = disableCsrf;
this.init();
});
settingsService.providerSubject.subscribe((provider) => {
this.provider = provider;
this.init();
});
} }
private init() { reset() {
this.alfrescoApi = <AlfrescoApi>new alfrescoApi({ this.alfrescoApi = <AlfrescoApi>new alfrescoApi({
provider: this.provider, provider: this.storage.getItem('AUTH_TYPE'),
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.appConfig.get<string>('ecmHost'), hostEcm: this.appConfig.get<string>('ecmHost'),
hostBpm: this.appConfig.get<string>('bpmHost'), hostBpm: this.appConfig.get<string>('bpmHost'),
contextRoot: 'alfresco', contextRoot: 'alfresco',
disableCsrf: this.disableCsrf disableCsrf: this.storage.getItem('DISABLE_CSRF') === 'true'
}); });
} }
} }

View File

@@ -24,6 +24,7 @@ import { AppConfigModule } from './app-config.service';
import { CookieService } from './cookie.service'; import { CookieService } from './cookie.service';
import { LogService } from './log.service'; import { LogService } from './log.service';
import { StorageService } from './storage.service'; import { StorageService } from './storage.service';
import { UserPreferencesService } from './user-preferences.service';
declare let jasmine: any; declare let jasmine: any;
@@ -31,6 +32,7 @@ describe('AlfrescoAuthenticationService', () => {
let apiService: AlfrescoApiService; let apiService: AlfrescoApiService;
let authService: AlfrescoAuthenticationService; let authService: AlfrescoAuthenticationService;
let settingsService: AlfrescoSettingsService; let settingsService: AlfrescoSettingsService;
let preferences: UserPreferencesService;
let storage: StorageService; let storage: StorageService;
let cookie: CookieService; let cookie: CookieService;
@@ -44,6 +46,7 @@ describe('AlfrescoAuthenticationService', () => {
AlfrescoApiService, AlfrescoApiService,
AlfrescoAuthenticationService, AlfrescoAuthenticationService,
StorageService, StorageService,
UserPreferencesService,
{ provide: CookieService, useClass: CookieServiceMock }, { provide: CookieService, useClass: CookieServiceMock },
LogService LogService
] ]
@@ -54,6 +57,7 @@ describe('AlfrescoAuthenticationService', () => {
apiService = TestBed.get(AlfrescoApiService); apiService = TestBed.get(AlfrescoApiService);
authService = TestBed.get(AlfrescoAuthenticationService); authService = TestBed.get(AlfrescoAuthenticationService);
settingsService = TestBed.get(AlfrescoSettingsService); settingsService = TestBed.get(AlfrescoSettingsService);
preferences = TestBed.get(UserPreferencesService);
cookie = TestBed.get(CookieService); cookie = TestBed.get(CookieService);
storage = TestBed.get(StorageService); storage = TestBed.get(StorageService);
storage.clear(); storage.clear();
@@ -68,10 +72,10 @@ describe('AlfrescoAuthenticationService', () => {
describe('remembe me', () => { describe('remembe me', () => {
beforeEach(() => { beforeEach(() => {
settingsService.setProviders('ECM'); preferences.authType = 'ECM';
}); });
it('should save the remember me cookie as a session cookie after successful login', (done) => { it('[ECM] should save the remember me cookie as a session cookie after successful login', (done) => {
authService.login('fake-username', 'fake-password', false).subscribe(() => { authService.login('fake-username', 'fake-password', false).subscribe(() => {
expect(cookie['ALFRESCO_REMEMBER_ME']).not.toBeUndefined(); expect(cookie['ALFRESCO_REMEMBER_ME']).not.toBeUndefined();
expect(cookie['ALFRESCO_REMEMBER_ME'].expiration).toBeNull(); expect(cookie['ALFRESCO_REMEMBER_ME'].expiration).toBeNull();
@@ -85,7 +89,7 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
it('should save the remember me cookie as a persistent cookie after successful login', (done) => { it('[ECM] should save the remember me cookie as a persistent cookie after successful login', (done) => {
authService.login('fake-username', 'fake-password', true).subscribe(() => { authService.login('fake-username', 'fake-password', true).subscribe(() => {
expect(cookie['ALFRESCO_REMEMBER_ME']).not.toBeUndefined(); expect(cookie['ALFRESCO_REMEMBER_ME']).not.toBeUndefined();
expect(cookie['ALFRESCO_REMEMBER_ME'].expiration).not.toBeNull(); expect(cookie['ALFRESCO_REMEMBER_ME'].expiration).not.toBeNull();
@@ -99,7 +103,7 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
it('should not save the remember me cookie after failed login', (done) => { it('[ECM] should not save the remember me cookie after failed login', (done) => {
authService.login('fake-username', 'fake-password').subscribe( authService.login('fake-username', 'fake-password').subscribe(
(res) => {}, (res) => {},
(err: any) => { (err: any) => {
@@ -126,10 +130,10 @@ describe('AlfrescoAuthenticationService', () => {
describe('when the setting is ECM', () => { describe('when the setting is ECM', () => {
beforeEach(() => { beforeEach(() => {
settingsService.setProviders('ECM'); preferences.authType = 'ECM';
}); });
it('should return an ECM ticket after the login done', (done) => { it('[ECM] should return an ECM ticket after the login done', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => { authService.login('fake-username', 'fake-password').subscribe(() => {
expect(authService.isLoggedIn()).toBe(true); expect(authService.isLoggedIn()).toBe(true);
expect(authService.getTicketEcm()).toEqual('fake-post-ticket'); expect(authService.getTicketEcm()).toEqual('fake-post-ticket');
@@ -144,11 +148,11 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
it('should save only ECM ticket on localStorage', (done) => { it('[ECM] should save only ECM ticket on localStorage', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => { authService.login('fake-username', 'fake-password').subscribe(() => {
expect(authService.isLoggedIn()).toBe(true); expect(authService.isLoggedIn()).toBe(true);
expect(authService.getTicketBpm()).toBeNull(); expect(authService.getTicketBpm()).toBeNull();
expect(authService.alfrescoApi.getInstance().bpmAuth.isLoggedIn()).toBeFalsy(); expect(apiService.getInstance().bpmAuth.isLoggedIn()).toBeFalsy();
done(); done();
}); });
@@ -159,7 +163,7 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
xit('should return ticket undefined when the credentials are wrong', (done) => { xit('[ECM] should return ticket undefined when the credentials are wrong', (done) => {
authService.login('fake-wrong-username', 'fake-wrong-password').subscribe( authService.login('fake-wrong-username', 'fake-wrong-password').subscribe(
(res) => { (res) => {
}, },
@@ -185,7 +189,7 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
it('should login in the ECM if no provider are defined calling the login', (done) => { it('[ECM] should login in the ECM if no provider are defined calling the login', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => { authService.login('fake-username', 'fake-password').subscribe(() => {
done(); done();
}); });
@@ -197,7 +201,7 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
it('should return a ticket undefined after logout', (done) => { it('[ECM] should return a ticket undefined after logout', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => { authService.login('fake-username', 'fake-password').subscribe(() => {
authService.logout().subscribe(() => { authService.logout().subscribe(() => {
expect(authService.isLoggedIn()).toBe(false); expect(authService.isLoggedIn()).toBe(false);
@@ -218,7 +222,7 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
it('ticket should be deleted only after logout request is accepted', (done) => { it('[ECM] ticket should be deleted only after logout request is accepted', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => { authService.login('fake-username', 'fake-password').subscribe(() => {
let logoutPromise = authService.logout(); let logoutPromise = authService.logout();
@@ -244,7 +248,7 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
it('should return false if the user is not logged in', () => { it('[ECM] should return false if the user is not logged in', () => {
expect(authService.isLoggedIn()).toBe(false); expect(authService.isLoggedIn()).toBe(false);
expect(authService.isEcmLoggedIn()).toBe(false); expect(authService.isEcmLoggedIn()).toBe(false);
}); });
@@ -253,10 +257,10 @@ describe('AlfrescoAuthenticationService', () => {
describe('when the setting is BPM', () => { describe('when the setting is BPM', () => {
beforeEach(() => { beforeEach(() => {
settingsService.setProviders('BPM'); preferences.authType = 'BPM';
}); });
it('should return an BPM ticket after the login done', (done) => { it('[BPM] should return an BPM ticket after the login done', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => { authService.login('fake-username', 'fake-password').subscribe(() => {
expect(authService.isLoggedIn()).toBe(true); expect(authService.isLoggedIn()).toBe(true);
expect(authService.getTicketBpm()).toEqual('Basic ZmFrZS11c2VybmFtZTpmYWtlLXBhc3N3b3Jk'); expect(authService.getTicketBpm()).toEqual('Basic ZmFrZS11c2VybmFtZTpmYWtlLXBhc3N3b3Jk');
@@ -269,11 +273,11 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
it('should save only BPM ticket on localStorage', (done) => { it('[BPM] should save only BPM ticket on localStorage', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => { authService.login('fake-username', 'fake-password').subscribe(() => {
expect(authService.isLoggedIn()).toBe(true); expect(authService.isLoggedIn()).toBe(true);
expect(authService.getTicketEcm()).toBeNull(); expect(authService.getTicketEcm()).toBeNull();
expect(authService.alfrescoApi.getInstance().ecmAuth.isLoggedIn()).toBeFalsy(); expect(apiService.getInstance().ecmAuth.isLoggedIn()).toBeFalsy();
done(); done();
}); });
@@ -284,7 +288,7 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
xit('should return ticket undefined when the credentials are wrong', (done) => { xit('[BPM] should return ticket undefined when the credentials are wrong', (done) => {
authService.login('fake-wrong-username', 'fake-wrong-password').subscribe( authService.login('fake-wrong-username', 'fake-wrong-password').subscribe(
(res) => { (res) => {
}, },
@@ -300,7 +304,7 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
it('ticket should be deleted only after logout request is accepted', (done) => { it('[BPM] ticket should be deleted only after logout request is accepted', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => { authService.login('fake-username', 'fake-password').subscribe(() => {
let logoutPromise = authService.logout(); let logoutPromise = authService.logout();
@@ -324,7 +328,7 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
it('should return a ticket undefined after logout', (done) => { it('[BPM] should return a ticket undefined after logout', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => { authService.login('fake-username', 'fake-password').subscribe(() => {
authService.logout().subscribe(() => { authService.logout().subscribe(() => {
expect(authService.isLoggedIn()).toBe(false); expect(authService.isLoggedIn()).toBe(false);
@@ -343,7 +347,7 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
it('should return an error when the logout return error', (done) => { it('[BPM] should return an error when the logout return error', (done) => {
authService.logout().subscribe( authService.logout().subscribe(
(res) => { (res) => {
}, },
@@ -362,10 +366,10 @@ describe('AlfrescoAuthenticationService', () => {
describe('when the setting is both ECM and BPM ', () => { describe('when the setting is both ECM and BPM ', () => {
beforeEach(() => { beforeEach(() => {
settingsService.setProviders('ALL'); preferences.authType = 'ALL';
}); });
it('should return both ECM and BPM tickets after the login done', (done) => { it('[ALL] should return both ECM and BPM tickets after the login done', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => { authService.login('fake-username', 'fake-password').subscribe(() => {
expect(authService.isLoggedIn()).toBe(true); expect(authService.isLoggedIn()).toBe(true);
expect(authService.getTicketEcm()).toEqual('fake-post-ticket'); expect(authService.getTicketEcm()).toEqual('fake-post-ticket');
@@ -386,7 +390,7 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
xit('should return login fail if only ECM call fail', (done) => { xit('[ALL] should return login fail if only ECM call fail', (done) => {
authService.login('fake-username', 'fake-password').subscribe( authService.login('fake-username', 'fake-password').subscribe(
(res) => { (res) => {
}, },
@@ -407,7 +411,7 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
xit('should return login fail if only BPM call fail', (done) => { xit('[ALL] should return login fail if only BPM call fail', (done) => {
authService.login('fake-username', 'fake-password').subscribe( authService.login('fake-username', 'fake-password').subscribe(
(res) => { (res) => {
}, },
@@ -430,7 +434,7 @@ describe('AlfrescoAuthenticationService', () => {
}); });
}); });
xit('should return ticket undefined when the credentials are wrong', (done) => { xit('[ALL] should return ticket undefined when the credentials are wrong', (done) => {
authService.login('fake-username', 'fake-password').subscribe( authService.login('fake-username', 'fake-password').subscribe(
(res) => { (res) => {
}, },

View File

@@ -18,10 +18,10 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs/Rx'; import { Observable, Subject } from 'rxjs/Rx';
import { AlfrescoApiService } from './alfresco-api.service'; import { AlfrescoApiService } from './alfresco-api.service';
import { AlfrescoSettingsService } from './alfresco-settings.service';
import { CookieService } from './cookie.service'; import { CookieService } from './cookie.service';
import { LogService } from './log.service'; import { LogService } from './log.service';
import { StorageService } from './storage.service'; import { StorageService } from './storage.service';
import { UserPreferencesService } from './user-preferences.service';
const REMEMBER_ME_COOKIE_KEY = 'ALFRESCO_REMEMBER_ME'; const REMEMBER_ME_COOKIE_KEY = 'ALFRESCO_REMEMBER_ME';
const REMEMBER_ME_UNTIL = 1000 * 60 * 60 * 24 * 30 ; const REMEMBER_ME_UNTIL = 1000 * 60 * 60 * 24 * 30 ;
@@ -33,8 +33,8 @@ export class AlfrescoAuthenticationService {
onLogout: Subject<any> = new Subject<any>(); onLogout: Subject<any> = new Subject<any>();
constructor( constructor(
private settingsService: AlfrescoSettingsService, private preferences: UserPreferencesService,
public alfrescoApi: AlfrescoApiService, private alfrescoApi: AlfrescoApiService,
private storage: StorageService, private storage: StorageService,
private cookie: CookieService, private cookie: CookieService,
private logService: LogService) { private logService: LogService) {
@@ -61,7 +61,10 @@ export class AlfrescoAuthenticationService {
this.saveRememberMeCookie(rememberMe); this.saveRememberMeCookie(rememberMe);
this.saveTickets(); this.saveTickets();
this.onLogin.next(response); this.onLogin.next(response);
return { type: this.settingsService.getProviders(), ticket: response }; return {
type: this.preferences.authType,
ticket: response
};
}) })
.catch(err => this.handleError(err)); .catch(err => this.handleError(err));
} }

View File

@@ -25,6 +25,7 @@ import { AppConfigModule } from './app-config.service';
import { CookieService } from './cookie.service'; import { CookieService } from './cookie.service';
import { LogService } from './log.service'; import { LogService } from './log.service';
import { StorageService } from './storage.service'; import { StorageService } from './storage.service';
import { UserPreferencesService } from './user-preferences.service';
declare let jasmine: any; declare let jasmine: any;
@@ -51,6 +52,7 @@ describe('AlfrescoContentService', () => {
AlfrescoAuthenticationService, AlfrescoAuthenticationService,
AlfrescoSettingsService, AlfrescoSettingsService,
StorageService, StorageService,
UserPreferencesService,
{ provide: CookieService, useClass: CookieServiceMock }, { provide: CookieService, useClass: CookieServiceMock },
LogService LogService
] ]

View File

@@ -16,8 +16,11 @@
*/ */
import { async, TestBed } from '@angular/core/testing'; import { async, TestBed } from '@angular/core/testing';
import { AlfrescoApiService } from './alfresco-api.service';
import { AlfrescoSettingsService } from './alfresco-settings.service'; import { AlfrescoSettingsService } from './alfresco-settings.service';
import { AppConfigModule } from './app-config.service'; import { AppConfigModule } from './app-config.service';
import { StorageService } from './storage.service';
import { UserPreferencesService } from './user-preferences.service';
describe('AlfrescoSettingsService', () => { describe('AlfrescoSettingsService', () => {
@@ -28,10 +31,11 @@ describe('AlfrescoSettingsService', () => {
imports: [ imports: [
AppConfigModule AppConfigModule
], ],
declarations: [
],
providers: [ providers: [
AlfrescoSettingsService AlfrescoApiService,
AlfrescoSettingsService,
UserPreferencesService,
StorageService
] ]
}).compileComponents(); }).compileComponents();
})); }));

View File

@@ -16,57 +16,60 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { AppConfigService } from './app-config.service'; import { AppConfigService } from './app-config.service';
import { UserPreferencesService } from './user-preferences.service';
@Injectable() @Injectable()
export class AlfrescoSettingsService { export class AlfrescoSettingsService {
static DEFAULT_CSRF_CONFIG: boolean = false; constructor(
private appConfig: AppConfigService,
private _csrfDisabled: boolean = AlfrescoSettingsService.DEFAULT_CSRF_CONFIG; private preferences: UserPreferencesService) {
private providers: string = 'ALL'; // ECM, BPM , ALL }
public csrfSubject: Subject<boolean> = new Subject<boolean>();
public providerSubject: Subject<string> = new Subject<string>();
constructor(private appConfig: AppConfigService) {}
/** @deprecated in 1.6.0 */
public get ecmHost(): string { public get ecmHost(): string {
console.log('AlfrescoSettingsService.ecmHost is deprecated. Use AppConfigService instead.');
return this.appConfig.get<string>('ecmHost'); return this.appConfig.get<string>('ecmHost');
} }
/** @deprecated in 1.7.0 */
public set csrfDisabled(csrfDisabled: boolean) { public set csrfDisabled(csrfDisabled: boolean) {
this.csrfSubject.next(csrfDisabled); console.log(`AlfrescoSettingsService.csrfDisabled is deprecated. Use UserPreferencesService.disableCSRF instead.`);
this._csrfDisabled = csrfDisabled; this.preferences.disableCSRF = csrfDisabled;
} }
/* @deprecated in 1.6.0 */ /** @deprecated in 1.6.0 */
public set ecmHost(ecmHostUrl: string) { public set ecmHost(ecmHostUrl: string) {
console.log('AlfrescoSettingsService.ecmHost is deprecated. Use AppConfigService instead.'); console.log('AlfrescoSettingsService.ecmHost is deprecated. Use AppConfigService instead.');
} }
/** @deprecated in 1.6.0 */
public get bpmHost(): string { public get bpmHost(): string {
console.log('AlfrescoSettingsService.bpmHost is deprecated. Use AppConfigService instead.');
return this.appConfig.get<string>('bpmHost'); return this.appConfig.get<string>('bpmHost');
} }
/* @deprecated in 1.6.0 */ /** @deprecated in 1.6.0 */
public set bpmHost(bpmHostUrl: string) { public set bpmHost(bpmHostUrl: string) {
console.log('AlfrescoSettingsService.bpmHost is deprecated. Use AppConfigService instead.'); console.log('AlfrescoSettingsService.bpmHost is deprecated. Use AppConfigService instead.');
} }
/* @deprecated in 1.6.0 */ /** @deprecated in 1.6.0 */
public getBPMApiBaseUrl(): string { public getBPMApiBaseUrl(): string {
console.log('AlfrescoSettingsService.getBPMApiBaseUrl is deprecated.'); console.log('AlfrescoSettingsService.getBPMApiBaseUrl is deprecated.');
return this.bpmHost + '/activiti-app'; return this.bpmHost + '/activiti-app';
} }
/** @deprecated in 1.7.0 */
public getProviders(): string { public getProviders(): string {
return this.providers; console.log(`AlfrescoSettingsService.getProviders is deprecated. Use UserPreferencesService.authType instead.`);
return this.preferences.authType;
} }
/** @deprecated in 1.7.0 */
public setProviders(providers: string) { public setProviders(providers: string) {
this.providerSubject.next(providers); console.log(`AlfrescoSettingsService.getProviders is deprecated. Use UserPreferencesService.authType instead.`);
this.providers = providers; this.preferences.authType = providers;
} }
} }

View File

@@ -28,6 +28,7 @@ import { AuthGuardBpm } from './auth-guard-bpm.service';
import { CookieService } from './cookie.service'; import { CookieService } from './cookie.service';
import { LogService } from './log.service'; import { LogService } from './log.service';
import { StorageService } from './storage.service'; import { StorageService } from './storage.service';
import { UserPreferencesService } from './user-preferences.service';
describe('AuthGuardService BPM', () => { describe('AuthGuardService BPM', () => {
@@ -45,6 +46,7 @@ describe('AuthGuardService BPM', () => {
AlfrescoApiService, AlfrescoApiService,
AlfrescoAuthenticationService, AlfrescoAuthenticationService,
StorageService, StorageService,
UserPreferencesService,
{ provide: CookieService, useClass: CookieServiceMock }, { provide: CookieService, useClass: CookieServiceMock },
LogService LogService
] ]

View File

@@ -28,6 +28,7 @@ import { AuthGuardEcm } from './auth-guard-ecm.service';
import { CookieService } from './cookie.service'; import { CookieService } from './cookie.service';
import { LogService } from './log.service'; import { LogService } from './log.service';
import { StorageService } from './storage.service'; import { StorageService } from './storage.service';
import { UserPreferencesService } from './user-preferences.service';
describe('AuthGuardService ECM', () => { describe('AuthGuardService ECM', () => {
@@ -45,6 +46,7 @@ describe('AuthGuardService ECM', () => {
AlfrescoApiService, AlfrescoApiService,
AlfrescoAuthenticationService, AlfrescoAuthenticationService,
StorageService, StorageService,
UserPreferencesService,
{ provide: CookieService, useClass: CookieServiceMock }, { provide: CookieService, useClass: CookieServiceMock },
LogService LogService
] ]

View File

@@ -28,6 +28,7 @@ import { AuthGuard } from './auth-guard.service';
import { CookieService } from './cookie.service'; import { CookieService } from './cookie.service';
import { LogService } from './log.service'; import { LogService } from './log.service';
import { StorageService } from './storage.service'; import { StorageService } from './storage.service';
import { UserPreferencesService } from './user-preferences.service';
describe('AuthGuardService', () => { describe('AuthGuardService', () => {
@@ -42,6 +43,7 @@ describe('AuthGuardService', () => {
AlfrescoSettingsService, AlfrescoSettingsService,
AlfrescoApiService, AlfrescoApiService,
AlfrescoAuthenticationService, AlfrescoAuthenticationService,
UserPreferencesService,
StorageService, StorageService,
{ provide: CookieService, useClass: CookieServiceMock }, { provide: CookieService, useClass: CookieServiceMock },
LogService LogService

View File

@@ -27,6 +27,7 @@ import { CookieService } from './cookie.service';
import { LogService } from './log.service'; import { LogService } from './log.service';
import { StorageService } from './storage.service'; import { StorageService } from './storage.service';
import { ThumbnailService } from './thumbnail.service'; import { ThumbnailService } from './thumbnail.service';
import { UserPreferencesService } from './user-preferences.service';
describe('ThumbnailService', () => { describe('ThumbnailService', () => {
@@ -38,6 +39,7 @@ describe('ThumbnailService', () => {
HttpModule HttpModule
], ],
providers: [ providers: [
UserPreferencesService,
AlfrescoAuthenticationService, AlfrescoAuthenticationService,
AlfrescoContentService, AlfrescoContentService,
AlfrescoSettingsService, AlfrescoSettingsService,

View File

@@ -16,6 +16,7 @@
*/ */
import { async, TestBed } from '@angular/core/testing'; import { async, TestBed } from '@angular/core/testing';
import { AlfrescoApiService } from './alfresco-api.service';
import { AppConfigModule } from './app-config.service'; import { AppConfigModule } from './app-config.service';
import { StorageService } from './storage.service'; import { StorageService } from './storage.service';
import { UserPreferencesService } from './user-preferences.service'; import { UserPreferencesService } from './user-preferences.service';
@@ -36,6 +37,7 @@ describe('UserPreferencesService', () => {
}) })
], ],
providers: [ providers: [
AlfrescoApiService,
StorageService, StorageService,
UserPreferencesService UserPreferencesService
] ]

View File

@@ -16,6 +16,7 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AlfrescoApiService } from './alfresco-api.service';
import { AppConfigService } from './app-config.service'; import { AppConfigService } from './app-config.service';
import { StorageService } from './storage.service'; import { StorageService } from './storage.service';
@@ -36,7 +37,9 @@ export class UserPreferencesService {
constructor( constructor(
appConfig: AppConfigService, appConfig: AppConfigService,
private storage: StorageService) { private storage: StorageService,
private apiService: AlfrescoApiService
) {
this.defaults.paginationSize = appConfig.get('pagination.size', 25); this.defaults.paginationSize = appConfig.get('pagination.size', 25);
} }
@@ -53,9 +56,31 @@ export class UserPreferencesService {
); );
} }
get(property: string): string { get(property: string, defaultValue?: string): string {
const key = this.getPropertyKey(property); const key = this.getPropertyKey(property);
return this.storage.getItem(key); const value = this.storage.getItem(key);
if (value === undefined) {
return defaultValue;
}
return value;
}
set authType(value: string) {
this.storage.setItem('AUTH_TYPE', value);
this.apiService.reset();
}
get authType(): string {
return this.storage.getItem('AUTH_TYPE') || 'ALL';
}
set disableCSRF(value: boolean) {
this.set('DISABLE_CSRF', value);
this.apiService.reset();
}
get disableCSRF(): boolean {
return this.get('DISABLE_CSRF') === 'true';
} }
set paginationSize(value: number) { set paginationSize(value: number) {