diff --git a/HRM.BO/User/UserAccessType.cs b/HRM.BO/User/UserAccessType.cs index 6cab01e..84605c7 100644 --- a/HRM.BO/User/UserAccessType.cs +++ b/HRM.BO/User/UserAccessType.cs @@ -33,6 +33,15 @@ namespace HRM.BO public int? ApprovedBy { get; set; } public DateTime? ApprovedDate { get; set; } + // Filled only by GetPending (the Pending approvals list), for display. + public string UserName { get; set; } + public string LoginID { get; set; } + /// Who requested this pending row: CreatedBy for a new access, ModifiedBy for a removal. + public int MakerID { get; set; } + public string MakerLoginID { get; set; } + /// When it was requested: CreatedDate for a new access, ModifiedDate for a removal. + public DateTime? RequestDate { get; set; } + #endregion } #endregion @@ -55,6 +64,8 @@ namespace HRM.BO void Approve(int userID, int approverID); /// Checker: drops every pending change of the user; access stays as it was. void Reject(int userID); + /// Every row waiting for approval, of every user, with user, payroll type and maker for display. + List GetPending(); } #endregion diff --git a/HRM.DA/DA/Users/UserAccessTypeDA.cs.cs b/HRM.DA/DA/Users/UserAccessTypeDA.cs.cs index 3d1e5c3..62e2b65 100644 --- a/HRM.DA/DA/Users/UserAccessTypeDA.cs.cs +++ b/HRM.DA/DA/Users/UserAccessTypeDA.cs.cs @@ -86,6 +86,21 @@ namespace HRM.DA return tc.ExecuteReader("SELECT * FROM UserAccessType WHERE UserID=%n", UserID); } + // Every row waiting for approval, of every user (Pending approvals list). + internal static IDataReader GetPending(TransactionContext tc) + { + return tc.ExecuteReader(@"SELECT ua.*, p.Description PayrollTypeName, u.LoginID UserLoginID, u.UserName UserFullName, + mk.LoginID MakerLoginID + FROM UserAccessType ua + JOIN PayrollType p ON p.PayrollTypeID = ua.PayrollTypeID + JOIN Users u ON u.UserID = ua.UserID + LEFT JOIN Users mk ON mk.UserID = CASE WHEN ua.Status=%n THEN ua.ModifiedBy ELSE ua.CreatedBy END + WHERE ua.Status IN (%n, %n) + ORDER BY u.UserName, p.Description", + (int)EnumAuthStatus.DeletedNotYetApprove, + (int)EnumAuthStatus.NewNotYetApprove, (int)EnumAuthStatus.DeletedNotYetApprove); + } + // Names of the payroll types a pending approval of this user will newly give access to. internal static IDataReader GetPendingNewDescriptions(TransactionContext tc, int userID) { diff --git a/HRM.DA/Service/Users/UserAccessTypeService.cs b/HRM.DA/Service/Users/UserAccessTypeService.cs index 6635024..da868c6 100644 --- a/HRM.DA/Service/Users/UserAccessTypeService.cs +++ b/HRM.DA/Service/Users/UserAccessTypeService.cs @@ -329,6 +329,43 @@ namespace HRM.DA } } + public List GetPending() + { + List items = new List(); + TransactionContext tc = null; + try + { + tc = TransactionContext.Begin(); + DataReader dr = new DataReader(UserAccessTypeDA.GetPending(tc)); + while (dr.Read()) + { + UserAccessType item = this.CreateObject(dr); + item.Description = dr.GetString("PayrollTypeName"); + item.LoginID = dr.GetString("UserLoginID"); + item.UserName = dr.GetString("UserFullName"); + item.MakerLoginID = dr.GetString("MakerLoginID"); + bool isRemoval = item.AccessTypeStatus == EnumAuthStatus.DeletedNotYetApprove; + item.MakerID = isRemoval ? (item.ModifiedBy ?? 0) : item.CreatedBy; + item.RequestDate = isRemoval + ? item.ModifiedDate + : (item.CreatedDate == DateTime.MinValue ? (DateTime?)null : item.CreatedDate); + items.Add(item); + } + dr.Close(); + tc.End(); + } + catch (Exception e) + { + #region Handle Exception + if (tc != null) + tc.HandleError(); + ExceptionLog.Write(e); + throw new ServiceException(e.Message, e); + #endregion + } + return items; + } + public void Reject(int userID) { TransactionContext tc = null; diff --git a/HRM.UI/ClientApp/src/app/_services/auth/auth.service.ts b/HRM.UI/ClientApp/src/app/_services/auth/auth.service.ts index 163b9ec..53125cd 100644 --- a/HRM.UI/ClientApp/src/app/_services/auth/auth.service.ts +++ b/HRM.UI/ClientApp/src/app/_services/auth/auth.service.ts @@ -237,6 +237,17 @@ export class AuthService { RejectUserAccessType(userID: number) { return this.apiService.httpPost('/Authentication/RejectUserAccessType/' + userID, {}); } + GetPendingUserAccessTypes() { + return this.apiService.httpGet('/Authentication/GetPendingUserAccessTypes'); + } + /** Returns { done: number, failed: { userID, message }[] }. */ + ApproveUserAccessTypes(userIDs: number[]) { + return this.apiService.httpPost('/Authentication/ApproveUserAccessTypes', userIDs); + } + /** Returns { done: number, failed: { userID, message }[] }. */ + RejectUserAccessTypes(userIDs: number[]) { + return this.apiService.httpPost('/Authentication/RejectUserAccessTypes', userIDs); + } changePassword(userData: any) { return this.apiService.httpPost('/Authentication/changePassword', userData); } diff --git a/HRM.UI/ClientApp/src/app/authentication/user-access-type/user-access-type.component.css b/HRM.UI/ClientApp/src/app/authentication/user-access-type/user-access-type.component.css index c758efd..305ee31 100644 --- a/HRM.UI/ClientApp/src/app/authentication/user-access-type/user-access-type.component.css +++ b/HRM.UI/ClientApp/src/app/authentication/user-access-type/user-access-type.component.css @@ -1,34 +1,567 @@ -/* This component uses ViewEncapsulation.None, so every rule carries the uat- prefix. */ +/* User Access Type page. This component uses ViewEncapsulation.None, so every rule carries the uat- prefix. + Colours follow the app tokens (src/styles/abstracts/_tokens.scss) and the User / Role page badges. */ -/* Banner shown while the selected user has an access change waiting for approval */ -.uat-pending { - margin-bottom: 12px; - padding: 10px 14px; - border: 1px solid #F5D9A8; +.uat-page { + display: flex; + flex-direction: column; + gap: 14px; +} + +/* ---------- header ---------- */ + +.uat-header { + display: flex; + align-items: center; + gap: 14px; +} + +.uat-header__icon { + width: 44px; + height: 44px; + border-radius: 10px; + background: #DEDEFF; + color: #414278; + display: flex; + align-items: center; + justify-content: center; + font-size: 20px; + flex-shrink: 0; +} + +.uat-title { + margin: 0 0 2px; + font-size: 18px; + font-weight: 600; + color: #1a1a1a; +} + +.uat-subtitle { + margin: 0; + font-size: 13px; + color: #888888; +} + +/* ---------- view switch ---------- */ + +.uat-views { + display: inline-flex; + gap: 4px; + padding: 4px; + border: 1px solid #E3E3EC; + border-radius: 10px; + background: #FFFFFF; + align-self: flex-start; +} + +.uat-view { + display: inline-flex; + align-items: center; + gap: 8px; + height: 34px; + padding: 0 14px; + border: none; border-radius: 8px; + background: transparent; + color: #424242; + font: inherit; + font-size: 13px; + font-weight: 600; + cursor: pointer; + transition: background-color 0.15s, color 0.15s; +} + +.uat-view:hover { + background: #F3F3FF; +} + +.uat-view.is-active { + background: #52527A; + color: #FFFFFF; +} + +.uat-view__count { + min-width: 20px; + padding: 0 6px; + border-radius: 999px; + background: #EEEEF2; + color: #5B5B6B; + font-size: 12px; + line-height: 18px; + text-align: center; +} + +.uat-view__count.has-items { background: #FFF2DB; color: #8A5300; +} + +.uat-view.is-active .uat-view__count { + background: rgba(255, 255, 255, 0.22); + color: #FFFFFF; +} + +/* ---------- pending approvals table ---------- */ + +.uat-table-wrap { + border: 1px solid #E3E3EC; + border-radius: 10px; + overflow: auto; + max-height: 560px; +} + +.uat-table { + width: 100%; + border-collapse: collapse; font-size: 13px; } -.uat-pending__note { - display: block; - margin-top: 4px; +.uat-table th { + position: sticky; + top: 0; + z-index: 1; + background: #F7F7FB; + color: #666666; + font-size: 12px; font-weight: 600; + text-align: left; + padding: 10px 12px; + border-bottom: 1px solid #E3E3EC; + white-space: nowrap; } -.uat-action { - margin-left: 6px; +.uat-table td { + padding: 10px 12px; + border-bottom: 1px solid #F0F0F4; + vertical-align: top; } -/* While a change waits for approval the ticks show the requested state and cannot be changed */ -.uat-locked .k-checkbox { - pointer-events: none; - opacity: 0.6; +.uat-table tbody tr:last-child td { + border-bottom: none; } -/* Status badge, same look as the User and Role pages */ -.uat-badge { +.uat-table tbody tr:hover { + background: #F7F7FB; +} + +.uat-table tbody tr.is-selected { + background: #F3F3FF; +} + +.uat-table tbody tr.is-mine { + color: #888888; +} + +.uat-table__check { + width: 40px; + text-align: center; +} + +.uat-table__open { + width: 70px; + text-align: right; +} + +.uat-block { + display: block; +} + +.uat-mine { + margin-top: 4px; +} + +/* ---------- layout ---------- */ + +.uat-layout { + display: grid; + grid-template-columns: 320px minmax(0, 1fr); + gap: 14px; + align-items: start; +} + +.uat-main { + display: flex; + flex-direction: column; + gap: 14px; + min-width: 0; +} + +.uat-card { + background: #FFFFFF; + border: 1px solid #E3E3EC; + border-radius: 12px; + padding: 16px; +} + +.uat-card__title { + margin: 0 0 2px; + font-size: 15px; + font-weight: 600; + color: #1a1a1a; +} + +/* Pending approvals table, "Requested by" cell: maker, date and "Your change" side by side */ +.uat-requested { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 4px 10px; +} + +/* Left column: user card, then the pending change card under it */ +.uat-side { + display: flex; + flex-direction: column; + gap: 14px; + min-width: 0; +} + +/* In the narrow left column the note sits above full-width buttons */ +.uat-side .uat-pending__actions { + flex-direction: column; + align-items: stretch; +} + +.uat-side .uat-pending__actions .uat-btns > button { + flex: 1; +} + +/* "3 of 12 selected" next to the Payroll access title */ +.uat-count { + display: inline-block; + margin-left: 8px; + padding: 0 10px; + border-radius: 999px; + background: #DEDEFF; + color: #414278; + font-size: 12px; + font-weight: 600; + line-height: 22px; + vertical-align: middle; +} + +.uat-label { + display: block; + margin-bottom: 8px; + font-size: 12px; + font-weight: 600; + color: #888888; + text-transform: uppercase; + letter-spacing: 0.05em; +} + +.uat-muted { + color: #888888; + font-size: 12px; +} + +.uat-btns { + display: flex; + gap: 8px; + flex-wrap: wrap; +} + +/* ---------- user card ---------- */ + +.uat-user__select { + width: 100%; +} + +.uat-user__option { + display: flex; + flex-direction: column; + line-height: 1.3; +} + +.uat-user__summary { + display: flex; + align-items: center; + gap: 12px; + margin-top: 16px; +} + +.uat-avatar { + width: 40px; + height: 40px; + border-radius: 50%; + background: #52527A; + color: #FFFFFF; + display: flex; + align-items: center; + justify-content: center; + font-weight: 600; + flex-shrink: 0; +} + +.uat-user__info { + display: flex; + flex-direction: column; + min-width: 0; +} + +.uat-user__name { + font-weight: 600; + color: #1a1a1a; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.uat-stats { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + margin-top: 14px; + padding: 10px 12px; + border-radius: 10px; + background: #F7F7FB; +} + +.uat-stat { + display: flex; + align-items: baseline; + gap: 6px; +} + +.uat-stat__value { + font-size: 20px; + font-weight: 700; + color: #414278; +} + +.uat-stat__label { + font-size: 12px; + color: #666666; +} + +.uat-legend { + margin-top: 16px; + padding-top: 14px; + border-top: 1px solid #F0F0F4; + display: flex; + flex-direction: column; + gap: 8px; +} + +.uat-legend__title { + font-size: 12px; + font-weight: 600; + color: #888888; + text-transform: uppercase; + letter-spacing: 0.05em; +} + +.uat-legend__row { + display: flex; + flex-direction: column; + align-items: flex-start; + gap: 2px; +} + +/* ---------- empty state ---------- */ + +.uat-empty { + padding: 48px 16px; + text-align: center; +} + +.uat-empty__icon { + font-size: 32px; + color: #C9C9D6; +} + +.uat-empty__title { + margin: 10px 0 4px; + font-weight: 600; + color: #424242; +} + +/* ---------- pending change ---------- */ + +.uat-pending { + border-color: #F5D9A8; + background: #FFFAF0; +} + +.uat-pending__head { + display: flex; + gap: 12px; + align-items: flex-start; + color: #8A5300; +} + +.uat-pending__head > .pi { + font-size: 20px; + margin-top: 2px; +} + +.uat-pending__title { + margin: 0 0 2px; + font-weight: 600; + font-size: 15px; +} + +.uat-pending__text { + margin: 0; + font-size: 13px; +} + +.uat-change { + margin-top: 12px; +} + +.uat-change__label { + display: block; + margin-bottom: 6px; + font-size: 12px; + font-weight: 600; + color: #8A5300; +} + +.uat-pending__actions { + margin-top: 16px; + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: 10px; +} + +.uat-pending__note { + font-size: 13px; + font-weight: 600; + color: #8A5300; +} + +/* ---------- chips ---------- */ + +.uat-chips { + display: flex; + flex-wrap: wrap; + gap: 6px; +} + +.uat-chip { + display: inline-flex; + align-items: center; + gap: 6px; + padding: 3px 10px; + border-radius: 999px; + font-size: 12px; + font-weight: 600; + line-height: 20px; +} + +.uat-chip .pi { + font-size: 10px; +} + +.uat-chip--add { background: #E6F4EC; color: #137A4B; } +.uat-chip--remove { background: #FDE8EA; color: #D11A2A; } + +/* ---------- payroll type list ---------- */ + +.uat-list__head { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: 10px; + margin-bottom: 12px; +} + +.uat-list__tools { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 6px; +} + +.uat-search { + width: 220px; +} + +.uat-list { + border: 1px solid #E3E3EC; + border-radius: 10px; + overflow: hidden; + max-height: 579px; + overflow-y: auto; +} + +.uat-row { + display: flex; + align-items: center; + gap: 12px; + margin: 0; + padding: 8px 14px; + border-bottom: 1px solid #F0F0F4; + cursor: pointer; + transition: background-color 0.15s; +} + +.uat-row:last-child { + border-bottom: none; +} + +.uat-row:hover { + background: #F7F7FB; +} + +.uat-row.is-ticked { + background: #F3F3FF; +} + +.uat-row__name { + flex: 1; + min-width: 0; + color: #1a1a1a; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.uat-list--locked .uat-row { + cursor: default; +} + +.uat-list--locked .uat-row:hover { + background: inherit; +} + +.uat-list--locked .uat-row.is-ticked:hover { + background: #F3F3FF; +} + +.uat-list__empty { + padding: 24px 16px; + text-align: center; +} + +/* ---------- save bar ---------- */ + +.uat-savebar { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: 10px; + margin-top: 14px; + padding-top: 14px; + border-top: 1px solid #F0F0F4; +} + +.uat-savebar__summary { + display: flex; + flex-wrap: wrap; + gap: 6px; + align-items: center; +} + +/* ---------- badges / pills (same look as the User and Role pages) ---------- */ + +.uat-badge, +.uat-pill { display: inline-flex; align-items: center; gap: 6px; @@ -47,6 +580,19 @@ background: currentColor; } -.uat-badge--success { background: #E6F4EC; color: #137A4B; } -.uat-badge--warning { background: #FFF2DB; color: #8A5300; } +.uat-badge--success, +.uat-pill--success { background: #E6F4EC; color: #137A4B; } +.uat-badge--warning, +.uat-pill--warning { background: #FFF2DB; color: #8A5300; } .uat-badge--neutral { background: #EEEEF2; color: #5B5B6B; } +.uat-badge--info { background: #E8EEFC; color: #2F4FB5; } + +@media (max-width: 900px) { + .uat-layout { + grid-template-columns: 1fr; + } + + .uat-search { + width: 100%; + } +} diff --git a/HRM.UI/ClientApp/src/app/authentication/user-access-type/user-access-type.component.html b/HRM.UI/ClientApp/src/app/authentication/user-access-type/user-access-type.component.html index 322a2d2..95a4d39 100644 --- a/HRM.UI/ClientApp/src/app/authentication/user-access-type/user-access-type.component.html +++ b/HRM.UI/ClientApp/src/app/authentication/user-access-type/user-access-type.component.html @@ -1,73 +1,287 @@ + - -
-
-
- -
-
+
- - -
-
-
-
+ +
+
+
+

