mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-5139] User name style and Discovery service initialization fix (#7010)
* [AAE-5139] User name style fix and Discovery serice fixed * * fixed unit test * * fixed test and us latest js-api events * * tests fixed * * update js api * * fixed test and lint
This commit is contained in:
@@ -43,9 +43,10 @@ describe('NodeDownloadDirective', () => {
|
||||
let dialogSpy;
|
||||
const mockOauth2Auth = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => Promise.resolve(),
|
||||
on: jasmine.createSpy('on')
|
||||
}
|
||||
callCustomApi: () => Promise.resolve()
|
||||
},
|
||||
isEcmLoggedIn: jasmine.createSpy('isEcmLoggedIn'),
|
||||
reply: jasmine.createSpy('reply')
|
||||
};
|
||||
|
||||
setupTestBed({
|
||||
|
@@ -62,5 +62,6 @@ export let searchMockApi = {
|
||||
},
|
||||
isEcmLoggedIn() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
reply: () => ''
|
||||
};
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, from, throwError, Observer, ReplaySubject, Subject } from 'rxjs';
|
||||
import { Observable, from, throwError, Observer, ReplaySubject } from 'rxjs';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { CookieService } from './cookie.service';
|
||||
import { LogService } from './log.service';
|
||||
@@ -38,12 +38,6 @@ export class AuthenticationService {
|
||||
private redirectUrl: RedirectionModel = null;
|
||||
|
||||
private bearerExcludedUrls: string[] = ['auth/realms', 'resources/', 'assets/'];
|
||||
|
||||
/**
|
||||
* Emits oAuth token exchange event
|
||||
*/
|
||||
onTokenExchange: Subject<string> = new Subject<string>();
|
||||
|
||||
/**
|
||||
* Emits Basic auth login event
|
||||
*/
|
||||
@@ -60,14 +54,8 @@ export class AuthenticationService {
|
||||
private alfrescoApi: AlfrescoApiService,
|
||||
private cookie: CookieService,
|
||||
private logService: LogService) {
|
||||
this.listenForOauthTokenExchange();
|
||||
}
|
||||
|
||||
private listenForOauthTokenExchange() {
|
||||
this.alfrescoApi.alfrescoApiInitialized.subscribe(() => {
|
||||
this.alfrescoApi.getInstance().oauth2Auth?.on('token_issued', () => {
|
||||
this.onTokenExchange.next(this.alfrescoApi.getInstance().oauth2Auth.token);
|
||||
});
|
||||
this.alfrescoApi.getInstance().reply('logged-in', () => this.onLogin.next());
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -220,7 +220,7 @@ describe('Discovery Api Service', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Oauth', () => {
|
||||
describe('OnLogin Event', () => {
|
||||
setupTestBed({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
@@ -234,7 +234,7 @@ describe('Discovery Api Service', () => {
|
||||
authenticationService = TestBed.inject(AuthenticationService);
|
||||
});
|
||||
|
||||
it('Should retrieve the info about the product for Oauth', done => {
|
||||
it('Should retrieve the info about the product on login/refresh the application', done => {
|
||||
spyOn(apiService.getInstance(), 'isEcmLoggedIn').and.returnValue(true);
|
||||
spyOn(service, 'getEcmProductInfo').and.returnValue(of(new EcmProductVersionModel(fakeEcmDiscoveryResponse)));
|
||||
|
||||
@@ -252,7 +252,7 @@ describe('Discovery Api Service', () => {
|
||||
done();
|
||||
}
|
||||
);
|
||||
authenticationService.onTokenExchange.next('<token>');
|
||||
authenticationService.onLogin.next('<token>');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { from, merge, Observable, throwError, Subject } from 'rxjs';
|
||||
import { from, Observable, throwError, Subject } from 'rxjs';
|
||||
import { BpmProductVersionModel, EcmProductVersionModel } from '../models/product-version.model';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { catchError, filter, map, switchMap, take } from 'rxjs/operators';
|
||||
import { catchError, map, switchMap, filter, take } from 'rxjs/operators';
|
||||
import { Activiti, SystemPropertiesRepresentation } from '@alfresco/js-api';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
|
||||
@@ -37,9 +37,10 @@ export class DiscoveryApiService {
|
||||
private apiService: AlfrescoApiService,
|
||||
private authenticationService: AuthenticationService) {
|
||||
|
||||
merge(this.authenticationService.onTokenExchange.pipe(take(1)), this.authenticationService.onLogin)
|
||||
this.authenticationService.onLogin
|
||||
.pipe(
|
||||
filter(() => this.apiService.getInstance()?.isEcmLoggedIn()),
|
||||
take(1),
|
||||
switchMap(() => this.getEcmProductInfo())
|
||||
)
|
||||
.subscribe((info) => this.ecmProductInfo$.next(info));
|
||||
|
@@ -48,7 +48,8 @@ describe('NodesApiService', () => {
|
||||
},
|
||||
isEcmLoggedIn() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
reply: jasmine.createSpy('reply')
|
||||
};
|
||||
|
||||
setupTestBed({
|
||||
|
Reference in New Issue
Block a user