diff options
Diffstat (limited to 'server/models')
-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, 34 insertions, 42 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts index ce0f3f7c5..2eed66fc2 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts | |||
@@ -16,6 +16,8 @@ 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' | ||
19 | import { ActorModel } from '../activitypub/actor' | 21 | import { ActorModel } from '../activitypub/actor' |
20 | import { ApplicationModel } from '../application/application' | 22 | import { ApplicationModel } from '../application/application' |
21 | import { AvatarModel } from '../avatar/avatar' | 23 | import { AvatarModel } from '../avatar/avatar' |
@@ -136,7 +138,12 @@ export class AccountModel extends Model<AccountModel> { | |||
136 | instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel | 138 | instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel |
137 | } | 139 | } |
138 | 140 | ||
139 | return instance.Actor.destroy({ transaction: options.transaction }) | 141 | if (instance.isOwned()) { |
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 | ||
140 | } | 147 | } |
141 | 148 | ||
142 | static load (id: number) { | 149 | static load (id: number) { |
@@ -239,12 +246,12 @@ export class AccountModel extends Model<AccountModel> { | |||
239 | } | 246 | } |
240 | 247 | ||
241 | return AccountModel.findAndCountAll(query) | 248 | return AccountModel.findAndCountAll(query) |
242 | .then(({ rows, count }) => { | 249 | .then(({ rows, count }) => { |
243 | return { | 250 | return { |
244 | data: rows, | 251 | data: rows, |
245 | total: count | 252 | total: count |
246 | } | 253 | } |
247 | }) | 254 | }) |
248 | } | 255 | } |
249 | 256 | ||
250 | toFormattedJSON (): Account { | 257 | toFormattedJSON (): Account { |
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index f231dba74..267032e2a 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts | |||
@@ -3,7 +3,6 @@ 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, | ||
7 | BelongsTo, | 6 | BelongsTo, |
8 | Column, | 7 | Column, |
9 | CreatedAt, | 8 | CreatedAt, |
@@ -38,8 +37,6 @@ import { ServerModel } from '../server/server' | |||
38 | import { throwIfNotValid } from '../utils' | 37 | import { throwIfNotValid } from '../utils' |
39 | import { VideoChannelModel } from '../video/video-channel' | 38 | import { VideoChannelModel } from '../video/video-channel' |
40 | import { ActorFollowModel } from './actor-follow' | 39 | import { ActorFollowModel } from './actor-follow' |
41 | import { logger } from '../../helpers/logger' | ||
42 | import { sendDeleteActor } from '../../lib/activitypub/send' | ||
43 | 40 | ||
44 | enum ScopeNames { | 41 | enum ScopeNames { |
45 | FULL = 'FULL' | 42 | FULL = 'FULL' |
@@ -227,28 +224,22 @@ export class ActorModel extends Model<ActorModel> { | |||
227 | 224 | ||
228 | @HasOne(() => AccountModel, { | 225 | @HasOne(() => AccountModel, { |
229 | foreignKey: { | 226 | foreignKey: { |
230 | allowNull: false | 227 | allowNull: true |
231 | } | 228 | }, |
229 | onDelete: 'cascade', | ||
230 | hooks: true | ||
232 | }) | 231 | }) |
233 | Account: AccountModel | 232 | Account: AccountModel |
234 | 233 | ||
235 | @HasOne(() => VideoChannelModel, { | 234 | @HasOne(() => VideoChannelModel, { |
236 | foreignKey: { | 235 | foreignKey: { |
237 | allowNull: false | 236 | allowNull: true |
238 | } | 237 | }, |
238 | onDelete: 'cascade', | ||
239 | hooks: true | ||
239 | }) | 240 | }) |
240 | VideoChannel: VideoChannelModel | 241 | VideoChannel: VideoChannelModel |
241 | 242 | ||
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 | |||
252 | static load (id: number) { | 243 | static load (id: number) { |
253 | return ActorModel.unscoped().findById(id) | 244 | return ActorModel.unscoped().findById(id) |
254 | } | 245 | } |
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 33a19f0ff..6567b00d6 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts | |||
@@ -1,27 +1,15 @@ | |||
1 | import { | 1 | import { |
2 | AllowNull, | 2 | AllowNull, BeforeDestroy, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Is, Model, Scopes, Table, |
3 | BeforeDestroy, | 3 | UpdatedAt, Default, DataType |
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 | ||
17 | } from 'sequelize-typescript' | 4 | } from 'sequelize-typescript' |
18 | import { ActivityPubActor } from '../../../shared/models/activitypub' | 5 | import { ActivityPubActor } from '../../../shared/models/activitypub' |
19 | import { VideoChannel } from '../../../shared/models/videos' | 6 | import { VideoChannel } from '../../../shared/models/videos' |
20 | import { | 7 | import { |
21 | isVideoChannelDescriptionValid, | 8 | isVideoChannelDescriptionValid, isVideoChannelNameValid, |
22 | isVideoChannelNameValid, | ||
23 | isVideoChannelSupportValid | 9 | isVideoChannelSupportValid |
24 | } from '../../helpers/custom-validators/video-channels' | 10 | } from '../../helpers/custom-validators/video-channels' |
11 | import { logger } from '../../helpers/logger' | ||
12 | import { sendDeleteActor } from '../../lib/activitypub/send' | ||
25 | import { AccountModel } from '../account/account' | 13 | import { AccountModel } from '../account/account' |
26 | import { ActorModel } from '../activitypub/actor' | 14 | import { ActorModel } from '../activitypub/actor' |
27 | import { getSort, throwIfNotValid } from '../utils' | 15 | import { getSort, throwIfNotValid } from '../utils' |
@@ -151,7 +139,13 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
151 | instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel | 139 | instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel |
152 | } | 140 | } |
153 | 141 | ||
154 | return instance.Actor.destroy({ transaction: options.transaction }) | 142 | if (instance.Actor.isOwned()) { |
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 | ||
155 | } | 149 | } |
156 | 150 | ||
157 | static countByAccount (accountId: number) { | 151 | static countByAccount (accountId: number) { |