feat(gitea): require a reason when the team refuses an application
CI / quality (push) Failing after 58s
CI / quality (push) Failing after 58s
A refusal without a reason leaves the member guessing why, which makes the recruitment feel arbitrary. The reject button now opens a modal, the reason is stored with the application, added to the review message and sent verbatim in the DM; when the DM cannot be delivered, the team gets it back to pass along.
This commit is contained in:
4 files changed
+122
-22
No files matched your search
@@ -309,6 +309,9 @@ function applicationEmbed(application, { reviewedBy = null } = {}) {
|
||||
{ name: 'Statut', value: statusLabel, inline: true },
|
||||
);
|
||||
|
||||
if (application.rejection_reason) {
|
||||
embed.addFields({ name: 'Raison du refus', value: String(application.rejection_reason).slice(0, 1000) });
|
||||
}
|
||||
if (reviewedBy) embed.addFields({ name: 'Traitée par', value: `<@${reviewedBy}>` });
|
||||
return embed;
|
||||
}
|
||||
@@ -466,10 +469,6 @@ async function submitApplication(interaction) {
|
||||
|
||||
// --- Review ------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Puts the new account in the organization's developer team. Recruited people
|
||||
* have no other organization, so this team is the only place they can work.
|
||||
*/
|
||||
/**
|
||||
* Removes what a recruited account could do outside the organization: no
|
||||
* personal repositories, no organization of its own. The team still allows
|
||||
@@ -489,6 +488,10 @@ export async function lockGiteaAccount(username) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the new account in the organization's developer team. Recruited people
|
||||
* have no other organization, so this team is the only place they can work.
|
||||
*/
|
||||
export async function addToDeveloperTeam(username) {
|
||||
const org = env.gitea.org;
|
||||
const teamName = env.gitea.devTeam;
|
||||
@@ -641,8 +644,56 @@ async function acceptApplication(interaction, application) {
|
||||
}
|
||||
}
|
||||
|
||||
async function rejectApplicationFlow(interaction, application) {
|
||||
if (rejectApplication(application.id, interaction.user.id) === 0) {
|
||||
/**
|
||||
* A refusal is written, not clicked away: the modal makes the reason mandatory,
|
||||
* and it is the only thing the member gets to read.
|
||||
*/
|
||||
export async function openRejectionModal(interaction, application) {
|
||||
await interaction.showModal(
|
||||
modal(`gitea-team:reject:${application.id}`, `Refus de la candidature #${application.id}`, [
|
||||
{
|
||||
id: 'reason',
|
||||
label: 'Pourquoi cette candidature est refusée',
|
||||
paragraph: true,
|
||||
maxLength: 500,
|
||||
placeholder: 'Le membre reçoit ce texte : sois précis et courtois.',
|
||||
},
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
function rejectionEmbed(reason) {
|
||||
return baseEmbed(COLORS.info)
|
||||
.setTitle('Ta candidature Gitea')
|
||||
.setDescription('Merci d’avoir postulé ! L’équipe n’a pas retenu ta candidature cette fois.')
|
||||
.addFields(
|
||||
{ name: 'La raison', value: String(reason).slice(0, 1000) },
|
||||
{
|
||||
name: 'Et ensuite',
|
||||
value: 'Tu peux continuer à contribuer sur le serveur et retenter plus tard.',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
async function submitRejection(interaction, idText) {
|
||||
if (!hasAccess(interaction.member, ACCESS_LEVELS.STAFF)) {
|
||||
throw new PermissionDeniedError('Seule l’équipe peut refuser une candidature.');
|
||||
}
|
||||
|
||||
const application = getApplication(Number.parseInt(idText, 10));
|
||||
if (!application) throw new UserFacingError('Cette candidature n’existe plus.');
|
||||
if (application.status !== 'pending') {
|
||||
throw new UserFacingError(
|
||||
`Cette candidature est déjà ${application.status === 'accepted' ? 'acceptée' : 'refusée'}.`,
|
||||
);
|
||||
}
|
||||
|
||||
const reason = interaction.fields.getTextInputValue('reason').trim();
|
||||
if (reason === '') {
|
||||
throw new UserFacingError('Indique la raison du refus : elle est envoyée au membre.');
|
||||
}
|
||||
|
||||
if (rejectApplication(application.id, interaction.user.id, reason) === 0) {
|
||||
throw new UserFacingError('Cette candidature vient d’être traitée par quelqu’un d’autre.');
|
||||
}
|
||||
|
||||
@@ -650,16 +701,7 @@ async function rejectApplicationFlow(interaction, application) {
|
||||
|
||||
const applicant = await interaction.client.users.fetch(application.user_id).catch(() => null);
|
||||
const notified = await applicant
|
||||
?.send({
|
||||
embeds: [
|
||||
baseEmbed(COLORS.info)
|
||||
.setTitle('Ta candidature Gitea')
|
||||
.setDescription(
|
||||
'Merci d’avoir postulé ! L’équipe n’a pas retenu ta candidature cette fois. ' +
|
||||
'Tu peux continuer à contribuer sur le serveur et retenter plus tard.',
|
||||
),
|
||||
],
|
||||
})
|
||||
?.send({ embeds: [rejectionEmbed(reason)] })
|
||||
.then(() => true)
|
||||
.catch(() => false);
|
||||
|
||||
@@ -671,9 +713,27 @@ async function rejectApplicationFlow(interaction, application) {
|
||||
});
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [applicationEmbed({ ...application, status: 'rejected' }, { reviewedBy: interaction.user.id })],
|
||||
embeds: [
|
||||
applicationEmbed(
|
||||
{ ...application, status: 'rejected', rejection_reason: reason },
|
||||
{ reviewedBy: interaction.user.id },
|
||||
),
|
||||
],
|
||||
components: [],
|
||||
});
|
||||
|
||||
if (!notified) {
|
||||
// The refusal is still recorded: the team can pass the reason along itself.
|
||||
await interaction.followUp({
|
||||
embeds: [
|
||||
errorEmbed(
|
||||
`Je n’ai pas pu écrire à <@${application.user_id}> (messages privés fermés). ` +
|
||||
`Transmets-lui la raison toi-même : « ${reason} »`,
|
||||
),
|
||||
],
|
||||
flags: MessageFlags.Ephemeral,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function reviewApplication(interaction, decision, idText) {
|
||||
@@ -692,7 +752,7 @@ export async function reviewApplication(interaction, decision, idText) {
|
||||
}
|
||||
|
||||
if (decision === 'reject') {
|
||||
await rejectApplicationFlow(interaction, application);
|
||||
await openRejectionModal(interaction, application);
|
||||
return;
|
||||
}
|
||||
await acceptApplication(interaction, application);
|
||||
@@ -722,7 +782,13 @@ export async function handleTeamModal(interaction) {
|
||||
case 'gitea-team:panel':
|
||||
await submitPanelEditor(interaction);
|
||||
return;
|
||||
default:
|
||||
default: {
|
||||
const rejection = /^gitea-team:reject:(\d+)$/.exec(interaction.customId);
|
||||
if (rejection) {
|
||||
await submitRejection(interaction, rejection[1]);
|
||||
return;
|
||||
}
|
||||
log.debug(`Ignored unknown recruitment modal ${interaction.customId}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user