From 8349d38771049e93637c81e4a57df81a1aa734b0 Mon Sep 17 00:00:00 2001 From: aporss Date: Tue, 7 Jan 2025 16:59:27 +0000 Subject: [PATCH] ui - use member comment as justification when approving self review roles and grops Signed-off-by: aporss --- .../pending-approval/PendingApprovalTable.js | 2 + .../PendingApprovalTableRow.js | 5 +- ui/src/redux/thunks/user.js | 60 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/ui/src/components/pending-approval/PendingApprovalTable.js b/ui/src/components/pending-approval/PendingApprovalTable.js index df1f330156f..51a748af237 100644 --- a/ui/src/components/pending-approval/PendingApprovalTable.js +++ b/ui/src/components/pending-approval/PendingApprovalTable.js @@ -415,6 +415,8 @@ class PendingApprovalTable extends React.Component { pendingState={this.state.pendingMap[key].pendingState} view={view} timeZone={this.props.timeZone} + selfServe={pending.selfServe} + auditRef={pending.auditRef} /> ); }); diff --git a/ui/src/components/pending-approval/PendingApprovalTableRow.js b/ui/src/components/pending-approval/PendingApprovalTableRow.js index a0e377d4544..fc20aa3bc7b 100644 --- a/ui/src/components/pending-approval/PendingApprovalTableRow.js +++ b/ui/src/components/pending-approval/PendingApprovalTableRow.js @@ -215,7 +215,10 @@ export default class PendingApprovalTableRow extends React.Component { onChange={(event) => { this.props.auditRefChange(key, event); }} - /> + {...(this.props.selfServe && { + defaultValue: this.props.auditRef, + })} + > {this.props.auditRefMissing ? ( Justification is Required ) : null} diff --git a/ui/src/redux/thunks/user.js b/ui/src/redux/thunks/user.js index 76b5b025c8e..dce4987af54 100644 --- a/ui/src/redux/thunks/user.js +++ b/ui/src/redux/thunks/user.js @@ -34,6 +34,62 @@ import { loadingSuccess, } from '../actions/loading'; +const ROLE = 'role'; +const GROUP = 'group'; + +const prepareSelfServePendingMembers = async (pendingMembers, category) => { + // SET MEMBER COMMENT AS AUDITREF FOR SELF-SERVE ROLES/GROUPS + // set of domains to search for roles/groups + let domains = new Set(); + Object.keys(pendingMembers).forEach((member) => { + const memberData = pendingMembers[member]; + if (memberData.category !== category) { + // only get domains that match category + return; + } + domains.add(memberData.domainName); + }); + + // get all roles/groups for domains in the set + let promises = []; + domains.forEach((domain) => { + if (category === ROLE) { + promises.push(API().getRoles(domain)); + } else if (category === GROUP) { + promises.push(API().getGroups(domain)); + } + }); + let listOfRolesPerDomain = await Promise.all(promises); + + Object.keys(pendingMembers).forEach((memberName) => { + const member = pendingMembers[memberName]; + if (member.category !== category) { + return; // category is different (can be role or group) + } + // category matches + for (let i = 0; i < listOfRolesPerDomain.length; i++) { + for (let j = 0; j < listOfRolesPerDomain[i].length; j++) { + const roleGroup = listOfRolesPerDomain[i][j]; + if (!roleGroup.selfServe) { + continue; // we only look for self-serve roles/groups + } + const [domain, rest] = roleGroup.name.split(':'); + if (domain !== member.domainName) { + break; // go to next "i" list containing roles/groups for diff domain + } + // domain matches + const [princType, roleGroupName] = rest.split('.'); + if (roleGroupName === member.roleName) { + // role/group name matches member's role/group and is self serve + // set audetRef as provided comment + member.auditRef = member.userComment; + member.selfServe = true; + } + } + } + }); +}; + export const getUserPendingMembers = () => async (dispatch, getState) => { const expiry = getExpiryTime(); try { @@ -44,6 +100,10 @@ export const getUserPendingMembers = () => async (dispatch, getState) => { ) { let userPendingMembersList = await API().getPendingDomainMembersList(); + + await prepareSelfServePendingMembers(userPendingMembersList, ROLE); + await prepareSelfServePendingMembers(userPendingMembersList, GROUP); + dispatch(loadUserPendingMembers(userPendingMembersList, expiry)); } } catch (error) {