mirror of https://github.com/Chocobozzz/PeerTube
Delete actor too when deleting account/video channel
parent
e20015d744
commit
e04551d796
|
@ -16,8 +16,6 @@ import {
|
||||||
} from 'sequelize-typescript'
|
} from 'sequelize-typescript'
|
||||||
import { Account } from '../../../shared/models/actors'
|
import { Account } from '../../../shared/models/actors'
|
||||||
import { isAccountDescriptionValid } from '../../helpers/custom-validators/accounts'
|
import { isAccountDescriptionValid } from '../../helpers/custom-validators/accounts'
|
||||||
import { logger } from '../../helpers/logger'
|
|
||||||
import { sendDeleteActor } from '../../lib/activitypub/send'
|
|
||||||
import { ActorModel } from '../activitypub/actor'
|
import { ActorModel } from '../activitypub/actor'
|
||||||
import { ApplicationModel } from '../application/application'
|
import { ApplicationModel } from '../application/application'
|
||||||
import { AvatarModel } from '../avatar/avatar'
|
import { AvatarModel } from '../avatar/avatar'
|
||||||
|
@ -138,12 +136,7 @@ export class AccountModel extends Model<AccountModel> {
|
||||||
instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel
|
instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instance.isOwned()) {
|
return instance.Actor.destroy({ transaction: options.transaction })
|
||||||
logger.debug('Sending delete of actor of account %s.', instance.Actor.url)
|
|
||||||
return sendDeleteActor(instance.Actor, options.transaction)
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static load (id: number) {
|
static load (id: number) {
|
||||||
|
@ -246,12 +239,12 @@ export class AccountModel extends Model<AccountModel> {
|
||||||
}
|
}
|
||||||
|
|
||||||
return AccountModel.findAndCountAll(query)
|
return AccountModel.findAndCountAll(query)
|
||||||
.then(({ rows, count }) => {
|
.then(({ rows, count }) => {
|
||||||
return {
|
return {
|
||||||
data: rows,
|
data: rows,
|
||||||
total: count
|
total: count
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
toFormattedJSON (): Account {
|
toFormattedJSON (): Account {
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { extname } from 'path'
|
||||||
import * as Sequelize from 'sequelize'
|
import * as Sequelize from 'sequelize'
|
||||||
import {
|
import {
|
||||||
AllowNull,
|
AllowNull,
|
||||||
|
BeforeDestroy,
|
||||||
BelongsTo,
|
BelongsTo,
|
||||||
Column,
|
Column,
|
||||||
CreatedAt,
|
CreatedAt,
|
||||||
|
@ -37,6 +38,8 @@ import { ServerModel } from '../server/server'
|
||||||
import { throwIfNotValid } from '../utils'
|
import { throwIfNotValid } from '../utils'
|
||||||
import { VideoChannelModel } from '../video/video-channel'
|
import { VideoChannelModel } from '../video/video-channel'
|
||||||
import { ActorFollowModel } from './actor-follow'
|
import { ActorFollowModel } from './actor-follow'
|
||||||
|
import { logger } from '../../helpers/logger'
|
||||||
|
import { sendDeleteActor } from '../../lib/activitypub/send'
|
||||||
|
|
||||||
enum ScopeNames {
|
enum ScopeNames {
|
||||||
FULL = 'FULL'
|
FULL = 'FULL'
|
||||||
|
@ -224,22 +227,28 @@ export class ActorModel extends Model<ActorModel> {
|
||||||
|
|
||||||
@HasOne(() => AccountModel, {
|
@HasOne(() => AccountModel, {
|
||||||
foreignKey: {
|
foreignKey: {
|
||||||
allowNull: true
|
allowNull: false
|
||||||
},
|
}
|
||||||
onDelete: 'cascade',
|
|
||||||
hooks: true
|
|
||||||
})
|
})
|
||||||
Account: AccountModel
|
Account: AccountModel
|
||||||
|
|
||||||
@HasOne(() => VideoChannelModel, {
|
@HasOne(() => VideoChannelModel, {
|
||||||
foreignKey: {
|
foreignKey: {
|
||||||
allowNull: true
|
allowNull: false
|
||||||
},
|
}
|
||||||
onDelete: 'cascade',
|
|
||||||
hooks: true
|
|
||||||
})
|
})
|
||||||
VideoChannel: VideoChannelModel
|
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) {
|
static load (id: number) {
|
||||||
return ActorModel.unscoped().findById(id)
|
return ActorModel.unscoped().findById(id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,27 @@
|
||||||
import {
|
import {
|
||||||
AllowNull, BeforeDestroy, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Is, Model, Scopes, Table,
|
AllowNull,
|
||||||
UpdatedAt, Default, DataType
|
BeforeDestroy,
|
||||||
|
BelongsTo,
|
||||||
|
Column,
|
||||||
|
CreatedAt,
|
||||||
|
DataType,
|
||||||
|
Default,
|
||||||
|
DefaultScope,
|
||||||
|
ForeignKey,
|
||||||
|
HasMany,
|
||||||
|
Is,
|
||||||
|
Model,
|
||||||
|
Scopes,
|
||||||
|
Table,
|
||||||
|
UpdatedAt
|
||||||
} from 'sequelize-typescript'
|
} from 'sequelize-typescript'
|
||||||
import { ActivityPubActor } from '../../../shared/models/activitypub'
|
import { ActivityPubActor } from '../../../shared/models/activitypub'
|
||||||
import { VideoChannel } from '../../../shared/models/videos'
|
import { VideoChannel } from '../../../shared/models/videos'
|
||||||
import {
|
import {
|
||||||
isVideoChannelDescriptionValid, isVideoChannelNameValid,
|
isVideoChannelDescriptionValid,
|
||||||
|
isVideoChannelNameValid,
|
||||||
isVideoChannelSupportValid
|
isVideoChannelSupportValid
|
||||||
} from '../../helpers/custom-validators/video-channels'
|
} from '../../helpers/custom-validators/video-channels'
|
||||||
import { logger } from '../../helpers/logger'
|
|
||||||
import { sendDeleteActor } from '../../lib/activitypub/send'
|
|
||||||
import { AccountModel } from '../account/account'
|
import { AccountModel } from '../account/account'
|
||||||
import { ActorModel } from '../activitypub/actor'
|
import { ActorModel } from '../activitypub/actor'
|
||||||
import { getSort, throwIfNotValid } from '../utils'
|
import { getSort, throwIfNotValid } from '../utils'
|
||||||
|
@ -139,13 +151,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
|
||||||
instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel
|
instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instance.Actor.isOwned()) {
|
return instance.Actor.destroy({ transaction: options.transaction })
|
||||||
logger.debug('Sending delete of actor of video channel %s.', instance.Actor.url)
|
|
||||||
|
|
||||||
return sendDeleteActor(instance.Actor, options.transaction)
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static countByAccount (accountId: number) {
|
static countByAccount (accountId: number) {
|
||||||
|
|
Loading…
Reference in New Issue