chore: Permanent team deletion (#2493)

This commit is contained in:
Tom Moor
2021-09-20 20:58:39 -07:00
committed by GitHub
parent a88b54d26d
commit e1601fbe72
10 changed files with 425 additions and 24 deletions

View File

@ -1,10 +1,11 @@
// @flow
import { subDays } from "date-fns";
import Router from "koa-router";
import { documentPermanentDeleter } from "../../commands/documentPermanentDeleter";
import documentPermanentDeleter from "../../commands/documentPermanentDeleter";
import teamPermanentDeleter from "../../commands/teamPermanentDeleter";
import { AuthenticationError } from "../../errors";
import Logger from "../../logging/logger";
import { Document, FileOperation } from "../../models";
import { Document, Team, FileOperation } from "../../models";
import { Op } from "../../sequelize";
const router = new Router();
@ -59,6 +60,25 @@ router.post("utils.gc", async (ctx) => {
})
);
Logger.info(
"utils",
`Permanently destroying upto ${limit} teams older than 30 days…`
);
const teams = await Team.findAll({
where: {
deletedAt: {
[Op.lt]: subDays(new Date(), 30),
},
},
paranoid: false,
limit,
});
for (const team of teams) {
await teamPermanentDeleter(team);
}
ctx.body = {
success: true,
};