feat(gitea): use a dedicated admin token for recruitment
CI / quality (push) Failing after 45s

Recruitment needs `write:admin` and `write:organization`, which the everyday
token must not carry. A second token keeps the repository and issue scopes
least privileged, falls back to `GITEA_TOKEN` so existing installs keep
working, and a 403 now names the missing scope instead of pretending Gitea
did not answer.
This commit is contained in:
BlackAngelTV committed 2026-12-06 18:01:43 +01:00
1 parent 9b45c9bf89
commit adc96e4d75
9 files changed
+141 -34

No files matched your search

+19 -13
View File
@@ -30,7 +30,7 @@ import {
setRecruitmentPanel,
} from '../../database/repositories/gitea-recruitment-repository.js';
import { baseEmbed, bullets, errorEmbed, successEmbed, warningEmbed } from '../../ui/embeds.js';
import { asList, findGiteaUser, gitea, isGiteaConfigured } from './gitea-client.js';
import { asList, findGiteaUser, giteaRecruitment, isGiteaRecruitmentConfigured } from './gitea-client.js';
import { replyGiteaFailure } from './gitea-modals.js';
/**
@@ -399,9 +399,9 @@ async function submitApplication(interaction) {
const emailError = validateEmail(email);
if (emailError) throw new UserFacingError(emailError);
if (!isGiteaConfigured()) {
if (!isGiteaRecruitmentConfigured()) {
throw new UserFacingError(
'Le recrutement Gitea n’est pas encore configuré : l’équipe doit renseigner `GITEA_URL` et `GITEA_TOKEN`. Réessaie plus tard.',
'Le recrutement Gitea n’est pas encore configuré : l’équipe doit renseigner `GITEA_URL` et `GITEA_RECRUITMENT_TOKEN`. Réessaie plus tard.',
);
}
@@ -476,7 +476,7 @@ async function submitApplication(interaction) {
*/
export async function lockGiteaAccount(username) {
try {
await gitea.updateUser(username, {
await giteaRecruitment.updateUser(username, {
restricted: true,
max_repo_creation: 0,
allow_create_organization: false,
@@ -497,11 +497,11 @@ export async function addToDeveloperTeam(username) {
const teamName = env.gitea.devTeam;
if (!org || !teamName) return { added: false, reason: 'organisation ou équipe non configurée' };
const teams = asList(await gitea.listTeams(org));
const teams = asList(await giteaRecruitment.listTeams(org));
const team = teams.find((entry) => String(entry.name).toLowerCase() === teamName.toLowerCase());
if (!team) return { added: false, reason: `équipe « ${teamName} » introuvable dans ${org}` };
await gitea.addTeamMember(team.id, username);
await giteaRecruitment.addTeamMember(team.id, username);
return { added: true, team: team.name };
}
@@ -540,9 +540,9 @@ function credentialsEmbed(username, password) {
}
async function acceptApplication(interaction, application) {
if (!isGiteaConfigured()) {
if (!isGiteaRecruitmentConfigured()) {
throw new UserFacingError(
'Gitea n’est pas configuré (`GITEA_URL` et `GITEA_TOKEN`) : impossible de créer le compte pour l’instant.',
'Gitea n’est pas configuré (`GITEA_URL` et `GITEA_RECRUITMENT_TOKEN`) : impossible de créer le compte pour l’instant.',
);
}
@@ -555,7 +555,7 @@ async function acceptApplication(interaction, application) {
let created;
try {
created = await gitea.createUser({
created = await giteaRecruitment.createUser({
username: application.gitea_username,
email: application.email,
password,
@@ -564,10 +564,16 @@ async function acceptApplication(interaction, application) {
} catch (error) {
releaseApplication(application.id);
log.error('Gitea refused a team account creation', error);
const reason =
error.status === 422
? 'Gitea a refusé : ce nom ou cette adresse e-mail est déjà utilisé. Demande au membre d’en choisir un autre.'
: 'Gitea n’a pas répondu. La candidature reste en attente : réessaie plus tard.';
let reason = 'Gitea n’a pas répondu. La candidature reste en attente : réessaie plus tard.';
if (error.status === 422) {
reason =
'Gitea a refusé : ce nom ou cette adresse e-mail est déjà utilisé. Demande au membre d’en choisir un autre.';
}
if (error.status === 403) {
reason =
'Gitea a refusé l’appel : le jeton de recrutement n’a pas les droits d’administration. ' +
'Il lui faut la portée `write:admin` (`GITEA_RECRUITMENT_TOKEN`).';
}
await interaction.followUp({
embeds: [errorEmbed(reason)],
flags: MessageFlags.Ephemeral,