From e04551d796adf69703a41af123207b2624237292 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 30 Jul 2018 11:33:58 +0200 Subject: Delete actor too when deleting account/video channel --- server/models/activitypub/actor.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'server/models/activitypub') diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index 267032e2a..f231dba74 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts @@ -3,6 +3,7 @@ import { extname } from 'path' import * as Sequelize from 'sequelize' import { AllowNull, + BeforeDestroy, BelongsTo, Column, CreatedAt, @@ -37,6 +38,8 @@ import { ServerModel } from '../server/server' import { throwIfNotValid } from '../utils' import { VideoChannelModel } from '../video/video-channel' import { ActorFollowModel } from './actor-follow' +import { logger } from '../../helpers/logger' +import { sendDeleteActor } from '../../lib/activitypub/send' enum ScopeNames { FULL = 'FULL' @@ -224,22 +227,28 @@ export class ActorModel extends Model { @HasOne(() => AccountModel, { foreignKey: { - allowNull: true - }, - onDelete: 'cascade', - hooks: true + allowNull: false + } }) Account: AccountModel @HasOne(() => VideoChannelModel, { foreignKey: { - allowNull: true - }, - onDelete: 'cascade', - hooks: true + allowNull: false + } }) VideoChannel: VideoChannelModel + @BeforeDestroy + static async sendDeleteIfOwned (instance: ActorModel, options) { + if (instance.isOwned()) { + logger.debug('Sending delete of actor %s.', instance.url) + return sendDeleteActor(instance, options.transaction) + } + + return undefined + } + static load (id: number) { return ActorModel.unscoped().findById(id) } -- cgit v1.2.3