Skip to content

Commit

Permalink
LIBCIR-368. Roll back handle redirect customization from LIBCIR-316
Browse files Browse the repository at this point in the history
In LIBCIR-316, the DSpace code was customized to redirect "handle" URLs
in such a way that the browser "Back" button properly returned to the
original page.

Code changes in DSpace 7.6 in the following commit/pull request:

* DSpace/dspace-angular@d4a5308
* DSpace/dspace-angular#2630

appear to make that customization no longer necessary (they also break
the current customization).

Restored the code changed in LIBCIR-316 to the DSpace 7.6.1 stock code.

https://umd-dit.atlassian.net/browse/LIBCIR-368
  • Loading branch information
dsteelma-umd committed Jan 18, 2024
1 parent 828c552 commit 4e89af0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 46 deletions.
20 changes: 0 additions & 20 deletions docs/MdsoarAngularCustomizations.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,6 @@ Angular code, to customize it for MD-SOAR.
This document is intended to cover specific changes made to Angular behavior
that are outside of "normal" DSpace customization.

## Angular routing for "handle" redirects

On the home page, the hyperlinks to the individual institutional communities in
the “Institutions in MD-SOAR” list use the “handle” URLs for the institutions
(i.e., <http://localhost:4000/handle/11603/1> for Frostburg), instead of the
“UUID” URLs (i.e.,
<http://localhost:4000/communities/e34f5843-e595-4050-9f20-3c730277abf8>
for Frostburg).

DSpace properly redirects a “handle” URL to a “UUID” URL, but when using the
“Back” button in the browser, the user is not returned to the original page.

Modified the “findByIdAndIDType” method in the
“src/app/core/data/dso-redirect.service.ts” class, so that the `router.navigate`
uses the `replaceUrl` option from `NavigationExtras` to skip the handle-to-UUID
redirect in the browser history, and enable the browser "Back" button to
return the user to the original page.

Also update tests in "src/app/core/data/dso-redirect.service.spec.ts"

## Disable "End User Agreement"

The "End User Agreement" is not needed, and so is disabled in the
Expand Down
22 changes: 4 additions & 18 deletions src/app/core/data/dso-redirect.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ describe('DsoRedirectService', () => {
redir.subscribe();
scheduler.schedule(() => redir);
scheduler.flush();
// UMD Customization
expect(router.navigate).toHaveBeenCalledWith(['/items/' + remoteData.payload.uuid], Object({ replaceUrl: true }));
// End UMD Customization
expect(redirectService.redirect).toHaveBeenCalledWith(`${environment.ui.nameSpace}/items/${remoteData.payload.uuid}`, 301);
});
it('should navigate to entities route with the corresponding entity type', () => {
remoteData.payload.type = 'item';
Expand All @@ -129,11 +127,7 @@ describe('DsoRedirectService', () => {
redir.subscribe();
scheduler.schedule(() => redir);
scheduler.flush();
// UMD Customization
expect(router.navigate).toHaveBeenCalledWith(
['/entities/publication/' + remoteData.payload.uuid], Object({ replaceUrl: true })
);
// End UMD Customization
expect(redirectService.redirect).toHaveBeenCalledWith(`${environment.ui.nameSpace}/entities/publication/${remoteData.payload.uuid}`, 301);
});

it('should navigate to collections route', () => {
Expand All @@ -142,11 +136,7 @@ describe('DsoRedirectService', () => {
redir.subscribe();
scheduler.schedule(() => redir);
scheduler.flush();
// UMD Customization
expect(router.navigate).toHaveBeenCalledWith(
['/collections/' + remoteData.payload.uuid] , Object({ replaceUrl: true })
);
// End UMD Customization
expect(redirectService.redirect).toHaveBeenCalledWith(`${environment.ui.nameSpace}/collections/${remoteData.payload.uuid}`, 301);
});

it('should navigate to communities route', () => {
Expand All @@ -155,11 +145,7 @@ describe('DsoRedirectService', () => {
redir.subscribe();
scheduler.schedule(() => redir);
scheduler.flush();
// UMD Customization
expect(router.navigate).toHaveBeenCalledWith(
['/communities/' + remoteData.payload.uuid], Object({ replaceUrl: true })
);
// End UMD Customization
expect(redirectService.redirect).toHaveBeenCalledWith(`${environment.ui.nameSpace}/communities/${remoteData.payload.uuid}`, 301);
});
});

Expand Down
10 changes: 2 additions & 8 deletions src/app/core/data/dso-redirect.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,8 @@ export class DsoRedirectService {
if (hasValue(dso.uuid)) {
let newRoute = getDSORoute(dso);
if (hasValue(newRoute)) {
this.router.navigate([newRoute],
// UMD Customization
// Using "replaceUrl: true", so that when processing a
// "/handle/"-based URL, the browser "Back" button can return
// the user to the original page.
{ replaceUrl: true }
// End UMD Customization
);
// Use a "301 Moved Permanently" redirect for SEO purposes
this.hardRedirectService.redirect(this.appConfig.ui.nameSpace.replace(/\/$/, '') + newRoute, 301);
}
}
}
Expand Down

0 comments on commit 4e89af0

Please sign in to comment.