chore: Permanent team deletion (#2493)
This commit is contained in:
@ -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,
|
||||
};
|
||||
|
Reference in New Issue
Block a user