Skip to content

Commit d16866c

Browse files
authored
Merge pull request #286 from aspnetboilerplate/permission-check
Resolve #285 - Removed permissions remain checked in Angular UI
2 parents bff738d + 3463c20 commit d16866c

File tree

12 files changed

+358
-43
lines changed

12 files changed

+358
-43
lines changed

angular/src/app/roles/edit-role/edit-role.component.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div bsModal #editRoleModal="bs-modal" class="modal fade" (onShown)="onShown()" tabindex="-1" role="dialog" aria-labelledby="edidtRoleModal" aria-hidden="true" [config]="{backdrop: 'static'}">
1+
<div bsModal #editRoleModal="bs-modal" class="modal fade" (onShown)="onShown()" tabindex="-1" role="dialog" aria-labelledby="edidtRoleModal" aria-hidden="true" [config]="{backdrop: 'static'}">
22
<div class="modal-dialog">
33

44
<div #modalContent class="modal-content">
@@ -10,7 +10,7 @@
1010
<span aria-hidden="true">&times;</span>
1111
</button>
1212
<h4 class="modal-title">
13-
<span>{{l("EditRole")}} <span *ngIf="role.isStatic"> (<span style="color:red">static</span>)</span></span>
13+
<span>{{l("EditRole")}} <span *ngIf="model.role.isStatic"> (<span style="color:red">static</span>)</span></span>
1414
</h4>
1515
</div>
1616
<div class="modal-body">
@@ -19,7 +19,7 @@ <h4 class="modal-title">
1919
<div class="col-sm-12">
2020
<div class="form-group form-float">
2121
<div class="form-line">
22-
<input id="rolename" [disabled]="role.isStatic" type="text" name="RoleName" [(ngModel)]="role.name" required maxlength="32" minlength="2" class="validate form-control">
22+
<input id="rolename" [disabled]="model.role.isStatic" type="text" name="RoleName" [(ngModel)]="model.role.name" required maxlength="32" minlength="2" class="validate form-control">
2323
<label for="rolename" class="form-label">{{l("RoleName")}}</label>
2424
</div>
2525
</div>
@@ -30,7 +30,7 @@ <h4 class="modal-title">
3030
<div class="col-sm-12">
3131
<div class="form-group form-float">
3232
<div class="form-line">
33-
<input id="displayname" type="text" name="DisplayName" [(ngModel)]="role.displayName" required maxlength="32" minlength="2" class="validate form-control">
33+
<input id="displayname" type="text" name="DisplayName" [(ngModel)]="model.role.displayName" required maxlength="32" minlength="2" class="validate form-control">
3434
<label for="displayname" class="form-label">{{l("DisplayName")}}</label>
3535
</div>
3636
</div>
@@ -41,7 +41,7 @@ <h4 class="modal-title">
4141
<div class="col-sm-12">
4242
<div class="form-group form-float">
4343
<div class="form-line">
44-
<textarea id="role-description" name="Description" [(ngModel)]="role.description" class="validate form-control"></textarea>
44+
<textarea id="role-description" name="Description" [(ngModel)]="model.role.description" class="validate form-control"></textarea>
4545
<label for="role-description" class="form-label">Role Description</label>
4646
</div>
4747
</div>
@@ -52,9 +52,9 @@ <h4 class="modal-title">
5252
<div class="col-sm-12">
5353
<h4>Permissions</h4>
5454

55-
<ng-template ngFor let-permission [ngForOf]="permissions.items" let-permissionIndex="index">
55+
<ng-template ngFor let-permission [ngForOf]="model.permissions" let-permissionIndex="index">
5656
<div class="col-sm-6">
57-
<input [disabled]="role.isStatic" type="checkbox" name="permission" value="{{permission.name}}" class="filled-in" id="permission-{{permissionIndex}}" checked="{{checkPermission(permission.name)}}" />
57+
<input [disabled]="model.role.isStatic" type="checkbox" name="permission" value="{{permission.name}}" class="filled-in" id="permission-{{permissionIndex}}" checked="{{checkPermission(permission.name)}}" />
5858
<label for="permission-{{permissionIndex}}">{{permission.displayName}}</label>
5959
</div>
6060
</ng-template>
@@ -74,4 +74,4 @@ <h4>Permissions</h4>
7474
</form>
7575
</div>
7676
</div>
77-
</div>
77+
</div>

