Skip to content

Commit

Permalink
ui - use member comment as justification when approving self review r…
Browse files Browse the repository at this point in the history
…oles and grops

Signed-off-by: aporss <[email protected]>
  • Loading branch information
ArtjomsPorss committed Jan 7, 2025
1 parent baf7c7c commit 8349d38
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ui/src/components/pending-approval/PendingApprovalTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
/>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})}
></StyledTextArea>
{this.props.auditRefMissing ? (
<ErrorDiv>Justification is Required</ErrorDiv>
) : null}
Expand Down
60 changes: 60 additions & 0 deletions ui/src/redux/thunks/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit 8349d38

Please sign in to comment.