aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/models/video/video-abuse.ts25
-rw-r--r--server/tests/api/videos/video-abuse.ts31
-rw-r--r--server/tests/utils/videos/videos.ts3
3 files changed, 27 insertions, 32 deletions
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts
index 65b734442..a6319bb79 100644
--- a/server/models/video/video-abuse.ts
+++ b/server/models/video/video-abuse.ts
@@ -1,7 +1,7 @@
1import { AfterCreate, AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 1import { AfterCreate, AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
2import { VideoAbuseObject } from '../../../shared/models/activitypub/objects' 2import { VideoAbuseObject } from '../../../shared/models/activitypub/objects'
3import { VideoAbuse } from '../../../shared/models/videos'
3import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos' 4import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos'
4import { CONFIG } from '../../initializers'
5import { Emailer } from '../../lib/emailer' 5import { Emailer } from '../../lib/emailer'
6import { AccountModel } from '../account/account' 6import { AccountModel } from '../account/account'
7import { getSort, throwIfNotValid } from '../utils' 7import { getSort, throwIfNotValid } from '../utils'
@@ -83,24 +83,17 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
83 }) 83 })
84 } 84 }
85 85
86 toFormattedJSON () { 86 toFormattedJSON (): VideoAbuse {
87 let reporterServerHost
88
89 if (this.Account.Actor.Server) {
90 reporterServerHost = this.Account.Actor.Server.host
91 } else {
92 // It means it's our video
93 reporterServerHost = CONFIG.WEBSERVER.HOST
94 }
95
96 return { 87 return {
97 id: this.id, 88 id: this.id,
98 reason: this.reason, 89 reason: this.reason,
99 reporterUsername: this.Account.name, 90 reporterAccount: this.Account.toFormattedJSON(),
100 reporterServerHost, 91 video: {
101 videoId: this.Video.id, 92 id: this.Video.id,
102 videoUUID: this.Video.uuid, 93 uuid: this.Video.uuid,
103 videoName: this.Video.name, 94 url: this.Video.url,
95 name: this.Video.name
96 },
104 createdAt: this.createdAt 97 createdAt: this.createdAt
105 } 98 }
106 } 99 }
diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts
index 3fcf5d8c7..f1c4ef0ce 100644
--- a/server/tests/api/videos/video-abuse.ts
+++ b/server/tests/api/videos/video-abuse.ts
@@ -2,6 +2,7 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { VideoAbuse } from '../../../../shared/models/videos'
5import { 6import {
6 flushAndRunMultipleServers, 7 flushAndRunMultipleServers,
7 flushTests, 8 flushTests,
@@ -83,11 +84,11 @@ describe('Test video abuses', function () {
83 expect(res1.body.data).to.be.an('array') 84 expect(res1.body.data).to.be.an('array')
84 expect(res1.body.data.length).to.equal(1) 85 expect(res1.body.data.length).to.equal(1)
85 86
86 const abuse = res1.body.data[0] 87 const abuse: VideoAbuse = res1.body.data[0]
87 expect(abuse.reason).to.equal('my super bad reason') 88 expect(abuse.reason).to.equal('my super bad reason')
88 expect(abuse.reporterUsername).to.equal('root') 89 expect(abuse.reporterAccount.name).to.equal('root')
89 expect(abuse.reporterServerHost).to.equal('localhost:9001') 90 expect(abuse.reporterAccount.host).to.equal('localhost:9001')
90 expect(abuse.videoId).to.equal(servers[0].video.id) 91 expect(abuse.video.id).to.equal(servers[0].video.id)
91 92
92 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) 93 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
93 expect(res2.body.total).to.equal(0) 94 expect(res2.body.total).to.equal(0)
@@ -111,27 +112,27 @@ describe('Test video abuses', function () {
111 expect(res1.body.data).to.be.an('array') 112 expect(res1.body.data).to.be.an('array')
112 expect(res1.body.data.length).to.equal(2) 113 expect(res1.body.data.length).to.equal(2)
113 114
114 const abuse1 = res1.body.data[0] 115 const abuse1: VideoAbuse = res1.body.data[0]
115 expect(abuse1.reason).to.equal('my super bad reason') 116 expect(abuse1.reason).to.equal('my super bad reason')
116 expect(abuse1.reporterUsername).to.equal('root') 117 expect(abuse1.reporterAccount.name).to.equal('root')
117 expect(abuse1.reporterServerHost).to.equal('localhost:9001') 118 expect(abuse1.reporterAccount.host).to.equal('localhost:9001')
118 expect(abuse1.videoId).to.equal(servers[0].video.id) 119 expect(abuse1.video.id).to.equal(servers[0].video.id)
119 120
120 const abuse2 = res1.body.data[1] 121 const abuse2: VideoAbuse = res1.body.data[1]
121 expect(abuse2.reason).to.equal('my super bad reason 2') 122 expect(abuse2.reason).to.equal('my super bad reason 2')
122 expect(abuse2.reporterUsername).to.equal('root') 123 expect(abuse2.reporterAccount.name).to.equal('root')
123 expect(abuse2.reporterServerHost).to.equal('localhost:9001') 124 expect(abuse2.reporterAccount.host).to.equal('localhost:9001')
124 expect(abuse2.videoId).to.equal(servers[1].video.id) 125 expect(abuse2.video.id).to.equal(servers[1].video.id)
125 126
126 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) 127 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
127 expect(res2.body.total).to.equal(1) 128 expect(res2.body.total).to.equal(1)
128 expect(res2.body.data).to.be.an('array') 129 expect(res2.body.data).to.be.an('array')
129 expect(res2.body.data.length).to.equal(1) 130 expect(res2.body.data.length).to.equal(1)
130 131
131 const abuse3 = res2.body.data[0] 132 const abuse3: VideoAbuse = res2.body.data[0]
132 expect(abuse3.reason).to.equal('my super bad reason 2') 133 expect(abuse3.reason).to.equal('my super bad reason 2')
133 expect(abuse3.reporterUsername).to.equal('root') 134 expect(abuse3.reporterAccount.name).to.equal('root')
134 expect(abuse3.reporterServerHost).to.equal('localhost:9001') 135 expect(abuse3.reporterAccount.host).to.equal('localhost:9001')
135 }) 136 })
136 137
137 after(async function () { 138 after(async function () {
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts
index 4b57f24b5..ec40c5465 100644
--- a/server/tests/utils/videos/videos.ts
+++ b/server/tests/utils/videos/videos.ts
@@ -420,7 +420,8 @@ async function completeVideoCheck (
420 expect(videoDetails.tags).to.deep.equal(attributes.tags) 420 expect(videoDetails.tags).to.deep.equal(attributes.tags)
421 expect(videoDetails.privacy).to.deep.equal(attributes.privacy) 421 expect(videoDetails.privacy).to.deep.equal(attributes.privacy)
422 expect(videoDetails.privacyLabel).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy]) 422 expect(videoDetails.privacyLabel).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy])
423 expect(videoDetails.account.name).to.equal(attributes.account) 423 expect(videoDetails.account.name).to.equal(attributes.account.name)
424 expect(videoDetails.account.host).to.equal(attributes.account.host)
424 expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled) 425 expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled)
425 426
426 expect(videoDetails.channel.displayName).to.equal(attributes.channel.name) 427 expect(videoDetails.channel.displayName).to.equal(attributes.channel.name)