aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-abuse.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-15 15:12:23 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:52 +0100
commit8e13fa7d09e9925b4559cbba6c5d72c5ff1bd391 (patch)
treea59070f4dc6b52a5b422bd31a8eb8ea3bff831a0 /server/models/video/video-abuse.ts
parent59c857da5961e2bcddcfd07832783c1e4afcd01a (diff)
downloadPeerTube-8e13fa7d09e9925b4559cbba6c5d72c5ff1bd391.tar.gz
PeerTube-8e13fa7d09e9925b4559cbba6c5d72c5ff1bd391.tar.zst
PeerTube-8e13fa7d09e9925b4559cbba6c5d72c5ff1bd391.zip
Add video abuse to activity pub
Diffstat (limited to 'server/models/video/video-abuse.ts')
-rw-r--r--server/models/video/video-abuse.ts44
1 files changed, 23 insertions, 21 deletions
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts
index c1d070ec0..f3fdeab52 100644
--- a/server/models/video/video-abuse.ts
+++ b/server/models/video/video-abuse.ts
@@ -1,7 +1,7 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3import { CONFIG } from '../../initializers' 3import { CONFIG } from '../../initializers'
4import { isVideoAbuseReporterUsernameValid, isVideoAbuseReasonValid } from '../../helpers' 4import { isVideoAbuseReasonValid } from '../../helpers'
5 5
6import { addMethodsToModel, getSort } from '../utils' 6import { addMethodsToModel, getSort } from '../utils'
7import { 7import {
@@ -18,16 +18,6 @@ let listForApi: VideoAbuseMethods.ListForApi
18export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { 18export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
19 VideoAbuse = sequelize.define<VideoAbuseInstance, VideoAbuseAttributes>('VideoAbuse', 19 VideoAbuse = sequelize.define<VideoAbuseInstance, VideoAbuseAttributes>('VideoAbuse',
20 { 20 {
21 reporterUsername: {
22 type: DataTypes.STRING,
23 allowNull: false,
24 validate: {
25 reporterUsernameValid: value => {
26 const res = isVideoAbuseReporterUsernameValid(value)
27 if (res === false) throw new Error('Video abuse reporter username is not valid.')
28 }
29 }
30 },
31 reason: { 21 reason: {
32 type: DataTypes.STRING, 22 type: DataTypes.STRING,
33 allowNull: false, 23 allowNull: false,
@@ -45,7 +35,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
45 fields: [ 'videoId' ] 35 fields: [ 'videoId' ]
46 }, 36 },
47 { 37 {
48 fields: [ 'reporterServerId' ] 38 fields: [ 'reporterAccountId' ]
49 } 39 }
50 ] 40 ]
51 } 41 }
@@ -69,8 +59,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
69toFormattedJSON = function (this: VideoAbuseInstance) { 59toFormattedJSON = function (this: VideoAbuseInstance) {
70 let reporterServerHost 60 let reporterServerHost
71 61
72 if (this.Server) { 62 if (this.Account.Server) {
73 reporterServerHost = this.Server.host 63 reporterServerHost = this.Account.Server.host
74 } else { 64 } else {
75 // It means it's our video 65 // It means it's our video
76 reporterServerHost = CONFIG.WEBSERVER.HOST 66 reporterServerHost = CONFIG.WEBSERVER.HOST
@@ -78,10 +68,12 @@ toFormattedJSON = function (this: VideoAbuseInstance) {
78 68
79 const json = { 69 const json = {
80 id: this.id, 70 id: this.id,
81 reporterServerHost,
82 reason: this.reason, 71 reason: this.reason,
83 reporterUsername: this.reporterUsername, 72 reporterUsername: this.Account.name,
84 videoId: this.videoId, 73 reporterServerHost,
74 videoId: this.Video.id,
75 videoUUID: this.Video.uuid,
76 videoName: this.Video.name,
85 createdAt: this.createdAt 77 createdAt: this.createdAt
86 } 78 }
87 79
@@ -91,9 +83,9 @@ toFormattedJSON = function (this: VideoAbuseInstance) {
91// ------------------------------ STATICS ------------------------------ 83// ------------------------------ STATICS ------------------------------
92 84
93function associate (models) { 85function associate (models) {
94 VideoAbuse.belongsTo(models.Server, { 86 VideoAbuse.belongsTo(models.Account, {
95 foreignKey: { 87 foreignKey: {
96 name: 'reporterServerId', 88 name: 'reporterAccountId',
97 allowNull: true 89 allowNull: true
98 }, 90 },
99 onDelete: 'CASCADE' 91 onDelete: 'CASCADE'
@@ -115,8 +107,18 @@ listForApi = function (start: number, count: number, sort: string) {
115 order: [ getSort(sort) ], 107 order: [ getSort(sort) ],
116 include: [ 108 include: [
117 { 109 {
118 model: VideoAbuse['sequelize'].models.Server, 110 model: VideoAbuse['sequelize'].models.Account,
119 required: false 111 required: true,
112 include: [
113 {
114 model: VideoAbuse['sequelize'].models.Server,
115 required: false
116 }
117 ]
118 },
119 {
120 model: VideoAbuse['sequelize'].models.Video,
121 required: true
120 } 122 }
121 ] 123 ]
122 } 124 }