Commit 1dfcfcb0 authored by Hamza HRAMCHI's avatar Hamza HRAMCHI
Browse files

FIX #17436 TIME 0:39 display saved authorized groups

parent 589d2ed6
......@@ -22,7 +22,7 @@
<ion-toggle slot="start" [name]="privilege.id" color="primary" [checked]="privilege.checked"
[(ngModel)]="privilege.checked" (click)="togglePrivilege(privilege, true)"></ion-toggle>
<ion-label (click)="togglePrivilege(privilege, false)">{{'lang.' + privilege.id + 'Admin' | translate}}</ion-label>
<ion-button *ngIf="privilege.id === 'manage_users' && privilege.checked" style="margin-right: 43%; margin-bottom: 10px;" fill="clear" shape="round"
<ion-button *ngIf="canManage(privilege)" style="margin-right: 43%; margin-bottom: 10px;" fill="clear" shape="round"
(click)="$event.stopPropagation(); openGroupList()"
[title]="'lang.groupsToManage' | translate">
<ion-icon name="people" [color]="getChecked() > 0 ? 'secondary' : 'primary'" style="font-size: 20px;"></ion-icon>
......
......@@ -91,6 +91,9 @@ export class GroupComponent implements OnInit {
this.groupClone = JSON.parse(JSON.stringify(this.group));
this.title = this.group.label;
this.updateDataTable();
if (this.group.privileges.find((privilige: any) => privilige.id === 'manage_users') !== undefined) {
this.getGroups();
}
}),
catchError((err: any) => {
this.notificationService.handleErrors(err);
......@@ -155,20 +158,28 @@ export class GroupComponent implements OnInit {
return new Promise((resolve) => {
this.http.get('../rest/groups/' + this.group.id + '/privilege/' + privilege.id).pipe(
tap((data: any) => {
if (!this.functions.empty(data.parameters.authorized)) {
const result: number[] = data.parameters.authorized;
const ids: number[] = this.allGroups.map((item: any) => item.id);
result.forEach((element: any) => {
if (ids.indexOf(element) === -1) {
const newGroup: any = this.allGroups.find((group: any) => group.id === element);
this.groups.push({
id: newGroup.id,
label: newGroup.label,
checked: true
});
this.allGroups.forEach((element: any, index: number) => {
if (this.groups.find((item: any) => item.id === element.id) === undefined) {
let checked: boolean;
if (data.parameters.authorized !== undefined) {
if (data.parameters.authorized.indexOf(element.id) > -1) {
checked = true;
} else {
checked = false;
}
} else {
checked = true;
}
});
}
this.groups.push(
{
id: element.id,
label: element.label,
checked: checked
}
);
}
});
this.groups = [...new Set(this.groups)];
resolve(true);
}),
catchError((err: any) => {
......@@ -355,8 +366,6 @@ export class GroupComponent implements OnInit {
await alert.present();
} else {
if (privilege.id === 'manage_users') {
console.log('privilege', privilege);
console.log('toggle', toggle);
if (!privilege.checked) {
this.getGroups();
} else {
......@@ -424,6 +433,10 @@ export class GroupComponent implements OnInit {
return compare(a[sort.active], b[sort.active], isAsc);
});
}
canManage(privilege: any) {
return privilege.id === 'manage_users' && privilege.checked && this.group.users.find((user: any) => user.id === this.authService.user.id) !== undefined;
}
}
function compare(a: number | string, b: number | string, isAsc: boolean) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment