Revision 59816
Added by Argiro Kokogiannaki over 3 years ago
claimsCuratorGuard.guard.ts | ||
---|---|---|
3 | 3 |
import {Observable} from 'rxjs'; |
4 | 4 |
import {Session} from './utils/helper.class'; |
5 | 5 |
import {LoginErrorCodes} from './utils/guardHelper.class'; |
6 |
import {filter, map} from "rxjs/operators";
|
|
6 |
import {map, tap} from "rxjs/operators";
|
|
7 | 7 |
import {UserManagementService} from "../services/user-management.service"; |
8 | 8 |
|
9 | 9 |
@Injectable() |
... | ... | |
15 | 15 |
|
16 | 16 |
check(path: string): Observable<boolean> | boolean { |
17 | 17 |
let errorCode = LoginErrorCodes.NOT_LOGIN; |
18 |
const obs = this.userManagementService.getUserInfo(false).pipe(map(user => {
|
|
18 |
return this.userManagementService.getUserInfo(false).pipe(map(user => {
|
|
19 | 19 |
if (user) { |
20 | 20 |
errorCode = LoginErrorCodes.NOT_ADMIN; |
21 | 21 |
} |
22 | 22 |
return Session.isClaimsCurator(user) || Session.isPortalAdministrator(user); |
23 |
}),tap(isAdmin => { |
|
24 |
if(!isAdmin) { |
|
25 |
this.router.navigate(['/user-info'], { |
|
26 |
queryParams: { |
|
27 |
'errorCode': errorCode, |
|
28 |
'redirectUrl': path |
|
29 |
} |
|
30 |
}); |
|
31 |
} |
|
23 | 32 |
})); |
24 |
obs.pipe(filter(isAdmin => !isAdmin)).subscribe(() => { |
|
25 |
this.router.navigate(['/user-info'], { |
|
26 |
queryParams: { |
|
27 |
'errorCode': errorCode, |
|
28 |
'redirectUrl': path |
|
29 |
} |
|
30 |
}); |
|
31 |
}); |
|
32 |
return obs; |
|
33 | 33 |
} |
34 | 34 |
|
35 | 35 |
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { |
Also available in: Unified diff
[Library|Trunk]
code clean up:
-remove app.* files from library
-remove unused imports, code, files (Old search pages for results, dataproviders, map search page, etc)
-remove Freeguard from modules
-unsubscribe all subscriptions
-Services: configuration, isvocabularies, user management: unsubscribe from app component or the component that uses them (clearSubscriptions())
-Fetchers: unsubscribe from the component that uses them (clearSubscriptions())