78243: edit item page fine-grained permission checks

This commit is contained in:
Kristof De Langhe
2021-04-08 17:54:27 +02:00
parent 3d51110217
commit a2e00bbd9f
32 changed files with 402 additions and 100 deletions

View File

@@ -201,10 +201,23 @@ export const redirectOn4xx = (router: Router, authService: AuthService) =>
*/
export const returnForbiddenUrlTreeOrLoginOnFalse = (router: Router, authService: AuthService, redirectUrl: string) =>
(source: Observable<boolean>): Observable<boolean | UrlTree> =>
source.pipe(
map((authorized) => [authorized]),
returnForbiddenUrlTreeOrLoginOnAllFalse(router, authService, redirectUrl),
);
/**
* Operator that returns a UrlTree to a forbidden page or the login page when the booleans received are all false
* @param router The router used to navigate to a forbidden page
* @param authService The AuthService used to determine whether or not the user is logged in
* @param redirectUrl The URL to redirect back to after logging in
*/
export const returnForbiddenUrlTreeOrLoginOnAllFalse = (router: Router, authService: AuthService, redirectUrl: string) =>
(source: Observable<boolean[]>): Observable<boolean | UrlTree> =>
observableCombineLatest(source, authService.isAuthenticated()).pipe(
map(([authorized, authenticated]: [boolean, boolean]) => {
if (authorized) {
return authorized;
map(([authorizedList, authenticated]: [boolean[], boolean]) => {
if (authorizedList.indexOf(true) > -1) {
return true;
} else {
if (authenticated) {
return router.parseUrl(getForbiddenRoute());