aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/models/account/account.ts21
-rw-r--r--server/models/activitypub/actor.ts25
-rw-r--r--server/models/video/video-channel.ts30
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'
17import { Account } from '../../../shared/models/actors' 17import { Account } from '../../../shared/models/actors'
18import { isAccountDescriptionValid } from '../../helpers/custom-validators/accounts' 18import { isAccountDescriptionValid } from '../../helpers/custom-validators/accounts'
19import { logger } from '../../helpers/logger'
20import { sendDeleteActor } from '../../lib/activitypub/send'
21import { ActorModel } from '../activitypub/actor' 19import { ActorModel } from '../activitypub/actor'
22import { ApplicationModel } from '../application/application' 20import { ApplicationModel } from '../application/application'
23import { AvatarModel } from '../avatar/avatar' 21import { 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'
3import * as Sequelize from 'sequelize' 3import * as Sequelize from 'sequelize'
4import { 4import {
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'
37import { throwIfNotValid } from '../utils' 38import { throwIfNotValid } from '../utils'
38import { VideoChannelModel } from '../video/video-channel' 39import { VideoChannelModel } from '../video/video-channel'
39import { ActorFollowModel } from './actor-follow' 40import { ActorFollowModel } from './actor-follow'
41import { logger } from '../../helpers/logger'
42import { sendDeleteActor } from '../../lib/activitypub/send'
40 43
41enum ScopeNames { 44enum 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 @@
1import { 1import {
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'
5import { ActivityPubActor } from '../../../shared/models/activitypub' 18import { ActivityPubActor } from '../../../shared/models/activitypub'
6import { VideoChannel } from '../../../shared/models/videos' 19import { VideoChannel } from '../../../shared/models/videos'
7import { 20import {
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'
11import { logger } from '../../helpers/logger'
12import { sendDeleteActor } from '../../lib/activitypub/send'
13import { AccountModel } from '../account/account' 25import { AccountModel } from '../account/account'
14import { ActorModel } from '../activitypub/actor' 26import { ActorModel } from '../activitypub/actor'
15import { getSort, throwIfNotValid } from '../utils' 27import { 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) {