Skip to content

Commit

Permalink
121780 Avoid admin menu related requests if user is anonymous
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen Pauwels committed Dec 2, 2024
1 parent 05508b6 commit 4d5e928
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/app/menu-resolver.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
combineLatest,
combineLatest as observableCombineLatest,
Observable,
of as observableOf, mergeMap,
} from 'rxjs';
import {
filter,
Expand Down Expand Up @@ -47,6 +48,7 @@ import { OnClickMenuItemModel } from './shared/menu/menu-item/models/onclick.mod
import { TextMenuItemModel } from './shared/menu/menu-item/models/text.model';
import { MenuItemType } from './shared/menu/menu-item-type.model';
import { MenuState } from './shared/menu/menu-state.model';
import { AuthService } from './core/auth/auth.service';

/**
* Creates all of the app's menus
Expand All @@ -62,6 +64,7 @@ export class MenuResolverService {
protected modalService: NgbModal,
protected scriptDataService: ScriptDataService,
protected configurationDataService: ConfigurationDataService,
protected authService: AuthService,
) {
}

Expand All @@ -71,7 +74,7 @@ export class MenuResolverService {
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
return combineLatest([
this.createPublicMenu$(),
this.createAdminMenu$(),
this.createAdminMenuIfLoggedIn$(),
]).pipe(
map((menusDone: boolean[]) => menusDone.every(Boolean)),
);
Expand Down Expand Up @@ -147,6 +150,15 @@ export class MenuResolverService {
return this.waitForMenu$(MenuID.PUBLIC);
}

/**
* Initialize all menu sections and items for {@link MenuID.ADMIN}, only if the user is logged in.
*/
createAdminMenuIfLoggedIn$() {
return this.authService.isAuthenticated().pipe(
mergeMap((isAuthenticated) => isAuthenticated ? this.createAdminMenu$() : observableOf(true))

Check failure on line 158 in src/app/menu-resolver.service.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Missing trailing comma

Check failure on line 158 in src/app/menu-resolver.service.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

Missing trailing comma
);
}

/**
* Initialize all menu sections and items for {@link MenuID.ADMIN}
*/
Expand All @@ -156,8 +168,6 @@ export class MenuResolverService {
this.createExportMenuSections();
this.createImportMenuSections();
this.createAccessControlMenuSections();
this.createReportMenuSections();

return this.waitForMenu$(MenuID.ADMIN);
}

Expand Down

0 comments on commit 4d5e928

Please sign in to comment.