[AAE-5021] Add listPeople method to PeopleContentService (#6947)

* [AAE-5021] Add listPeople method to PeopleContentService

* lint

* Replace Person with EcmUserModel

* Update imports to @alfresco/adf-core

* Change to const + lint
This commit is contained in:
Thomas Hunter
2021-04-28 17:50:53 +02:00
committed by GitHub
parent 42c81e46bb
commit 9cbae9abd8
11 changed files with 124 additions and 46 deletions

View File

@@ -17,13 +17,16 @@ Gets information about a Content Services user.
Gets information about the user who is currently logged in. Gets information about the user who is currently logged in.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<any>` - User information - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<any>` - User information
- **getPerson**(personId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<any>`<br/> - **getPerson**(personId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<any>`<br/>
Gets information about a user identified by their username. Gets information about a user identified by their ID.
- _personId:_ `string` - ID of the target user - _personId:_ `string` - ID of the target user
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<any>` - User information - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<any>` - User information
- **createPerson**(newPerson: [PersonBodyCreate](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/content-rest-api/docs/PersonBodyCreate.md)): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`EcmUserModel`](../../core/models/ecm-user.model.md)`>`<br/> - **listPeople**(options: `any`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`EcmUserModel`](../../core/models/ecm-user.model.md)`[]>`<br/> Gets information on a list of users
- _options:_ `any` - Optional parameters supported by JS-API
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`EcmUserModel`](../../core/models/ecm-user.model.md)`[]>`
- **createPerson**(newPerson: [`PersonBodyCreate`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/content-rest-api/docs/PersonBodyCreate.md)): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`EcmUserModel`](../../core/models/ecm-user.model.md)`>`<br/>
Creates new person. Creates new person.
- _newPerson:_ `<`[PersonBodyCreate](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/content-rest-api/docs/PersonBodyCreate.md)`>` - Object containing the new person details - _newPerson:_ `<`[`PersonBodyCreate`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/content-rest-api/docs/PersonBodyCreate.md)`>` - Object containing the new person details
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html) `<`[`EcmUserModel`](../../core/models/ecm-user.model.md)`[]>` - Created new person. - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`EcmUserModel`](../../core/models/ecm-user.model.md)`>` - Created new person.
## Details ## Details
@@ -33,12 +36,10 @@ in the [Ecm User model docs](../models/ecm-user.model.md). The `avatarId` passed
returned for a particular person. returned for a particular person.
See the See the
[getPerson](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/PeopleApi.md#getPerson) [getPerson](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/PeopleApi.md#getPerson),
method in the Alfresco JS API for more information about the REST calls used by this service. [listPeople](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/PeopleApi.md#listPeople) and
See the
[createPerson](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/PeopleApi.md#createPerson) [createPerson](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/PeopleApi.md#createPerson)
method in the Alfresco JS API for more information about the REST calls used by this service. methods in the Alfresco JS API for more information about the REST calls used by this service.
## See also ## See also

View File

@@ -17,8 +17,9 @@
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { BehaviorSubject } from 'rxjs'; import { BehaviorSubject } from 'rxjs';
import { Group, NodeEntry, Person } from '@alfresco/js-api'; import { Group, NodeEntry } from '@alfresco/js-api';
import { NodePermissionService } from '../../services/node-permission.service'; import { NodePermissionService } from '../../services/node-permission.service';
import { EcmUserModel } from '@alfresco/adf-core';
@Component({ @Component({
selector: 'adf-user-name-column', selector: 'adf-user-name-column',
@@ -59,7 +60,7 @@ export class UserNameColumnComponent implements OnInit {
} }
} }
private updatePerson(person: Person) { private updatePerson(person: EcmUserModel) {
if (person) { if (person) {
this.displayText$.next(`${person.firstName ?? ''} ${person.lastName ?? ''}`); this.displayText$.next(`${person.firstName ?? ''} ${person.lastName ?? ''}`);
this.subTitleText$.next(person.email ?? ''); this.subTitleText$.next(person.email ?? '');

View File

@@ -15,9 +15,10 @@
* limitations under the License. * limitations under the License.
*/ */
import { Group, Node, NodeEntry, PermissionElement, Person } from '@alfresco/js-api'; import { Group, Node, NodeEntry, PermissionElement } from '@alfresco/js-api';
import { PermissionDisplayModel } from './permission.model'; import { PermissionDisplayModel } from './permission.model';
import { RoleModel } from './role.model'; import { RoleModel } from './role.model';
import { EcmUserModel } from '@alfresco/adf-core';
export interface NodePermissionsModel { export interface NodePermissionsModel {
node: Node; node: Node;
@@ -31,7 +32,7 @@ export class MemberModel {
role: string; role: string;
accessStatus: PermissionElement.AccessStatusEnum | string; accessStatus: PermissionElement.AccessStatusEnum | string;
entry: { entry: {
person?: Person; person?: EcmUserModel;
group?: Group; group?: Group;
}; };
readonly: boolean = false; readonly: boolean = false;
@@ -46,7 +47,7 @@ export class MemberModel {
const result = new MemberModel(); const result = new MemberModel();
if (entry.nodeType === 'cm:person') { if (entry.nodeType === 'cm:person') {
const person = new Person({ const person = new EcmUserModel({
firstName: entry.properties['cm:firstName'], firstName: entry.properties['cm:firstName'],
lastName: entry.properties['cm:lastName'], lastName: entry.properties['cm:lastName'],
email: entry.properties['cm:email'], email: entry.properties['cm:email'],

View File

@@ -15,8 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { AlfrescoApiService, NodesApiService, SearchService, TranslationService } from '@alfresco/adf-core'; import { AlfrescoApiService, NodesApiService, SearchService, TranslationService, EcmUserModel } from '@alfresco/adf-core';
import { Group, GroupMemberEntry, GroupMemberPaging, Node, PathElement, PermissionElement, Person, QueryBody } from '@alfresco/js-api'; import { Group, GroupMemberEntry, GroupMemberPaging, Node, PathElement, PermissionElement, QueryBody } from '@alfresco/js-api';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { forkJoin, from, Observable, of, throwError } from 'rxjs'; import { forkJoin, from, Observable, of, throwError } from 'rxjs';
import { catchError, map, switchMap } from 'rxjs/operators'; import { catchError, map, switchMap } from 'rxjs/operators';
@@ -287,14 +287,14 @@ export class NodePermissionService {
); );
} }
transformNodeToUserPerson(node: Node): { person: Person, group: Group } { transformNodeToUserPerson(node: Node): { person: EcmUserModel, group: Group } {
let person = null, group = null; let person = null, group = null;
if (node.nodeType === 'cm:person') { if (node.nodeType === 'cm:person') {
const firstName = node.properties['cm:firstName']; const firstName = node.properties['cm:firstName'];
const lastName = node.properties['cm:lastName']; const lastName = node.properties['cm:lastName'];
const email = node.properties['cm:email']; const email = node.properties['cm:email'];
const id = node.properties['cm:userName']; const id = node.properties['cm:userName'];
person = new Person({ id, firstName, lastName, email}); person = new EcmUserModel({ id, firstName, lastName, email});
} }
if (node.nodeType === 'cm:authorityContainer') { if (node.nodeType === 'cm:authorityContainer') {

View File

@@ -18,7 +18,7 @@
import { EcmCompanyModel } from '../models/ecm-company.model'; import { EcmCompanyModel } from '../models/ecm-company.model';
import { PersonEntry, Person } from '@alfresco/js-api'; import { PersonEntry, Person } from '@alfresco/js-api';
export let fakeEcmCompany: EcmCompanyModel = { export const fakeEcmCompany: EcmCompanyModel = {
organization: 'company-fake-name', organization: 'company-fake-name',
address1: 'fake-address-1', address1: 'fake-address-1',
address2: 'fake-address-2', address2: 'fake-address-2',
@@ -29,7 +29,7 @@ export let fakeEcmCompany: EcmCompanyModel = {
email: 'fakeCompany@fake.com' email: 'fakeCompany@fake.com'
}; };
export let fakeEcmUser = { export const fakeEcmUser = {
id: 'fake-id', id: 'fake-id',
firstName: 'fake-ecm-first-name', firstName: 'fake-ecm-first-name',
lastName: 'fake-ecm-last-name', lastName: 'fake-ecm-last-name',
@@ -50,7 +50,18 @@ export let fakeEcmUser = {
emailNotificationsEnabled: true emailNotificationsEnabled: true
}; };
export let fakeEcmUserNoImage = { export const fakeEcmUser2 = {
id: 'another-fake-id',
firstName: 'another-fake-first-name',
lastName: 'another',
displayName: 'admin.adf User',
email: 'admin.adf@alfresco.com',
company: null,
enabled: true,
emailNotificationsEnabled: true
};
export const fakeEcmUserNoImage = {
id: 'fake-id', id: 'fake-id',
firstName: 'fake-first-name', firstName: 'fake-first-name',
lastName: 'fake-last-name', lastName: 'fake-last-name',
@@ -71,7 +82,7 @@ export let fakeEcmUserNoImage = {
emailNotificationsEnabled: true emailNotificationsEnabled: true
}; };
export let fakeEcmEditedUser = { export const fakeEcmEditedUser = {
id: 'fake-id', id: 'fake-id',
firstName: null, firstName: null,
lastName: 'fake-last-name', lastName: 'fake-last-name',
@@ -92,6 +103,26 @@ export let fakeEcmEditedUser = {
emailNotificationsEnabled: true emailNotificationsEnabled: true
}; };
export const fakeEcmUserList = {
list: {
pagination: {
count: 2,
hasMoreItems: false,
totalItems: 2,
skipCount: 0,
maxItems: 100
},
entries: [
{
entry: fakeEcmUser
},
{
entry: fakeEcmUser2
}
]
}
};
export const createNewPersonMock = { export const createNewPersonMock = {
id: 'fake-id', id: 'fake-id',
firstName: 'fake-ecm-first-name', firstName: 'fake-ecm-first-name',

View File

@@ -15,13 +15,13 @@
* limitations under the License. * limitations under the License.
*/ */
import { Person } from '@alfresco/js-api'; import { EcmUserModel } from './ecm-user.model';
export class CommentModel { export class CommentModel {
id: number; id: number;
message: string; message: string;
created: Date; created: Date;
createdBy: Person; createdBy: EcmUserModel;
isSelected: boolean; isSelected: boolean;
constructor(obj?: any) { constructor(obj?: any) {

View File

@@ -15,28 +15,32 @@
* limitations under the License. * limitations under the License.
*/ */
import { Person } from '@alfresco/js-api'; import { Capabilities } from '@alfresco/js-api';
import { EcmCompanyModel } from './ecm-company.model'; import { EcmCompanyModel } from './ecm-company.model';
export class EcmUserModel implements Person { export class EcmUserModel {
id: string; id: string;
firstName: string; firstName: string;
lastName: string; lastName?: string;
description: string; displayName?: string;
avatarId: string; description?: string;
avatarId?: string;
email: string; email: string;
skypeId: string; skypeId?: string;
googleId: string; googleId?: string;
instantMessageId: string; instantMessageId?: string;
jobTitle: string; jobTitle?: string;
location: string; location?: string;
company: EcmCompanyModel; company: EcmCompanyModel;
mobile: string; mobile?: string;
telephone: string; telephone?: string;
statusUpdatedAt: Date; statusUpdatedAt?: Date;
userStatus: string; userStatus?: string;
enabled: boolean; enabled: boolean;
emailNotificationsEnabled: boolean; emailNotificationsEnabled?: boolean;
aspectNames?: string[];
properties?: { [key: string]: string; };
capabilities?: Capabilities;
constructor(obj?: any) { constructor(obj?: any) {
this.id = obj && obj.id || null; this.id = obj && obj.id || null;
@@ -57,5 +61,8 @@ export class EcmUserModel implements Person {
this.userStatus = obj && obj.userStatus; this.userStatus = obj && obj.userStatus;
this.enabled = obj && obj.enabled; this.enabled = obj && obj.enabled;
this.emailNotificationsEnabled = obj && obj.emailNotificationsEnabled; this.emailNotificationsEnabled = obj && obj.emailNotificationsEnabled;
this.aspectNames = obj && obj.aspectNames;
this.properties = obj && obj.properties;
this.capabilities = obj && obj.capabilities;
} }
} }

View File

@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { fakeEcmUser, createNewPersonMock, getFakeUserWithContentAdminCapability } from '../mock/ecm-user.service.mock'; import { fakeEcmUser, fakeEcmUserList, createNewPersonMock, getFakeUserWithContentAdminCapability } from '../mock/ecm-user.service.mock';
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock'; import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
import { CoreTestingModule } from '../testing/core.testing.module'; import { CoreTestingModule } from '../testing/core.testing.module';
import { PeopleContentService } from './people-content.service'; import { PeopleContentService } from './people-content.service';
@@ -25,6 +25,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { LogService } from './log.service'; import { LogService } from './log.service';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { EcmUserModel } from '../models/ecm-user.model';
describe('PeopleContentService', () => { describe('PeopleContentService', () => {
@@ -71,6 +72,25 @@ describe('PeopleContentService', () => {
}); });
}); });
it('should be able to list people', (done) => {
spyOn(service.peopleApi, 'listPeople').and.returnValue(Promise.resolve(fakeEcmUserList));
service.listPeople().subscribe((people: EcmUserModel[]) => {
expect(people).toBeDefined();
expect(people.length).toEqual(2);
expect(people[0].id).toEqual('fake-id');
expect(people[1].id).toEqual('another-fake-id');
done();
});
});
it('should call listPeople api method', (done) => {
const listPeopleSpy = spyOn(service.peopleApi, 'listPeople').and.returnValue(Promise.resolve(fakeEcmUserList));
service.listPeople().subscribe(() => {
expect(listPeopleSpy).toHaveBeenCalled();
done();
});
});
it('should be able to create new person', (done) => { it('should be able to create new person', (done) => {
spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve({ entry: fakeEcmUser })); spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve({ entry: fakeEcmUser }));
service.createPerson(createNewPersonMock).subscribe((person) => { service.createPerson(createNewPersonMock).subscribe((person) => {

View File

@@ -63,6 +63,25 @@ export class PeopleContentService {
return this.getPerson('-me-'); return this.getPerson('-me-');
} }
/**
* Gets a list of people.
* @param opts Optional parameters supported by JS-API
* @returns Array of people
*/
listPeople(options?): Observable<EcmUserModel[]> {
const promise = this.peopleApi.listPeople(options);
return from(promise).pipe(
map(response => {
const people: EcmUserModel[] = [];
response.list.entries.forEach((person: PersonEntry) => {
people.push(<EcmUserModel> person?.entry);
});
return people;
}),
catchError((err) => this.handleError(err))
);
}
/** /**
* Creates new person. * Creates new person.
* @param newPerson Object containing the new person details. * @param newPerson Object containing the new person details.

View File

@@ -18,12 +18,11 @@
import { Component, SimpleChange, ViewChild } from '@angular/core'; import { Component, SimpleChange, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { AppConfigService, setupTestBed, DataRowEvent, ObjectDataRow } from '@alfresco/adf-core'; import { AppConfigService, setupTestBed, DataRowEvent, ObjectDataRow, EcmUserModel } from '@alfresco/adf-core';
import { ServiceTaskListCloudComponent } from './service-task-list-cloud.component'; import { ServiceTaskListCloudComponent } from './service-task-list-cloud.component';
import { fakeServiceTask, fakeCustomSchema } from '../mock/fake-task-response.mock'; import { fakeServiceTask, fakeCustomSchema } from '../mock/fake-task-response.mock';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { Person } from '@alfresco/js-api';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { TaskListCloudSortingModel } from '../models/task-list-sorting.model'; import { TaskListCloudSortingModel } from '../models/task-list-sorting.model';
import { skip } from 'rxjs/operators'; import { skip } from 'rxjs/operators';
@@ -42,7 +41,7 @@ class CustomTaskListComponent {
@ViewChild(ServiceTaskListCloudComponent) @ViewChild(ServiceTaskListCloudComponent)
taskList: ServiceTaskListCloudComponent; taskList: ServiceTaskListCloudComponent;
getFullName(person: Person): string { getFullName(person: EcmUserModel): string {
return `${person.firstName} ${person.lastName}`; return `${person.firstName} ${person.lastName}`;
} }
} }

View File

@@ -18,13 +18,12 @@
import { Component, SimpleChange, ViewChild } from '@angular/core'; import { Component, SimpleChange, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { AppConfigService, setupTestBed, DataRowEvent, ObjectDataRow } from '@alfresco/adf-core'; import { AppConfigService, setupTestBed, DataRowEvent, ObjectDataRow, EcmUserModel } from '@alfresco/adf-core';
import { TaskListCloudService } from '../services/task-list-cloud.service'; import { TaskListCloudService } from '../services/task-list-cloud.service';
import { TaskListCloudComponent } from './task-list-cloud.component'; import { TaskListCloudComponent } from './task-list-cloud.component';
import { fakeGlobalTask, fakeCustomSchema } from '../mock/fake-task-response.mock'; import { fakeGlobalTask, fakeCustomSchema } from '../mock/fake-task-response.mock';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { Person } from '@alfresco/js-api';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { TaskListCloudSortingModel } from '../models/task-list-sorting.model'; import { TaskListCloudSortingModel } from '../models/task-list-sorting.model';
import { skip } from 'rxjs/operators'; import { skip } from 'rxjs/operators';
@@ -47,7 +46,7 @@ class CustomTaskListComponent {
@ViewChild(TaskListCloudComponent) @ViewChild(TaskListCloudComponent)
taskList: TaskListCloudComponent; taskList: TaskListCloudComponent;
getFullName(person: Person): string { getFullName(person: EcmUserModel): string {
return `${person.firstName} ${person.lastName}`; return `${person.firstName} ${person.lastName}`;
} }
} }