aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-abuse.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-05-02 22:38:18 +0200
committerRigel Kent <par@rigelk.eu>2020-05-04 15:01:44 +0200
commit0d3a2982a9b29bd66a05e4b36e606518d4c09959 (patch)
tree13bdc0886216a3bcf1cbaaf63d2c030237f871ca /server/models/video/video-abuse.ts
parentc2a89b70ce75c4955cbdb1ced6fd20a5010a8c9b (diff)
downloadPeerTube-0d3a2982a9b29bd66a05e4b36e606518d4c09959.tar.gz
PeerTube-0d3a2982a9b29bd66a05e4b36e606518d4c09959.tar.zst
PeerTube-0d3a2982a9b29bd66a05e4b36e606518d4c09959.zip
Switching to a named filters/single input on video-abuse
Diffstat (limited to 'server/models/video/video-abuse.ts')
-rw-r--r--server/models/video/video-abuse.ts66
1 files changed, 63 insertions, 3 deletions
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts
index 628f1caa6..b1f8fed90 100644
--- a/server/models/video/video-abuse.ts
+++ b/server/models/video/video-abuse.ts
@@ -9,7 +9,7 @@ import {
9 isVideoAbuseStateValid 9 isVideoAbuseStateValid
10} from '../../helpers/custom-validators/video-abuses' 10} from '../../helpers/custom-validators/video-abuses'
11import { AccountModel } from '../account/account' 11import { AccountModel } from '../account/account'
12import { buildBlockedAccountSQL, getSort, throwIfNotValid, searchAttribute } from '../utils' 12import { buildBlockedAccountSQL, getSort, throwIfNotValid, searchAttribute, parseQueryStringFilter } from '../utils'
13import { VideoModel } from './video' 13import { VideoModel } from './video'
14import { VideoAbuseState, VideoDetails } from '../../../shared' 14import { VideoAbuseState, VideoDetails } from '../../../shared'
15import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants' 15import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants'
@@ -26,10 +26,17 @@ export enum ScopeNames {
26 26
27@Scopes(() => ({ 27@Scopes(() => ({
28 [ScopeNames.FOR_API]: (options: { 28 [ScopeNames.FOR_API]: (options: {
29 // search
29 search?: string 30 search?: string
30 searchReporter?: string 31 searchReporter?: string
32 searchReportee?: string
31 searchVideo?: string 33 searchVideo?: string
32 searchVideoChannel?: string 34 searchVideoChannel?: string
35 // filters
36 id?: number
37 state?: VideoAbuseState
38 is?: any
39 // accountIds
33 serverAccountId: number 40 serverAccountId: number
34 userAccountId: number 41 userAccountId: number
35 }) => { 42 }) => {
@@ -71,6 +78,24 @@ export enum ScopeNames {
71 }) 78 })
72 } 79 }
73 80
81 if (options.id) {
82 where = Object.assign(where, {
83 id: options.id
84 })
85 }
86
87 if (options.state) {
88 where = Object.assign(where, {
89 state: options.state
90 })
91 }
92
93 if (options.is) {
94 where = Object.assign(where, {
95 ...options.is
96 })
97 }
98
74 return { 99 return {
75 attributes: { 100 attributes: {
76 include: [ 101 include: [
@@ -167,7 +192,13 @@ export enum ScopeNames {
167 }, 192 },
168 { 193 {
169 model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, { withAccount: true } as SummaryOptions ] }), 194 model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, { withAccount: true } as SummaryOptions ] }),
170 where: searchAttribute(options.searchVideoChannel, 'name') 195 where: searchAttribute(options.searchVideoChannel, 'name'),
196 include: [
197 {
198 model: AccountModel,
199 where: searchAttribute(options.searchReportee, 'name')
200 }
201 ]
171 }, 202 },
172 { 203 {
173 attributes: [ 'id', 'reason', 'unfederated' ], 204 attributes: [ 'id', 'reason', 'unfederated' ],
@@ -280,7 +311,36 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
280 } 311 }
281 312
282 const filters = { 313 const filters = {
283 search, 314 ...parseQueryStringFilter(search, {
315 id: {
316 prefix: '#',
317 handler: v => v
318 },
319 state: {
320 prefix: 'state:',
321 handler: v => {
322 if (v === "accepted") return VideoAbuseState.ACCEPTED
323 if (v === "pending") return VideoAbuseState.PENDING
324 if (v === "rejected") return VideoAbuseState.REJECTED
325 return undefined
326 }
327 },
328 is: {
329 prefix: 'is:',
330 handler: v => {
331 if (v === "deleted") return { deletedVideo: { [Op.not]: null } }
332 return undefined
333 }
334 },
335 searchReporter: {
336 prefix: 'reporter:',
337 handler: v => v
338 },
339 searchReportee: {
340 prefix: 'reportee:',
341 handler: v => v
342 }
343 }),
284 serverAccountId, 344 serverAccountId,
285 userAccountId 345 userAccountId
286 } 346 }