User and ROle Permission

This commit is contained in:
Mohaimen Hasan 2026-11-17 10:58:33 +06:00
parent 182effa8b5
commit 46ad335dbe
4 changed files with 75 additions and 38 deletions

View File

@ -1,5 +1,5 @@
<app-loading-panel></app-loading-panel> <app-loading-panel></app-loading-panel>
<kendo-grid [kendoGridBinding]="gridView" <kendo-grid #rlGrid [kendoGridBinding]="gridView"
class="rl-grid" class="rl-grid"
kendoGridSelectBy="id" kendoGridSelectBy="id"
[pageSize]="20" [pageSize]="20"
@ -34,10 +34,12 @@
</div> </div>
<div class="rl-toolbar__actions"> <div class="rl-toolbar__actions">
<button kendoGridExcelCommand type="button" fillMode="outline" <!-- Plain buttons, not kendoGridExcelCommand/kendoGridPDFCommand: grid toolbar commands take the
[svgIcon]="apiService.KendoSVGIcon['fileExcel']">Export to Excel</button> focus on any toolbar click, which steals it from the search box. -->
<button kendoGridPDFCommand type="button" fillMode="outline" <button kendoButton type="button" fillMode="outline"
[svgIcon]="apiService.KendoSVGIcon['filePdf']">Export to PDF</button> [svgIcon]="apiService.KendoSVGIcon['fileExcel']" (click)="rlGrid.saveAsExcel()">Export to Excel</button>
<button kendoButton type="button" fillMode="outline"
[svgIcon]="apiService.KendoSVGIcon['filePdf']" (click)="rlGrid.saveAsPDF()">Export to PDF</button>
<button kendoButton type="button" themeColor="primary" [svgIcon]="apiService.KendoSVGIcon['plus']" (click)="addHandler()">Add new</button> <button kendoButton type="button" themeColor="primary" [svgIcon]="apiService.KendoSVGIcon['plus']" (click)="addHandler()">Add new</button>
</div> </div>
</div> </div>
@ -75,7 +77,10 @@
<button class="k-button k-primary" kendoButton [svgIcon]="apiService.KendoSVGIcon['edit']" (click)="ViewPermission(roles.indexOf(dataItem));">Edit</button> <button class="k-button k-primary" kendoButton [svgIcon]="apiService.KendoSVGIcon['edit']" (click)="ViewPermission(roles.indexOf(dataItem));">Edit</button>
} }
@if (dataItem.roleStatus !=1 && dataItem.roleStatus !=5) { @if (dataItem.roleStatus !=1 && dataItem.roleStatus !=5) {
<button class="k-button k-primary" kendoButton [svgIcon]="apiService.KendoSVGIcon['edit']" (click)="Approve(roles.indexOf(dataItem));">Approve</button> <button class="k-button k-primary" kendoButton [svgIcon]="apiService.KendoSVGIcon['edit']"
[disabled]="isMakerOf(dataItem)"
[attr.title]="isMakerOf(dataItem) ? 'You made this change, so another user must approve it.' : null"
(click)="Approve(roles.indexOf(dataItem));">Approve</button>
} }
</ng-template> </ng-template>
</kendo-grid-command-column> </kendo-grid-command-column>

View File

