From 9b45c9bf8920c24eabe91ab65cf27aeb19ad9599 Mon Sep 17 00:00:00 2001 From: BlackAngelTV Date: Sun, 6 Dec 2026 17:18:11 +0100 Subject: [PATCH] feat(gitea): require a reason when the team refuses an application 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. --- .../migrations/014-gitea-rejection-reason.sql | 6 + .../gitea-recruitment-repository.js | 6 +- src/services/gitea/team-recruitment.js | 104 ++++++++++++++---- tests/team-recruitment.test.js | 28 +++++ 4 files changed, 122 insertions(+), 22 deletions(-) create mode 100644 src/database/migrations/014-gitea-rejection-reason.sql diff --git a/src/database/migrations/014-gitea-rejection-reason.sql b/src/database/migrations/014-gitea-rejection-reason.sql new file mode 100644 index 0000000..516b80a --- /dev/null +++ b/src/database/migrations/014-gitea-rejection-reason.sql @@ -0,0 +1,6 @@ +-- Reason shown to the applicant when the team refuses an application. +-- +-- A refusal without a reason reads as a rejection of the person; the team writes +-- one sentence and the bot forwards it verbatim in the DM. + +ALTER TABLE gitea_applications ADD COLUMN rejection_reason TEXT; diff --git a/src/database/repositories/gitea-recruitment-repository.js b/src/database/repositories/gitea-recruitment-repository.js index 1428344..6e9eb51 100644 --- a/src/database/repositories/gitea-recruitment-repository.js +++ b/src/database/repositories/gitea-recruitment-repository.js @@ -84,14 +84,14 @@ export function releaseApplication(id) { .run(id).changes; } -export function rejectApplication(id, reviewerId) { +export function rejectApplication(id, reviewerId, reason = null) { return getDatabase() .prepare( `UPDATE gitea_applications - SET status = 'rejected', reviewed_by = ?, reviewed_at = datetime('now') + SET status = 'rejected', reviewed_by = ?, reviewed_at = datetime('now'), rejection_reason = ? WHERE id = ? AND status = 'pending'`, ) - .run(reviewerId, id).changes; + .run(reviewerId, reason, id).changes; } export function setApplicationGiteaUser(id, giteaUserId) { diff --git a/src/services/gitea/team-recruitment.js b/src/services/gitea/team-recruitment.js index 4c3b421..3eae769 100644 --- a/src/services/gitea/team-recruitment.js +++ b/src/services/gitea/team-recruitment.js @@ -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}`); + } } } diff --git a/tests/team-recruitment.test.js b/tests/team-recruitment.test.js index 23f2fdc..7d67b65 100644 --- a/tests/team-recruitment.test.js +++ b/tests/team-recruitment.test.js @@ -18,6 +18,7 @@ import { ensureRecruitmentPanel, generatePassword, openApplicationModal, + openRejectionModal, validateEmail, validateGiteaUsername, } from '../src/services/gitea/team-recruitment.js'; @@ -69,6 +70,25 @@ describe('application answers', () => { ['languages', 'level', 'experience', 'username', 'email'], ); }); + + /** A refusal must carry a written reason, not a silent click. */ + it('asks the team for a reason when it refuses an application', async () => { + let shown; + await openRejectionModal( + { + showModal: async (modal) => { + shown = modal.toJSON(); + }, + }, + { id: 7 }, + ); + + assert.equal(shown.custom_id, 'gitea-team:reject:7'); + assert.equal(shown.components.length, 1); + assert.equal(shown.components[0].components[0].custom_id, 'reason'); + assert.equal(shown.components[0].components[0].style, 2, 'the reason is a paragraph'); + assert.equal(shown.components[0].components[0].required, true); + }); }); describe('recruitment repository', () => { @@ -134,6 +154,14 @@ describe('recruitment repository', () => { assert.equal(rejectApplication(id, 'staff'), 0); }); + it('keeps the reason of the refusal for the member', () => { + const id = apply(); + + rejectApplication(id, 'staff', 'Il manque une présentation sur le salon.'); + + assert.equal(getApplication(id).rejection_reason, 'Il manque une présentation sur le salon.'); + }); + it('keeps one panel row per guild and updates it', () => { assert.equal(getRecruitmentPanel(GUILD_ID), null); });