mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
use people api and new js api where possible (#5888)
* use people api and new js api where possible * fix code and tests * cleanup tests
This commit is contained in:
parent
a0aaf0ea58
commit
4aa936bb9c
@ -76,7 +76,7 @@ export class PropertyGroupTranslatorService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private translate(property: Property, propertyValues: any, constraints: Constraint[]): CardViewItem {
|
private translate(property: Property, propertyValues: any, constraints: Constraint[]): CardViewItem {
|
||||||
let propertyValue;
|
let propertyValue: any;
|
||||||
if (propertyValues && propertyValues[property.name]) {
|
if (propertyValues && propertyValues[property.name]) {
|
||||||
propertyValue = propertyValues[property.name];
|
propertyValue = propertyValues[property.name];
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ export class PropertyGroupTranslatorService {
|
|||||||
constraints: constraints
|
constraints: constraints
|
||||||
};
|
};
|
||||||
|
|
||||||
let cardViewItemProperty;
|
let cardViewItemProperty: CardViewItem;
|
||||||
|
|
||||||
if (this.isListOfValues(propertyDefinition.constraints)) {
|
if (this.isListOfValues(propertyDefinition.constraints)) {
|
||||||
const options = propertyDefinition.constraints[0].parameters.allowedValues.map((value) => ({ key: value, label: value }));
|
const options = propertyDefinition.constraints[0].parameters.allowedValues.map((value) => ({ key: value, label: value }));
|
||||||
@ -154,7 +154,7 @@ export class PropertyGroupTranslatorService {
|
|||||||
return definition?.properties.find((item) => item.id === propertyName)?.constraints ?? [];
|
return definition?.properties.find((item) => item.id === propertyName)?.constraints ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkECMTypeValidity(ecmPropertyType) {
|
private checkECMTypeValidity(ecmPropertyType: string) {
|
||||||
if (PropertyGroupTranslatorService.RECOGNISED_ECM_TYPES.indexOf(ecmPropertyType) === -1) {
|
if (PropertyGroupTranslatorService.RECOGNISED_ECM_TYPES.indexOf(ecmPropertyType) === -1) {
|
||||||
this.logService.error(`Unknown type for mapping: ${ecmPropertyType}`);
|
this.logService.error(`Unknown type for mapping: ${ecmPropertyType}`);
|
||||||
}
|
}
|
||||||
|
@ -74,14 +74,14 @@ describe('DocumentList', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
eventMock = {
|
eventMock = {
|
||||||
preventDefault: function () {
|
preventDefault: function () {}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fixture = TestBed.createComponent(DocumentListComponent);
|
fixture = TestBed.createComponent(DocumentListComponent);
|
||||||
|
|
||||||
element = fixture.nativeElement;
|
element = fixture.nativeElement;
|
||||||
documentList = fixture.componentInstance;
|
documentList = fixture.componentInstance;
|
||||||
|
|
||||||
documentListService = TestBed.inject(DocumentListService);
|
documentListService = TestBed.inject(DocumentListService);
|
||||||
apiService = TestBed.inject(AlfrescoApiService);
|
apiService = TestBed.inject(AlfrescoApiService);
|
||||||
customResourcesService = TestBed.inject(CustomResourcesService);
|
customResourcesService = TestBed.inject(CustomResourcesService);
|
||||||
@ -101,8 +101,8 @@ describe('DocumentList', () => {
|
|||||||
documentList.ngOnInit();
|
documentList.ngOnInit();
|
||||||
documentList.currentFolderId = 'no-node';
|
documentList.currentFolderId = 'no-node';
|
||||||
|
|
||||||
spyGetSites = spyOn(apiService.sitesApi, 'getSites').and.returnValue(Promise.resolve(fakeGetSitesAnswer));
|
spyGetSites = spyOn(customResourcesService.sitesApi, 'listSites').and.returnValue(Promise.resolve(fakeGetSitesAnswer));
|
||||||
spyFavorite = spyOn(apiService.favoritesApi, 'getFavorites').and.returnValue(Promise.resolve({ list: { entries: [] } }));
|
spyFavorite = spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue(Promise.resolve({ list: { entries: [] } }));
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -1287,15 +1287,16 @@ describe('DocumentList', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch trashcan', () => {
|
it('should fetch trashcan', () => {
|
||||||
spyOn(apiService.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve(null));
|
const trashcanApi = customResourcesService.trashcanApi;
|
||||||
|
spyOn(trashcanApi, 'listDeletedNodes').and.returnValue(Promise.resolve(null));
|
||||||
|
|
||||||
documentList.currentFolderId = '-trashcan-';
|
documentList.currentFolderId = '-trashcan-';
|
||||||
documentList.loadFolder();
|
documentList.loadFolder();
|
||||||
expect(apiService.nodesApi.getDeletedNodes).toHaveBeenCalled();
|
expect(trashcanApi.listDeletedNodes).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit error when fetch trashcan fails', (done) => {
|
it('should emit error when fetch trashcan fails', (done) => {
|
||||||
spyOn(apiService.nodesApi, 'getDeletedNodes').and.returnValue(Promise.reject('error'));
|
spyOn(customResourcesService.trashcanApi, 'listDeletedNodes').and.returnValue(Promise.reject('error'));
|
||||||
|
|
||||||
const disposableError = documentList.error.subscribe((val) => {
|
const disposableError = documentList.error.subscribe((val) => {
|
||||||
expect(val).toBe('error');
|
expect(val).toBe('error');
|
||||||
@ -1308,17 +1309,16 @@ describe('DocumentList', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch shared links', () => {
|
it('should fetch shared links', () => {
|
||||||
const sharedlinksApi = apiService.getInstance().core.sharedlinksApi;
|
const sharedlinksApi = customResourcesService.sharedLinksApi;
|
||||||
spyOn(sharedlinksApi, 'findSharedLinks').and.returnValue(Promise.resolve(null));
|
spyOn(sharedlinksApi, 'listSharedLinks').and.returnValue(Promise.resolve(null));
|
||||||
|
|
||||||
documentList.currentFolderId = '-sharedlinks-';
|
documentList.currentFolderId = '-sharedlinks-';
|
||||||
documentList.loadFolder();
|
documentList.loadFolder();
|
||||||
expect(sharedlinksApi.findSharedLinks).toHaveBeenCalled();
|
expect(sharedlinksApi.listSharedLinks).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit error when fetch shared links fails', (done) => {
|
it('should emit error when fetch shared links fails', (done) => {
|
||||||
spyOn(apiService.getInstance().core.sharedlinksApi, 'findSharedLinks')
|
spyOn(customResourcesService.sharedLinksApi, 'listSharedLinks').and.returnValue(Promise.reject('error'));
|
||||||
.and.returnValue(Promise.reject('error'));
|
|
||||||
|
|
||||||
const disposableError = documentList.error.subscribe((val) => {
|
const disposableError = documentList.error.subscribe((val) => {
|
||||||
expect(val).toBe('error');
|
expect(val).toBe('error');
|
||||||
@ -1331,11 +1331,11 @@ describe('DocumentList', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch sites', () => {
|
it('should fetch sites', () => {
|
||||||
const sitesApi = apiService.getInstance().core.sitesApi;
|
const sitesApi = customResourcesService.sitesApi;
|
||||||
|
|
||||||
documentList.currentFolderId = '-sites-';
|
documentList.currentFolderId = '-sites-';
|
||||||
documentList.loadFolder();
|
documentList.loadFolder();
|
||||||
expect(sitesApi.getSites).toHaveBeenCalled();
|
expect(sitesApi.listSites).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit error when fetch sites fails', (done) => {
|
it('should emit error when fetch sites fails', (done) => {
|
||||||
@ -1352,17 +1352,16 @@ describe('DocumentList', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch user membership sites', () => {
|
it('should fetch user membership sites', () => {
|
||||||
const peopleApi = apiService.getInstance().core.peopleApi;
|
const sitesApi = customResourcesService.sitesApi;
|
||||||
spyOn(peopleApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.resolve(fakeGetSiteMembership));
|
spyOn(sitesApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.resolve(fakeGetSiteMembership));
|
||||||
|
|
||||||
documentList.currentFolderId = '-mysites-';
|
documentList.currentFolderId = '-mysites-';
|
||||||
documentList.loadFolder();
|
documentList.loadFolder();
|
||||||
expect(peopleApi.listSiteMembershipsForPerson).toHaveBeenCalled();
|
expect(sitesApi.listSiteMembershipsForPerson).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit error when fetch membership sites fails', (done) => {
|
it('should emit error when fetch membership sites fails', (done) => {
|
||||||
spyOn(apiService.getInstance().core.peopleApi, 'listSiteMembershipsForPerson')
|
spyOn(customResourcesService.sitesApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.reject('error'));
|
||||||
.and.returnValue(Promise.reject('error'));
|
|
||||||
|
|
||||||
const disposableError = documentList.error.subscribe((val) => {
|
const disposableError = documentList.error.subscribe((val) => {
|
||||||
expect(val).toBe('error');
|
expect(val).toBe('error');
|
||||||
@ -1375,11 +1374,11 @@ describe('DocumentList', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch favorites', () => {
|
it('should fetch favorites', () => {
|
||||||
const favoritesApi = apiService.getInstance().core.favoritesApi;
|
const favoritesApi = customResourcesService.favoritesApi;
|
||||||
|
|
||||||
documentList.currentFolderId = '-favorites-';
|
documentList.currentFolderId = '-favorites-';
|
||||||
documentList.loadFolder();
|
documentList.loadFolder();
|
||||||
expect(favoritesApi.getFavorites).toHaveBeenCalled();
|
expect(favoritesApi.listFavorites).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit error when fetch favorites fails', (done) => {
|
it('should emit error when fetch favorites fails', (done) => {
|
||||||
@ -1410,9 +1409,7 @@ describe('DocumentList', () => {
|
|||||||
|
|
||||||
it('should have correct currentFolderId on loading folder by node id', () => {
|
it('should have correct currentFolderId on loading folder by node id', () => {
|
||||||
documentList.currentFolderId = '12345-some-id-6789';
|
documentList.currentFolderId = '12345-some-id-6789';
|
||||||
|
spyOn(customResourcesService.sitesApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.resolve(fakeGetSiteMembership));
|
||||||
const peopleApi = apiService.getInstance().core.peopleApi;
|
|
||||||
spyOn(peopleApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.resolve(fakeGetSiteMembership));
|
|
||||||
|
|
||||||
documentList.currentFolderId = '-mysites-';
|
documentList.currentFolderId = '-mysites-';
|
||||||
documentList.loadFolder();
|
documentList.loadFolder();
|
||||||
|
@ -19,19 +19,18 @@ import { CustomResourcesService } from './custom-resources.service';
|
|||||||
import { PaginationModel, AlfrescoApiServiceMock, AppConfigService, LogService, AppConfigServiceMock, StorageService } from '@alfresco/adf-core';
|
import { PaginationModel, AlfrescoApiServiceMock, AppConfigService, LogService, AppConfigServiceMock, StorageService } from '@alfresco/adf-core';
|
||||||
|
|
||||||
describe('CustomResourcesService', () => {
|
describe('CustomResourcesService', () => {
|
||||||
let customActionService: CustomResourcesService;
|
let customResourcesService: CustomResourcesService;
|
||||||
let alfrescoApiService: AlfrescoApiServiceMock;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const logService = new LogService(new AppConfigServiceMock(null));
|
const logService = new LogService(new AppConfigServiceMock(null));
|
||||||
|
const alfrescoApiService = new AlfrescoApiServiceMock(new AppConfigService(null), new StorageService());
|
||||||
|
|
||||||
alfrescoApiService = new AlfrescoApiServiceMock(new AppConfigService(null), new StorageService());
|
customResourcesService = new CustomResourcesService(alfrescoApiService, logService);
|
||||||
customActionService = new CustomResourcesService(alfrescoApiService, logService);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('loadFavorites', () => {
|
describe('loadFavorites', () => {
|
||||||
it('should return a list of items with default properties when target properties does not exist', (done) => {
|
it('should return a list of items with default properties when target properties does not exist', (done) => {
|
||||||
spyOn(alfrescoApiService.favoritesApi, 'getFavorites').and.returnValue(Promise.resolve({
|
spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue(Promise.resolve({
|
||||||
list: {
|
list: {
|
||||||
entries: [
|
entries: [
|
||||||
{
|
{
|
||||||
@ -52,7 +51,7 @@ describe('CustomResourcesService', () => {
|
|||||||
skipCount: 0
|
skipCount: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
customActionService.loadFavorites(pagination).subscribe((result) => {
|
customResourcesService.loadFavorites(pagination).subscribe((result) => {
|
||||||
expect(result.list.entries).toEqual([
|
expect(result.list.entries).toEqual([
|
||||||
{
|
{
|
||||||
entry: {
|
entry: {
|
||||||
@ -70,7 +69,7 @@ describe('CustomResourcesService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return a list of items with merged properties when target properties exist', (done) => {
|
it('should return a list of items with merged properties when target properties exist', (done) => {
|
||||||
spyOn(alfrescoApiService.favoritesApi, 'getFavorites').and.returnValue(Promise.resolve({
|
spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue(Promise.resolve({
|
||||||
list: {
|
list: {
|
||||||
entries: [
|
entries: [
|
||||||
{
|
{
|
||||||
@ -94,7 +93,7 @@ describe('CustomResourcesService', () => {
|
|||||||
skipCount: 0
|
skipCount: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
customActionService.loadFavorites(pagination).subscribe((result) => {
|
customResourcesService.loadFavorites(pagination).subscribe((result) => {
|
||||||
expect(result.list.entries).toEqual([
|
expect(result.list.entries).toEqual([
|
||||||
{
|
{
|
||||||
entry: {
|
entry: {
|
||||||
|
@ -15,36 +15,72 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import { AlfrescoApiService, LogService, PaginationModel } from '@alfresco/adf-core';
|
||||||
AlfrescoApiService,
|
|
||||||
LogService,
|
|
||||||
PaginationModel
|
|
||||||
} from '@alfresco/adf-core';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
NodePaging,
|
NodePaging,
|
||||||
PersonEntry,
|
|
||||||
SitePaging,
|
|
||||||
DeletedNodesPaging,
|
DeletedNodesPaging,
|
||||||
SearchRequest,
|
SearchRequest,
|
||||||
SharedLinkPaging,
|
SharedLinkPaging,
|
||||||
FavoritePaging,
|
FavoritePaging,
|
||||||
SiteMemberPaging,
|
SiteMemberPaging,
|
||||||
SiteRolePaging
|
SiteRolePaging,
|
||||||
|
PeopleApi,
|
||||||
|
SitesApi,
|
||||||
|
SearchApi,
|
||||||
|
FavoritesApi,
|
||||||
|
SharedlinksApi,
|
||||||
|
TrashcanApi,
|
||||||
|
NodesApi
|
||||||
} from '@alfresco/js-api';
|
} from '@alfresco/js-api';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Observable, from, of, throwError } from 'rxjs';
|
import { Observable, from, of, throwError } from 'rxjs';
|
||||||
import { catchError, map } from 'rxjs/operators';
|
import { catchError, map } from 'rxjs/operators';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({ providedIn: 'root' })
|
||||||
providedIn: 'root'
|
|
||||||
})
|
|
||||||
export class CustomResourcesService {
|
export class CustomResourcesService {
|
||||||
|
|
||||||
private CREATE_PERMISSION = 'create';
|
private CREATE_PERMISSION = 'create';
|
||||||
|
|
||||||
constructor(private apiService: AlfrescoApiService,
|
private _peopleApi: PeopleApi;
|
||||||
private logService: LogService) {
|
private _sitesApi: SitesApi;
|
||||||
|
private _trashcanApi: TrashcanApi;
|
||||||
|
private _searchApi: SearchApi;
|
||||||
|
private _sharedLinksApi: SharedlinksApi;
|
||||||
|
private _favoritesApi: FavoritesApi;
|
||||||
|
private _nodesApi: NodesApi;
|
||||||
|
|
||||||
|
constructor(private apiService: AlfrescoApiService, private logService: LogService) {}
|
||||||
|
|
||||||
|
private get api() {
|
||||||
|
return this.apiService.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
get peopleApi(): PeopleApi {
|
||||||
|
return this._peopleApi || (this._peopleApi = new PeopleApi(this.api));
|
||||||
|
}
|
||||||
|
|
||||||
|
get sitesApi(): SitesApi {
|
||||||
|
return this._sitesApi || (this._sitesApi = new SitesApi(this.api));
|
||||||
|
}
|
||||||
|
|
||||||
|
get searchApi(): SearchApi {
|
||||||
|
return this._searchApi || (this._searchApi = new SearchApi(this.api));
|
||||||
|
}
|
||||||
|
|
||||||
|
get favoritesApi(): FavoritesApi {
|
||||||
|
return this._favoritesApi || (this._favoritesApi = new FavoritesApi(this.api));
|
||||||
|
}
|
||||||
|
|
||||||
|
get sharedLinksApi(): SharedlinksApi {
|
||||||
|
return this._sharedLinksApi || (this._sharedLinksApi = new SharedlinksApi(this.api));
|
||||||
|
}
|
||||||
|
|
||||||
|
get trashcanApi(): TrashcanApi {
|
||||||
|
return this._trashcanApi || (this._trashcanApi = new TrashcanApi(this.api));
|
||||||
|
}
|
||||||
|
|
||||||
|
get nodesApi(): NodesApi {
|
||||||
|
return this._nodesApi || (this._nodesApi = new NodesApi(this.api));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,8 +115,8 @@ export class CustomResourcesService {
|
|||||||
];
|
];
|
||||||
|
|
||||||
return new Observable((observer) => {
|
return new Observable((observer) => {
|
||||||
this.apiService.peopleApi.getPerson(personId)
|
this.peopleApi.getPerson(personId)
|
||||||
.then((person: PersonEntry) => {
|
.then((person) => {
|
||||||
const username = person.entry.id;
|
const username = person.entry.id;
|
||||||
const filterQueries = [
|
const filterQueries = [
|
||||||
{ query: `cm:modified:[NOW/DAY-30DAYS TO NOW/DAY+1DAY]` },
|
{ query: `cm:modified:[NOW/DAY-30DAYS TO NOW/DAY+1DAY]` },
|
||||||
@ -94,7 +130,7 @@ export class CustomResourcesService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const query: SearchRequest = new SearchRequest({
|
const query = new SearchRequest({
|
||||||
query: {
|
query: {
|
||||||
query: '*',
|
query: '*',
|
||||||
language: 'afts'
|
language: 'afts'
|
||||||
@ -111,7 +147,7 @@ export class CustomResourcesService {
|
|||||||
skipCount: pagination.skipCount
|
skipCount: pagination.skipCount
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return this.apiService.searchApi.search(query)
|
return this.searchApi.search(query)
|
||||||
.then((searchResult) => {
|
.then((searchResult) => {
|
||||||
observer.next(searchResult);
|
observer.next(searchResult);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
@ -147,7 +183,7 @@ export class CustomResourcesService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return new Observable((observer) => {
|
return new Observable((observer) => {
|
||||||
this.apiService.favoritesApi.getFavorites('-me-', options)
|
this.favoritesApi.listFavorites('-me-', options)
|
||||||
.then((result: FavoritePaging) => {
|
.then((result: FavoritePaging) => {
|
||||||
const page: FavoritePaging = {
|
const page: FavoritePaging = {
|
||||||
list: {
|
list: {
|
||||||
@ -195,7 +231,7 @@ export class CustomResourcesService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return new Observable((observer) => {
|
return new Observable((observer) => {
|
||||||
this.apiService.peopleApi.listSiteMembershipsForPerson('-me-', options)
|
this.sitesApi.listSiteMembershipsForPerson('-me-', options)
|
||||||
.then((result: SiteRolePaging) => {
|
.then((result: SiteRolePaging) => {
|
||||||
const page: SiteMemberPaging = new SiteMemberPaging( {
|
const page: SiteMemberPaging = new SiteMemberPaging( {
|
||||||
list: {
|
list: {
|
||||||
@ -236,8 +272,10 @@ export class CustomResourcesService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return new Observable((observer) => {
|
return new Observable((observer) => {
|
||||||
this.apiService.sitesApi.getSites(options)
|
this.sitesApi
|
||||||
.then((page: SitePaging) => {
|
.listSites(options)
|
||||||
|
.then(
|
||||||
|
(page) => {
|
||||||
page.list.entries.map(
|
page.list.entries.map(
|
||||||
({ entry }: any) => {
|
({ entry }: any) => {
|
||||||
entry.name = entry.name || entry.title;
|
entry.name = entry.name || entry.title;
|
||||||
@ -269,7 +307,7 @@ export class CustomResourcesService {
|
|||||||
skipCount: pagination.skipCount
|
skipCount: pagination.skipCount
|
||||||
};
|
};
|
||||||
|
|
||||||
return from(this.apiService.nodesApi.getDeletedNodes(options))
|
return from(this.trashcanApi.listDeletedNodes(options))
|
||||||
.pipe(catchError((err) => this.handleError(err)));
|
.pipe(catchError((err) => this.handleError(err)));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -291,7 +329,7 @@ export class CustomResourcesService {
|
|||||||
where
|
where
|
||||||
};
|
};
|
||||||
|
|
||||||
return from(this.apiService.sharedLinksApi.findSharedLinks(options))
|
return from(this.sharedLinksApi.listSharedLinks(options))
|
||||||
.pipe(catchError((err) => this.handleError(err)));
|
.pipe(catchError((err) => this.handleError(err)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,7 +407,7 @@ export class CustomResourcesService {
|
|||||||
|
|
||||||
} else if (nodeId) {
|
} else if (nodeId) {
|
||||||
// cases when nodeId is '-my-', '-root-' or '-shared-'
|
// cases when nodeId is '-my-', '-root-' or '-shared-'
|
||||||
return from(this.apiService.nodesApi.getNode(nodeId)
|
return from(this.nodesApi.getNode(nodeId)
|
||||||
.then((node) => [node.entry.id]));
|
.then((node) => [node.entry.id]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,41 +18,30 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { fakeEcmUser } from '../mock/ecm-user.service.mock';
|
import { fakeEcmUser } from '../mock/ecm-user.service.mock';
|
||||||
import { EcmUserService } from '../services/ecm-user.service';
|
import { EcmUserService } from '../services/ecm-user.service';
|
||||||
import { setupTestBed } from '../testing/setup-test-bed';
|
|
||||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { AuthenticationService } from './authentication.service';
|
import { AuthenticationService } from './authentication.service';
|
||||||
import { ContentService } from './content.service';
|
import { ContentService } from './content.service';
|
||||||
|
|
||||||
declare let jasmine: any;
|
|
||||||
|
|
||||||
describe('EcmUserService', () => {
|
describe('EcmUserService', () => {
|
||||||
|
|
||||||
let service: EcmUserService;
|
let service: EcmUserService;
|
||||||
let authService: AuthenticationService;
|
let authService: AuthenticationService;
|
||||||
let contentService: ContentService;
|
let contentService: ContentService;
|
||||||
|
|
||||||
setupTestBed({
|
|
||||||
imports: [
|
|
||||||
TranslateModule.forRoot(),
|
|
||||||
CoreTestingModule
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
TranslateModule.forRoot(),
|
||||||
|
CoreTestingModule
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
service = TestBed.inject(EcmUserService);
|
service = TestBed.inject(EcmUserService);
|
||||||
authService = TestBed.inject(AuthenticationService);
|
authService = TestBed.inject(AuthenticationService);
|
||||||
contentService = TestBed.inject(ContentService);
|
contentService = TestBed.inject(ContentService);
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
jasmine.Ajax.install();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jasmine.Ajax.uninstall();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when user is logged in', () => {
|
describe('when user is logged in', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -60,6 +49,7 @@ describe('EcmUserService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to retrieve current user info', (done) => {
|
it('should be able to retrieve current user info', (done) => {
|
||||||
|
spyOn(service.peopleApi, 'getPerson').and.returnValue(Promise.resolve({ entry: fakeEcmUser }));
|
||||||
service.getCurrentUserInfo().subscribe(
|
service.getCurrentUserInfo().subscribe(
|
||||||
(user) => {
|
(user) => {
|
||||||
expect(user).toBeDefined();
|
expect(user).toBeDefined();
|
||||||
@ -67,23 +57,8 @@ describe('EcmUserService', () => {
|
|||||||
expect(user.lastName).toEqual('fake-ecm-last-name');
|
expect(user.lastName).toEqual('fake-ecm-last-name');
|
||||||
expect(user.email).toEqual('fakeEcm@ecmUser.com');
|
expect(user.email).toEqual('fakeEcm@ecmUser.com');
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
);
|
||||||
status: 200,
|
|
||||||
contentType: 'application/json',
|
|
||||||
responseText: JSON.stringify({entry: fakeEcmUser})
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be able to log errors on call', (done) => {
|
|
||||||
service.getCurrentUserInfo().subscribe(() => {
|
|
||||||
}, () => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
||||||
status: 403
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should retrieve avatar url for current user', () => {
|
it('should retrieve avatar url for current user', () => {
|
||||||
@ -92,13 +67,5 @@ describe('EcmUserService', () => {
|
|||||||
|
|
||||||
expect(urlRs).toEqual('fake/url/image/for/ecm/user');
|
expect(urlRs).toEqual('fake/url/image/for/ecm/user');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not call content service without avatar id', () => {
|
|
||||||
spyOn(contentService, 'getContentUrl').and.callThrough();
|
|
||||||
const urlRs = service.getUserProfileImage(undefined);
|
|
||||||
|
|
||||||
expect(urlRs).toBeNull();
|
|
||||||
expect(contentService.getContentUrl).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -16,22 +16,26 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Observable, from, throwError } from 'rxjs';
|
import { Observable, from } from 'rxjs';
|
||||||
import { map, catchError } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { ContentService } from './content.service';
|
import { ContentService } from './content.service';
|
||||||
import { AlfrescoApiService } from './alfresco-api.service';
|
import { AlfrescoApiService } from './alfresco-api.service';
|
||||||
import { LogService } from './log.service';
|
|
||||||
import { EcmUserModel } from '../models/ecm-user.model';
|
import { EcmUserModel } from '../models/ecm-user.model';
|
||||||
import { PersonEntry } from '@alfresco/js-api';
|
import { PeopleApi } from '@alfresco/js-api';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class EcmUserService {
|
export class EcmUserService {
|
||||||
|
|
||||||
|
private _peopleApi: PeopleApi;
|
||||||
|
|
||||||
constructor(private apiService: AlfrescoApiService,
|
constructor(private apiService: AlfrescoApiService,
|
||||||
private contentService: ContentService,
|
private contentService: ContentService) {
|
||||||
private logService: LogService) {
|
}
|
||||||
|
|
||||||
|
get peopleApi(): PeopleApi {
|
||||||
|
return this._peopleApi || (this._peopleApi = new PeopleApi(this.apiService.getInstance()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,12 +44,9 @@ export class EcmUserService {
|
|||||||
* @returns User information
|
* @returns User information
|
||||||
*/
|
*/
|
||||||
getUserInfo(userName: string): Observable<EcmUserModel> {
|
getUserInfo(userName: string): Observable<EcmUserModel> {
|
||||||
return from(this.apiService.getInstance().core.peopleApi.getPerson(userName))
|
return from(this.peopleApi.getPerson(userName))
|
||||||
.pipe(
|
.pipe(
|
||||||
map((personEntry: PersonEntry) => {
|
map((personEntry) => new EcmUserModel(personEntry.entry))
|
||||||
return new EcmUserModel(personEntry.entry);
|
|
||||||
}),
|
|
||||||
catchError((err) => this.handleError(err))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,19 +64,6 @@ export class EcmUserService {
|
|||||||
* @returns Image URL
|
* @returns Image URL
|
||||||
*/
|
*/
|
||||||
getUserProfileImage(avatarId: string): string {
|
getUserProfileImage(avatarId: string): string {
|
||||||
if (avatarId) {
|
return this.contentService.getContentUrl(avatarId);
|
||||||
return this.contentService.getContentUrl(avatarId);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Throw the error
|
|
||||||
* @param error
|
|
||||||
*/
|
|
||||||
private handleError(error: any) {
|
|
||||||
this.logService.error(error);
|
|
||||||
return throwError(error || 'Server error');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,6 @@ import { RolesService } from './roles.service';
|
|||||||
import { Logger } from '../../utils/logger';
|
import { Logger } from '../../utils/logger';
|
||||||
|
|
||||||
export class IdentityService {
|
export class IdentityService {
|
||||||
|
|
||||||
api: ApiService;
|
|
||||||
|
|
||||||
constructor(api: ApiService) {
|
|
||||||
this.api = api;
|
|
||||||
}
|
|
||||||
|
|
||||||
ROLES = {
|
ROLES = {
|
||||||
ACTIVITI_USER: 'ACTIVITI_USER',
|
ACTIVITI_USER: 'ACTIVITI_USER',
|
||||||
ACTIVITI_ADMIN: 'ACTIVITI_ADMIN',
|
ACTIVITI_ADMIN: 'ACTIVITI_ADMIN',
|
||||||
@ -35,6 +28,8 @@ export class IdentityService {
|
|||||||
ACTIVITI_IDENTITY: 'ACTIVITI_IDENTITY'
|
ACTIVITI_IDENTITY: 'ACTIVITI_IDENTITY'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constructor(public api: ApiService) {}
|
||||||
|
|
||||||
async createIdentityUserWithRole(roles: string[]): Promise<any> {
|
async createIdentityUserWithRole(roles: string[]): Promise<any> {
|
||||||
const rolesService = new RolesService(this.api);
|
const rolesService = new RolesService(this.api);
|
||||||
const user = await this.createIdentityUser();
|
const user = await this.createIdentityUser();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user