Skip to content

Commit

Permalink
[Bug] Roles / Permissions: Pre-Selected Toggle Buttons Not Retaining …
Browse files Browse the repository at this point in the history
…Enabled Permissions
  • Loading branch information
samuelmbabhazi committed Sep 27, 2024
1 parent b7e3216 commit 45966e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ <h4>
></nb-icon>
</button>
</nb-form-field>
<nb-autocomplete
#autocomplete
(selectedChange)="onSelectionChange($event)"
>
<nb-autocomplete #autocomplete (selectedChange)="onSelectionChange($event)">
<nb-option
*ngFor="let role of roles$ | async"
[value]="role.name"
Expand All @@ -41,10 +38,7 @@ <h4>
</nb-autocomplete>
</div>
</div>
<div
class="col-6"
*ngxPermissionsOnly="['CHANGE_ROLES_PERMISSIONS']"
>
<div class="col-6" *ngxPermissionsOnly="['CHANGE_ROLES_PERMISSIONS']">
<ng-container *ngIf="isWantToCreate">
<div class="actions create">
<button
Expand All @@ -59,9 +53,7 @@ <h4>
{{ 'BUTTONS.CREATE_NEW_ROLE' | translate : { name: input.value } }}
</div>
</ng-container>
<ng-container
*ngIf="role && role.isSystem === false && !isWantToCreate"
>
<ng-container *ngIf="role && role.isSystem === false && !isWantToCreate">
<div class="actions delete">
<button
nbButton
Expand All @@ -71,10 +63,7 @@ <h4>
size="small"
[nbTooltip]="'BUTTONS.DELETE' | translate"
>
<nb-icon
status="danger"
icon="trash-2-outline"
></nb-icon>
<nb-icon status="danger" icon="trash-2-outline"></nb-icon>
</button>
{{ 'BUTTONS.DELETE_EXISTING_ROLE' | translate : { name: role.name } }}
</div>
Expand All @@ -85,35 +74,20 @@ <h4>
<div class="col-12 col-xl-6">
<nb-card>
<nb-card-header>
{{
'ORGANIZATIONS_PAGE.PERMISSIONS.GROUPS.GENERAL'
| translate
}}
{{ 'ORGANIZATIONS_PAGE.PERMISSIONS.GROUPS.GENERAL' | translate }}
</nb-card-header>
<nb-card-body class="permission-items-col">
<nb-toggle
*ngFor="let permission of permissionGroups.GENERAL"
[(checked)]="enabledPermissions[permission]"
(checkedChange)="
permissionChanged(
permission,
$event,
!isDisabledGeneralPermissions()
)
"
(checkedChange)="permissionChanged(permission, $event, !isDisabledGeneralPermissions())"
labelPosition="start"
status="basic"
[disabled]="isDisabledGeneralPermissions()"
>
<div class="custom-permission-view">
<strong>{{
'ORGANIZATIONS_PAGE.PERMISSIONS.' +
permission | translate
}}</strong>
<small>{{
'ORGANIZATIONS_PAGE.PERMISSIONS.' +
permission | translate
}}</small>
<strong>{{ 'ORGANIZATIONS_PAGE.PERMISSIONS.' + permission | translate }}</strong>
<small>{{ 'ORGANIZATIONS_PAGE.PERMISSIONS.' + permission | translate }}</small>
</div>
</nb-toggle>
</nb-card-body>
Expand All @@ -122,46 +96,28 @@ <h4>
<div class="col-12 col-xl-6">
<nb-card>
<nb-card-header
>{{
'ORGANIZATIONS_PAGE.PERMISSIONS.GROUPS.ADMINISTRATION'
| translate
}}
>{{ 'ORGANIZATIONS_PAGE.PERMISSIONS.GROUPS.ADMINISTRATION' | translate }}
<nb-icon
[nbTooltip]="
'ORGANIZATIONS_PAGE.PERMISSIONS.ONLY_ADMIN'
| translate
"
[nbTooltip]="'ORGANIZATIONS_PAGE.PERMISSIONS.ONLY_ADMIN' | translate"
icon="question-mark-circle-outline"
size="tiny"
>
</nb-icon>
</nb-card-header>
<nb-card-body class="permission-items-col">
<nb-toggle
*ngFor="
let permission of getAdministrationPermissions()
"
*ngFor="let permission of getAdministrationPermissions()"
[(checked)]="enabledPermissions[permission]"
(checkedChange)="
permissionChanged(
permission,
$event,
!isDisabledAdministrationPermissions()
)
permissionChanged(permission, $event, !isDisabledAdministrationPermissions())
"
labelPosition="start"
status="basic"
[disabled]="isDisabledAdministrationPermissions()"
>
<div class="custom-permission-view">
<strong>{{
'ORGANIZATIONS_PAGE.PERMISSIONS.' +
permission | translate
}}</strong>
<small>{{
'ORGANIZATIONS_PAGE.PERMISSIONS.' +
permission | translate
}}</small>
<strong>{{ 'ORGANIZATIONS_PAGE.PERMISSIONS.' + permission | translate }}</strong>
<small>{{ 'ORGANIZATIONS_PAGE.PERMISSIONS.' + permission | translate }}</small>
</div>
</nb-toggle>
</nb-card-body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,16 @@ export class RolesPermissionsComponent extends TranslationBaseComponent implemen
})
.finally(() => (this.loading = false))
).items;

console.log(this.permissions[0].enabled);
this.permissions.forEach((p) => {
this.enabledPermissions[p.permission] = p.enabled;
// Vérification si la permission existe déjà dans l'objet

Check warning on line 150 in apps/gauzy/src/app/pages/settings/roles-permissions/roles-permissions.component.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Vérification)

Check warning on line 150 in apps/gauzy/src/app/pages/settings/roles-permissions/roles-permissions.component.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (existe)

Check warning on line 150 in apps/gauzy/src/app/pages/settings/roles-permissions/roles-permissions.component.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (dans)
if (this.enabledPermissions.hasOwnProperty(p.permission)) {
// Log des doublons rencontrés

Check warning on line 152 in apps/gauzy/src/app/pages/settings/roles-permissions/roles-permissions.component.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (doublons)

Check warning on line 152 in apps/gauzy/src/app/pages/settings/roles-permissions/roles-permissions.component.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (rencontrés)
console.log(`Doublon détecté pour la permission: ${p.permission}`);

Check warning on line 153 in apps/gauzy/src/app/pages/settings/roles-permissions/roles-permissions.component.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Doublon)

Check warning on line 153 in apps/gauzy/src/app/pages/settings/roles-permissions/roles-permissions.component.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (détecté)
} else {
// Si la permission n'existe pas, on l'ajoute

Check warning on line 155 in apps/gauzy/src/app/pages/settings/roles-permissions/roles-permissions.component.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (n'existe)

Check warning on line 155 in apps/gauzy/src/app/pages/settings/roles-permissions/roles-permissions.component.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (l'ajoute)
this.enabledPermissions[p.permission] = p.enabled;
}
});
}

Expand Down

0 comments on commit 45966e7

Please sign in to comment.