diff --git a/HRM.DA/Service/Users/RoleService.cs b/HRM.DA/Service/Users/RoleService.cs index 564226f..e30b6e3 100644 --- a/HRM.DA/Service/Users/RoleService.cs +++ b/HRM.DA/Service/Users/RoleService.cs @@ -334,6 +334,11 @@ namespace HRM.DA try { tc = TransactionContext.Begin(true); + + // Audit of the permission rows, by PermissionCode, read before they are deleted and + // re-inserted below, so each kept menu keeps who/when it was created and approved. + Dictionary existingPermissions = new Dictionary(); + if (oRole.IsNew) { int id = tc.GenerateID("Role", "RoleID"); @@ -344,6 +349,15 @@ namespace HRM.DA } else { + DataReader existingReader = new DataReader(RoleDA.GetRolePermissionByRoleID(tc, oRole.ID)); + while (existingReader.Read()) + { + Role.RolePermission existingPermission = this.CreateRolePermissionObject(existingReader); + if (existingPermission.PermissionCode != null && !existingPermissions.ContainsKey(existingPermission.PermissionCode)) + existingPermissions.Add(existingPermission.PermissionCode, existingPermission); + } + existingReader.Close(); + RoleDA.Update(tc, oRole); #region Delete Children RoleDA.Delete(tc, "RolePermission", "RoleID", oRole.ID); @@ -372,11 +386,34 @@ namespace HRM.DA newid = newid + 1; } + // Whoever made this change: the editor, or the creator for a new role. On approval + // the controller keeps the maker in ModifiedBy, so this is still the maker. + int makerID = (oRole.ModifiedBy ?? 0) > 0 ? oRole.ModifiedBy.Value : oRole.CreatedBy; + foreach (Role.RolePermission rolePermission in oRole.RolePermissions) { rolePermission.RoleID = oRole.ID; - rolePermission.CreatedBy = oRole.CreatedBy; - rolePermission.CreatedDate = oRole.CreatedDate; + + Role.RolePermission existingPermission = null; + if (rolePermission.PermissionCode != null) + existingPermissions.TryGetValue(rolePermission.PermissionCode, out existingPermission); + + if (existingPermission != null) + { + // Menu the role already had: keep its original audit. + rolePermission.CreatedBy = existingPermission.CreatedBy; + rolePermission.CreatedDate = existingPermission.CreatedDate; + rolePermission.ApproveBy = existingPermission.ApproveBy; + rolePermission.ApproveDate = existingPermission.ApproveDate; + } + else + { + // Menu added by this change. + rolePermission.CreatedBy = makerID; + rolePermission.CreatedDate = DateTime.Now; + rolePermission.ApproveBy = null; + rolePermission.ApproveDate = null; + } //if (oRole.RoleStatus == EnumAuthStatus.Approved ) //{ // if (rolePermission.Status == EnumAuthStatus.DeletedNotYetApprove) @@ -391,6 +428,17 @@ namespace HRM.DA rolePermission.Status = EnumAuthStatus.Approved; else rolePermission.Status = EnumAuthStatus.None; + + // A menu approved by this approval (new, or still pending before it) gets this + // approver; a menu that was already approved keeps its earlier approver. + bool approvedNow = existingPermission == null + || existingPermission.Status == EnumAuthStatus.NewNotYetApprove + || existingPermission.Status == EnumAuthStatus.EditedNotYetApprove; + if (rolePermission.Status == EnumAuthStatus.Approved && approvedNow) + { + rolePermission.ApproveBy = oRole.ApproveBy; + rolePermission.ApproveDate = oRole.ApproveDate; + } } else { diff --git a/HRM.UI/ClientApp/src/app/authentication/role/role-permission-list/role-permission-list.component.css b/HRM.UI/ClientApp/src/app/authentication/role/role-permission-list/role-permission-list.component.css index e02abfc..876b23f 100644 --- a/HRM.UI/ClientApp/src/app/authentication/role/role-permission-list/role-permission-list.component.css +++ b/HRM.UI/ClientApp/src/app/authentication/role/role-permission-list/role-permission-list.component.css @@ -1 +1,45 @@ - +/* Table design matching the User page grid (users-list.component.scss). + This component uses ViewEncapsulation.None, so every rule is scoped under .rl-grid. */ + +/* Uniform, compact rows */ +.rl-grid .k-grid-table td { + padding-top: 4px; + padding-bottom: 4px; + vertical-align: middle; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.rl-grid .k-grid-toolbar { + padding: 8px 12px; +} + +/* Status badge */ +.rl-grid .rl-badge { + display: inline-flex; + align-items: center; + gap: 6px; + padding: 2px 10px; + border-radius: 999px; + font-size: 12px; + font-weight: 600; + line-height: 20px; + white-space: nowrap; +} + +.rl-grid .rl-badge__dot { + width: 6px; + height: 6px; + border-radius: 50%; + background: currentColor; +} + +.rl-grid .rl-badge--success { background: #E6F4EC; color: #137A4B; } +.rl-grid .rl-badge--neutral { background: #EEEEF2; color: #5B5B6B; } +.rl-grid .rl-badge--warning { background: #FFF2DB; color: #8A5300; } + +/* Role Type badge, same shape as the Status badge */ +.rl-grid .rl-badge--admin { background: #E8EEFC; color: #2F4FB5; } +.rl-grid .rl-badge--ess { background: #F1EAFB; color: #6B3FA0; } +.rl-grid .rl-badge--mobile { background: #E4F5F7; color: #0F6E7A; } diff --git a/HRM.UI/ClientApp/src/app/authentication/role/role-permission-list/role-permission-list.component.html b/HRM.UI/ClientApp/src/app/authentication/role/role-permission-list/role-permission-list.component.html index 32804b9..0e9d87b 100644 --- a/HRM.UI/ClientApp/src/app/authentication/role/role-permission-list/role-permission-list.component.html +++ b/HRM.UI/ClientApp/src/app/authentication/role/role-permission-list/role-permission-list.component.html @@ -1,8 +1,11 @@ - + + + + {{ roleTypeString(dataItem.roleType) }} + + + - {{ statusString(dataItem.roleStatus)}} + + {{ statusString(dataItem.roleStatus)}} + @if (dataItem.roleStatus ==1 || dataItem.roleStatus ==5) { - + } @if (dataItem.roleStatus !=1 && dataItem.roleStatus !=5) { - + } + + + + + + + + + + + + + + {{ roleTypeString(dataItem.roleType) }} + + + {{ statusString(dataItem.roleStatus) }} + + @@ -42,14 +80,15 @@ @if (showModal) { - - - Role Permission - - - - +
+ + + Role Permission + + + + +
}