mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-5373] - Every getPerson() call changes current user (#8830)
This commit is contained in:
@@ -15,9 +15,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { fakeEcmUserList, createNewPersonMock, fakeEcmUser, fakeEcmAdminUser } from '../mocks/ecm-user.service.mock';
|
||||
import { AuthenticationService, AlfrescoApiService, AlfrescoApiServiceMock, CoreTestingModule, LogService } from '@alfresco/adf-core';
|
||||
import { PeopleContentService, PeopleContentQueryRequestModel } from './people-content.service';
|
||||
import {
|
||||
createNewPersonMock,
|
||||
fakeEcmAdminUser,
|
||||
fakeEcmUser,
|
||||
fakeEcmUser2,
|
||||
fakeEcmUserList
|
||||
} from '../mocks/ecm-user.service.mock';
|
||||
import {
|
||||
AlfrescoApiService,
|
||||
AlfrescoApiServiceMock,
|
||||
AuthenticationService,
|
||||
CoreTestingModule,
|
||||
LogService
|
||||
} from '@alfresco/adf-core';
|
||||
import { PeopleContentQueryRequestModel, PeopleContentService } from './people-content.service';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
@@ -135,4 +147,18 @@ describe('PeopleContentService', () => {
|
||||
authenticationService.onLogout.next(true);
|
||||
expect(peopleContentService.isCurrentUserAdmin()).toBe(false);
|
||||
});
|
||||
|
||||
it('should not change current user on every getPerson call', async () => {
|
||||
const getCurrentPersonSpy = spyOn(peopleContentService.peopleApi, 'getPerson').and.returnValue(Promise.resolve({entry: fakeEcmAdminUser} as any));
|
||||
await peopleContentService.getCurrentUserInfo().toPromise();
|
||||
|
||||
getCurrentPersonSpy.and.returnValue(Promise.resolve({entry: fakeEcmUser2} as any));
|
||||
await peopleContentService.getPerson('fake-id').toPromise();
|
||||
|
||||
expect(getCurrentPersonSpy.calls.count()).toEqual(2);
|
||||
const currentUser = await peopleContentService.getCurrentUserInfo().toPromise();
|
||||
expect(peopleContentService.isCurrentUserAdmin()).toBe(true);
|
||||
expect(currentUser.id).toEqual(fakeEcmAdminUser.id);
|
||||
expect(currentUser.id).not.toEqual(fakeEcmUser2.id);
|
||||
});
|
||||
});
|
||||
|
@@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, from, throwError, of } from 'rxjs';
|
||||
import { AuthenticationService, AlfrescoApiService, LogService } from '@alfresco/adf-core';
|
||||
import { from, Observable, of, throwError } from 'rxjs';
|
||||
import { AlfrescoApiService, AuthenticationService, LogService } from '@alfresco/adf-core';
|
||||
import { catchError, map, tap } from 'rxjs/operators';
|
||||
import { PeopleApi, PersonBodyCreate, Pagination, PersonBodyUpdate } from '@alfresco/js-api';
|
||||
import { Pagination, PeopleApi, PersonBodyCreate, PersonBodyUpdate } from '@alfresco/js-api';
|
||||
import { EcmUserModel } from '../models/ecm-user.model';
|
||||
import { ContentService } from './content.service';
|
||||
|
||||
@@ -77,7 +77,6 @@ export class PeopleContentService {
|
||||
return from(this.peopleApi.getPerson(personId))
|
||||
.pipe(
|
||||
map((personEntry) => new EcmUserModel(personEntry.entry)),
|
||||
tap(user => this.currentUser = user),
|
||||
catchError((error) => this.handleError(error)));
|
||||
}
|
||||
|
||||
@@ -94,7 +93,7 @@ export class PeopleContentService {
|
||||
if (this.currentUser) {
|
||||
return of(this.currentUser);
|
||||
}
|
||||
return this.getPerson('-me-');
|
||||
return this.getPerson('-me-').pipe(tap(user => (this.currentUser = user)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user