]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Revert "Delete actor too when deleting account/video channel"
authorChocobozzz <me@florianbigard.com>
Mon, 30 Jul 2018 11:39:20 +0000 (13:39 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 30 Jul 2018 11:39:20 +0000 (13:39 +0200)
This reverts commit e04551d796adf69703a41af123207b2624237292.

See https://github.com/Chocobozzz/PeerTube/issues/870#issuecomment-408814420

server/models/account/account.ts
server/models/activitypub/actor.ts
server/models/video/video-channel.ts

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