feat(gitea): recruit developers from a Discord panel into FWS
Recruited people need a Gitea account without a public signup on the forge. The panel posts in its own Gitea category, the single modal keeps the whole application in one gesture, and acceptance creates a restricted account in the FWS organization, adds it to the Dev team, grants the Discord Dev role and sends the temporary password by DM. Restrictions keep the new account working inside the organization only, with no personal repository of its own.
This commit is contained in:
14 files changed
+1269
-10
No files matched your search
@@ -0,0 +1,40 @@
|
||||
-- Gitea team recruitment (M20)
|
||||
--
|
||||
-- Applications are stored before the team reviews them: the panel is pressed by
|
||||
-- members, not staff, so losing an application on restart would mean asking
|
||||
-- someone to fill the whole form again. The panel message is remembered too, so
|
||||
-- re-running the installation edits it instead of stacking a second copy.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS gitea_applications (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
guild_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
languages TEXT NOT NULL,
|
||||
level TEXT NOT NULL,
|
||||
experience TEXT,
|
||||
gitea_username TEXT NOT NULL,
|
||||
email TEXT NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'accepted', 'rejected')),
|
||||
channel_id TEXT,
|
||||
message_id TEXT,
|
||||
reviewed_by TEXT,
|
||||
reviewed_at TEXT,
|
||||
gitea_user_id INTEGER,
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
-- One open application per member: a second one would give the team two
|
||||
-- buttons for the same person and could create their Gitea account twice.
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_gitea_applications_pending_member
|
||||
ON gitea_applications (guild_id, user_id) WHERE status = 'pending';
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_gitea_applications_status
|
||||
ON gitea_applications (guild_id, status);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS gitea_recruitment_panels (
|
||||
guild_id TEXT PRIMARY KEY,
|
||||
category_id TEXT,
|
||||
channel_id TEXT NOT NULL,
|
||||
message_id TEXT,
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
@@ -0,0 +1,129 @@
|
||||
import { getDatabase } from '../index.js';
|
||||
|
||||
// --- Applications -----------------------------------------------------------
|
||||
|
||||
export function createApplication({
|
||||
guildId,
|
||||
userId,
|
||||
languages,
|
||||
level,
|
||||
experience = null,
|
||||
giteaUsername,
|
||||
email,
|
||||
}) {
|
||||
const { lastInsertRowid } = getDatabase()
|
||||
.prepare(
|
||||
`INSERT INTO gitea_applications
|
||||
(guild_id, user_id, languages, level, experience, gitea_username, email)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
||||
)
|
||||
.run(guildId, userId, languages, level, experience, giteaUsername, email);
|
||||
return Number(lastInsertRowid);
|
||||
}
|
||||
|
||||
export function getApplication(id) {
|
||||
return getDatabase().prepare('SELECT * FROM gitea_applications WHERE id = ?').get(id) ?? null;
|
||||
}
|
||||
|
||||
export function getPendingApplicationByMember({ guildId, userId }) {
|
||||
return (
|
||||
getDatabase()
|
||||
.prepare(
|
||||
`SELECT * FROM gitea_applications
|
||||
WHERE guild_id = ? AND user_id = ? AND status = 'pending'`,
|
||||
)
|
||||
.get(guildId, userId) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
/** Gitea compares usernames without case, so the pending check must too. */
|
||||
export function getPendingApplicationByUsername({ guildId, username }) {
|
||||
return (
|
||||
getDatabase()
|
||||
.prepare(
|
||||
`SELECT * FROM gitea_applications
|
||||
WHERE guild_id = ? AND status = 'pending' AND lower(gitea_username) = lower(?)`,
|
||||
)
|
||||
.get(guildId, username) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
export function listPendingApplications({ guildId, limit = 25 }) {
|
||||
return getDatabase()
|
||||
.prepare(
|
||||
`SELECT * FROM gitea_applications
|
||||
WHERE guild_id = ? AND status = 'pending'
|
||||
ORDER BY id ASC LIMIT ?`,
|
||||
)
|
||||
.all(guildId, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserves an application before the Gitea call: the conditional update makes
|
||||
* the second click on « Accepter » lose the race instead of creating a second
|
||||
* account.
|
||||
*/
|
||||
export function claimApplication(id, reviewerId) {
|
||||
return getDatabase()
|
||||
.prepare(
|
||||
`UPDATE gitea_applications
|
||||
SET status = 'accepted', reviewed_by = ?, reviewed_at = datetime('now')
|
||||
WHERE id = ? AND status = 'pending'`,
|
||||
)
|
||||
.run(reviewerId, id).changes;
|
||||
}
|
||||
|
||||
/** Puts a claimed application back in the queue after a failed Gitea call. */
|
||||
export function releaseApplication(id) {
|
||||
return getDatabase()
|
||||
.prepare(
|
||||
`UPDATE gitea_applications
|
||||
SET status = 'pending', reviewed_by = NULL, reviewed_at = NULL, gitea_user_id = NULL
|
||||
WHERE id = ? AND status = 'accepted'`,
|
||||
)
|
||||
.run(id).changes;
|
||||
}
|
||||
|
||||
export function rejectApplication(id, reviewerId) {
|
||||
return getDatabase()
|
||||
.prepare(
|
||||
`UPDATE gitea_applications
|
||||
SET status = 'rejected', reviewed_by = ?, reviewed_at = datetime('now')
|
||||
WHERE id = ? AND status = 'pending'`,
|
||||
)
|
||||
.run(reviewerId, id).changes;
|
||||
}
|
||||
|
||||
export function setApplicationGiteaUser(id, giteaUserId) {
|
||||
return getDatabase()
|
||||
.prepare('UPDATE gitea_applications SET gitea_user_id = ? WHERE id = ?')
|
||||
.run(giteaUserId ?? null, id).changes;
|
||||
}
|
||||
|
||||
export function setApplicationMessage(id, { channelId, messageId }) {
|
||||
return getDatabase()
|
||||
.prepare('UPDATE gitea_applications SET channel_id = ?, message_id = ? WHERE id = ?')
|
||||
.run(channelId, messageId, id).changes;
|
||||
}
|
||||
|
||||
// --- Recruitment panel ------------------------------------------------------
|
||||
|
||||
export function getRecruitmentPanel(guildId) {
|
||||
return (
|
||||
getDatabase().prepare('SELECT * FROM gitea_recruitment_panels WHERE guild_id = ?').get(guildId) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
export function setRecruitmentPanel({ guildId, categoryId, channelId, messageId }) {
|
||||
getDatabase()
|
||||
.prepare(
|
||||
`INSERT INTO gitea_recruitment_panels (guild_id, category_id, channel_id, message_id)
|
||||
VALUES (?, ?, ?, ?)
|
||||
ON CONFLICT (guild_id) DO UPDATE SET
|
||||
category_id = excluded.category_id,
|
||||
channel_id = excluded.channel_id,
|
||||
message_id = excluded.message_id,
|
||||
updated_at = datetime('now')`,
|
||||
)
|
||||
.run(guildId, categoryId ?? null, channelId, messageId ?? null);
|
||||
}
|
||||
Reference in new issue
Block a user