Skip to content
Open
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
62 changes: 61 additions & 1 deletion src/app/core/data/collection-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,47 @@ export class CollectionDataService extends ComColDataService<Collection> {
}

/**
* Get all collections the user is authorized to submit to
* Get all collections the user is admin of
*
* @param query limit the returned collection to those with metadata values
* matching the query terms.
* @param options The [[FindListOptions]] object
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
* no valid cached version. Defaults to true
* @param reRequestOnStale Whether or not the request should automatically be re-
* requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
* {@link HALLink}s should be automatically resolved
* @return Observable<RemoteData<PaginatedList<Collection>>>
* collection list
*/
getAdminAuthorizedCollection(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<PaginatedList<Collection>>> {
const searchHref = 'findAdminAuthorized';
return this.getAuthorizedCollection(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
}

/**
* Get all collections the user is authorized to edit
*
* @param query limit the returned collection to those with metadata values
* matching the query terms.
* @param options The [[FindListOptions]] object
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
* no valid cached version. Defaults to true
* @param reRequestOnStale Whether or not the request should automatically be re-
* requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
* {@link HALLink}s should be automatically resolved
* @return Observable<RemoteData<PaginatedList<Collection>>>
* collection list
*/
getEditAuthorizedCollection(query: string,options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<PaginatedList<Collection>>> {
const searchHref = 'findEditAuthorized';
return this.getAuthorizedCollection(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
}

/**
* Get all collections the user is authorized to submit
*
* @param query limit the returned collection to those with metadata values
* matching the query terms.
Expand All @@ -77,7 +117,27 @@ export class CollectionDataService extends ComColDataService<Collection> {
* requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
* {@link HALLink}s should be automatically resolved
* @return Observable<RemoteData<PaginatedList<Collection>>>
* collection list
*/
getSubmitAuthorizedCollection(query: string,options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<PaginatedList<Collection>>> {
const searchHref = 'findSubmitAuthorized';
return this.getAuthorizedCollection(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
}

/**
* Get all collections the user is authorized to perform a specific action on
*
* @param query limit the returned collection to those with metadata values
* matching the query terms.
* @param options The [[FindListOptions]] object
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
* no valid cached version. Defaults to true
* @param reRequestOnStale Whether or not the request should automatically be re-
* requested after the response becomes stale
* @param searchHref The backend search endpoint to use (default to submit)
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
* {@link HALLink}s should be automatically resolved
* @return Observable<RemoteData<PaginatedList<Collection>>>
* collection list
*/
Expand Down
64 changes: 62 additions & 2 deletions src/app/core/data/community-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,66 @@ export class CommunityDataService extends ComColDataService<Community> {
super('communities', requestService, rdbService, objectCache, halService, comparator, notificationsService, bitstreamDataService);
}

/**
* Get all communities the user is admin of
*
* @param query limit the returned collection to those with metadata values
* matching the query terms.
* @param options The [[FindListOptions]] object
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
* no valid cached version. Defaults to true
* @param reRequestOnStale Whether or not the request should automatically be re-
* requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
* {@link HALLink}s should be automatically resolved
* @return Observable<RemoteData<PaginatedList<Community>>>
* community list
*/
getAdminAuthorizedCommunity(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Community>[]): Observable<RemoteData<PaginatedList<Community>>> {
const searchHref = 'findAdminAuthorized';
return this.getAuthorizedCommunity(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
}

/**
* Get all communities the user is authorized to add a new subcommunity or collection to
*
* @param query limit the returned collection to those with metadata values
* matching the query terms.
* @param options The [[FindListOptions]] object
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
* no valid cached version. Defaults to true
* @param reRequestOnStale Whether or not the request should automatically be re-
* requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
* {@link HALLink}s should be automatically resolved
* @return Observable<RemoteData<PaginatedList<Community>>>
* community list
*/
getAddAuthorizedCommunity(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Community>[]): Observable<RemoteData<PaginatedList<Community>>> {
const searchHref = 'findAddAuthorized';
return this.getAuthorizedCommunity(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
}

/**
* Get all communities the user is authorized to edit
*
* @param query limit the returned collection to those with metadata values
* matching the query terms.
* @param options The [[FindListOptions]] object
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
* no valid cached version. Defaults to true
* @param reRequestOnStale Whether or not the request should automatically be re-
* requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
* {@link HALLink}s should be automatically resolved
* @return Observable<RemoteData<PaginatedList<Community>>>
* community list
*/
getEditAuthorizedCommunity(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Community>[]): Observable<RemoteData<PaginatedList<Community>>> {
const searchHref = 'findEditAuthorized';
return this.getAuthorizedCommunity(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
}

/**
* Get all communities the user is authorized to submit to
*
Expand All @@ -50,13 +110,13 @@ export class CommunityDataService extends ComColDataService<Community> {
* no valid cached version. Defaults to true
* @param reRequestOnStale Whether or not the request should automatically be re-
* requested after the response becomes stale
* @param searchHref The search endpoint to use, defaults to 'findAdminAuthorized'
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
* {@link HALLink}s should be automatically resolved
* @return Observable<RemoteData<PaginatedList<Community>>>
* community list
*/
getAuthorizedCommunity(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Community>[]): Observable<RemoteData<PaginatedList<Community>>> {
const searchHref = 'findAdminAuthorized';
getAuthorizedCommunity(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, searchHref: string = 'findAdminAuthorized', ...linksToFollow: FollowLinkConfig<Community>[]): Observable<RemoteData<PaginatedList<Community>>> {
options = Object.assign({}, options, {
searchParams: [new RequestParam('query', query)],
});
Expand Down
38 changes: 38 additions & 0 deletions src/app/core/data/item-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,26 @@ export abstract class BaseItemDataService extends IdentifiableDataService<Item>
);
}

/**
* Find the list of items for which the current user has editing rights.
*
* @param query limit the returned collection to those with metadata values
* matching the query terms
* @param options The [[FindListOptions]] object
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
* no valid cached version. Defaults to true
* @param reRequestOnStale Whether or not the request should automatically be re-
* requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
* {@link HALLink}s should be automatically resolved
* @return Observable<RemoteData<PaginatedList<Item>>>
* item list
*/
public findEditAuthorized(query: string, options: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Item>[]): Observable<RemoteData<PaginatedList<Item>>> {
options = { ...options, searchParams: [new RequestParam('query', query)] };
return this.searchBy('findEditAuthorized', options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}

/**
* Invalidate the cache of the item
* @param itemUUID
Expand All @@ -369,6 +389,24 @@ export abstract class BaseItemDataService extends IdentifiableDataService<Item>
this.patchData.commitUpdates(method);
}

/**
* Make a new FindListRequest with given search method
*
* @param searchMethod The search method for the object
* @param options The [[FindListOptions]] object
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
* no valid cached version. Defaults to true
* @param reRequestOnStale Whether or not the request should automatically be re-
* requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
* {@link HALLink}s should be automatically resolved
* @return {Observable<RemoteData<PaginatedList<T>>}
* Return an observable that emits response from the server
*/
public searchBy(searchMethod: string, options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<Item>[]): Observable<RemoteData<PaginatedList<Item>>> {
return this.searchData.searchBy(searchMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}

/**
* Send a patch request for a specified object
* @param {T} object The object to send a patch request for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { RouterTestingModule } from '@angular/router/testing';
import { CollectionDataService } from '@dspace/core/data/collection-data.service';
import { NotificationsService } from '@dspace/core/notification-system/notifications.service';
import { ActionType } from '@dspace/core/resource-policy/models/action-type.model';
import { Collection } from '@dspace/core/shared/collection.model';
import { DSpaceObjectType } from '@dspace/core/shared/dspace-object-type.model';
import { createPaginatedList } from '@dspace/core/testing/utils.test';
Expand All @@ -33,7 +34,9 @@ describe('AuthorizedCollectionSelectorComponent', () => {
id: 'authorized-collection',
});
collectionService = jasmine.createSpyObj('collectionService', {
getAuthorizedCollection: createSuccessfulRemoteDataObject$(createPaginatedList([collection])),
getSubmitAuthorizedCollection: createSuccessfulRemoteDataObject$(createPaginatedList([collection])),
getAdminAuthorizedCollection: createSuccessfulRemoteDataObject$(createPaginatedList([collection])),
getEditAuthorizedCollection: createSuccessfulRemoteDataObject$(createPaginatedList([collection])),
getAuthorizedCollectionByEntityType: createSuccessfulRemoteDataObject$(createPaginatedList([collection])),
});
notificationsService = jasmine.createSpyObj('notificationsService', ['error']);
Expand All @@ -60,42 +63,57 @@ describe('AuthorizedCollectionSelectorComponent', () => {
});

describe('search', () => {
describe('when has no entity type', () => {
it('should call getAuthorizedCollection and return the authorized collection in a SearchResult', (done) => {
component.search('', 1).subscribe((resultRD) => {
expect(collectionService.getAuthorizedCollection).toHaveBeenCalled();
expect(resultRD.payload.page.length).toEqual(1);
expect(resultRD.payload.page[0].indexableObject).toEqual(collection);
done();
describe('when action type is ADD', () => {
describe('when has no entity type', () => {
it('should call getSubmitAuthorizedCollection and return the authorized collection in a SearchResult', (done) => {
component.action = ActionType.ADD;
fixture.detectChanges();
component.search('', 1).subscribe((resultRD) => {
expect(collectionService.getSubmitAuthorizedCollection).toHaveBeenCalled();
expect(resultRD.payload.page.length).toEqual(1);
expect(resultRD.payload.page[0].indexableObject).toEqual(collection);
done();
});
});
});

describe('when has entity type', () => {
it('should call getAuthorizedCollectionByEntityType and return the authorized collection in a SearchResult', (done) => {
component.entityType = 'test';
component.action = ActionType.ADD;
fixture.detectChanges();
component.search('', 1).subscribe((resultRD) => {
expect(collectionService.getAuthorizedCollectionByEntityType).toHaveBeenCalled();
expect(resultRD.payload.page.length).toEqual(1);
expect(resultRD.payload.page[0].indexableObject).toEqual(collection);
done();
});
});
});
});

describe('when has entity type', () => {
it('should call getAuthorizedCollectionByEntityType and return the authorized collection in a SearchResult', (done) => {
component.entityType = 'test';
describe('when action type is WRITE', () => {
it('should call getEditAuthorizedCollection', (done) => {
component.action = ActionType.WRITE;
fixture.detectChanges();
component.search('', 1).subscribe((resultRD) => {
expect(collectionService.getAuthorizedCollectionByEntityType).toHaveBeenCalled();
expect(collectionService.getEditAuthorizedCollection).toHaveBeenCalled();
expect(resultRD.payload.page.length).toEqual(1);
expect(resultRD.payload.page[0].indexableObject).toEqual(collection);
done();
});
});
});

describe('when using searchHref', () => {
it('should call getAuthorizedCollection with "findAdminAuthorized" when overridden', (done) => {
component.searchHref = 'findAdminAuthorized';

component.search('', 1).subscribe(() => {
expect(collectionService.getAuthorizedCollection).toHaveBeenCalledWith(
'', jasmine.any(Object), true, false, 'findAdminAuthorized', jasmine.anything(),
);
describe('when action is not provided', () => {
it('should call getAdminAuthorizedCollection', (done) => {
component.search('', 1).subscribe((resultRD) => {
expect(collectionService.getAdminAuthorizedCollection).toHaveBeenCalled();
expect(resultRD.payload.page.length).toEqual(1);
expect(resultRD.payload.page[0].indexableObject).toEqual(collection);
done();
});
});
});

});
});
Loading
Loading