Merge pull request #1105 from atmire/Edit-item-page-permission-checks

Edit item page permission checks
This commit is contained in:
Tim Donohue
2021-05-04 09:24:16 -05:00
committed by GitHub
38 changed files with 772 additions and 114 deletions

View File

@@ -207,10 +207,23 @@ export const redirectOn4xx = <T>(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.some((b: boolean) => b === true)) {
return true;
} else {
if (authenticated) {
return router.parseUrl(getForbiddenRoute());