Skip to content

Commit

Permalink
Merge branch 'master' into 8072-resource-can-be-added-multiple-times
Browse files Browse the repository at this point in the history
  • Loading branch information
dogi authored Jan 14, 2025
2 parents b4ce351 + 3db52ef commit b528a69
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/app/home/home-router.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const routes: Routes = [
{ path: 'upgrade/myplanet', component: UpgradeComponent, data: { myPlanet: true } },
{ path: 'teams', loadChildren: () => import('../teams/teams.module').then(m => m.TeamsModule) },
{ path: 'enterprises', loadChildren: () => import('../teams/teams.module').then(m => m.TeamsModule), data: { mode: 'enterprise' } },
{ path: 'health', component: HealthListComponent },
{ path: 'health/profile/:id', loadChildren: () => import('../health/health.module').then(m => m.HealthModule) },
{ path: 'health', component: HealthListComponent, data: { roles: [ '_admin', 'health' ] } },
{ path: 'health/profile/:id', loadChildren: () => import('../health/health.module').then(m => m.HealthModule), data: { roles: [ '_admin', 'health' ] } },
{ path: 'nation', component: TeamsViewComponent, data: { mode: 'services' } },
{ path: 'earth', component: TeamsViewComponent, data: { mode: 'services' } },
{ path: myDashboardRoute, component: DashboardComponent },
Expand Down
14 changes: 9 additions & 5 deletions src/app/shared/auth-guard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ export class AuthService {
return this.pouchAuthService.getSessionInfo();
}

private checkUser(url: any): Observable<boolean> {
private checkUser(url: any, roles: any[]): Observable<boolean> {
return this.getSession$().pipe(
switchMap((sessionInfo) => {
if (sessionInfo.userCtx.name) {
// If user already matches one on the user service, do not make additional call to CouchDB
if (sessionInfo.userCtx.name === this.userService.get().name) {
const user = this.userService.get();
if (sessionInfo.userCtx.name === user.name) {
if (roles.length > 0) {
const hasRole = roles.some(role => user.roles.includes(role));
return hasRole ? of(true) : of(false);
}
return of(true);
}
this.stateService.requestBaseData();
Expand All @@ -46,15 +51,14 @@ export class AuthService {
// change if session has expired
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
let currentRoute: ActivatedRouteSnapshot | null = route;

const roles: Array<string> = currentRoute.data?.roles ?? [];
while (currentRoute) {
if (currentRoute.data && currentRoute.data.requiresAuth === false) {
return of(true);
}
currentRoute = currentRoute.parent;
}

return this.checkUser(state.url);
return this.checkUser(state.url, roles);
}

// For login route will redirect to main app if there is an active session
Expand Down
4 changes: 4 additions & 0 deletions src/app/shared/forms/planet-tag-input-dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { DialogsPromptComponent } from '../../shared/dialogs/dialogs-prompt.comp
:host mat-dialog-content {
overflow-y: auto;
max-height: calc(100vh - 100px);
width: 600px;
}
:host .mat-list-option span {
font-weight: inherit;
Expand All @@ -35,6 +36,9 @@ import { DialogsPromptComponent } from '../../shared/dialogs/dialogs-prompt.comp
:host mat-dialog-actions {
padding: 0;
}
button[mat-stroked-button] {
min-width: 64px;
}
` ]
})
export class PlanetTagInputDialogComponent {
Expand Down
2 changes: 1 addition & 1 deletion src/app/teams/teams-view.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h3 *ngIf="mode==='services'" class="margin-lr-3 ellipsis-title">{{configuration
<ng-template #actionButtons>
<ng-container [ngSwitch]="userStatus" *ngIf="user.isUserAdmin || user.roles.length">
<ng-container *ngSwitchCase="'member'">
<a class="margin-lr-3" [routerLink]="['surveys']" mat-stroked-button mat-button i18n>Manage Surveys</a>
<a class="toolbar-button margin-lr-3" [routerLink]="['surveys']" mat-stroked-button mat-button i18n>Manage Surveys</a>
<button *ngIf="mode!=='services'" mat-stroked-button mat-button class=" toolbar-button margin-lr-3" (click)="openInviteMemberDialog()" i18n [disabled]="disableAddingMembers">
Add Members
</button>
Expand Down

0 comments on commit b528a69

Please sign in to comment.