diff options
author | Chocobozzz <me@florianbigard.com> | 2020-07-08 15:51:46 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-07-10 14:02:41 +0200 |
commit | 310b5219b38427f0c2c7ba57225afdd8f3064380 (patch) | |
tree | 853ff7e4e66425ca47b0999384eeb08ed14b28ff /server/models/video | |
parent | 811cef146c841ef8530bc812c05dfee77e0f2998 (diff) | |
download | PeerTube-310b5219b38427f0c2c7ba57225afdd8f3064380.tar.gz PeerTube-310b5219b38427f0c2c7ba57225afdd8f3064380.tar.zst PeerTube-310b5219b38427f0c2c7ba57225afdd8f3064380.zip |
Add new abuses tests
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video-comment.ts | 42 |
1 files changed, 1 insertions, 41 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index fb6078ed8..fa4d13c3b 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts | |||
@@ -3,7 +3,6 @@ import { uniq } from 'lodash' | |||
3 | import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' | 3 | import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' |
4 | import { | 4 | import { |
5 | AllowNull, | 5 | AllowNull, |
6 | BeforeDestroy, | ||
7 | BelongsTo, | 6 | BelongsTo, |
8 | Column, | 7 | Column, |
9 | CreatedAt, | 8 | CreatedAt, |
@@ -16,7 +15,6 @@ import { | |||
16 | Table, | 15 | Table, |
17 | UpdatedAt | 16 | UpdatedAt |
18 | } from 'sequelize-typescript' | 17 | } from 'sequelize-typescript' |
19 | import { logger } from '@server/helpers/logger' | ||
20 | import { getServerActor } from '@server/models/application/application' | 18 | import { getServerActor } from '@server/models/application/application' |
21 | import { MAccount, MAccountId, MUserAccountId } from '@server/types/models' | 19 | import { MAccount, MAccountId, MUserAccountId } from '@server/types/models' |
22 | import { VideoPrivacy } from '@shared/models' | 20 | import { VideoPrivacy } from '@shared/models' |
@@ -242,51 +240,13 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
242 | 240 | ||
243 | @HasMany(() => VideoCommentAbuseModel, { | 241 | @HasMany(() => VideoCommentAbuseModel, { |
244 | foreignKey: { | 242 | foreignKey: { |
245 | name: 'commentId', | 243 | name: 'videoCommentId', |
246 | allowNull: true | 244 | allowNull: true |
247 | }, | 245 | }, |
248 | onDelete: 'set null' | 246 | onDelete: 'set null' |
249 | }) | 247 | }) |
250 | CommentAbuses: VideoCommentAbuseModel[] | 248 | CommentAbuses: VideoCommentAbuseModel[] |
251 | 249 | ||
252 | @BeforeDestroy | ||
253 | static async saveEssentialDataToAbuses (instance: VideoCommentModel, options) { | ||
254 | const tasks: Promise<any>[] = [] | ||
255 | |||
256 | if (!Array.isArray(instance.CommentAbuses)) { | ||
257 | instance.CommentAbuses = await instance.$get('CommentAbuses') | ||
258 | |||
259 | if (instance.CommentAbuses.length === 0) return undefined | ||
260 | } | ||
261 | |||
262 | if (!instance.Video) { | ||
263 | instance.Video = await instance.$get('Video') | ||
264 | } | ||
265 | |||
266 | logger.info('Saving video comment %s for abuse.', instance.url) | ||
267 | |||
268 | const details = Object.assign(instance.toFormattedJSON(), { | ||
269 | Video: { | ||
270 | id: instance.Video.id, | ||
271 | name: instance.Video.name, | ||
272 | uuid: instance.Video.uuid | ||
273 | } | ||
274 | }) | ||
275 | |||
276 | for (const abuse of instance.CommentAbuses) { | ||
277 | abuse.deletedComment = details | ||
278 | |||
279 | tasks.push(abuse.save({ transaction: options.transaction })) | ||
280 | } | ||
281 | |||
282 | Promise.all(tasks) | ||
283 | .catch(err => { | ||
284 | logger.error('Some errors when saving details of comment %s in its abuses before destroy hook.', instance.url, { err }) | ||
285 | }) | ||
286 | |||
287 | return undefined | ||
288 | } | ||
289 | |||
290 | static loadById (id: number, t?: Transaction): Bluebird<MComment> { | 250 | static loadById (id: number, t?: Transaction): Bluebird<MComment> { |
291 | const query: FindOptions = { | 251 | const query: FindOptions = { |
292 | where: { | 252 | where: { |