angular/src/app/roles/edit-role/edit-role.component.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
import { Component, ViewChild, Injector, Output, EventEmitter, ElementRef, OnInit } from '@angular/core';
1+
import { Component, ViewChild, Injector, Output, EventEmitter, ElementRef } from '@angular/core';
22
import { ModalDirective } from 'ngx-bootstrap';
3-
import { RoleServiceProxy, RoleDto, ListResultDtoOfPermissionDto } from '@shared/service-proxies/service-proxies';
3+
import { RoleServiceProxy, GetRoleForEditOutput, RoleDto } from '@shared/service-proxies/service-proxies';
44
import { AppComponentBase } from '@shared/app-component-base';
55
import { finalize } from 'rxjs/operators';
66

77
@Component({
88
selector: 'edit-role-modal',
99
templateUrl: './edit-role.component.html'
1010
})
11-
export class EditRoleComponent extends AppComponentBase implements OnInit {
11+
export class EditRoleComponent extends AppComponentBase {
1212
@ViewChild('editRoleModal') modal: ModalDirective;
1313
@ViewChild('modalContent') modalContent: ElementRef;
1414

1515
active: boolean = false;
1616
saving: boolean = false;
1717

18-
permissions: ListResultDtoOfPermissionDto = null;
19-
role: RoleDto = null;
18+
model: GetRoleForEditOutput = null;
2019

2120
@Output() modalSave: EventEmitter<any> = new EventEmitter<any>();
2221
constructor(
@@ -26,21 +25,14 @@ export class EditRoleComponent extends AppComponentBase implements OnInit {
2625
super(injector);
2726
}
2827

29-
ngOnInit(): void {
30-
this._roleService.getAllPermissions()
31-
.subscribe((permissions: ListResultDtoOfPermissionDto) => {
32-
this.permissions = permissions;
33-
});
34-
}
35-
3628
show(id: number): void {
37-
this._roleService.get(id)
29+
this._roleService.getRoleForEdit(id)
3830
.pipe(finalize(() => {
3931
this.active = true;
4032
this.modal.show();
4133
}))
42-
.subscribe((result: RoleDto) => {
43-
this.role = result;
34+
.subscribe((result: GetRoleForEditOutput) => {
35+
this.model = result;
4436
});
4537
}
4638

@@ -49,7 +41,7 @@ export class EditRoleComponent extends AppComponentBase implements OnInit {
4941
}
5042

5143
checkPermission(permissionName: string): string {
52-
if (this.role.permissions.indexOf(permissionName) != -1) {
44+
if (this.model.grantedPermissionNames.indexOf(permissionName) != -1) {
5345
return "checked";
5446
}
5547
else {
@@ -58,6 +50,8 @@ export class EditRoleComponent extends AppComponentBase implements OnInit {
5850
}
5951

6052
save(): void {
53+
const role = this.model.role;
54+
6155
var permissions = [];
6256
$(this.modalContent.nativeElement).find("[name=permission]").each(
6357
function (index: number, elem: Element) {
@@ -67,9 +61,18 @@ export class EditRoleComponent extends AppComponentBase implements OnInit {
6761
}
6862
)
6963

70-
this.role.permissions = permissions;
7164
this.saving = true;
72-
this._roleService.update(this.role)
65+
var input = new RoleDto();
66+
67+
input.name = role.name;
68+
input.displayName = role.displayName;
69+
input.description = role.description;
70+
input.id = role.id;
71+
input.isStatic = role.isStatic;
72+
input.permissions = permissions;
73+
74+
75+
this._roleService.update(input)
7376
.pipe(finalize(() => { this.saving = false; }))
7477
.subscribe(() => {
7578
this.notify.info(this.l('SavedSuccessfully'));

0 commit comments

Comments
 (0)