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 | |
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')
-rw-r--r-- | server/models/account/account.ts | 21 | ||||
-rw-r--r-- | server/models/activitypub/actor.ts | 25 | ||||
-rw-r--r-- | server/models/video/video-channel.ts | 30 |
3 files changed, 42 insertions, 34 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 2eed66fc2..ce0f3f7c5 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts | |||
@@ -16,8 +16,6 @@ import { | |||
16 | } from 'sequelize-typescript' | 16 | } from 'sequelize-typescript' |
17 | import { Account } from '../../../shared/models/actors' | 17 | import { Account } from '../../../shared/models/actors' |
18 | import { isAccountDescriptionValid } from '../../helpers/custom-validators/accounts' | 18 | import { isAccountDescriptionValid } from '../../helpers/custom-validators/accounts' |
19 | import { logger } from '../../helpers/logger' | ||
20 | import { sendDeleteActor } from '../../lib/activitypub/send' | ||
21 | import { ActorModel } from '../activitypub/actor' | 19 | import { ActorModel } from '../activitypub/actor' |
22 | import { ApplicationModel } from '../application/application' | 20 | import { ApplicationModel } from '../application/application' |
23 | import { AvatarModel } from '../avatar/avatar' | 21 | import { AvatarModel } from '../avatar/avatar' |
@@ -138,12 +136,7 @@ export class AccountModel extends Model<AccountModel> { | |||
138 | instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel | 136 | instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel |
139 | } | 137 | } |
140 | 138 | ||
141 | if (instance.isOwned()) { | 139 | return instance.Actor.destroy({ transaction: options.transaction }) |
142 | logger.debug('Sending delete of actor of account %s.', instance.Actor.url) | ||
143 | return sendDeleteActor(instance.Actor, options.transaction) | ||
144 | } | ||
145 | |||
146 | return undefined | ||
147 | } | 140 | } |
148 | 141 | ||
149 | static load (id: number) { | 142 | static load (id: number) { |
@@ -246,12 +239,12 @@ export class AccountModel extends Model<AccountModel> { | |||
246 | } | 239 | } |
247 | 240 | ||
248 | return AccountModel.findAndCountAll(query) | 241 | return AccountModel.findAndCountAll(query) |
249 | .then(({ rows, count }) => { | 242 | .then(({ rows, count }) => { |
250 | return { | 243 | return { |
251 | data: rows, | 244 | data: rows, |
252 | total: count | 245 | total: count |
253 | } | 246 | } |
254 | }) | 247 | }) |
255 | } | 248 | } |
256 | 249 | ||
257 | toFormattedJSON (): Account { | 250 | toFormattedJSON (): Account { |
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 | } |
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 6567b00d6..33a19f0ff 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts | |||
@@ -1,15 +1,27 @@ | |||
1 | import { | 1 | import { |
2 | AllowNull, BeforeDestroy, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Is, Model, Scopes, Table, | 2 | AllowNull, |
3 | UpdatedAt, Default, DataType | 3 | BeforeDestroy, |
4 | BelongsTo, | ||
5 | Column, | ||
6 | CreatedAt, | ||
7 | DataType, | ||
8 | Default, | ||
9 | DefaultScope, | ||
10 | ForeignKey, | ||
11 | HasMany, | ||
12 | Is, | ||
13 | Model, | ||
14 | Scopes, | ||
15 | Table, | ||
16 | UpdatedAt | ||
4 | } from 'sequelize-typescript' | 17 | } from 'sequelize-typescript' |
5 | import { ActivityPubActor } from '../../../shared/models/activitypub' | 18 | import { ActivityPubActor } from '../../../shared/models/activitypub' |
6 | import { VideoChannel } from '../../../shared/models/videos' | 19 | import { VideoChannel } from '../../../shared/models/videos' |
7 | import { | 20 | import { |
8 | isVideoChannelDescriptionValid, isVideoChannelNameValid, | 21 | isVideoChannelDescriptionValid, |
22 | isVideoChannelNameValid, | ||
9 | isVideoChannelSupportValid | 23 | isVideoChannelSupportValid |
10 | } from '../../helpers/custom-validators/video-channels' | 24 | } from '../../helpers/custom-validators/video-channels' |
11 | import { logger } from '../../helpers/logger' | ||
12 | import { sendDeleteActor } from '../../lib/activitypub/send' | ||
13 | import { AccountModel } from '../account/account' | 25 | import { AccountModel } from '../account/account' |
14 | import { ActorModel } from '../activitypub/actor' | 26 | import { ActorModel } from '../activitypub/actor' |
15 | import { getSort, throwIfNotValid } from '../utils' | 27 | import { getSort, throwIfNotValid } from '../utils' |
@@ -139,13 +151,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
139 | instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel | 151 | instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel |
140 | } | 152 | } |
141 | 153 | ||
142 | if (instance.Actor.isOwned()) { | 154 | return instance.Actor.destroy({ transaction: options.transaction }) |
143 | logger.debug('Sending delete of actor of video channel %s.', instance.Actor.url) | ||
144 | |||
145 | return sendDeleteActor(instance.Actor, options.transaction) | ||
146 | } | ||
147 | |||
148 | return undefined | ||
149 | } | 155 | } |
150 | 156 | ||
151 | static countByAccount (accountId: number) { | 157 | static countByAccount (accountId: number) { |