diff options
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video-abuse.ts | 66 |
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' |
11 | import { AccountModel } from '../account/account' | 11 | import { AccountModel } from '../account/account' |
12 | import { buildBlockedAccountSQL, getSort, throwIfNotValid, searchAttribute } from '../utils' | 12 | import { buildBlockedAccountSQL, getSort, throwIfNotValid, searchAttribute, parseQueryStringFilter } from '../utils' |
13 | import { VideoModel } from './video' | 13 | import { VideoModel } from './video' |
14 | import { VideoAbuseState, VideoDetails } from '../../../shared' | 14 | import { VideoAbuseState, VideoDetails } from '../../../shared' |
15 | import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants' | 15 | import { 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 | } |