Skip to content

Commit 8350f50

Browse files
author
Maciej Kleban
committed
Convert navigateToUrl to hard redirect on user agreement page
1 parent d0a6d94 commit 8350f50

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

src/app/info/end-user-agreement/end-user-agreement.component.spec.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { NO_ERRORS_SCHEMA } from '@angular/core';
22
import {
33
ComponentFixture,
4+
fakeAsync,
45
TestBed,
6+
tick,
57
waitForAsync,
68
} from '@angular/core/testing';
79
import { By } from '@angular/platform-browser';
@@ -13,7 +15,9 @@ import { LogOutAction } from '@dspace/core/auth/auth.actions';
1315
import { AuthService } from '@dspace/core/auth/auth.service';
1416
import { EndUserAgreementService } from '@dspace/core/end-user-agreement/end-user-agreement.service';
1517
import { NotificationsService } from '@dspace/core/notification-system/notifications.service';
18+
import { HardRedirectService } from '@dspace/core/services/hard-redirect.service';
1619
import { ActivatedRouteStub } from '@dspace/core/testing/active-router.stub';
20+
import { URLCombiner } from '@dspace/core/url-combiner/url-combiner';
1721
import { Store } from '@ngrx/store';
1822
import { TranslateModule } from '@ngx-translate/core';
1923
import { of } from 'rxjs';
@@ -32,11 +36,14 @@ describe('EndUserAgreementComponent', () => {
3236
let store;
3337
let router: Router;
3438
let route: ActivatedRoute;
39+
let hardRedirectService: HardRedirectService;
3540

3641
let redirectUrl;
42+
let baseUrl;
3743

3844
function init() {
3945
redirectUrl = 'redirect/url';
46+
baseUrl = 'https://dspace.test';
4047

4148
endUserAgreementService = jasmine.createSpyObj('endUserAgreementService', {
4249
hasCurrentUserOrCookieAcceptedAgreement: of(false),
@@ -53,6 +60,15 @@ describe('EndUserAgreementComponent', () => {
5360
redirect: redirectUrl,
5461
}),
5562
}) as any;
63+
hardRedirectService = jasmine.createSpyObj('hardRedirectService', {
64+
redirect: null,
65+
getBaseUrl: baseUrl,
66+
});
67+
68+
endUserAgreementService = jasmine.createSpyObj('endUserAgreementService', {
69+
hasCurrentUserOrCookieAcceptedAgreement: of(false),
70+
setUserAcceptedAgreement: of(true),
71+
});
5672
}
5773

5874
beforeEach(waitForAsync(() => {
@@ -66,6 +82,7 @@ describe('EndUserAgreementComponent', () => {
6682
{ provide: Store, useValue: store },
6783
{ provide: Router, useValue: router },
6884
{ provide: ActivatedRoute, useValue: route },
85+
{ provide: HardRedirectService, useValue: hardRedirectService },
6986
],
7087
schemas: [NO_ERRORS_SCHEMA],
7188
})
@@ -128,9 +145,10 @@ describe('EndUserAgreementComponent', () => {
128145
expect(notificationsService.success).toHaveBeenCalled();
129146
});
130147

131-
it('should navigate the user to the redirect url', () => {
132-
expect(router.navigateByUrl).toHaveBeenCalledWith(redirectUrl);
133-
});
148+
it('should navigate the user to the redirect url', fakeAsync(() => {
149+
tick();
150+
expect(hardRedirectService.redirect).toHaveBeenCalledWith(new URLCombiner(baseUrl, redirectUrl).toString());
151+
}));
134152
});
135153

136154
describe('when accepting the agreement was unsuccessful', () => {

src/app/info/end-user-agreement/end-user-agreement.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { LogOutAction } from '@dspace/core/auth/auth.actions';
1111
import { AuthService } from '@dspace/core/auth/auth.service';
1212
import { EndUserAgreementService } from '@dspace/core/end-user-agreement/end-user-agreement.service';
1313
import { NotificationsService } from '@dspace/core/notification-system/notifications.service';
14+
import { HardRedirectService } from '@dspace/core/services/hard-redirect.service';
15+
import { URLCombiner } from '@dspace/core/url-combiner/url-combiner';
1416
import { isNotEmpty } from '@dspace/shared/utils/empty.util';
1517
import { Store } from '@ngrx/store';
1618
import {
@@ -55,7 +57,8 @@ export class EndUserAgreementComponent implements OnInit {
5557
protected authService: AuthService,
5658
protected store: Store<AppState>,
5759
protected router: Router,
58-
protected route: ActivatedRoute) {
60+
protected route: ActivatedRoute,
61+
protected hardRedirectService: HardRedirectService) {
5962
}
6063

6164
/**
@@ -92,7 +95,8 @@ export class EndUserAgreementComponent implements OnInit {
9295
take(1),
9396
).subscribe((redirectUrl) => {
9497
if (isNotEmpty(redirectUrl)) {
95-
this.router.navigateByUrl(decodeURIComponent(redirectUrl));
98+
const fullRedirectUrl = new URLCombiner(this.hardRedirectService.getBaseUrl(), decodeURIComponent(redirectUrl));
99+
this.hardRedirectService.redirect(fullRedirectUrl.toString());
96100
}
97101
});
98102
}

src/assets/i18n/en.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7469,7 +7469,7 @@
74697469
"submission.sections.describe.relationship-lookup.external-source.import-modal.isOrgUnitOfDataset.added.local-entity": "Successfully added local organization to the selection",
74707470

74717471
"submission.sections.describe.relationship-lookup.external-source.import-modal.isOrgUnitOfDataset.added.new-entity": "Successfully imported and added external organization to the selection",
7472-
7472+
74737473
"admin.edit-cms-metadata.success": "Metadata successfully updated",
74747474

74757475
"admin.edit-cms-metadata.back-button": "Back",

0 commit comments

Comments
 (0)