feat(gitea): require a reason when the team refuses an application
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:
BlackAngelTV committed 2026-12-06 17:18:11 +01:00
1 parent 6f3ec439d4
commit 9b45c9bf89
4 files changed
+122 -22

No files matched your search

@@ -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;
@@ -84,14 +84,14 @@ export function releaseApplication(id) {
.run(id).changes; .run(id).changes;
} }
export function rejectApplication(id, reviewerId) { export function rejectApplication(id, reviewerId, reason = null) {
return getDatabase() return getDatabase()
.prepare( .prepare(
`UPDATE gitea_applications `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'`, WHERE id = ? AND status = 'pending'`,
) )
.run(reviewerId, id).changes; .run(reviewerId, reason, id).changes;
} }
export function setApplicationGiteaUser(id, giteaUserId) { export function setApplicationGiteaUser(id, giteaUserId) {
+85 -19
View File
@@ -309,6 +309,9 @@ function applicationEmbed(application, { reviewedBy = null } = {}) {
{ name: 'Statut', value: statusLabel, inline: true }, { 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}>` }); if (reviewedBy) embed.addFields({ name: 'Traitée par', value: `<@${reviewedBy}>` });
return embed; return embed;
} }
@@ -466,10 +469,6 @@ async function submitApplication(interaction) {
// --- Review ------------------------------------------------------------------ // --- 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 * Removes what a recruited account could do outside the organization: no
* personal repositories, no organization of its own. The team still allows * 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) { export async function addToDeveloperTeam(username) {
const org = env.gitea.org; const org = env.gitea.org;
const teamName = env.gitea.devTeam; 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.'); 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 applicant = await interaction.client.users.fetch(application.user_id).catch(() => null);
const notified = await applicant const notified = await applicant
?.send({ ?.send({ embeds: [rejectionEmbed(reason)] })
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.',
),
],
})
.then(() => true) .then(() => true)
.catch(() => false); .catch(() => false);
@@ -671,9 +713,27 @@ async function rejectApplicationFlow(interaction, application) {
}); });
await interaction.editReply({ 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: [], 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) { export async function reviewApplication(interaction, decision, idText) {
@@ -692,7 +752,7 @@ export async function reviewApplication(interaction, decision, idText) {
} }
if (decision === 'reject') { if (decision === 'reject') {
await rejectApplicationFlow(interaction, application); await openRejectionModal(interaction, application);
return; return;
} }
await acceptApplication(interaction, application); await acceptApplication(interaction, application);
@@ -722,7 +782,13 @@ export async function handleTeamModal(interaction) {
case 'gitea-team:panel': case 'gitea-team:panel':
await submitPanelEditor(interaction); await submitPanelEditor(interaction);
return; 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}`); log.debug(`Ignored unknown recruitment modal ${interaction.customId}`);
} }
}
} }
+28
View File
@@ -18,6 +18,7 @@ import {
ensureRecruitmentPanel, ensureRecruitmentPanel,
generatePassword, generatePassword,
openApplicationModal, openApplicationModal,
openRejectionModal,
validateEmail, validateEmail,
validateGiteaUsername, validateGiteaUsername,
} from '../src/services/gitea/team-recruitment.js'; } from '../src/services/gitea/team-recruitment.js';
@@ -69,6 +70,25 @@ describe('application answers', () => {
['languages', 'level', 'experience', 'username', 'email'], ['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', () => { describe('recruitment repository', () => {
@@ -134,6 +154,14 @@ describe('recruitment repository', () => {
assert.equal(rejectApplication(id, 'staff'), 0); 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', () => { it('keeps one panel row per guild and updates it', () => {
assert.equal(getRecruitmentPanel(GUILD_ID), null); assert.equal(getRecruitmentPanel(GUILD_ID), null);
}); });