server: change data structure to track deletion completion
This commit is contained in:
parent
c7ab8839dc
commit
85e985d13f
7 changed files with 28 additions and 9 deletions
|
@ -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"`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -163,11 +163,11 @@ export class User {
|
||||||
// Indicates the user was deleted by an admin.
|
// Indicates the user was deleted by an admin.
|
||||||
// The users' data is not deleted from the database to keep them from reappearing.
|
// 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.
|
// A hard delete of the record may follow if we receive a matching Delete activity.
|
||||||
@Column('boolean', {
|
@Column('integer', {
|
||||||
default: false,
|
nullable: true,
|
||||||
comment: 'Whether the User is deleted.',
|
comment: 'How many delivery jobs are outstanding before the deletion is completed.',
|
||||||
})
|
})
|
||||||
public isDeleted: boolean;
|
public isDeleted: number | null;
|
||||||
|
|
||||||
@Column('varchar', {
|
@Column('varchar', {
|
||||||
length: 128, array: true, default: '{}',
|
length: 128, array: true, default: '{}',
|
||||||
|
|
|
@ -369,7 +369,7 @@ export const UserRepository = db.getRepository(User).extend({
|
||||||
autoAcceptFollowed: profile!.autoAcceptFollowed,
|
autoAcceptFollowed: profile!.autoAcceptFollowed,
|
||||||
noCrawle: profile!.noCrawle,
|
noCrawle: profile!.noCrawle,
|
||||||
isExplorable: user.isExplorable,
|
isExplorable: user.isExplorable,
|
||||||
isDeleted: user.isDeleted,
|
isDeleted: user.isDeleted != null,
|
||||||
hideOnlineStatus: user.hideOnlineStatus,
|
hideOnlineStatus: user.hideOnlineStatus,
|
||||||
hasUnreadSpecifiedNotes: NoteUnreads.count({
|
hasUnreadSpecifiedNotes: NoteUnreads.count({
|
||||||
where: { userId: user.id, isSpecified: true },
|
where: { userId: user.id, isSpecified: true },
|
||||||
|
|
|
@ -16,7 +16,7 @@ export async function deleteActor(actor: CacheableRemoteUser, uri: string): Prom
|
||||||
// anyway, the user is gone now so dont care
|
// anyway, the user is gone now so dont care
|
||||||
return 'ok: gone';
|
return 'ok: gone';
|
||||||
}
|
}
|
||||||
if (user.isDeleted) {
|
if (user.isDeleted != null) {
|
||||||
// the actual deletion already happened by an admin, just delete the record
|
// the actual deletion already happened by an admin, just delete the record
|
||||||
await Users.delete(actor.id);
|
await Users.delete(actor.id);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { IsNull } from 'typeorm';
|
||||||
import { Users } from '@/models/index.js';
|
import { Users } from '@/models/index.js';
|
||||||
import { ApiError } from '@/server/api/error.js';
|
import { ApiError } from '@/server/api/error.js';
|
||||||
import { deleteAccount } from '@/services/delete-account.js';
|
import { deleteAccount } from '@/services/delete-account.js';
|
||||||
|
@ -24,7 +25,7 @@ export const paramDef = {
|
||||||
export default define(meta, paramDef, async (ps) => {
|
export default define(meta, paramDef, async (ps) => {
|
||||||
const user = await Users.findOneBy({
|
const user = await Users.findOneBy({
|
||||||
id: ps.userId,
|
id: ps.userId,
|
||||||
isDeleted: false,
|
isDeleted: IsNull(),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
|
|
|
@ -27,7 +27,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
Users.findOneByOrFail({ id: user.id }),
|
Users.findOneByOrFail({ id: user.id }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (userDetailed.isDeleted) {
|
if (userDetailed.isDeleted != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ export async function deleteAccount(user: {
|
||||||
host: string | null;
|
host: string | null;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
await Users.update(user.id, {
|
await Users.update(user.id, {
|
||||||
isDeleted: true,
|
isDeleted: -1,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Users.isLocalUser(user)) {
|
if (Users.isLocalUser(user)) {
|
||||||
|
|
Loading…
Reference in a new issue