From 268eebed921ac13a9ce0f4717f4923aa24190657 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Aug 2018 16:54:01 +0200 Subject: Add state and moderationComment for abuses on server side --- server/initializers/constants.ts | 14 +++++-- .../migrations/0250-video-abuse-state.ts | 47 ++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 server/initializers/migrations/0250-video-abuse-state.ts (limited to 'server/initializers') diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index ea561b686..a008bf4c5 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -3,7 +3,7 @@ import { dirname, join } from 'path' import { JobType, VideoRateType, VideoState } from '../../shared/models' import { ActivityPubActorType } from '../../shared/models/activitypub' import { FollowState } from '../../shared/models/actors' -import { VideoPrivacy } from '../../shared/models/videos' +import { VideoPrivacy, VideoAbuseState } from '../../shared/models/videos' // Do not use barrels, remain constants as independent as possible import { buildPath, isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' @@ -15,7 +15,7 @@ let config: IConfig = require('config') // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 245 +const LAST_MIGRATION_VERSION = 250 // --------------------------------------------------------------------------- @@ -258,7 +258,8 @@ const CONSTRAINTS_FIELDS = { BLOCKED_REASON: { min: 3, max: 250 } // Length }, VIDEO_ABUSES: { - REASON: { min: 2, max: 300 } // Length + REASON: { min: 2, max: 300 }, // Length + MODERATION_COMMENT: { min: 2, max: 300 } // Length }, VIDEO_CHANNELS: { NAME: { min: 3, max: 120 }, // Length @@ -409,6 +410,12 @@ const VIDEO_IMPORT_STATES = { [VideoImportState.SUCCESS]: 'Success' } +const VIDEO_ABUSE_STATES = { + [VideoAbuseState.PENDING]: 'Pending', + [VideoAbuseState.REJECTED]: 'Rejected', + [VideoAbuseState.ACCEPTED]: 'Accepted' +} + const VIDEO_MIMETYPE_EXT = { 'video/webm': '.webm', 'video/ogg': '.ogv', @@ -625,6 +632,7 @@ export { VIDEO_MIMETYPE_EXT, VIDEO_TRANSCODING_FPS, FFMPEG_NICE, + VIDEO_ABUSE_STATES, JOB_REQUEST_TIMEOUT, USER_PASSWORD_RESET_LIFETIME, IMAGE_MIMETYPE_EXT, diff --git a/server/initializers/migrations/0250-video-abuse-state.ts b/server/initializers/migrations/0250-video-abuse-state.ts new file mode 100644 index 000000000..acb668ae1 --- /dev/null +++ b/server/initializers/migrations/0250-video-abuse-state.ts @@ -0,0 +1,47 @@ +import * as Sequelize from 'sequelize' +import { CONSTRAINTS_FIELDS } from '../constants' +import { VideoAbuseState } from '../../../shared/models/videos' + +async function up (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize +}): Promise { + { + const data = { + type: Sequelize.INTEGER, + allowNull: true, + defaultValue: null + } + await utils.queryInterface.addColumn('videoAbuse', 'state', data) + } + + { + const query = 'UPDATE "videoAbuse" SET "state" = ' + VideoAbuseState.PENDING + await utils.sequelize.query(query) + } + + { + const data = { + type: Sequelize.INTEGER, + allowNull: false, + defaultValue: null + } + await utils.queryInterface.changeColumn('videoAbuse', 'state', data) + } + + { + const data = { + type: Sequelize.STRING(CONSTRAINTS_FIELDS.VIDEO_ABUSES.MODERATION_COMMENT.max), + allowNull: true, + defaultValue: null + } + await utils.queryInterface.addColumn('videoAbuse', 'moderationComment', data) + } +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { up, down } -- cgit v1.2.3