User Access Type

+

Choose which payroll types a user can work in. Every change is approved by another administrator before it takes effect.

+
-
- @if (hasPending) { -
- This user has an access change waiting for approval. The user keeps the current access until it is approved. - @if (isMakerOfPending) { - You made this change, so another user must approve or reject it. - } -
- } -
-
- - - - - - - @if (_selectedUserID) { - - {{ statusOf(dataItem.id).text }} - - } - - - -
+ +
+ + +
+ + @if (activeView === 'pending') { +
+
+
+

Pending approvals

+

Every user whose payroll access change is waiting for approval. Select several and approve or reject them at once.

-
- - @if (hasPending) { - - + +
+ + @if (pendingGroups.length === 0) { +
+ +

Nothing to approve

+

No user access change is waiting for approval.

+
+ } @else { +
+ + + + + + + + + + + + + @for (g of pendingGroups; track g.userID) { + + + + + + + + + } + +
+ + UserWill get access toWill lose access toRequested by
+ + + {{ g.userName }} + {{ g.loginID }} + +
+ @for (n of g.adds; track n) { {{ n }} } + @if (g.adds.length === 0) { - } +
+
+
+ @for (n of g.removes; track n) { {{ n }} } + @if (g.removes.length === 0) { - } +
+
+
+ {{ g.makers.join(', ') || '-' }} + @if (g.requestDate) { + {{ g.requestDate | date: 'dd MMM yyyy, h:mm a' }} + } + @if (g.isMine) { + Your change + } +
+
+ +
+
+ +
+
+ {{ selectedPendingIDs.length }} of {{ selectablePending.length }} selected +
+
+ + +
+
+ } +
+ } + + @if (activeView === 'manage') { +
+ + +
+
+ + + + + {{ dataItem?.userName }} + @if (dataItem?.loginID) { + {{ dataItem.loginID }} } + + + + + @if (selectedUser) { +
+
{{ (selectedUser.userName || '?').charAt(0) | uppercase }}
+
+ {{ selectedUser.userName }} + {{ selectedUser.loginID }} +
+ +
+
+ {{ liveCount }} + payroll types in use +
+
+ @if (hasPending) { + Waiting for approval + } @else { + Up to date + } +
+
+ } + +
+ Status +
Activeuser can use it
+
New - Not Yet Approvednot usable until approved
+
Removal - Not Yet Approvedstill usable until approved
+
+ + @if (selectedUser && hasPending) { +
+
+ +
+

Change waiting for approval

+

Until it is approved, {{ selectedUser.userName }} keeps the current access.

+
+
+ @if (pendingAddNames.length > 0) { +
+ Will get access to +
+ @for (n of pendingAddNames; track n) { {{ n }} } +
+
+ } + @if (pendingRemoveNames.length > 0) { +
+ Will lose access to +
+ @for (n of pendingRemoveNames; track n) { {{ n }} } +
+
+ } + +
+ @if (isMakerOfPending) { + You made this change, so another administrator must approve or reject it. + } +
+ + +
+
+
+ } +
+ + +
+ + @if (!selectedUser) { +
+ +

Select a user

+

Their payroll access and any change waiting for approval will show here.

+
+ } @else { + + +
+
+
+

+ Payroll access + {{ _selectedPayrollTypes.length }} of {{ _payrollTypes?.length || 0 }} selected +

+

{{ hasPending ? 'Locked while the change waits for approval.' : 'Tick the payroll types this user should have.' }}

+
+
+ + @if (!hasPending) { + + + } +
+
+ +
+ @for (p of visiblePayrollTypes; track p.id) { + + } @empty { +
No payroll type matches the search.
+ } +
+ + + @if (!hasPending) { +
+
+ @if (hasDraftChanges) { + @if (draftAddNames.length > 0) { {{ draftAddNames.length }} to add } + @if (draftRemoveNames.length > 0) { {{ draftRemoveNames.length }} to remove } + } @else { + No changes yet. + } +
+
+ + +
+
+ } +
+ } +
+
+ } +
diff --git a/HRM.UI/ClientApp/src/app/authentication/user-access-type/user-access-type.component.ts b/HRM.UI/ClientApp/src/app/authentication/user-access-type/user-access-type.component.ts index a428c3f..a3f3696 100644 --- a/HRM.UI/ClientApp/src/app/authentication/user-access-type/user-access-type.component.ts +++ b/HRM.UI/ClientApp/src/app/authentication/user-access-type/user-access-type.component.ts @@ -54,12 +54,15 @@ export class UserAccessTypeComponent implements OnInit { this.useService.GetCurrentUser().subscribe( (resp: any) => { this.currentUserID = resp?.userID; + // After the current user is known, so "your own change" can be marked. + this.loadPending(); }, ); this.useService.GetUsers(EnumUserType.User) .subscribe( (resp: any) => { this._users = resp; + this.filteredUsers = (resp ?? []).slice(); }, (err: any) => { //ON ERROR @@ -88,6 +91,141 @@ export class UserAccessTypeComponent implements OnInit { this.setSelectableSettings(); } + // ---------- Pending approvals (many users at once) ---------- + + /** Which view the page shows. */ + activeView: 'manage' | 'pending' = 'manage'; + /** One entry per user with a change waiting for approval. */ + pendingGroups: { + userID: number, userName: string, loginID: string, + adds: string[], removes: string[], makers: string[], requestDate: Date, isMine: boolean, + }[] = []; + selectedPendingIDs: number[] = []; + + loadPending(): void { + this.useService.GetPendingUserAccessTypes().subscribe( + (rows: any[]) => { + const groups = new Map(); + (rows ?? []).forEach(r => { + let g = groups.get(r.userID); + if (!g) { + g = { userID: r.userID, userName: r.userName, loginID: r.loginID, + adds: [], removes: [], makers: [], makerIDs: [], requestDate: null, isMine: false }; + groups.set(r.userID, g); + } + if (r.accessTypeStatus == EnumAuthStatus.Deleted_Not_Yet_Approve) { + g.removes.push(r.description); + } else { + g.adds.push(r.description); + } + const maker = r.makerLoginID || (r.makerID ? '#' + r.makerID : ''); + if (maker && !g.makers.includes(maker)) { + g.makers.push(maker); + } + if (r.makerID && !g.makerIDs.includes(r.makerID)) { + g.makerIDs.push(r.makerID); + } + const d = r.requestDate ? new Date(r.requestDate) : null; + if (d && (!g.requestDate || d > g.requestDate)) { + g.requestDate = d; + } + }); + this.pendingGroups = Array.from(groups.values()).map(g => ({ + ...g, isMine: g.makerIDs.includes(this.currentUserID), + })); + // Keep only selections that are still pending and selectable. + this.selectedPendingIDs = this.selectedPendingIDs.filter(id => + this.pendingGroups.some(g => g.userID == id && !g.isMine)); + }, + (err: any) => { + this.pendingGroups = []; + } + ); + } + + /** Pending users the logged-in user may decide (not their own changes). */ + get selectablePending() { + return this.pendingGroups.filter(g => !g.isMine); + } + + isPendingSelected(userID: number): boolean { + return this.selectedPendingIDs.includes(userID); + } + + togglePendingSelection(userID: number): void { + const g = this.pendingGroups.find(x => x.userID == userID); + if (!g || g.isMine) { + return; + } + this.selectedPendingIDs = this.isPendingSelected(userID) + ? this.selectedPendingIDs.filter(x => x != userID) + : [...this.selectedPendingIDs, userID]; + } + + get allPendingSelected(): boolean { + return this.selectablePending.length > 0 && this.selectablePending.every(g => this.isPendingSelected(g.userID)); + } + + toggleAllPending(): void { + this.selectedPendingIDs = this.allPendingSelected ? [] : this.selectablePending.map(g => g.userID); + } + + /** Opens one pending user in the Manage access view. */ + openPendingUser(userID: number): void { + this.activeView = 'manage'; + this._selectedUserID = userID; + this.RefreshGrid(userID); + } + + bulkApprove(): void { + this.bulkDecide(true); + } + + bulkReject(): void { + this.bulkDecide(false); + } + + private bulkDecide(approve: boolean): void { + const ids = this.selectedPendingIDs.slice(); + if (ids.length == 0) { + this.notificationService.showWarning('Select at least one user.'); + return; + } + const call = approve ? this.useService.ApproveUserAccessTypes(ids) : this.useService.RejectUserAccessTypes(ids); + let result: any; + this.loadingPanel.ShowLoadingPanel = true; + call.subscribe( + (resp: any) => { + result = resp; + }, + (err: any) => { + this.loadingPanel.ShowLoadingPanel = false; + this.notificationService.showError(err?.error ?? err); + }, + () => { + this.loadingPanel.ShowLoadingPanel = false; + const done = result?.done ?? 0; + const failed: any[] = result?.failed ?? []; + if (done > 0) { + this.notificationService.showSuccess( + (approve ? 'Approved' : 'Rejected') + ' for ' + done + (done == 1 ? ' user.' : ' users.')); + } + if (failed.length > 0) { + const names = failed.map(f => { + const g = this.pendingGroups.find(x => x.userID == f.userID); + return (g?.userName ?? ('User ' + f.userID)) + ': ' + f.message; + }); + this.notificationService.showError(names.join(' | ')); + } + this.selectedPendingIDs = []; + this.loadPending(); + if (this._selectedUserID && ids.includes(this._selectedUserID)) { + this.RefreshGrid(this._selectedUserID); + } + } + ); + } + setSelectableSettings(): void { this.selectableSettings = { checkboxOnly: true, @@ -95,6 +233,120 @@ export class UserAccessTypeComponent implements OnInit { }; } + // ---------- view helpers (screen only; saving and approval logic is below) ---------- + + /** Users dropdown, narrowed by what is typed in it. */ + filteredUsers: User[] = []; + /** Search box over the payroll type list. */ + payrollSearch = ''; + + onUserFilter(term: string): void { + const t = (term ?? '').trim().toLowerCase(); + this.filteredUsers = (this._users ?? []).filter(u => + !t || (u.userName ?? '').toLowerCase().includes(t) || (u.loginID ?? '').toLowerCase().includes(t)); + } + + get selectedUser(): User { + return (this._users ?? []).find(u => u.id == this._selectedUserID); + } + + /** Payroll types shown in the list, after the search box. */ + get visiblePayrollTypes(): PayrollType[] { + const t = this.payrollSearch.trim().toLowerCase(); + return (this._payrollTypes ?? []).filter(p => !t || (p.description ?? '').toLowerCase().includes(t)); + } + + isTicked(payrollTypeID: number): boolean { + return this._selectedPayrollTypes.includes(payrollTypeID); + } + + /** Ticks or unticks one payroll type. Locked while a change waits for approval. */ + toggle(payrollTypeID: number): void { + if (this.hasPending || !this._selectedUserID) { + return; + } + this._selectedPayrollTypes = this.isTicked(payrollTypeID) + ? this._selectedPayrollTypes.filter(x => x != payrollTypeID) + : [...this._selectedPayrollTypes, payrollTypeID]; + } + + selectAllVisible(): void { + if (this.hasPending || !this._selectedUserID) { + return; + } + const ids = this.visiblePayrollTypes.map(p => p.id).filter(id => !this.isTicked(id)); + this._selectedPayrollTypes = [...this._selectedPayrollTypes, ...ids]; + } + + clearAllVisible(): void { + if (this.hasPending || !this._selectedUserID) { + return; + } + const ids = this.visiblePayrollTypes.map(p => p.id); + this._selectedPayrollTypes = this._selectedPayrollTypes.filter(x => !ids.includes(x)); + } + + /** Undoes unsaved ticks: back to what the user has now. */ + resetSelection(): void { + this._selectedPayrollTypes = (this._userAcessTypes ?? []) + .filter(x => x.accessTypeStatus != EnumAuthStatus.Deleted_Not_Yet_Approve) + .map(x => x.payrollTypeID); + } + + payrollName(payrollTypeID: number): string { + return (this._payrollTypes ?? []).find(p => p.id == payrollTypeID)?.description ?? ''; + } + + /** Payroll types the user can use right now (approved, or a removal not yet approved). */ + get liveCount(): number { + return (this._userAcessTypes ?? []).filter(x => x.accessTypeStatus != EnumAuthStatus.New_Not_Yet_Approve).length; + } + + /** Waiting for approval: access to be given. */ + get pendingAddNames(): string[] { + return (this._userAcessTypes ?? []).filter(x => x.accessTypeStatus == EnumAuthStatus.New_Not_Yet_Approve) + .map(x => this.payrollName(x.payrollTypeID)); + } + + /** Waiting for approval: access to be taken away. */ + get pendingRemoveNames(): string[] { + return (this._userAcessTypes ?? []).filter(x => x.accessTypeStatus == EnumAuthStatus.Deleted_Not_Yet_Approve) + .map(x => this.payrollName(x.payrollTypeID)); + } + + /** Unsaved ticks that would give new access. */ + get draftAddNames(): string[] { + return this._selectedPayrollTypes + .filter(id => !(this._userAcessTypes ?? []).some(x => x.payrollTypeID == id)) + .map(id => this.payrollName(id)); + } + + /** Unsaved unticks that would take access away. */ + get draftRemoveNames(): string[] { + return (this._userAcessTypes ?? []) + .filter(x => !this.isPendingStatus(x.accessTypeStatus) && !this.isTicked(x.payrollTypeID)) + .map(x => this.payrollName(x.payrollTypeID)); + } + + /** Badge on one payroll type row: unsaved ticks first, then the saved status. */ + rowBadge(payrollTypeID: number): { text: string, tone: string } { + const saved = this.statusOf(payrollTypeID); + if (!this.hasPending) { + const row = (this._userAcessTypes ?? []).find(x => x.payrollTypeID == payrollTypeID); + if (!row && this.isTicked(payrollTypeID)) { + return { text: 'To be added', tone: 'info' }; + } + if (row && !this.isTicked(payrollTypeID)) { + return { text: 'To be removed', tone: 'info' }; + } + } + return saved; + } + + get hasDraftChanges(): boolean { + return this.draftAddNames.length > 0 || this.draftRemoveNames.length > 0; + } + // ---------- maker-checker ---------- private isPendingStatus(status: EnumAuthStatus): boolean { @@ -156,6 +408,7 @@ export class UserAccessTypeComponent implements OnInit { this.loadingPanel.ShowLoadingPanel = false; this.notificationService.showSuccess(approve ? 'Approved Successfully.' : 'Rejected Successfully.'); this.RefreshGrid(userID); + this.loadPending(); } ); } @@ -245,6 +498,7 @@ export class UserAccessTypeComponent implements OnInit { this.notificationService.showSuccess('Saved. The change is waiting for approval.'); // this.loadGrid(); this.RefreshGrid(this._userAcessTypesforSave[0].userID); + this.loadPending(); } ); diff --git a/HRM.UI/Controllers/Auth/AuthController.cs b/HRM.UI/Controllers/Auth/AuthController.cs index cf8ca05..7aec0e7 100644 --- a/HRM.UI/Controllers/Auth/AuthController.cs +++ b/HRM.UI/Controllers/Auth/AuthController.cs @@ -1684,6 +1684,92 @@ namespace HRM.UI.Controllers return Ok(true); } + // Pending approvals list: every user access change waiting for approval, one row per payroll type. + [HttpGet("GetPendingUserAccessTypes")] + public ActionResult GetPendingUserAccessTypes() + { + try + { + CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); + if (!CanManageUserAccessType(currentUser)) + { + return StatusCode(StatusCodes.Status403Forbidden, "You are not allowed to see user access type approvals."); + } + return Ok(this._userAccessTypeService.GetPending()); + } + catch (Exception e) + { + return StatusCode(StatusCodes.Status500InternalServerError, e.Message); + } + } + + // Checker, many users at once: approves each user's pending change on its own, with the same + // checks as ApproveUserAccessType, so one user that cannot be approved does not stop the rest. + [HttpPost("ApproveUserAccessTypes")] + public ActionResult ApproveUserAccessTypes(List userIDs) + { + return DecideUserAccessTypes(userIDs, true); + } + + // Checker, many users at once: rejects each user's pending change on its own (see ApproveUserAccessTypes). + [HttpPost("RejectUserAccessTypes")] + public ActionResult RejectUserAccessTypes(List userIDs) + { + return DecideUserAccessTypes(userIDs, false); + } + + private ActionResult DecideUserAccessTypes(List userIDs, bool approve) + { + CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); + try + { + if (!CanManageUserAccessType(currentUser)) + { + return StatusCode(StatusCodes.Status403Forbidden, "You are not allowed to approve or reject user access types."); + } + if (userIDs == null || userIDs.Count == 0) + { + return BadRequest("Select at least one user."); + } + } + catch (Exception e) + { + return StatusCode(StatusCodes.Status500InternalServerError, e.Message); + } + + int done = 0; + var failed = new List(); + foreach (int userID in userIDs.Distinct()) + { + try + { + List pending = this._userAccessTypeService.GetByUserID(userID).Where(IsPendingAccess).ToList(); + if (pending.Count == 0) + { + failed.Add(new { userID, message = "No access change waiting for approval." }); + continue; + } + if (pending.Any(x => AccessMakerID(x) == currentUser.UserID)) + { + failed.Add(new { userID, message = "You made this change yourself; another user must decide it." }); + continue; + } + + if (approve) + this._userAccessTypeService.Approve(userID, currentUser.UserID); + else + this._userAccessTypeService.Reject(userID); + done++; + } + catch (Exception e) + { + failed.Add(new { userID, message = e.Message }); + } + } + + return Ok(new { done, failed }); + } + // password history //[HttpGet] //[Route("getPasswordHistoryList")]