Skip to content

Commit

Permalink
Simplify self-approval mode
Browse files Browse the repository at this point in the history
Do not ask the user to select an approver when self-approval is enabled
and there are no profile-specific approvers set.
  • Loading branch information
knyar committed Jul 25, 2024
1 parent 49ab052 commit f4be127
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions functions/access_request_prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,41 @@ async function buildView(
async function buildApproverBlock(
client: SlackAPIClient,
userId?: string,
showSelf?: boolean,
canSelfApprove?: boolean,
emails?: string[],
) {
if (!emails?.length && canSelfApprove) {
return {
block_id: "approver",
type: "input",
label: {
type: "plain_text",
emoji: true,
text: ":sleuth_or_spy: Who should approve?",
},
element: {
action_id: ACTION_APPROVER,
type: "radio_buttons",
initial_option: {
value: userId,
text: {
type: "plain_text",
text: "No approval neeeded",
},
},
options: [
{
value: userId,
text: {
type: "plain_text",
text: "No approval neeeded",
},
},
],
},
};
}

if (!emails?.length || emails.length > 10) {
// We can't use radio buttons for this.
return {
Expand Down Expand Up @@ -547,7 +579,7 @@ async function buildApproverBlock(
// Filter the list of approvers to successful responses.
const approvers = users.filter((u) =>
u.ok && u.user && !u.user.deleted &&
(showSelf || emails.length == 1 || u.user.id != userId)
(canSelfApprove || emails.length == 1 || u.user.id != userId)
);

// Warn about any users who could not be found by email.
Expand Down

0 comments on commit f4be127

Please sign in to comment.