diff options
author | Chocobozzz <me@florianbigard.com> | 2018-07-30 11:33:58 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-07-30 11:34:34 +0200 |
commit | e04551d796adf69703a41af123207b2624237292 (patch) | |
tree | e5e306785e417d66cb60a1dcff7fe038dd2049cf /server/models/activitypub | |
parent | e20015d744fe9d637bfa6924194f54eecbbd6722 (diff) | |
download | PeerTube-e04551d796adf69703a41af123207b2624237292.tar.gz PeerTube-e04551d796adf69703a41af123207b2624237292.tar.zst PeerTube-e04551d796adf69703a41af123207b2624237292.zip |
Delete actor too when deleting account/video channel
Diffstat (limited to 'server/models/activitypub')
-rw-r--r-- | server/models/activitypub/actor.ts | 25 |
1 files changed, 17 insertions, 8 deletions
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' | |||
3 | import * as Sequelize from 'sequelize' | 3 | import * as Sequelize from 'sequelize' |
4 | import { | 4 | import { |
5 | AllowNull, | 5 | AllowNull, |
6 | BeforeDestroy, | ||
6 | BelongsTo, | 7 | BelongsTo, |
7 | Column, | 8 | Column, |
8 | CreatedAt, | 9 | CreatedAt, |
@@ -37,6 +38,8 @@ import { ServerModel } from '../server/server' | |||
37 | import { throwIfNotValid } from '../utils' | 38 | import { throwIfNotValid } from '../utils' |
38 | import { VideoChannelModel } from '../video/video-channel' | 39 | import { VideoChannelModel } from '../video/video-channel' |
39 | import { ActorFollowModel } from './actor-follow' | 40 | import { ActorFollowModel } from './actor-follow' |
41 | import { logger } from '../../helpers/logger' | ||
42 | import { sendDeleteActor } from '../../lib/activitypub/send' | ||
40 | 43 | ||
41 | enum ScopeNames { | 44 | enum ScopeNames { |
42 | FULL = 'FULL' | 45 | FULL = 'FULL' |
@@ -224,22 +227,28 @@ export class ActorModel extends Model<ActorModel> { | |||
224 | 227 | ||
225 | @HasOne(() => AccountModel, { | 228 | @HasOne(() => AccountModel, { |
226 | foreignKey: { | 229 | foreignKey: { |
227 | allowNull: true | 230 | allowNull: false |
228 | }, | 231 | } |
229 | onDelete: 'cascade', | ||
230 | hooks: true | ||
231 | }) | 232 | }) |
232 | Account: AccountModel | 233 | Account: AccountModel |
233 | 234 | ||
234 | @HasOne(() => VideoChannelModel, { | 235 | @HasOne(() => VideoChannelModel, { |
235 | foreignKey: { | 236 | foreignKey: { |
236 | allowNull: true | 237 | allowNull: false |
237 | }, | 238 | } |
238 | onDelete: 'cascade', | ||
239 | hooks: true | ||
240 | }) | 239 | }) |
241 | VideoChannel: VideoChannelModel | 240 | VideoChannel: VideoChannelModel |
242 | 241 | ||
242 | @BeforeDestroy | ||
243 | static async sendDeleteIfOwned (instance: ActorModel, options) { | ||
244 | if (instance.isOwned()) { | ||
245 | logger.debug('Sending delete of actor %s.', instance.url) | ||
246 | return sendDeleteActor(instance, options.transaction) | ||
247 | } | ||
248 | |||
249 | return undefined | ||
250 | } | ||
251 | |||
243 | static load (id: number) { | 252 | static load (id: number) { |
244 | return ActorModel.unscoped().findById(id) | 253 | return ActorModel.unscoped().findById(id) |
245 | } | 254 | } |