mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-06-03 14:18:03 +02:00
Remove all user repositories when banning
Use removeQueue instead of cacheQueue so each repo transitions to REMOVING status and is fully deleted, not just cache-cleared.
This commit is contained in:
@@ -810,14 +810,28 @@ router.post(
|
|||||||
"/users/:username/ban",
|
"/users/:username/ban",
|
||||||
async (req: express.Request, res: express.Response) => {
|
async (req: express.Request, res: express.Response) => {
|
||||||
try {
|
try {
|
||||||
const result = await UserModel.updateOne(
|
const user = await UserModel.findOne({ username: req.params.username });
|
||||||
{ username: req.params.username },
|
if (!user) {
|
||||||
{ $set: { status: "banned" } }
|
|
||||||
);
|
|
||||||
if (result.matchedCount === 0) {
|
|
||||||
throw new AnonymousError("user_not_found", { httpStatus: 404 });
|
throw new AnonymousError("user_not_found", { httpStatus: 404 });
|
||||||
}
|
}
|
||||||
res.json({ ok: true });
|
await UserModel.updateOne(
|
||||||
|
{ _id: user._id },
|
||||||
|
{ $set: { status: "banned" } }
|
||||||
|
);
|
||||||
|
const repos = await AnonymizedRepositoryModel.find(
|
||||||
|
{ owner: user._id, status: { $nin: ["removed", "removing"] } },
|
||||||
|
{ repoId: 1 }
|
||||||
|
).lean();
|
||||||
|
let queued = 0;
|
||||||
|
for (const repo of repos) {
|
||||||
|
try {
|
||||||
|
await removeQueue.add(repo.repoId, { repoId: repo.repoId }, { jobId: `repo-${repo.repoId}` });
|
||||||
|
queued++;
|
||||||
|
} catch {
|
||||||
|
// job may already exist in the queue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.json({ ok: true, reposQueued: queued });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, res, req);
|
handleError(error, res, req);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user