import { isAbuseModerationCommentValid, isAbuseReasonValid, isAbuseStateValid } from '@server/helpers/custom-validators/abuses'
import {
Abuse,
+ AbuseFilter,
AbuseObject,
AbusePredefinedReasons,
abusePredefinedReasonsMap,
AbusePredefinedReasonsString,
AbuseState,
AbuseVideoIs,
- VideoAbuse
+ VideoAbuse,
+ VideoCommentAbuse
} from '@shared/models'
-import { AbuseFilter } from '@shared/models/moderation/abuse/abuse-filter'
-import { CONSTRAINTS_FIELDS, ABUSE_STATES } from '../../initializers/constants'
+import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants'
import { MAbuse, MAbuseAP, MAbuseFormattable, MUserAccountId } from '../../types/models'
import { AccountModel, ScopeNames as AccountScopeNames } from '../account/account'
import { buildBlockedAccountSQL, getSort, searchAttribute, throwIfNotValid } from '../utils'
import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from '../video/video-channel'
import { VideoAbuseModel } from './video-abuse'
import { VideoCommentAbuseModel } from './video-comment-abuse'
+import { VideoCommentModel } from '../video/video-comment'
export enum ScopeNames {
FOR_API = 'FOR_API'
serverAccountId: number
userAccountId: number
}) => {
- const onlyBlacklisted = options.videoIs === 'blacklisted'
- const videoRequired = !!(onlyBlacklisted || options.searchVideo || options.searchVideoChannel)
+ const whereAnd: WhereOptions[] = []
- const where = {
+ whereAnd.push({
reporterAccountId: {
[Op.notIn]: literal('(' + buildBlockedAccountSQL([ options.serverAccountId, options.userAccountId ]) + ')')
}
- }
+ })
if (options.search) {
const escapedSearch = AbuseModel.sequelize.escape('%' + options.search + '%')
- Object.assign(where, {
+ whereAnd.push({
[Op.or]: [
{
[Op.and]: [
})
}
- if (options.id) Object.assign(where, { id: options.id })
- if (options.state) Object.assign(where, { state: options.state })
+ if (options.id) whereAnd.push({ id: options.id })
+ if (options.state) whereAnd.push({ state: options.state })
if (options.videoIs === 'deleted') {
- Object.assign(where, {
+ whereAnd.push({
'$VideoAbuse.deletedVideo$': {
[Op.not]: null
}
}
if (options.predefinedReasonId) {
- Object.assign(where, {
+ whereAnd.push({
predefinedReasons: {
[Op.contains]: [ options.predefinedReasonId ]
}
})
}
+ if (options.filter === 'account') {
+ whereAnd.push({
+ videoId: null,
+ commentId: null
+ })
+ }
+
+ const onlyBlacklisted = options.videoIs === 'blacklisted'
+ const videoRequired = !!(onlyBlacklisted || options.searchVideo || options.searchVideoChannel)
+
return {
attributes: {
include: [
required: true,
where: searchAttribute(options.searchReportee, 'name')
},
+ {
+ model: VideoCommentAbuseModel.unscoped(),
+ required: options.filter === 'comment',
+ include: [
+ {
+ model: VideoCommentModel.unscoped(),
+ required: false,
+ include: [
+ {
+ model: VideoModel.unscoped(),
+ attributes: [ 'name', 'id', 'uuid' ],
+ required: true
+ }
+ ]
+ }
+ ]
+ },
{
model: VideoAbuseModel,
required: options.filter === 'video' || !!options.videoIs || videoRequired,
include: [
{
model: AccountModel.scope(AccountScopeNames.SUMMARY),
- required: true,
- where: searchAttribute(options.searchReportee, 'name')
+ required: true
}
]
},
]
}
],
- where
+ where: {
+ [Op.and]: whereAnd
+ }
}
}
}))
})
VideoAbuse: VideoAbuseModel
+ // FIXME: deprecated in 2.3. Remove these validators
static loadByIdAndVideoId (id: number, videoId?: number, uuid?: string): Bluebird<MAbuse> {
const videoWhere: WhereOptions = {}
return AbuseModel.findOne(query)
}
+ static loadById (id: number): Bluebird<MAbuse> {
+ const query = {
+ where: {
+ id
+ }
+ }
+
+ return AbuseModel.findOne(query)
+ }
+
static listForApi (parameters: {
start: number
count: number
const countReportsForReporteeDeletedVideo = this.get('countReportsForReportee__deletedVideo') as number
let video: VideoAbuse
+ let comment: VideoCommentAbuse
if (this.VideoAbuse) {
const abuseModel = this.VideoAbuse
}
}
+ if (this.VideoCommentAbuse) {
+ const abuseModel = this.VideoCommentAbuse
+ const entity = abuseModel.VideoComment || abuseModel.deletedComment
+
+ comment = {
+ id: entity.id,
+ text: entity.text,
+
+ deleted: !abuseModel.VideoComment,
+
+ video: {
+ id: entity.Video.id,
+ name: entity.Video.name,
+ uuid: entity.Video.uuid
+ }
+ }
+ }
+
return {
id: this.id,
reason: this.reason,
moderationComment: this.moderationComment,
video,
- comment: null,
+ comment,
createdAt: this.createdAt,
updatedAt: this.updatedAt,