Skip to content

Commit

Permalink
chore: remove sideeffect from permissions compution (#789)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephGit authored Nov 6, 2024
1 parent 8444a81 commit a9f6e80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
9 changes: 4 additions & 5 deletions AMW_angular/io/src/app/settings/settings.component.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
<app-page>
<div class="page-title">Settings</div>
{{ loadingPermissions() }}
@if (canViewSettings) {
@if (permissions().canViewSettings) {
<div class="page-content row">
<div class="col-2">
<nav class="nav nav-pills flex-column">
<a class="nav-link" routerLink="/settings/environments" routerLinkActive="active">Environments</a>
<a class="nav-link" routerLink="/settings/property-types" routerLinkActive="active">Property Types</a>
@if (canViewPermissionsTab) {
@if (permissions().canViewPermissionsTab) {
<a class="nav-link" routerLink="/settings/tags" routerLinkActive="active">Tags</a>
}
<a class="nav-link" routerLink="/settings/functions" routerLinkActive="active">Functions</a>
<a class="nav-link" routerLink="/settings/deployment-parameter" routerLinkActive="active"
>Deployment Parameter</a
>
<a class="nav-link" routerLink="/settings/releases" routerLinkActive="active">Releases</a>
@if (canViewPermissionsTab) {
@if (permissions().canViewPermissionsTab) {
<a class="nav-link" routerLink="/settings/permission" routerLinkActive="active">Roles and Permissions</a>
} @if (canViewAppInfo) {
} @if (permissions().canViewAppInfo) {
<a class="nav-link" routerLink="/settings/application-info" routerLinkActive="active">Application Info</a>
}
</nav>
Expand Down
19 changes: 7 additions & 12 deletions AMW_angular/io/src/app/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@ import { PageComponent } from '../layout/page/page.component';
})
export class SettingsComponent {
authService = inject(AuthService);
canViewSettings = false;
canViewPermissionsTab = false;
canViewAppInfo = false;

loadingPermissions = computed(() => {
permissions = computed(() => {
if (this.authService.restrictions().length > 0) {
this.getUserPermissions();
return {
canViewSettings: this.authService.hasPermission('SETTING_PANEL_LIST', 'ALL'),
canViewPermissionsTab: this.authService.hasPermission('ROLES_AND_PERMISSIONS_TAB', 'ALL'),
canViewAppInfo: this.authService.hasPermission('RELEASE', 'READ'),
};
} else {
return `<div>Could not load permissions</div>`;
return { canViewSettings: false, canViewPermissionsTab: false, canViewAppInfo: false };
}
});

private getUserPermissions() {
this.canViewSettings = this.authService.hasPermission('SETTING_PANEL_LIST', 'ALL');
this.canViewPermissionsTab = this.authService.hasPermission('ROLES_AND_PERMISSIONS_TAB', 'ALL');
this.canViewAppInfo = this.authService.hasPermission('RELEASE', 'READ');
}
}

0 comments on commit a9f6e80

Please sign in to comment.