mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge branch 'w2p-72699_Hard-redirect-after-log-in' into w2p-72541_User-agreement-and-Privacy-statement
This commit is contained in:
@@ -322,31 +322,28 @@ describe('AuthService test', () => {
|
|||||||
expect(storage.remove).toHaveBeenCalled();
|
expect(storage.remove).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set redirect url to previous page', () => {
|
it('should redirect to reload with redirect url', () => {
|
||||||
(storage.get as jasmine.Spy).and.returnValue('/collection/123');
|
authService.navigateToRedirectUrl('/collection/123');
|
||||||
authService.redirectAfterLoginSuccess();
|
|
||||||
// Reload with redirect URL set to /collection/123
|
// Reload with redirect URL set to /collection/123
|
||||||
expect(hardRedirectService.redirect).toHaveBeenCalledWith(jasmine.stringMatching(new RegExp('/reload/[0-9]*\\?redirect=' + encodeURIComponent('/collection/123'))));
|
expect(hardRedirectService.redirect).toHaveBeenCalledWith(jasmine.stringMatching(new RegExp('/reload/[0-9]*\\?redirect=' + encodeURIComponent('/collection/123'))));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set redirect url to current page', () => {
|
it('should redirect to reload with /home', () => {
|
||||||
(storage.get as jasmine.Spy).and.returnValue('/home');
|
authService.navigateToRedirectUrl('/home');
|
||||||
authService.redirectAfterLoginSuccess();
|
|
||||||
// Reload with redirect URL set to /home
|
// Reload with redirect URL set to /home
|
||||||
expect(hardRedirectService.redirect).toHaveBeenCalledWith(jasmine.stringMatching(new RegExp('/reload/[0-9]*\\?redirect=' + encodeURIComponent('/home'))));
|
expect(hardRedirectService.redirect).toHaveBeenCalledWith(jasmine.stringMatching(new RegExp('/reload/[0-9]*\\?redirect=' + encodeURIComponent('/home'))));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect to regular reload and not to /login', () => {
|
it('should redirect to regular reload and not to /login', () => {
|
||||||
(storage.get as jasmine.Spy).and.returnValue('/login');
|
authService.navigateToRedirectUrl('/login');
|
||||||
authService.redirectAfterLoginSuccess();
|
|
||||||
// Reload without a redirect URL
|
// Reload without a redirect URL
|
||||||
expect(hardRedirectService.redirect).toHaveBeenCalledWith(jasmine.stringMatching(new RegExp('/reload/[0-9]*(?!\\?)$')));
|
expect(hardRedirectService.redirect).toHaveBeenCalledWith(jasmine.stringMatching(new RegExp('/reload/[0-9]*(?!\\?)$')));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not redirect when no redirect url is found', () => {
|
it('should redirect to regular reload when no redirect url is found', () => {
|
||||||
authService.redirectAfterLoginSuccess();
|
authService.navigateToRedirectUrl(undefined);
|
||||||
// Reload without a redirect URL
|
// Reload without a redirect URL
|
||||||
expect(hardRedirectService.redirect).not.toHaveBeenCalled();
|
expect(hardRedirectService.redirect).toHaveBeenCalledWith(jasmine.stringMatching(new RegExp('/reload/[0-9]*(?!\\?)$')));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('impersonate', () => {
|
describe('impersonate', () => {
|
||||||
|
@@ -78,37 +78,6 @@ export class AuthService {
|
|||||||
select(isAuthenticated),
|
select(isAuthenticated),
|
||||||
startWith(false)
|
startWith(false)
|
||||||
).subscribe((authenticated: boolean) => this._authenticated = authenticated);
|
).subscribe((authenticated: boolean) => this._authenticated = authenticated);
|
||||||
|
|
||||||
// If current route is different from the one setted in authentication guard
|
|
||||||
// and is not the login route, clear redirect url and messages
|
|
||||||
const routeUrl$ = this.store.pipe(
|
|
||||||
select(routerStateSelector),
|
|
||||||
filter((routerState: RouterReducerState) => isNotUndefined(routerState)
|
|
||||||
&& isNotUndefined(routerState.state) && isNotEmpty(routerState.state.url)),
|
|
||||||
filter((routerState: RouterReducerState) => !this.isLoginRoute(routerState.state.url)),
|
|
||||||
map((routerState: RouterReducerState) => routerState.state.url)
|
|
||||||
);
|
|
||||||
const redirectUrl$ = this.store.pipe(select(getRedirectUrl), distinctUntilChanged());
|
|
||||||
routeUrl$.pipe(
|
|
||||||
withLatestFrom(redirectUrl$),
|
|
||||||
map(([routeUrl, redirectUrl]) => [routeUrl, redirectUrl])
|
|
||||||
).pipe(filter(([routeUrl, redirectUrl]) => isNotEmpty(redirectUrl) && (routeUrl !== redirectUrl)))
|
|
||||||
.subscribe(() => {
|
|
||||||
this.clearRedirectUrl();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if is a login page route
|
|
||||||
*
|
|
||||||
* @param {string} url
|
|
||||||
* @returns {Boolean}.
|
|
||||||
*/
|
|
||||||
protected isLoginRoute(url: string) {
|
|
||||||
const urlTree: UrlTree = this.router.parseUrl(url);
|
|
||||||
const g: UrlSegmentGroup = urlTree.root.children[PRIMARY_OUTLET];
|
|
||||||
const segment = '/' + g.toString();
|
|
||||||
return segment === LOGIN_ROUTE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user