Skip to content

Commit bca7828

Browse files
authored
Merge pull request DSpace#4918 from toniprieto/find-authorized-endpoints
Update DSO creation and edition selectors in admin menu to use more specific authorization endpoints
2 parents b5f4c94 + 3dd5aa3 commit bca7828

22 files changed

+479
-51
lines changed

src/app/core/data/collection-data.service.ts

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,47 @@ export class CollectionDataService extends ComColDataService<Collection> {
6666
}
6767

6868
/**
69-
* Get all collections the user is authorized to submit to
69+
* Get all collections the user is admin of
70+
*
71+
* @param query limit the returned collection to those with metadata values
72+
* matching the query terms.
73+
* @param options The [[FindListOptions]] object
74+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
75+
* no valid cached version. Defaults to true
76+
* @param reRequestOnStale Whether or not the request should automatically be re-
77+
* requested after the response becomes stale
78+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
79+
* {@link HALLink}s should be automatically resolved
80+
* @return Observable<RemoteData<PaginatedList<Collection>>>
81+
* collection list
82+
*/
83+
getAdminAuthorizedCollection(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<PaginatedList<Collection>>> {
84+
const searchHref = 'findAdminAuthorized';
85+
return this.getAuthorizedCollection(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
86+
}
87+
88+
/**
89+
* Get all collections the user is authorized to edit
90+
*
91+
* @param query limit the returned collection to those with metadata values
92+
* matching the query terms.
93+
* @param options The [[FindListOptions]] object
94+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
95+
* no valid cached version. Defaults to true
96+
* @param reRequestOnStale Whether or not the request should automatically be re-
97+
* requested after the response becomes stale
98+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
99+
* {@link HALLink}s should be automatically resolved
100+
* @return Observable<RemoteData<PaginatedList<Collection>>>
101+
* collection list
102+
*/
103+
getEditAuthorizedCollection(query: string,options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<PaginatedList<Collection>>> {
104+
const searchHref = 'findEditAuthorized';
105+
return this.getAuthorizedCollection(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
106+
}
107+
108+
/**
109+
* Get all collections the user is authorized to submit
70110
*
71111
* @param query limit the returned collection to those with metadata values
72112
* matching the query terms.
@@ -77,7 +117,27 @@ export class CollectionDataService extends ComColDataService<Collection> {
77117
* requested after the response becomes stale
78118
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
79119
* {@link HALLink}s should be automatically resolved
120+
* @return Observable<RemoteData<PaginatedList<Collection>>>
121+
* collection list
122+
*/
123+
getSubmitAuthorizedCollection(query: string,options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<PaginatedList<Collection>>> {
124+
const searchHref = 'findSubmitAuthorized';
125+
return this.getAuthorizedCollection(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
126+
}
127+
128+
/**
129+
* Get all collections the user is authorized to perform a specific action on
130+
*
131+
* @param query limit the returned collection to those with metadata values
132+
* matching the query terms.
133+
* @param options The [[FindListOptions]] object
134+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
135+
* no valid cached version. Defaults to true
136+
* @param reRequestOnStale Whether or not the request should automatically be re-
137+
* requested after the response becomes stale
80138
* @param searchHref The backend search endpoint to use (default to submit)
139+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
140+
* {@link HALLink}s should be automatically resolved
81141
* @return Observable<RemoteData<PaginatedList<Collection>>>
82142
* collection list
83143
*/

src/app/core/data/community-data.service.ts

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,66 @@ export class CommunityDataService extends ComColDataService<Community> {
4040
super('communities', requestService, rdbService, objectCache, halService, comparator, notificationsService, bitstreamDataService);
4141
}
4242

43+
/**
44+
* Get all communities the user is admin of
45+
*
46+
* @param query limit the returned collection to those with metadata values
47+
* matching the query terms.
48+
* @param options The [[FindListOptions]] object
49+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
50+
* no valid cached version. Defaults to true
51+
* @param reRequestOnStale Whether or not the request should automatically be re-
52+
* requested after the response becomes stale
53+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
54+
* {@link HALLink}s should be automatically resolved
55+
* @return Observable<RemoteData<PaginatedList<Community>>>
56+
* community list
57+
*/
58+
getAdminAuthorizedCommunity(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Community>[]): Observable<RemoteData<PaginatedList<Community>>> {
59+
const searchHref = 'findAdminAuthorized';
60+
return this.getAuthorizedCommunity(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
61+
}
62+
63+
/**
64+
* Get all communities the user is authorized to add a new subcommunity or collection to
65+
*
66+
* @param query limit the returned collection to those with metadata values
67+
* matching the query terms.
68+
* @param options The [[FindListOptions]] object
69+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
70+
* no valid cached version. Defaults to true
71+
* @param reRequestOnStale Whether or not the request should automatically be re-
72+
* requested after the response becomes stale
73+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
74+
* {@link HALLink}s should be automatically resolved
75+
* @return Observable<RemoteData<PaginatedList<Community>>>
76+
* community list
77+
*/
78+
getAddAuthorizedCommunity(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Community>[]): Observable<RemoteData<PaginatedList<Community>>> {
79+
const searchHref = 'findAddAuthorized';
80+
return this.getAuthorizedCommunity(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
81+
}
82+
83+
/**
84+
* Get all communities the user is authorized to edit
85+
*
86+
* @param query limit the returned collection to those with metadata values
87+
* matching the query terms.
88+
* @param options The [[FindListOptions]] object
89+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
90+
* no valid cached version. Defaults to true
91+
* @param reRequestOnStale Whether or not the request should automatically be re-
92+
* requested after the response becomes stale
93+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
94+
* {@link HALLink}s should be automatically resolved
95+
* @return Observable<RemoteData<PaginatedList<Community>>>
96+
* community list
97+
*/
98+
getEditAuthorizedCommunity(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Community>[]): Observable<RemoteData<PaginatedList<Community>>> {
99+
const searchHref = 'findEditAuthorized';
100+
return this.getAuthorizedCommunity(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
101+
}
102+
43103
/**
44104
* Get all communities the user is authorized to submit to
45105
*
@@ -50,13 +110,13 @@ export class CommunityDataService extends ComColDataService<Community> {
50110
* no valid cached version. Defaults to true
51111
* @param reRequestOnStale Whether or not the request should automatically be re-
52112
* requested after the response becomes stale
113+
* @param searchHref The search endpoint to use, defaults to 'findAdminAuthorized'
53114
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
54115
* {@link HALLink}s should be automatically resolved
55116
* @return Observable<RemoteData<PaginatedList<Community>>>
56117
* community list
57118
*/
58-
getAuthorizedCommunity(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Community>[]): Observable<RemoteData<PaginatedList<Community>>> {
59-
const searchHref = 'findAdminAuthorized';
119+
getAuthorizedCommunity(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, searchHref: string = 'findAdminAuthorized', ...linksToFollow: FollowLinkConfig<Community>[]): Observable<RemoteData<PaginatedList<Community>>> {
60120
options = Object.assign({}, options, {
61121
searchParams: [new RequestParam('query', query)],
62122
});

src/app/core/data/item-data.service.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,26 @@ export abstract class BaseItemDataService extends IdentifiableDataService<Item>
353353
);
354354
}
355355

356+
/**
357+
* Find the list of items for which the current user has editing rights.
358+
*
359+
* @param query limit the returned collection to those with metadata values
360+
* matching the query terms
361+
* @param options The [[FindListOptions]] object
362+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
363+
* no valid cached version. Defaults to true
364+
* @param reRequestOnStale Whether or not the request should automatically be re-
365+
* requested after the response becomes stale
366+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
367+
* {@link HALLink}s should be automatically resolved
368+
* @return Observable<RemoteData<PaginatedList<Item>>>
369+
* item list
370+
*/
371+
public findEditAuthorized(query: string, options: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Item>[]): Observable<RemoteData<PaginatedList<Item>>> {
372+
options = { ...options, searchParams: [new RequestParam('query', query)] };
373+
return this.searchBy('findEditAuthorized', options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
374+
}
375+
356376
/**
357377
* Invalidate the cache of the item
358378
* @param itemUUID
@@ -369,6 +389,24 @@ export abstract class BaseItemDataService extends IdentifiableDataService<Item>
369389
this.patchData.commitUpdates(method);
370390
}
371391

392+
/**
393+
* Make a new FindListRequest with given search method
394+
*
395+
* @param searchMethod The search method for the object
396+
* @param options The [[FindListOptions]] object
397+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
398+
* no valid cached version. Defaults to true
399+
* @param reRequestOnStale Whether or not the request should automatically be re-
400+
* requested after the response becomes stale
401+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
402+
* {@link HALLink}s should be automatically resolved
403+
* @return {Observable<RemoteData<PaginatedList<T>>}
404+
* Return an observable that emits response from the server
405+
*/
406+
public searchBy(searchMethod: string, options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<Item>[]): Observable<RemoteData<PaginatedList<Item>>> {
407+
return this.searchData.searchBy(searchMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
408+
}
409+
372410
/**
373411
* Send a patch request for a specified object
374412
* @param {T} object The object to send a patch request for

src/app/shared/dso-selector/dso-selector/authorized-collection-selector/authorized-collection-selector.component.spec.ts

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import { RouterTestingModule } from '@angular/router/testing';
88
import { CollectionDataService } from '@dspace/core/data/collection-data.service';
99
import { NotificationsService } from '@dspace/core/notification-system/notifications.service';
10+
import { ActionType } from '@dspace/core/resource-policy/models/action-type.model';
1011
import { Collection } from '@dspace/core/shared/collection.model';
1112
import { DSpaceObjectType } from '@dspace/core/shared/dspace-object-type.model';
1213
import { createPaginatedList } from '@dspace/core/testing/utils.test';
@@ -33,7 +34,9 @@ describe('AuthorizedCollectionSelectorComponent', () => {
3334
id: 'authorized-collection',
3435
});
3536
collectionService = jasmine.createSpyObj('collectionService', {
36-
getAuthorizedCollection: createSuccessfulRemoteDataObject$(createPaginatedList([collection])),
37+
getSubmitAuthorizedCollection: createSuccessfulRemoteDataObject$(createPaginatedList([collection])),
38+
getAdminAuthorizedCollection: createSuccessfulRemoteDataObject$(createPaginatedList([collection])),
39+
getEditAuthorizedCollection: createSuccessfulRemoteDataObject$(createPaginatedList([collection])),
3740
getAuthorizedCollectionByEntityType: createSuccessfulRemoteDataObject$(createPaginatedList([collection])),
3841
});
3942
notificationsService = jasmine.createSpyObj('notificationsService', ['error']);
@@ -60,42 +63,57 @@ describe('AuthorizedCollectionSelectorComponent', () => {
6063
});
6164

6265
describe('search', () => {
63-
describe('when has no entity type', () => {
64-
it('should call getAuthorizedCollection and return the authorized collection in a SearchResult', (done) => {
65-
component.search('', 1).subscribe((resultRD) => {
66-
expect(collectionService.getAuthorizedCollection).toHaveBeenCalled();
67-
expect(resultRD.payload.page.length).toEqual(1);
68-
expect(resultRD.payload.page[0].indexableObject).toEqual(collection);
69-
done();
66+
describe('when action type is ADD', () => {
67+
describe('when has no entity type', () => {
68+
it('should call getSubmitAuthorizedCollection and return the authorized collection in a SearchResult', (done) => {
69+
component.action = ActionType.ADD;
70+
fixture.detectChanges();
71+
component.search('', 1).subscribe((resultRD) => {
72+
expect(collectionService.getSubmitAuthorizedCollection).toHaveBeenCalled();
73+
expect(resultRD.payload.page.length).toEqual(1);
74+
expect(resultRD.payload.page[0].indexableObject).toEqual(collection);
75+
done();
76+
});
77+
});
78+
});
79+
80+
describe('when has entity type', () => {
81+
it('should call getAuthorizedCollectionByEntityType and return the authorized collection in a SearchResult', (done) => {
82+
component.entityType = 'test';
83+
component.action = ActionType.ADD;
84+
fixture.detectChanges();
85+
component.search('', 1).subscribe((resultRD) => {
86+
expect(collectionService.getAuthorizedCollectionByEntityType).toHaveBeenCalled();
87+
expect(resultRD.payload.page.length).toEqual(1);
88+
expect(resultRD.payload.page[0].indexableObject).toEqual(collection);
89+
done();
90+
});
7091
});
7192
});
7293
});
7394

74-
describe('when has entity type', () => {
75-
it('should call getAuthorizedCollectionByEntityType and return the authorized collection in a SearchResult', (done) => {
76-
component.entityType = 'test';
95+
describe('when action type is WRITE', () => {
96+
it('should call getEditAuthorizedCollection', (done) => {
97+
component.action = ActionType.WRITE;
7798
fixture.detectChanges();
7899
component.search('', 1).subscribe((resultRD) => {
79-
expect(collectionService.getAuthorizedCollectionByEntityType).toHaveBeenCalled();
100+
expect(collectionService.getEditAuthorizedCollection).toHaveBeenCalled();
80101
expect(resultRD.payload.page.length).toEqual(1);
81102
expect(resultRD.payload.page[0].indexableObject).toEqual(collection);
82103
done();
83104
});
84105
});
85106
});
86107

87-
describe('when using searchHref', () => {
88-
it('should call getAuthorizedCollection with "findAdminAuthorized" when overridden', (done) => {
89-
component.searchHref = 'findAdminAuthorized';
90-
91-
component.search('', 1).subscribe(() => {
92-
expect(collectionService.getAuthorizedCollection).toHaveBeenCalledWith(
93-
'', jasmine.any(Object), true, false, 'findAdminAuthorized', jasmine.anything(),
94-
);
108+
describe('when action is not provided', () => {
109+
it('should call getAdminAuthorizedCollection', (done) => {
110+
component.search('', 1).subscribe((resultRD) => {
111+
expect(collectionService.getAdminAuthorizedCollection).toHaveBeenCalled();
112+
expect(resultRD.payload.page.length).toEqual(1);
113+
expect(resultRD.payload.page[0].indexableObject).toEqual(collection);
95114
done();
96115
});
97116
});
98117
});
99-
100118
});
101119
});

0 commit comments

Comments
 (0)