isVideoAbuseStateValid
} from '../../helpers/custom-validators/video-abuses'
import { AccountModel } from '../account/account'
-import { buildBlockedAccountSQL, getSort, throwIfNotValid, searchAttribute } from '../utils'
+import { buildBlockedAccountSQL, getSort, throwIfNotValid, searchAttribute, parseQueryStringFilter } from '../utils'
import { VideoModel } from './video'
import { VideoAbuseState, VideoDetails } from '../../../shared'
import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants'
@Scopes(() => ({
[ScopeNames.FOR_API]: (options: {
+ // search
search?: string
searchReporter?: string
+ searchReportee?: string
searchVideo?: string
searchVideoChannel?: string
+ // filters
+ id?: number
+ state?: VideoAbuseState
+ is?: any
+ // accountIds
serverAccountId: number
userAccountId: number
}) => {
})
}
+ if (options.id) {
+ where = Object.assign(where, {
+ id: options.id
+ })
+ }
+
+ if (options.state) {
+ where = Object.assign(where, {
+ state: options.state
+ })
+ }
+
+ let onlyBlacklisted = false
+ if (options.is === "deleted") {
+ where = Object.assign(where, {
+ deletedVideo: { [Op.not]: null }
+ })
+ } else if (options.is === "blacklisted") {
+ onlyBlacklisted = true
+ }
+
return {
attributes: {
include: [
},
{
model: VideoModel,
- required: false,
+ required: onlyBlacklisted,
where: searchAttribute(options.searchVideo, 'name'),
include: [
{
},
{
model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, { withAccount: true } as SummaryOptions ] }),
- where: searchAttribute(options.searchVideoChannel, 'name')
+ where: searchAttribute(options.searchVideoChannel, 'name'),
+ include: [
+ {
+ model: AccountModel,
+ where: searchAttribute(options.searchReportee, 'name')
+ }
+ ]
},
{
attributes: [ 'id', 'reason', 'unfederated' ],
- model: VideoBlacklistModel
+ model: VideoBlacklistModel,
+ required: onlyBlacklisted
}
]
}
}
const filters = {
- search,
+ ...parseQueryStringFilter(search, {
+ id: {
+ prefix: '#',
+ handler: v => v
+ },
+ state: {
+ prefix: 'state:',
+ handler: v => {
+ if (v === "accepted") return VideoAbuseState.ACCEPTED
+ if (v === "pending") return VideoAbuseState.PENDING
+ if (v === "rejected") return VideoAbuseState.REJECTED
+ return undefined
+ }
+ },
+ is: {
+ prefix: 'is:',
+ handler: v => {
+ if (v === "deleted") return v
+ if (v === "blacklisted") return v
+ return undefined
+ }
+ },
+ searchReporter: {
+ prefix: 'reporter:',
+ handler: v => v
+ },
+ searchReportee: {
+ prefix: 'reportee:',
+ handler: v => v
+ }
+ }),
serverAccountId,
userAccountId
}