From a26c718db47d71b2e986389f664b73a5c087fe98 Mon Sep 17 00:00:00 2001 From: im-shubham-vish Date: Tue, 9 Sep 2025 18:35:18 +0530 Subject: [PATCH] Fix to set Edit Collection to utilize findAdminAuthorized instead of findSubmitAuthorized --- src/app/core/data/collection-data.service.ts | 4 ++-- .../collection-dropdown.component.ts | 8 +++++++- ...thorized-collection-selector.component.spec.ts | 14 ++++++++++++++ .../authorized-collection-selector.component.ts | 8 +++++++- ...uthorized-community-selector.component.spec.ts | 15 ++++++--------- .../edit-collection-selector.component.html | 1 + 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/app/core/data/collection-data.service.ts b/src/app/core/data/collection-data.service.ts index b2d5476d21..ee6a5677da 100644 --- a/src/app/core/data/collection-data.service.ts +++ b/src/app/core/data/collection-data.service.ts @@ -77,11 +77,11 @@ export class CollectionDataService extends ComColDataService { * requested after the response becomes stale * @param linksToFollow List of {@link FollowLinkConfig} that indicate which * {@link HALLink}s should be automatically resolved + * @param searchHref The backend search endpoint to use (default to submit) * @return Observable>> * collection list */ - getAuthorizedCollection(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig[]): Observable>> { - const searchHref = 'findSubmitAuthorized'; + getAuthorizedCollection(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, searchHref: string = 'findSubmitAuthorized', ...linksToFollow: FollowLinkConfig[]): Observable>> { options = Object.assign({}, options, { searchParams: [new RequestParam('query', query)], }); diff --git a/src/app/shared/collection-dropdown/collection-dropdown.component.ts b/src/app/shared/collection-dropdown/collection-dropdown.component.ts index e574110370..2eae85eff6 100644 --- a/src/app/shared/collection-dropdown/collection-dropdown.component.ts +++ b/src/app/shared/collection-dropdown/collection-dropdown.component.ts @@ -144,6 +144,12 @@ export class CollectionDropdownComponent implements OnInit, OnDestroy { */ @Input() entityType: string; + /** + * Search endpoint to use for finding authorized collections. + * Defaults to 'findSubmitAuthorized', but can be overridden (e.g. to 'findAdminAuthorized') + */ + @Input() searchHref = 'findSubmitAuthorized'; + /** * Emit to notify whether search is complete */ @@ -252,7 +258,7 @@ export class CollectionDropdownComponent implements OnInit, OnDestroy { followLink('parentCommunity')); } else { searchListService$ = this.collectionDataService - .getAuthorizedCollection(query, findOptions, true, true, followLink('parentCommunity')); + .getAuthorizedCollection(query, findOptions, true, true, this.searchHref, followLink('parentCommunity')); } this.searchListCollection$ = searchListService$.pipe( getFirstCompletedRemoteData(), diff --git a/src/app/shared/dso-selector/dso-selector/authorized-collection-selector/authorized-collection-selector.component.spec.ts b/src/app/shared/dso-selector/dso-selector/authorized-collection-selector/authorized-collection-selector.component.spec.ts index 1695d43f52..2e951a7b15 100644 --- a/src/app/shared/dso-selector/dso-selector/authorized-collection-selector/authorized-collection-selector.component.spec.ts +++ b/src/app/shared/dso-selector/dso-selector/authorized-collection-selector/authorized-collection-selector.component.spec.ts @@ -83,5 +83,19 @@ describe('AuthorizedCollectionSelectorComponent', () => { }); }); }); + + 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() + ); + done(); + }); + }); + }); + }); }); diff --git a/src/app/shared/dso-selector/dso-selector/authorized-collection-selector/authorized-collection-selector.component.ts b/src/app/shared/dso-selector/dso-selector/authorized-collection-selector/authorized-collection-selector.component.ts index 7ee16ffedb..b81ec1c699 100644 --- a/src/app/shared/dso-selector/dso-selector/authorized-collection-selector/authorized-collection-selector.component.ts +++ b/src/app/shared/dso-selector/dso-selector/authorized-collection-selector/authorized-collection-selector.component.ts @@ -66,6 +66,12 @@ export class AuthorizedCollectionSelectorComponent extends DSOSelectorComponent */ @Input() entityType: string; + /** + * Search endpoint to use for finding authorized collections. + * Defaults to 'findSubmitAuthorized', but can be overridden (e.g. to 'findAdminAuthorized') + */ + @Input() searchHref = 'findSubmitAuthorized'; + constructor( protected searchService: SearchService, protected collectionDataService: CollectionDataService, @@ -104,7 +110,7 @@ export class AuthorizedCollectionSelectorComponent extends DSOSelectorComponent findOptions); } else { searchListService$ = this.collectionDataService - .getAuthorizedCollection(query, findOptions, useCache, false, followLink('parentCommunity')); + .getAuthorizedCollection(query, findOptions, useCache, false, this.searchHref, followLink('parentCommunity')); } return searchListService$.pipe( getFirstCompletedRemoteData(), diff --git a/src/app/shared/dso-selector/dso-selector/authorized-community-selector/authorized-community-selector.component.spec.ts b/src/app/shared/dso-selector/dso-selector/authorized-community-selector/authorized-community-selector.component.spec.ts index 1f322c461d..d11291c756 100644 --- a/src/app/shared/dso-selector/dso-selector/authorized-community-selector/authorized-community-selector.component.spec.ts +++ b/src/app/shared/dso-selector/dso-selector/authorized-community-selector/authorized-community-selector.component.spec.ts @@ -59,16 +59,13 @@ describe('AuthorizedCommunitySelectorComponent', () => { }); describe('search', () => { - describe('when has no entity type', () => { - it('should call getAuthorizedCommunity and return the authorized community in a SearchResult', (done) => { - component.search('', 1).subscribe((resultRD) => { - expect(communityService.getAuthorizedCommunity).toHaveBeenCalled(); - expect(resultRD.payload.page.length).toEqual(1); - expect(resultRD.payload.page[0].indexableObject).toEqual(community); - done(); - }); + it('should call getAuthorizedCommunity and return the authorized community in a SearchResult', (done) => { + component.search('', 1).subscribe((resultRD) => { + expect(communityService.getAuthorizedCommunity).toHaveBeenCalled(); + expect(resultRD.payload.page.length).toEqual(1); + expect(resultRD.payload.page[0].indexableObject).toEqual(community); + done(); }); }); - }); }); diff --git a/src/app/shared/dso-selector/modal-wrappers/edit-collection-selector/edit-collection-selector.component.html b/src/app/shared/dso-selector/modal-wrappers/edit-collection-selector/edit-collection-selector.component.html index 3ab9eddceb..ceadcf2bb3 100644 --- a/src/app/shared/dso-selector/modal-wrappers/edit-collection-selector/edit-collection-selector.component.html +++ b/src/app/shared/dso-selector/modal-wrappers/edit-collection-selector/edit-collection-selector.component.html @@ -9,6 +9,7 @@ }