@ -73,9 +73,29 @@ export class RolePermissionListComponent implements OnInit {
public ngOnInit(): void { public ngOnInit(): void {
this.selectedRole = new Role(); this.selectedRole = new Role();
this.showModal = false; this.showModal = false;
this.useService.GetCurrentUser().subscribe(
(resp: any) => {
this.currentUserID = resp?.userID;
},
);
this.load(); this.load();
} }
/** Logged-in user's ID: the maker of a pending role cannot approve it. */
currentUserID: number;
/**
* True when the logged-in user made the role's pending change: whoever last edited it, or its
* creator if it was never edited (same rule as the entry dialog and the server). Their Approve is disabled.
*/
isMakerOf(role: Role): boolean {
if (this.currentUserID == undefined || role == undefined) {
return false;
}
const makerID = (role.modifiedBy ?? 0) > 0 ? role.modifiedBy : role.createdBy;
return makerID == this.currentUserID;
}
load() { load() {
this.useService.getAllRoles() this.useService.getAllRoles()

View File

@ -30,13 +30,8 @@
</ng-template> </ng-template>
</kendo-dropdownlist> </kendo-dropdownlist>
<kendo-textbox <input kendoTextBox class="ul-search" placeholder="Search login ID or name"
class="ul-search" [value]="searchText" (input)="onSearch($event.target.value)" />
placeholder="Search login ID or name"
[clearButton]="true"
[value]="searchText"
(valueChange)="onSearch($event)">
</kendo-textbox>
<div class="ul-chips" role="group" aria-label="Filter by status"> <div class="ul-chips" role="group" aria-label="Filter by status">
<button type="button" class="ul-chip" [class.is-selected]="statusFilter === 'all'" (click)="setStatusFilter('all')"> <button type="button" class="ul-chip" [class.is-selected]="statusFilter === 'all'" (click)="setStatusFilter('all')">
@ -57,13 +52,10 @@
<div class="ul-toolbar__actions"> <div class="ul-toolbar__actions">
<button kendoButton type="button" fillMode="flat" [svgIcon]="icons.refresh" <button kendoButton type="button" fillMode="flat" [svgIcon]="icons.refresh"
title="Reload list" aria-label="Reload list" (click)="RefreshControl()"></button> title="Reload list" aria-label="Reload list" (click)="RefreshControl()"></button>
<kendo-dropdownbutton <!-- Plain buttons, not kendoGridExcelCommand/kendoGridPDFCommand: grid toolbar commands take the
[data]="exportItems" focus on any toolbar click, which closed the User type dropdown before it could open. -->
[svgIcon]="icons.export" <button kendoButton type="button" fillMode="outline" [svgIcon]="icons.excel" (click)="grid.saveAsExcel()">Export to Excel</button>
fillMode="outline" <button kendoButton type="button" fillMode="outline" [svgIcon]="icons.pdf" (click)="grid.saveAsPDF()">Export to PDF</button>
(itemClick)="onExport($event)">
Export
</kendo-dropdownbutton>
<button kendoButton type="button" themeColor="primary" [svgIcon]="icons.add" (click)="addHandler()">Add user</button> <button kendoButton type="button" themeColor="primary" [svgIcon]="icons.add" (click)="addHandler()">Add user</button>
</div> </div>
</div> </div>
@ -92,22 +84,19 @@
<span>{{ dataItem.createdDate | date: 'dd MMM yyyy' }}</span> <span>{{ dataItem.createdDate | date: 'dd MMM yyyy' }}</span>
} }
@if (dataItem.createdByName) { @if (dataItem.createdByName) {
<span class="ul-muted"> · {{ dataItem.createdByName }}</span> <span class="ul-badge ul-badge--info ul-created-by" title="Created by"><span class="ul-badge__dot"></span>{{ dataItem.createdByName }}</span>
} }
</ng-template> </ng-template>
</kendo-grid-column> </kendo-grid-column>
<kendo-grid-column title="" [width]="64" [filterable]="false" [sortable]="false" class="ul-actions-cell" headerClass="ul-actions-cell"> <!-- Same look as the Role page's last column: one button per action. Which actions a row gets
is still decided by actionsFor() (dataItem.actions), and a click still runs onRowAction(). -->
<kendo-grid-column title="Actions" [width]="180" [filterable]="false" [sortable]="false">
<ng-template kendoGridCellTemplate let-dataItem> <ng-template kendoGridCellTemplate let-dataItem>
<kendo-dropdownbutton @for (a of dataItem.actions; track a.action) {
[data]="dataItem.actions" <button class="k-button k-primary ul-row-action" kendoButton [svgIcon]="a.svgIcon"
[svgIcon]="icons.more" (click)="onRowAction(a, dataItem)">{{ a.text }}</button>
fillMode="flat" }
[popupSettings]="{ align: 'right' }"
[attr.aria-label]="'Actions for ' + dataItem.loginID"
title="Actions"
(itemClick)="onRowAction($event, dataItem)">
</kendo-dropdownbutton>
</ng-template> </ng-template>
</kendo-grid-column> </kendo-grid-column>
@ -139,12 +128,14 @@
</div> </div>
@if (showModal) { @if (showModal) {
<div class="blur-background">
<kendo-dialog (close)="onPopUpClose()" [minWidth]="750" [width]="650"> <kendo-dialog (close)="onPopUpClose()" [minWidth]="750" [width]="650">
<kendo-dialog-titlebar> <kendo-dialog-titlebar>
Add/Edit User Add/Edit User
</kendo-dialog-titlebar> </kendo-dialog-titlebar>
<app-users-entry [inputObject]="_user" (saveCompleted)="saveCompleted($event)"></app-users-entry> <app-users-entry [inputObject]="_user" (saveCompleted)="saveCompleted($event)"></app-users-entry>
</kendo-dialog> </kendo-dialog>
</div>
} }
@if (showReason) { @if (showReason) {

View File

@ -103,9 +103,15 @@
// ---------- grid ---------- // ---------- grid ----------
:host ::ng-deep .ul-grid { :host ::ng-deep .ul-grid {
// The global `.k-dropdownlist { width: 100% !important }` (styles/vendors/kendo/_calendar.scss)
// made the User type dropdown fill the whole toolbar row and pushed the rest onto the next line.
// Keep it compact so dropdown, search, chips and buttons stay on one line, like the Role page.
.ul-type.k-dropdownlist {
width: 170px !important;
}
// Uniform, compact rows // Uniform, compact rows
.k-grid-table td { .k-grid-table td {
height: 44px;
padding-top: 4px; padding-top: 4px;
padding-bottom: 4px; padding-bottom: 4px;
vertical-align: middle; vertical-align: middle;
@ -126,6 +132,11 @@
} }
} }
// Row action buttons (last column), side by side like the Role page
.ul-row-action + .ul-row-action {
margin-left: 6px;
}
.ul-login { .ul-login {
font-weight: 600; font-weight: 600;
color: $gray-700; color: $gray-700;
@ -160,6 +171,12 @@
.ul-badge--warning { background: $userlist-warning-bg; color: $userlist-warning; } .ul-badge--warning { background: $userlist-warning-bg; color: $userlist-warning; }
.ul-badge--neutral { background: $userlist-neutral-bg; color: $userlist-neutral; } .ul-badge--neutral { background: $userlist-neutral-bg; color: $userlist-neutral; }
.ul-badge--danger { background: $userlist-danger-bg; color: $danger; } .ul-badge--danger { background: $userlist-danger-bg; color: $danger; }
// "Created by" name next to the date in the Created column
.ul-badge--info { background: #E8EEFC; color: #2F4FB5; }
.ul-created-by {
margin-left: 8px;
}
.ul-empty { .ul-empty {
padding: 32px 16px; padding: 32px 16px;
@ -194,4 +211,8 @@
.ul-search { .ul-search {
width: 100%; width: 100%;
} }
:host ::ng-deep .ul-grid .ul-type.k-dropdownlist {
width: 100% !important;
}
} }