diff --git a/src/app/access-control/group-registry/group-form/group-form.component.spec.ts b/src/app/access-control/group-registry/group-form/group-form.component.spec.ts index 96f1b861520..274bec70eed 100644 --- a/src/app/access-control/group-registry/group-form/group-form.component.spec.ts +++ b/src/app/access-control/group-registry/group-form/group-form.component.spec.ts @@ -1,4 +1,7 @@ -import { CommonModule } from '@angular/common'; +import { + APP_BASE_HREF, + CommonModule, +} from '@angular/common'; import { HttpClient } from '@angular/common/http'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { @@ -46,6 +49,7 @@ import { RemoteData } from '../../../core/data/remote-data'; import { EPersonDataService } from '../../../core/eperson/eperson-data.service'; import { GroupDataService } from '../../../core/eperson/group-data.service'; import { Group } from '../../../core/eperson/models/group.model'; +import { Collection } from '../../../core/shared/collection.model'; import { DSpaceObject } from '../../../core/shared/dspace-object.model'; import { HALEndpointService } from '../../../core/shared/hal-endpoint.service'; import { NoContent } from '../../../core/shared/NoContent.model'; @@ -263,6 +267,7 @@ describe('GroupFormComponent', () => { { provide: ActivatedRoute, useValue: route }, { provide: Router, useValue: router }, { provide: AuthorizationDataService, useValue: authorizationService }, + { provide: APP_BASE_HREF, useValue: '/repository/' }, ], schemas: [CUSTOM_ELEMENTS_SCHEMA], }) @@ -407,6 +412,29 @@ describe('GroupFormComponent', () => { }); }); + describe('linkedEditRolesRoute$', () => { + beforeEach(() => { + const collection = Object.assign(new Collection(), { + id: 'collection-id', + type: Collection.type.value, + metadata: {}, + }); + spyOn(groupsDataServiceStub, 'getActiveGroup').and.returnValue(of(Object.assign(new Group(), { + name: 'COLLECTION_collection-id_SUBMIT', + metadata: {}, + object: createSuccessfulRemoteDataObject$(collection), + }))); + component.ngOnInit(); + }); + + it('should resolve the edit roles route against the base href', (done) => { + component.linkedEditRolesRoute$.subscribe((editRolesRoute: string) => { + expect(editRolesRoute).toBe('/repository/collections/collection-id/edit/roles'); + done(); + }); + }); + }); + describe('check form validation', () => { beforeEach(() => { diff --git a/src/app/access-control/group-registry/group-form/group-form.component.ts b/src/app/access-control/group-registry/group-form/group-form.component.ts index 4808f6316b4..c2b7a4ec284 100644 --- a/src/app/access-control/group-registry/group-form/group-form.component.ts +++ b/src/app/access-control/group-registry/group-form/group-form.component.ts @@ -1,4 +1,7 @@ -import { AsyncPipe } from '@angular/common'; +import { + AsyncPipe, + Location, +} from '@angular/common'; import { ChangeDetectorRef, Component, @@ -200,6 +203,7 @@ export class GroupFormComponent implements OnInit, OnDestroy { public requestService: RequestService, protected changeDetectorRef: ChangeDetectorRef, public dsoNameService: DSONameService, + protected location: Location, ) { } @@ -535,7 +539,8 @@ export class GroupFormComponent implements OnInit, OnDestroy { /** * Get the route to the edit roles tab of the active {@link Group}'s linked object (community or collection linked - * to a workflow group) if it has one + * to a workflow group) if it has one. + * It lands in the raw `` of a translation, so it is resolved against the base href here. */ getLinkedEditRolesRoute(): Observable { return this.activeGroupLinkedDSO$.pipe( @@ -543,9 +548,9 @@ export class GroupFormComponent implements OnInit, OnDestroy { map((dso: DSpaceObject) => { switch ((dso as any).type) { case Community.type.value: - return getCommunityEditRolesRoute(dso.id); + return this.location.prepareExternalUrl(getCommunityEditRolesRoute(dso.id)); case Collection.type.value: - return getCollectionEditRolesRoute(dso.id); + return this.location.prepareExternalUrl(getCollectionEditRolesRoute(dso.id)); } }), ); diff --git a/src/app/admin/admin-reports/filtered-collections/filtered-collections.component.html b/src/app/admin/admin-reports/filtered-collections/filtered-collections.component.html index c696fa23ba2..aa5c150cba0 100644 --- a/src/app/admin/admin-reports/filtered-collections/filtered-collections.component.html +++ b/src/app/admin/admin-reports/filtered-collections/filtered-collections.component.html @@ -51,8 +51,8 @@

{{ "admin.reports.collections.head" | @for (coll of results.collections; track coll) { - {{ coll.communityLabel }} - {{ coll.label }} + {{ coll.communityLabel }} + {{ coll.label }} {{ coll.nbTotalItems }} {{ coll.allFiltersValue }} @for (filter of results.summary.values | keyvalue; track filter) { diff --git a/src/app/admin/admin-reports/filtered-collections/filtered-collections.component.spec.ts b/src/app/admin/admin-reports/filtered-collections/filtered-collections.component.spec.ts index 4c0025a0dc4..ba31a654409 100644 --- a/src/app/admin/admin-reports/filtered-collections/filtered-collections.component.spec.ts +++ b/src/app/admin/admin-reports/filtered-collections/filtered-collections.component.spec.ts @@ -94,4 +94,28 @@ describe('FiltersComponent', () => { }); })); }); + + describe('result links', () => { + beforeEach(() => { + spyOn(component, 'getFilteredCollections').and.returnValue(of({ + ...expected, + payload: { + collections: [{ + label: 'Collection', handle: '123456789/2', + community_label: 'Community', community_handle: '123456789/1', + nb_total_items: 1, all_filters_value: 1, values: {}, + }], + summary: { label: 'Test', nb_total_items: 1, all_filters_value: 1, values: {} }, + }, + } as RawRestResponse)); + component.submit(); + fixture.detectChanges(); + }); + + it('should link to the handle relative to the base href', () => { + const hrefs = Array.from(fixture.nativeElement.querySelectorAll('tbody a')) + .map((a) => a.getAttribute('href')); + expect(hrefs).toEqual(['handle/123456789/1', 'handle/123456789/2']); + }); + }); }); diff --git a/src/app/admin/admin-reports/filtered-items/filtered-items.component.html b/src/app/admin/admin-reports/filtered-items/filtered-items.component.html index e515999003e..d10a9bdeafe 100644 --- a/src/app/admin/admin-reports/filtered-items/filtered-items.component.html +++ b/src/app/admin/admin-reports/filtered-items/filtered-items.component.html @@ -170,10 +170,10 @@

{{'admin.reports.items.head' | transl {{ item.index }} {{ item.uuid }} @if (item.owningCollection) { - {{ item.owningCollection.name }} + {{ item.owningCollection.name }} } @if (item.handle) { - {{ item.handle }} + {{ item.handle }} } {{ item.name }} @for (field of queryForm.value['additionalFields']; track field) { diff --git a/src/app/info/feedback/feedback-form/feedback-form.component.spec.ts b/src/app/info/feedback/feedback-form/feedback-form.component.spec.ts index 56275ad5a35..cd47a8e600a 100644 --- a/src/app/info/feedback/feedback-form/feedback-form.component.spec.ts +++ b/src/app/info/feedback/feedback-form/feedback-form.component.spec.ts @@ -1,3 +1,4 @@ +import { APP_BASE_HREF } from '@angular/common'; import { DebugElement, NO_ERRORS_SCHEMA, @@ -22,6 +23,7 @@ import { BtnDisabledDirective } from '../../../shared/btn-disabled.directive'; import { NativeWindowMockFactory } from '../../../shared/mocks/mock-native-window-ref'; import { RouterMock } from '../../../shared/mocks/router.mock'; import { NotificationsService } from '../../../shared/notifications/notifications.service'; +import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils'; import { AuthServiceStub } from '../../../shared/testing/auth-service.stub'; import { EPersonMock } from '../../../shared/testing/eperson.mock'; import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub'; @@ -55,6 +57,7 @@ describe('FeedbackFormComponent', () => { { provide: AuthService, useValue: authService }, { provide: NativeWindowService, useFactory: NativeWindowMockFactory }, { provide: Router, useValue: routerStub }, + { provide: APP_BASE_HREF, useValue: '/repository/' }, ], schemas: [NO_ERRORS_SCHEMA], }).compileComponents(); @@ -71,8 +74,8 @@ describe('FeedbackFormComponent', () => { expect(component).toBeTruthy(); }); - it('should have page value', () => { - expect(component.feedbackForm.controls.page.value).toEqual('http://localhost/home'); + it('should have page value including the base href', () => { + expect(component.feedbackForm.controls.page.value).toEqual('http://localhost/repository/home'); }); it('should have email if ePerson', () => { @@ -101,6 +104,12 @@ describe('FeedbackFormComponent', () => { fixture.detectChanges(); expect(feedbackDataServiceStub.create).toHaveBeenCalled(); }); + + it('after a successful submit should navigate back to the router url of the page', () => { + feedbackDataServiceStub.create.and.returnValue(createSuccessfulRemoteDataObject$({})); + component.createFeedback(); + expect(routerStub.navigateByUrl).toHaveBeenCalledWith('/home'); + }); }); diff --git a/src/app/info/feedback/feedback-form/feedback-form.component.ts b/src/app/info/feedback/feedback-form/feedback-form.component.ts index 6d15e2cce3a..06375b2f4df 100644 --- a/src/app/info/feedback/feedback-form/feedback-form.component.ts +++ b/src/app/info/feedback/feedback-form/feedback-form.component.ts @@ -1,4 +1,5 @@ +import { Location } from '@angular/common'; import { Component, Inject, @@ -60,6 +61,11 @@ export class FeedbackFormComponent implements OnInit { page: [''], }); + /** + * The router url of the page the feedback is about, to go back to after a successful submit + */ + private previousUrl: string; + constructor( @Inject(NativeWindowService) protected _window: NativeWindowRef, public routeService: RouteService, @@ -68,7 +74,8 @@ export class FeedbackFormComponent implements OnInit { protected translate: TranslateService, private feedbackDataService: FeedbackDataService, private authService: AuthService, - private router: Router) { + private router: Router, + private location: Location) { } /** @@ -86,7 +93,9 @@ export class FeedbackFormComponent implements OnInit { if (!url) { url = getHomePageRoute(); } - const relatedUrl = new URLCombiner(this._window.nativeWindow.origin, url).toString(); + this.previousUrl = url; + // The REST API only accepts a page under dspace.ui.url, so the base href must be part of it + const relatedUrl = new URLCombiner(this._window.nativeWindow.origin, this.location.prepareExternalUrl(url)).toString(); this.feedbackForm.patchValue({ page: relatedUrl }); }); @@ -96,12 +105,11 @@ export class FeedbackFormComponent implements OnInit { * Function to create the feedback from form values */ createFeedback(): void { - const url = this.feedbackForm.value.page.replace(this._window.nativeWindow.origin, ''); this.feedbackDataService.create(this.feedbackForm.value).pipe(getFirstCompletedRemoteData()).subscribe((response: RemoteData) => { if (response.isSuccess) { this.notificationsService.success(this.translate.instant('info.feedback.create.success')); this.feedbackForm.reset(); - this.router.navigateByUrl(url); + this.router.navigateByUrl(this.previousUrl); } }); } diff --git a/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.spec.ts b/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.spec.ts index 919702911b2..09c514e94fa 100644 --- a/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.spec.ts +++ b/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.spec.ts @@ -1,3 +1,4 @@ +import { APP_BASE_HREF } from '@angular/common'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { ComponentFixture, @@ -9,9 +10,9 @@ import { import { By } from '@angular/platform-browser'; import { ActivatedRoute, + provideRouter, Router, } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; import { TranslateModule } from '@ngx-translate/core'; import { of } from 'rxjs'; @@ -86,8 +87,11 @@ describe('GrantDenyRequestCopyComponent', () => { }); TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), GrantDenyRequestCopyComponent, VarDirective], + imports: [TranslateModule.forRoot(), GrantDenyRequestCopyComponent, VarDirective], providers: [ + // RouterTestingModule would replace Location with a mock that ignores APP_BASE_HREF + provideRouter([]), + { provide: APP_BASE_HREF, useValue: '/repository/' }, { provide: ActivatedRoute, useValue: route }, { provide: AuthService, useValue: authService }, { provide: ItemDataService, useValue: itemDataService }, @@ -115,7 +119,7 @@ describe('GrantDenyRequestCopyComponent', () => { it('should initialise itemUrl$', (done) => { component.itemUrl$.subscribe((result) => { - expect(result).toEqual(itemUrl); + expect(result).toEqual(`/repository${itemUrl}`); done(); }); }); diff --git a/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.ts b/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.ts index ae1d5dc43ec..f1aec78df27 100644 --- a/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.ts +++ b/src/app/request-copy/grant-deny-request-copy/grant-deny-request-copy.component.ts @@ -1,4 +1,7 @@ -import { AsyncPipe } from '@angular/common'; +import { + AsyncPipe, + Location, +} from '@angular/common'; import { Component, OnInit, @@ -66,7 +69,7 @@ export class GrantDenyRequestCopyComponent implements OnInit { itemName$: Observable; /** - * The url of the item + * The url of the item, resolved against the base href because it lands in the raw `` of a translation */ itemUrl$: Observable; @@ -86,6 +89,7 @@ export class GrantDenyRequestCopyComponent implements OnInit { private authService: AuthService, private itemDataService: ItemDataService, private nameService: DSONameService, + private location: Location, ) { } @@ -106,7 +110,7 @@ export class GrantDenyRequestCopyComponent implements OnInit { ); this.itemUrl$ = this.itemRD$.pipe( getFirstSucceededRemoteDataPayload(), - map((item) => getItemPageRoute(item)), + map((item) => this.location.prepareExternalUrl(getItemPageRoute(item))), ); this.denyRoute$ = this.itemRequestRD$.pipe( diff --git a/src/app/suggestions-page/suggestions-page.component.spec.ts b/src/app/suggestions-page/suggestions-page.component.spec.ts index e39f17c35ce..098199de12a 100644 --- a/src/app/suggestions-page/suggestions-page.component.spec.ts +++ b/src/app/suggestions-page/suggestions-page.component.spec.ts @@ -1,4 +1,7 @@ -import { CommonModule } from '@angular/common'; +import { + APP_BASE_HREF, + CommonModule, +} from '@angular/common'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { ComponentFixture, @@ -91,6 +94,7 @@ describe('SuggestionPageComponent', () => { { provide: NotificationsService, useValue: new NotificationsServiceStub() }, { provide: TranslateService, useValue: getMockTranslateService() }, { provide: PaginationService, useValue: paginationService }, + { provide: APP_BASE_HREF, useValue: '/repository/' }, SuggestionsPageComponent, ], schemas: [NO_ERRORS_SCHEMA], @@ -176,6 +180,17 @@ describe('SuggestionPageComponent', () => { expect(component.updatePage).toHaveBeenCalled(); }); + it('should link the imported item in the notification against the base href', () => { + component.targetId$ = of('testid'); + + scheduler.schedule(() => component.approveAndImport({ collectionId: '1234' } as unknown as SuggestionApproveAndImport)); + scheduler.flush(); + + expect(TestBed.inject(TranslateService).instant).toHaveBeenCalledWith('suggestion.approveAndImport.success', { + url: '/repository/workspaceitems/1234/edit', + }); + }); + it('should approve and import multiple suggestions', () => { spyOn(component, 'updatePage').and.callThrough(); component.targetId$ = of('testid'); diff --git a/src/app/suggestions-page/suggestions-page.component.ts b/src/app/suggestions-page/suggestions-page.component.ts index b93347e0046..1d9920b4089 100644 --- a/src/app/suggestions-page/suggestions-page.component.ts +++ b/src/app/suggestions-page/suggestions-page.component.ts @@ -1,4 +1,7 @@ -import { AsyncPipe } from '@angular/common'; +import { + AsyncPipe, + Location, +} from '@angular/common'; import { Component, OnInit, @@ -132,6 +135,7 @@ export class SuggestionsPageComponent implements OnInit { private suggestionTargetsStateService: SuggestionTargetsStateService, private translateService: TranslateService, private workspaceItemService: WorkspaceitemDataService, + private location: Location, ) { } @@ -245,7 +249,9 @@ export class SuggestionsPageComponent implements OnInit { approveAndImport(event: SuggestionApproveAndImport) { this.suggestionService.approveAndImport(this.workspaceItemService, event.suggestion, event.collectionId).pipe( tap((workspaceitem: WorkspaceItem) => { - const content = this.translateService.instant('suggestion.approveAndImport.success', { url: getWorkspaceItemEditRoute(workspaceitem.id) }); + // The url lands in a raw of the notification, so it needs the base href + const url = this.location.prepareExternalUrl(getWorkspaceItemEditRoute(workspaceitem.id)); + const content = this.translateService.instant('suggestion.approveAndImport.success', { url }); this.notificationService.success('', content, { timeOut:0 }, true); this.suggestionTargetsStateService.dispatchRefreshUserSuggestionsAction(); }), diff --git a/src/styles/_global-styles.scss b/src/styles/_global-styles.scss index 6b794f06f64..992bd95f32e 100644 --- a/src/styles/_global-styles.scss +++ b/src/styles/_global-styles.scss @@ -567,8 +567,9 @@ ngb-tooltip-window { margin: var(--bs-btn-padding-y) 0; line-height: var(--bs-btn-line-height); display: inline-block; - -webkit-mask: url('/assets/images/grip-vertical.svg') no-repeat center; - mask: url('/assets/images/grip-vertical.svg') no-repeat center; + // '^' makes the build emit a relative url, so the icon also loads under a non-root base href + -webkit-mask: url('^assets/images/grip-vertical.svg') no-repeat center; + mask: url('^assets/images/grip-vertical.svg') no-repeat center; -webkit-mask-size: contain; mask-size: contain; background-color: currentColor;