Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions docs/core/services/people-content.service.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ Gets information about a Content Services user.
Gets information about the user who is currently logged in.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<any>` - User information
- **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
- **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.
- _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.
- _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.

## Details

Expand All @@ -33,12 +36,10 @@ in the [Ecm User model docs](../models/ecm-user.model.md). The `avatarId` passed
returned for a particular person.

See the
[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.

See the
[getPerson](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/PeopleApi.md#getPerson),
[listPeople](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/PeopleApi.md#listPeople) and
[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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

import { Component, Input, OnInit } from '@angular/core';
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 { EcmUserModel } from '@alfresco/adf-core';

@Component({
selector: 'adf-user-name-column',
Expand Down Expand Up @@ -59,7 +60,7 @@ export class UserNameColumnComponent implements OnInit {
}
}

private updatePerson(person: Person) {
private updatePerson(person: EcmUserModel) {
if (person) {
this.displayText$.next(`${person.firstName ?? ''} ${person.lastName ?? ''}`);
this.subTitleText$.next(person.email ?? '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
* 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 { RoleModel } from './role.model';
import { EcmUserModel } from '@alfresco/adf-core';

export interface NodePermissionsModel {
node: Node;
Expand All @@ -31,7 +32,7 @@ export class MemberModel {
role: string;
accessStatus: PermissionElement.AccessStatusEnum | string;
entry: {
person?: Person;
person?: EcmUserModel;
group?: Group;
};
readonly: boolean = false;
Expand All @@ -46,7 +47,7 @@ export class MemberModel {
const result = new MemberModel();

if (entry.nodeType === 'cm:person') {
const person = new Person({
const person = new EcmUserModel({
firstName: entry.properties['cm:firstName'],
lastName: entry.properties['cm:lastName'],
email: entry.properties['cm:email'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

import { AlfrescoApiService, NodesApiService, SearchService, TranslationService } from '@alfresco/adf-core';
import { Group, GroupMemberEntry, GroupMemberPaging, Node, PathElement, PermissionElement, Person, QueryBody } from '@alfresco/js-api';
import { AlfrescoApiService, NodesApiService, SearchService, TranslationService, EcmUserModel } from '@alfresco/adf-core';
import { Group, GroupMemberEntry, GroupMemberPaging, Node, PathElement, PermissionElement, QueryBody } from '@alfresco/js-api';
import { Injectable } from '@angular/core';
import { forkJoin, from, Observable, of, throwError } from 'rxjs';
import { catchError, map, switchMap } from 'rxjs/operators';
Expand Down Expand Up @@ -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;
if (node.nodeType === 'cm:person') {
const firstName = node.properties['cm:firstName'];
const lastName = node.properties['cm:lastName'];
const email = node.properties['cm:email'];
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') {
Expand Down
39 changes: 35 additions & 4 deletions lib/core/mock/ecm-user.service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { EcmCompanyModel } from '../models/ecm-company.model';
import { PersonEntry, Person } from '@alfresco/js-api';

export let fakeEcmCompany: EcmCompanyModel = {
export const fakeEcmCompany: EcmCompanyModel = {
organization: 'company-fake-name',
address1: 'fake-address-1',
address2: 'fake-address-2',
Expand All @@ -29,7 +29,7 @@ export let fakeEcmCompany: EcmCompanyModel = {
email: 'fakeCompany@fake.com'
};

export let fakeEcmUser = {
export const fakeEcmUser = {
id: 'fake-id',
firstName: 'fake-ecm-first-name',
lastName: 'fake-ecm-last-name',
Expand All @@ -50,7 +50,18 @@ export let fakeEcmUser = {
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',
firstName: 'fake-first-name',
lastName: 'fake-last-name',
Expand All @@ -71,7 +82,7 @@ export let fakeEcmUserNoImage = {
emailNotificationsEnabled: true
};

export let fakeEcmEditedUser = {
export const fakeEcmEditedUser = {
id: 'fake-id',
firstName: null,
lastName: 'fake-last-name',
Expand All @@ -92,6 +103,26 @@ export let fakeEcmEditedUser = {
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 = {
id: 'fake-id',
firstName: 'fake-ecm-first-name',
Expand Down
4 changes: 2 additions & 2 deletions lib/core/models/comment.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
* limitations under the License.
*/

import { Person } from '@alfresco/js-api';
import { EcmUserModel } from './ecm-user.model';

export class CommentModel {
id: number;
message: string;
created: Date;
createdBy: Person;
createdBy: EcmUserModel;
isSelected: boolean;

constructor(obj?: any) {
Expand Down
37 changes: 22 additions & 15 deletions lib/core/models/ecm-user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,32 @@
* limitations under the License.
*/

import { Person } from '@alfresco/js-api';
import { Capabilities } from '@alfresco/js-api';
import { EcmCompanyModel } from './ecm-company.model';

export class EcmUserModel implements Person {
export class EcmUserModel {
id: string;
firstName: string;
lastName: string;
description: string;
avatarId: string;
lastName?: string;
displayName?: string;
description?: string;
avatarId?: string;
email: string;
skypeId: string;
googleId: string;
instantMessageId: string;
jobTitle: string;
location: string;
skypeId?: string;
googleId?: string;
instantMessageId?: string;
jobTitle?: string;
location?: string;
company: EcmCompanyModel;
mobile: string;
telephone: string;
statusUpdatedAt: Date;
userStatus: string;
mobile?: string;
telephone?: string;
statusUpdatedAt?: Date;
userStatus?: string;
enabled: boolean;
emailNotificationsEnabled: boolean;
emailNotificationsEnabled?: boolean;
aspectNames?: string[];
properties?: { [key: string]: string; };
capabilities?: Capabilities;

constructor(obj?: any) {
this.id = obj && obj.id || null;
Expand All @@ -57,5 +61,8 @@ export class EcmUserModel implements Person {
this.userStatus = obj && obj.userStatus;
this.enabled = obj && obj.enabled;
this.emailNotificationsEnabled = obj && obj.emailNotificationsEnabled;
this.aspectNames = obj && obj.aspectNames;
this.properties = obj && obj.properties;
this.capabilities = obj && obj.capabilities;
}
}
22 changes: 21 additions & 1 deletion lib/core/services/people-content.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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 { CoreTestingModule } from '../testing/core.testing.module';
import { PeopleContentService } from './people-content.service';
Expand All @@ -25,6 +25,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { TestBed } from '@angular/core/testing';
import { LogService } from './log.service';
import { of } from 'rxjs';
import { EcmUserModel } from '../models/ecm-user.model';

describe('PeopleContentService', () => {

Expand Down Expand Up @@ -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) => {
spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve({ entry: fakeEcmUser }));
service.createPerson(createNewPersonMock).subscribe((person) => {
Expand Down
19 changes: 19 additions & 0 deletions lib/core/services/people-content.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ export class PeopleContentService {
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.
* @param newPerson Object containing the new person details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
import { Component, SimpleChange, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
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 { fakeServiceTask, fakeCustomSchema } from '../mock/fake-task-response.mock';
import { of } from 'rxjs';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { Person } from '@alfresco/js-api';
import { TranslateModule } from '@ngx-translate/core';
import { TaskListCloudSortingModel } from '../models/task-list-sorting.model';
import { skip } from 'rxjs/operators';
Expand All @@ -42,7 +41,7 @@ class CustomTaskListComponent {
@ViewChild(ServiceTaskListCloudComponent)
taskList: ServiceTaskListCloudComponent;

getFullName(person: Person): string {
getFullName(person: EcmUserModel): string {
return `${person.firstName} ${person.lastName}`;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
import { Component, SimpleChange, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
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 { TaskListCloudComponent } from './task-list-cloud.component';
import { fakeGlobalTask, fakeCustomSchema } from '../mock/fake-task-response.mock';
import { of } from 'rxjs';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { Person } from '@alfresco/js-api';
import { TranslateModule } from '@ngx-translate/core';
import { TaskListCloudSortingModel } from '../models/task-list-sorting.model';
import { skip } from 'rxjs/operators';
Expand All @@ -47,7 +46,7 @@ class CustomTaskListComponent {
@ViewChild(TaskListCloudComponent)
taskList: TaskListCloudComponent;

getFullName(person: Person): string {
getFullName(person: EcmUserModel): string {
return `${person.firstName} ${person.lastName}`;
}
}
Expand Down