X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fabuse%2Fabuse.ts;h=4c6a96a86d3f882c0afd06ca5035aa2118d8f3d9;hb=77239b425a8e00822a53c9907415832a473c3eb6;hp=2a407c3d264bc4669bd3ba7283c8e2d5c19f13ce;hpb=bd45d503e5d007e730f4e81dccd7e7864c9a85cc;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/abuse/abuse.ts b/server/models/abuse/abuse.ts index 2a407c3d2..4c6a96a86 100644 --- a/server/models/abuse/abuse.ts +++ b/server/models/abuse/abuse.ts @@ -1,6 +1,5 @@ -import * as Bluebird from 'bluebird' import { invert } from 'lodash' -import { literal, Op, QueryTypes, WhereOptions } from 'sequelize' +import { literal, Op, QueryTypes } from 'sequelize' import { AllowNull, BelongsTo, @@ -17,7 +16,7 @@ import { UpdatedAt } from 'sequelize-typescript' import { isAbuseModerationCommentValid, isAbuseReasonValid, isAbuseStateValid } from '@server/helpers/custom-validators/abuses' -import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' +import { abusePredefinedReasonsMap } from '@shared/core-utils' import { AbuseFilter, AbuseObject, @@ -31,6 +30,7 @@ import { UserAbuse, UserVideoAbuse } from '@shared/models' +import { AttributesOnly } from '@shared/typescript-utils' import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants' import { MAbuseAdminFormattable, MAbuseAP, MAbuseFull, MAbuseReporter, MAbuseUserFormattable, MUserAccountId } from '../../types/models' import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account' @@ -188,7 +188,7 @@ export enum ScopeNames { } ] }) -export class AbuseModel extends Model { +export class AbuseModel extends Model>> { @AllowNull(false) @Default(null) @@ -265,33 +265,7 @@ export class AbuseModel extends Model { }) VideoAbuse: VideoAbuseModel - // FIXME: deprecated in 2.3. Remove these validators - static loadByIdAndVideoId (id: number, videoId?: number, uuid?: string): Bluebird { - const videoWhere: WhereOptions = {} - - if (videoId) videoWhere.videoId = videoId - if (uuid) videoWhere.deletedVideo = { uuid } - - const query = { - include: [ - { - model: VideoAbuseModel, - required: true, - where: videoWhere - }, - { - model: AccountModel, - as: 'ReporterAccount' - } - ], - where: { - id - } - } - return AbuseModel.findOne(query) - } - - static loadByIdWithReporter (id: number): Bluebird { + static loadByIdWithReporter (id: number): Promise { const query = { where: { id @@ -307,7 +281,7 @@ export class AbuseModel extends Model { return AbuseModel.findOne(query) } - static loadFull (id: number): Bluebird { + static loadFull (id: number): Promise { const query = { where: { id @@ -461,10 +435,10 @@ export class AbuseModel extends Model { } buildBaseVideoCommentAbuse (this: MAbuseUserFormattable) { - if (!this.VideoCommentAbuse) return null + // Associated video comment could have been destroyed if the video has been deleted + if (!this.VideoCommentAbuse?.VideoComment) return null - const abuseModel = this.VideoCommentAbuse - const entity = abuseModel.VideoComment + const entity = this.VideoCommentAbuse.VideoComment return { id: entity.id, @@ -561,13 +535,7 @@ export class AbuseModel extends Model { : null, countReportsForReporter: (countReportsForReporter || 0), - countReportsForReportee: (countReportsForReportee || 0), - - // FIXME: deprecated in 2.3, remove this - startAt: null, - endAt: null, - count: countReportsForVideo || 0, - nth: nthReportForVideo || 0 + countReportsForReportee: (countReportsForReportee || 0) }) } @@ -595,6 +563,7 @@ export class AbuseModel extends Model { return { type: 'Flag' as 'Flag', content: this.reason, + mediaType: 'text/markdown', object, tag: predefinedReasons.map(r => ({ type: 'Hashtag' as 'Hashtag',