]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-abuse.ts
Merge branch 'release/1.4.0' into develop
[github/Chocobozzz/PeerTube.git] / server / models / video / video-abuse.ts
index eacd651cc1233dd4679d74cd0349a0f905b6aed3..3636db18de73c125e02fbf5c0831c98b2d6a524c 100644 (file)
@@ -7,10 +7,13 @@ import {
   isVideoAbuseStateValid
 } from '../../helpers/custom-validators/video-abuses'
 import { AccountModel } from '../account/account'
-import { getSort, throwIfNotValid } from '../utils'
+import { buildBlockedAccountSQL, getSort, throwIfNotValid } from '../utils'
 import { VideoModel } from './video'
 import { VideoAbuseState } from '../../../shared'
 import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants'
+import { MUserAccountId, MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models'
+import * as Bluebird from 'bluebird'
+import { literal, Op } from 'sequelize'
 
 @Table({
   tableName: 'videoAbuse',
@@ -39,7 +42,7 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
 
   @AllowNull(true)
   @Default(null)
-  @Is('VideoAbuseModerationComment', value => throwIfNotValid(value, isVideoAbuseModerationCommentValid, 'moderationComment'))
+  @Is('VideoAbuseModerationComment', value => throwIfNotValid(value, isVideoAbuseModerationCommentValid, 'moderationComment', true))
   @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_ABUSES.MODERATION_COMMENT.max))
   moderationComment: string
 
@@ -73,7 +76,7 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
   })
   Video: VideoModel
 
-  static loadByIdAndVideoId (id: number, videoId: number) {
+  static loadByIdAndVideoId (id: number, videoId: number): Bluebird<MVideoAbuse> {
     const query = {
       where: {
         id,
@@ -83,11 +86,25 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
     return VideoAbuseModel.findOne(query)
   }
 
-  static listForApi (start: number, count: number, sort: string) {
+  static listForApi (parameters: {
+    start: number,
+    count: number,
+    sort: string,
+    serverAccountId: number
+    user?: MUserAccountId
+  }) {
+    const { start, count, sort, user, serverAccountId } = parameters
+    const userAccountId = user ? user.Account.id : undefined
+
     const query = {
       offset: start,
       limit: count,
       order: getSort(sort),
+      where: {
+        reporterAccountId: {
+          [Op.notIn]: literal('(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')')
+        }
+      },
       include: [
         {
           model: AccountModel,
@@ -106,7 +123,7 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
       })
   }
 
-  toFormattedJSON (): VideoAbuse {
+  toFormattedJSON (this: MVideoAbuseFormattable): VideoAbuse {
     return {
       id: this.id,
       reason: this.reason,
@@ -125,7 +142,7 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
     }
   }
 
-  toActivityPubObject (): VideoAbuseObject {
+  toActivityPubObject (this: MVideoAbuseVideo): VideoAbuseObject {
     return {
       type: 'Flag' as 'Flag',
       content: this.reason,