Skip to content

Commit ab59b05

Browse files
authored
Merge pull request #5123 from toniprieto/find-authorized-endpoints-7x
[Port dspace-7_x] Update DSO creation and edition selectors in admin menu to use more specific authorization endpoints (Includes port of #4639)
2 parents 6cefee7 + d0e4ca5 commit ab59b05

23 files changed

Lines changed: 675 additions & 30 deletions

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

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class CollectionDataService extends ComColDataService<Collection> {
5656
}
5757

5858
/**
59-
* Get all collections the user is authorized to submit to
59+
* Get all collections the user is admin of
6060
*
6161
* @param query limit the returned collection to those with metadata values
6262
* matching the query terms.
@@ -70,8 +70,68 @@ export class CollectionDataService extends ComColDataService<Collection> {
7070
* @return Observable<RemoteData<PaginatedList<Collection>>>
7171
* collection list
7272
*/
73-
getAuthorizedCollection(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<PaginatedList<Collection>>> {
73+
getAdminAuthorizedCollection(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<PaginatedList<Collection>>> {
74+
const searchHref = 'findAdminAuthorized';
75+
return this.getAuthorizedCollection(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
76+
}
77+
78+
/**
79+
* Get all collections the user is authorized to edit
80+
*
81+
* @param query limit the returned collection to those with metadata values
82+
* matching the query terms.
83+
* @param options The [[FindListOptions]] object
84+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
85+
* no valid cached version. Defaults to true
86+
* @param reRequestOnStale Whether or not the request should automatically be re-
87+
* requested after the response becomes stale
88+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
89+
* {@link HALLink}s should be automatically resolved
90+
* @return Observable<RemoteData<PaginatedList<Collection>>>
91+
* collection list
92+
*/
93+
getEditAuthorizedCollection(query: string,options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<PaginatedList<Collection>>> {
94+
const searchHref = 'findEditAuthorized';
95+
return this.getAuthorizedCollection(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
96+
}
97+
98+
/**
99+
* Get all collections the user is authorized to submit
100+
*
101+
* @param query limit the returned collection to those with metadata values
102+
* matching the query terms.
103+
* @param options The [[FindListOptions]] object
104+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
105+
* no valid cached version. Defaults to true
106+
* @param reRequestOnStale Whether or not the request should automatically be re-
107+
* requested after the response becomes stale
108+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
109+
* {@link HALLink}s should be automatically resolved
110+
* @return Observable<RemoteData<PaginatedList<Collection>>>
111+
* collection list
112+
*/
113+
getSubmitAuthorizedCollection(query: string,options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<PaginatedList<Collection>>> {
74114
const searchHref = 'findSubmitAuthorized';
115+
return this.getAuthorizedCollection(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
116+
}
117+
118+
/**
119+
* Get all collections the user is authorized to perform a specific action on
120+
*
121+
* @param query limit the returned collection to those with metadata values
122+
* matching the query terms.
123+
* @param options The [[FindListOptions]] object
124+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
125+
* no valid cached version. Defaults to true
126+
* @param reRequestOnStale Whether or not the request should automatically be re-
127+
* requested after the response becomes stale
128+
* @param searchHref The backend search endpoint to use (default to submit)
129+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
130+
* {@link HALLink}s should be automatically resolved
131+
* @return Observable<RemoteData<PaginatedList<Collection>>>
132+
* collection list
133+
*/
134+
getAuthorizedCollection(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, searchHref: string = 'findSubmitAuthorized', ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<PaginatedList<Collection>>> {
75135
options = Object.assign({}, options, {
76136
searchParams: [new RequestParam('query', query)]
77137
});

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

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ import { Observable } from 'rxjs';
44
import { filter, map, switchMap, take } from 'rxjs/operators';
55
import { NotificationsService } from '../../shared/notifications/notifications.service';
66
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
7+
import { RequestParam } from '../cache/models/request-param.model';
78
import { ObjectCacheService } from '../cache/object-cache.service';
89
import { Community } from '../shared/community.model';
910
import { COMMUNITY } from '../shared/community.resource-type';
1011
import { HALEndpointService } from '../shared/hal-endpoint.service';
12+
import { getAllCompletedRemoteData } from '../shared/operators';
13+
import { BitstreamDataService } from './bitstream-data.service';
1114
import { ComColDataService } from './comcol-data.service';
1215
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
1316
import { PaginatedList } from './paginated-list.model';
1417
import { RemoteData } from './remote-data';
1518
import { RequestService } from './request.service';
16-
import { BitstreamDataService } from './bitstream-data.service';
1719
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
1820
import { isNotEmpty } from '../../shared/empty.util';
1921
import { FindListOptions } from './find-list-options.model';
@@ -36,6 +38,92 @@ export class CommunityDataService extends ComColDataService<Community> {
3638
super('communities', requestService, rdbService, objectCache, halService, comparator, notificationsService, bitstreamDataService);
3739
}
3840

41+
/**
42+
* Get all communities the user is admin of
43+
*
44+
* @param query limit the returned collection to those with metadata values
45+
* matching the query terms.
46+
* @param options The [[FindListOptions]] object
47+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
48+
* no valid cached version. Defaults to true
49+
* @param reRequestOnStale Whether or not the request should automatically be re-
50+
* requested after the response becomes stale
51+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
52+
* {@link HALLink}s should be automatically resolved
53+
* @return Observable<RemoteData<PaginatedList<Community>>>
54+
* community list
55+
*/
56+
getAdminAuthorizedCommunity(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Community>[]): Observable<RemoteData<PaginatedList<Community>>> {
57+
const searchHref = 'findAdminAuthorized';
58+
return this.getAuthorizedCommunity(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
59+
}
60+
61+
/**
62+
* Get all communities the user is authorized to add a new subcommunity or collection to
63+
*
64+
* @param query limit the returned collection to those with metadata values
65+
* matching the query terms.
66+
* @param options The [[FindListOptions]] object
67+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
68+
* no valid cached version. Defaults to true
69+
* @param reRequestOnStale Whether or not the request should automatically be re-
70+
* requested after the response becomes stale
71+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
72+
* {@link HALLink}s should be automatically resolved
73+
* @return Observable<RemoteData<PaginatedList<Community>>>
74+
* community list
75+
*/
76+
getAddAuthorizedCommunity(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Community>[]): Observable<RemoteData<PaginatedList<Community>>> {
77+
const searchHref = 'findAddAuthorized';
78+
return this.getAuthorizedCommunity(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
79+
}
80+
81+
/**
82+
* Get all communities the user is authorized to edit
83+
*
84+
* @param query limit the returned collection to those with metadata values
85+
* matching the query terms.
86+
* @param options The [[FindListOptions]] object
87+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
88+
* no valid cached version. Defaults to true
89+
* @param reRequestOnStale Whether or not the request should automatically be re-
90+
* requested after the response becomes stale
91+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
92+
* {@link HALLink}s should be automatically resolved
93+
* @return Observable<RemoteData<PaginatedList<Community>>>
94+
* community list
95+
*/
96+
getEditAuthorizedCommunity(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Community>[]): Observable<RemoteData<PaginatedList<Community>>> {
97+
const searchHref = 'findEditAuthorized';
98+
return this.getAuthorizedCommunity(query, options, useCachedVersionIfAvailable, reRequestOnStale, searchHref, ...linksToFollow);
99+
}
100+
101+
/**
102+
* Get all communities the user is authorized to submit to
103+
*
104+
* @param query limit the returned community to those with metadata values
105+
* matching the query terms.
106+
* @param options The [[FindListOptions]] object
107+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
108+
* no valid cached version. Defaults to true
109+
* @param reRequestOnStale Whether or not the request should automatically be re-
110+
* requested after the response becomes stale
111+
* @param searchHref The search endpoint to use, defaults to 'findAdminAuthorized'
112+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
113+
* {@link HALLink}s should be automatically resolved
114+
* @return Observable<RemoteData<PaginatedList<Community>>>
115+
* community list
116+
*/
117+
getAuthorizedCommunity(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, searchHref: string = 'findAdminAuthorized', ...linksToFollow: FollowLinkConfig<Community>[]): Observable<RemoteData<PaginatedList<Community>>> {
118+
options = Object.assign({}, options, {
119+
searchParams: [new RequestParam('query', query)],
120+
});
121+
122+
return this.searchBy(searchHref, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow).pipe(
123+
getAllCompletedRemoteData(),
124+
);
125+
}
126+
39127
// this method is overridden in order to make it public
40128
getEndpoint() {
41129
return this.halService.getEndpoint(this.linkPath);

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ import { RestRequestMethod } from './rest-request-method';
4646
import { CreateData, CreateDataImpl } from './base/create-data';
4747
import { RequestParam } from '../cache/models/request-param.model';
4848
import { dataService } from './base/data-service.decorator';
49+
import { SearchDataImpl } from './base/search-data';
50+
import { FollowLinkConfig } from 'src/app/shared/utils/follow-link-config.model';
4951

5052
/**
5153
* An abstract service for CRUD operations on Items
@@ -56,6 +58,7 @@ export abstract class BaseItemDataService extends IdentifiableDataService<Item>
5658
private createData: CreateData<Item>;
5759
private patchData: PatchData<Item>;
5860
private deleteData: DeleteData<Item>;
61+
private searchData: SearchDataImpl<Item>;
5962

6063
protected constructor(
6164
protected linkPath,
@@ -74,6 +77,7 @@ export abstract class BaseItemDataService extends IdentifiableDataService<Item>
7477
this.createData = new CreateDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive);
7578
this.patchData = new PatchDataImpl<Item>(this.linkPath, requestService, rdbService, objectCache, halService, comparator, this.responseMsToLive, this.constructIdEndpoint);
7679
this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint);
80+
this.searchData = new SearchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
7781
}
7882

7983
/**
@@ -321,6 +325,26 @@ export abstract class BaseItemDataService extends IdentifiableDataService<Item>
321325
);
322326
}
323327

328+
/**
329+
* Find the list of items for which the current user has editing rights.
330+
*
331+
* @param query limit the returned collection to those with metadata values
332+
* matching the query terms
333+
* @param options The [[FindListOptions]] object
334+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
335+
* no valid cached version. Defaults to true
336+
* @param reRequestOnStale Whether or not the request should automatically be re-
337+
* requested after the response becomes stale
338+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
339+
* {@link HALLink}s should be automatically resolved
340+
* @return Observable<RemoteData<PaginatedList<Item>>>
341+
* item list
342+
*/
343+
public findEditAuthorized(query: string, options: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Item>[]): Observable<RemoteData<PaginatedList<Item>>> {
344+
options = { ...options, searchParams: [new RequestParam('query', query)] };
345+
return this.searchBy('findEditAuthorized', options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
346+
}
347+
324348
/**
325349
* Invalidate the cache of the item
326350
* @param itemUUID
@@ -337,6 +361,24 @@ export abstract class BaseItemDataService extends IdentifiableDataService<Item>
337361
this.patchData.commitUpdates(method);
338362
}
339363

364+
/**
365+
* Make a new FindListRequest with given search method
366+
*
367+
* @param searchMethod The search method for the object
368+
* @param options The [[FindListOptions]] object
369+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
370+
* no valid cached version. Defaults to true
371+
* @param reRequestOnStale Whether or not the request should automatically be re-
372+
* requested after the response becomes stale
373+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
374+
* {@link HALLink}s should be automatically resolved
375+
* @return {Observable<RemoteData<PaginatedList<T>>}
376+
* Return an observable that emits response from the server
377+
*/
378+
public searchBy(searchMethod: string, options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<Item>[]): Observable<RemoteData<PaginatedList<Item>>> {
379+
return this.searchData.searchBy(searchMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
380+
}
381+
340382
/**
341383
* Send a patch request for a specified object
342384
* @param {T} object The object to send a patch request for

src/app/shared/collection-dropdown/collection-dropdown.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ export class CollectionDropdownComponent implements OnInit, OnDestroy {
112112
*/
113113
@Input() entityType: string;
114114

115+
/**
116+
* Search endpoint to use for finding authorized collections.
117+
* Defaults to 'findSubmitAuthorized', but can be overridden (e.g. to 'findAdminAuthorized')
118+
*/
119+
@Input() searchHref = 'findSubmitAuthorized';
120+
115121
/**
116122
* Emit to notify whether search is complete
117123
*/
@@ -220,7 +226,7 @@ export class CollectionDropdownComponent implements OnInit, OnDestroy {
220226
followLink('parentCommunity'));
221227
} else {
222228
searchListService$ = this.collectionDataService
223-
.getAuthorizedCollection(query, findOptions, true, true, followLink('parentCommunity'));
229+
.getAuthorizedCollection(query, findOptions, true, true, this.searchHref, followLink('parentCommunity'));
224230
}
225231
this.searchListCollection$ = searchListService$.pipe(
226232
getFirstCompletedRemoteData(),

0 commit comments

Comments
 (0)