Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify self-approval mode #2

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading