aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-abuse.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-04-16 14:22:27 +0200
committerRigel Kent <par@rigelk.eu>2020-05-01 16:41:02 +0200
commit68d19a0ace01cb7a3550da420d27663e2db1b98d (patch)
treefcdac5341001b9e6d15ddd0ca8239372ec2b3053 /server/models/video/video-abuse.ts
parent165ee2929bc76fc7f9985ae81cc33736820c7865 (diff)
downloadPeerTube-68d19a0ace01cb7a3550da420d27663e2db1b98d.tar.gz
PeerTube-68d19a0ace01cb7a3550da420d27663e2db1b98d.tar.zst
PeerTube-68d19a0ace01cb7a3550da420d27663e2db1b98d.zip
Make sure a report doesn't get deleted upon the deletion of its video
Diffstat (limited to 'server/models/video/video-abuse.ts')
-rw-r--r--server/models/video/video-abuse.ts37
1 files changed, 26 insertions, 11 deletions
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts
index da8c1577c..ea9856213 100644
--- a/server/models/video/video-abuse.ts
+++ b/server/models/video/video-abuse.ts
@@ -9,7 +9,7 @@ import {
9import { AccountModel } from '../account/account' 9import { AccountModel } from '../account/account'
10import { buildBlockedAccountSQL, getSort, throwIfNotValid } from '../utils' 10import { buildBlockedAccountSQL, getSort, throwIfNotValid } from '../utils'
11import { VideoModel } from './video' 11import { VideoModel } from './video'
12import { VideoAbuseState } from '../../../shared' 12import { VideoAbuseState, Video } from '../../../shared'
13import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants' 13import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants'
14import { MUserAccountId, MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models' 14import { MUserAccountId, MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models'
15import * as Bluebird from 'bluebird' 15import * as Bluebird from 'bluebird'
@@ -46,6 +46,11 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
46 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_ABUSES.MODERATION_COMMENT.max)) 46 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_ABUSES.MODERATION_COMMENT.max))
47 moderationComment: string 47 moderationComment: string
48 48
49 @AllowNull(true)
50 @Default(null)
51 @Column(DataType.JSONB)
52 deletedVideo: Video
53
49 @CreatedAt 54 @CreatedAt
50 createdAt: Date 55 createdAt: Date
51 56
@@ -58,9 +63,9 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
58 63
59 @BelongsTo(() => AccountModel, { 64 @BelongsTo(() => AccountModel, {
60 foreignKey: { 65 foreignKey: {
61 allowNull: false 66 allowNull: true
62 }, 67 },
63 onDelete: 'cascade' 68 onDelete: 'set null'
64 }) 69 })
65 Account: AccountModel 70 Account: AccountModel
66 71
@@ -70,17 +75,21 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
70 75
71 @BelongsTo(() => VideoModel, { 76 @BelongsTo(() => VideoModel, {
72 foreignKey: { 77 foreignKey: {
73 allowNull: false 78 allowNull: true
74 }, 79 },
75 onDelete: 'cascade' 80 onDelete: 'set null'
76 }) 81 })
77 Video: VideoModel 82 Video: VideoModel
78 83
79 static loadByIdAndVideoId (id: number, videoId: number): Bluebird<MVideoAbuse> { 84 static loadByIdAndVideoId (id: number, videoId?: number, uuid?: string): Bluebird<MVideoAbuse> {
85 const videoAttributes = {}
86 if (videoId) videoAttributes['videoId'] = videoId
87 if (uuid) videoAttributes['deletedVideo'] = { uuid }
88
80 const query = { 89 const query = {
81 where: { 90 where: {
82 id, 91 id,
83 videoId 92 ...videoAttributes
84 } 93 }
85 } 94 }
86 return VideoAbuseModel.findOne(query) 95 return VideoAbuseModel.findOne(query)
@@ -112,7 +121,7 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
112 }, 121 },
113 { 122 {
114 model: VideoModel, 123 model: VideoModel,
115 required: true 124 required: false
116 } 125 }
117 ] 126 ]
118 } 127 }
@@ -124,6 +133,10 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
124 } 133 }
125 134
126 toFormattedJSON (this: MVideoAbuseFormattable): VideoAbuse { 135 toFormattedJSON (this: MVideoAbuseFormattable): VideoAbuse {
136 const video = this.Video
137 ? this.Video
138 : this.deletedVideo
139
127 return { 140 return {
128 id: this.id, 141 id: this.id,
129 reason: this.reason, 142 reason: this.reason,
@@ -134,9 +147,11 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
134 }, 147 },
135 moderationComment: this.moderationComment, 148 moderationComment: this.moderationComment,
136 video: { 149 video: {
137 id: this.Video.id, 150 id: video.id,
138 uuid: this.Video.uuid, 151 uuid: video.uuid,
139 name: this.Video.name 152 name: video.name,
153 nsfw: video.nsfw,
154 deleted: !this.Video
140 }, 155 },
141 createdAt: this.createdAt 156 createdAt: this.createdAt
142 } 157 }