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
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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],
})
Expand Down Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { AsyncPipe } from '@angular/common';
import {
AsyncPipe,
Location,
} from '@angular/common';
import {
ChangeDetectorRef,
Component,
Expand Down Expand Up @@ -200,6 +203,7 @@ export class GroupFormComponent implements OnInit, OnDestroy {
public requestService: RequestService,
protected changeDetectorRef: ChangeDetectorRef,
public dsoNameService: DSONameService,
protected location: Location,
) {
}

Expand Down Expand Up @@ -535,17 +539,18 @@ 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 `<a href>` of a translation, so it is resolved against the base href here.
*/
getLinkedEditRolesRoute(): Observable<string> {
return this.activeGroupLinkedDSO$.pipe(
hasValueOperator(),
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));
}
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ <h1 id="header" class="border-bottom pb-2">{{ "admin.reports.collections.head" |
<tbody>
@for (coll of results.collections; track coll) {
<tr>
<td><a href="/handle/{{ coll.communityHandle }}" rel="noopener noreferrer" target="_blank">{{ coll.communityLabel }}</a></td>
<td><a href="/handle/{{ coll.handle }}" rel="noopener noreferrer" target="_blank">{{ coll.label }}</a></td>
<td><a href="handle/{{ coll.communityHandle }}" rel="noopener noreferrer" target="_blank">{{ coll.communityLabel }}</a></td>
<td><a href="handle/{{ coll.handle }}" rel="noopener noreferrer" target="_blank">{{ coll.label }}</a></td>
<td class="num">{{ coll.nbTotalItems }}</td>
<td class="num">{{ coll.allFiltersValue }}</td>
@for (filter of results.summary.values | keyvalue; track filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLAnchorElement>(fixture.nativeElement.querySelectorAll('tbody a'))
.map((a) => a.getAttribute('href'));
expect(hrefs).toEqual(['handle/123456789/1', 'handle/123456789/2']);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ <h1 id="header" class="border-bottom pb-2">{{'admin.reports.items.head' | transl
<td class="num">{{ item.index }}</td>
<td>{{ item.uuid }}</td>
<td>@if (item.owningCollection) {
<a href="/handle/{{ item.owningCollection.handle }}" rel="noopener noreferrer" target="_blank">{{ item.owningCollection.name }}</a>
<a href="handle/{{ item.owningCollection.handle }}" rel="noopener noreferrer" target="_blank">{{ item.owningCollection.name }}</a>
}</td>
<td>@if (item.handle) {
<a href="/handle/{{ item.handle }}" rel="noopener noreferrer" target="_blank">{{ item.handle }}</a>
<a href="handle/{{ item.handle }}" rel="noopener noreferrer" target="_blank">{{ item.handle }}</a>
}</td>
<td>{{ item.name }}</td>
@for (field of queryForm.value['additionalFields']; track field) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { APP_BASE_HREF } from '@angular/common';
import {
DebugElement,
NO_ERRORS_SCHEMA,
Expand All @@ -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';
Expand Down Expand Up @@ -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();
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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');
});
});


Expand Down
16 changes: 12 additions & 4 deletions src/app/info/feedback/feedback-form/feedback-form.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import { Location } from '@angular/common';
import {
Component,
Inject,
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
}

/**
Expand All @@ -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 });
});

Expand All @@ -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<NoContent>) => {
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);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { APP_BASE_HREF } from '@angular/common';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import {
ComponentFixture,
Expand All @@ -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';

Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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();
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { AsyncPipe } from '@angular/common';
import {
AsyncPipe,
Location,
} from '@angular/common';
import {
Component,
OnInit,
Expand Down Expand Up @@ -66,7 +69,7 @@ export class GrantDenyRequestCopyComponent implements OnInit {
itemName$: Observable<string>;

/**
* The url of the item
* The url of the item, resolved against the base href because it lands in the raw `<a href>` of a translation
*/
itemUrl$: Observable<string>;

Expand All @@ -86,6 +89,7 @@ export class GrantDenyRequestCopyComponent implements OnInit {
private authService: AuthService,
private itemDataService: ItemDataService,
private nameService: DSONameService,
private location: Location,
) {

}
Expand All @@ -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(
Expand Down
17 changes: 16 additions & 1 deletion src/app/suggestions-page/suggestions-page.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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');
Expand Down
10 changes: 8 additions & 2 deletions src/app/suggestions-page/suggestions-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { AsyncPipe } from '@angular/common';
import {
AsyncPipe,
Location,
} from '@angular/common';
import {
Component,
OnInit,
Expand Down Expand Up @@ -132,6 +135,7 @@ export class SuggestionsPageComponent implements OnInit {
private suggestionTargetsStateService: SuggestionTargetsStateService,
private translateService: TranslateService,
private workspaceItemService: WorkspaceitemDataService,
private location: Location,
) {
}

Expand Down Expand Up @@ -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 <a href> 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();
}),
Expand Down
5 changes: 3 additions & 2 deletions src/styles/_global-styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading