server: change data structure to track deletion completion

This commit is contained in:
Johann150 2023-01-08 17:57:36 +01:00
parent c7ab8839dc
commit 85e985d13f
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
7 changed files with 28 additions and 9 deletions

View file

@ -0,0 +1,18 @@
export class deletionProgress1673201544000 {
name = 'deletionProgress1673201544000';
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "user" RENAME COLUMN "isDeleted" TO "isDeletedOld"`);
await queryRunner.query(`ALTER TABLE "user" ADD "isDeleted" integer`);
await queryRunner.query(`UPDATE "user" SET "isDeleted" = CASE WHEN "host" IS NULL THEN -1 ELSE 0 END WHERE "isDeletedOld"`);
await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "isDeletedOld"`);
}
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "user" RENAME COLUMN "isDeleted" TO "isDeletedOld"`);
await queryRunner.query(`ALTER TABLE "user" ADD "isDeleted" boolean NOT NULL DEFAULT false`);
await queryRunner.query(`UPDATE "user" SET "isDeleted" = "isDeletedOld" IS NOT NULL`);
await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "isDeletedOld"`);
}
}

View file

@ -163,11 +163,11 @@ export class User {
// Indicates the user was deleted by an admin.
// The users' data is not deleted from the database to keep them from reappearing.
// A hard delete of the record may follow if we receive a matching Delete activity.
@Column('boolean', {
default: false,
comment: 'Whether the User is deleted.',
@Column('integer', {
nullable: true,
comment: 'How many delivery jobs are outstanding before the deletion is completed.',
})
public isDeleted: boolean;
public isDeleted: number | null;
@Column('varchar', {
length: 128, array: true, default: '{}',

View file

@ -369,7 +369,7 @@ export const UserRepository = db.getRepository(User).extend({
autoAcceptFollowed: profile!.autoAcceptFollowed,
noCrawle: profile!.noCrawle,
isExplorable: user.isExplorable,
isDeleted: user.isDeleted,
isDeleted: user.isDeleted != null,
hideOnlineStatus: user.hideOnlineStatus,
hasUnreadSpecifiedNotes: NoteUnreads.count({
where: { userId: user.id, isSpecified: true },

View file

@ -16,7 +16,7 @@ export async function deleteActor(actor: CacheableRemoteUser, uri: string): Prom
// anyway, the user is gone now so dont care
return 'ok: gone';
}
if (user.isDeleted) {
if (user.isDeleted != null) {
// the actual deletion already happened by an admin, just delete the record
await Users.delete(actor.id);
} else {

View file

@ -1,3 +1,4 @@
import { IsNull } from 'typeorm';
import { Users } from '@/models/index.js';
import { ApiError } from '@/server/api/error.js';
import { deleteAccount } from '@/services/delete-account.js';
@ -24,7 +25,7 @@ export const paramDef = {
export default define(meta, paramDef, async (ps) => {
const user = await Users.findOneBy({
id: ps.userId,
isDeleted: false,
isDeleted: IsNull(),
});
if (user == null) {

View file

@ -27,7 +27,7 @@ export default define(meta, paramDef, async (ps, user) => {
Users.findOneByOrFail({ id: user.id }),
]);
if (userDetailed.isDeleted) {
if (userDetailed.isDeleted != null) {
return;
}

View file

@ -8,7 +8,7 @@ export async function deleteAccount(user: {
host: string | null;
}): Promise<void> {
await Users.update(user.id, {
isDeleted: true,
isDeleted: -1,
});
if (Users.isLocalUser(user)) {