[ACS-5373] - Every getPerson() call changes current user (#8830)

This commit is contained in:
DominikIwanek
2023-08-17 17:08:46 +02:00
committed by GitHub
parent 673010d271
commit f8d587bc2e
2 changed files with 33 additions and 8 deletions

View File

@@ -15,9 +15,21 @@
* limitations under the License. * limitations under the License.
*/ */
import { fakeEcmUserList, createNewPersonMock, fakeEcmUser, fakeEcmAdminUser } from '../mocks/ecm-user.service.mock'; import {
import { AuthenticationService, AlfrescoApiService, AlfrescoApiServiceMock, CoreTestingModule, LogService } from '@alfresco/adf-core'; createNewPersonMock,
import { PeopleContentService, PeopleContentQueryRequestModel } from './people-content.service'; 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 { TranslateModule } from '@ngx-translate/core';
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
@@ -135,4 +147,18 @@ describe('PeopleContentService', () => {
authenticationService.onLogout.next(true); authenticationService.onLogout.next(true);
expect(peopleContentService.isCurrentUserAdmin()).toBe(false); 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);
});
}); });

View File

@@ -16,10 +16,10 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, from, throwError, of } from 'rxjs'; import { from, Observable, of, throwError } from 'rxjs';
import { AuthenticationService, AlfrescoApiService, LogService } from '@alfresco/adf-core'; import { AlfrescoApiService, AuthenticationService, LogService } from '@alfresco/adf-core';
import { catchError, map, tap } from 'rxjs/operators'; 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 { EcmUserModel } from '../models/ecm-user.model';
import { ContentService } from './content.service'; import { ContentService } from './content.service';
@@ -77,7 +77,6 @@ export class PeopleContentService {
return from(this.peopleApi.getPerson(personId)) return from(this.peopleApi.getPerson(personId))
.pipe( .pipe(
map((personEntry) => new EcmUserModel(personEntry.entry)), map((personEntry) => new EcmUserModel(personEntry.entry)),
tap(user => this.currentUser = user),
catchError((error) => this.handleError(error))); catchError((error) => this.handleError(error)));
} }
@@ -94,7 +93,7 @@ export class PeopleContentService {
if (this.currentUser) { if (this.currentUser) {
return of(this.currentUser); return of(this.currentUser);
} }
return this.getPerson('-me-'); return this.getPerson('-me-').pipe(tap(user => (this.currentUser = user)));
} }
/** /**