aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-08-29 14:31:04 +0200
committerChocobozzz <me@florianbigard.com>2019-08-29 14:31:04 +0200
commitf0a47bc92aa20b91b46197a4d3fc430aea962848 (patch)
tree104bb5dd7facc0d4db09c7deeea9e189f930e72e /server
parent3155c8606cff211f495bf71c75c56cae85a5430f (diff)
downloadPeerTube-f0a47bc92aa20b91b46197a4d3fc430aea962848.tar.gz
PeerTube-f0a47bc92aa20b91b46197a4d3fc430aea962848.tar.zst
PeerTube-f0a47bc92aa20b91b46197a4d3fc430aea962848.zip
Hide video abuses from muted accounts
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/abuse.ts13
-rw-r--r--server/models/video/video-abuse.ts21
-rw-r--r--server/tests/api/videos/video-abuse.ts77
3 files changed, 102 insertions, 9 deletions
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts
index 39c841ffe..4ae899b7e 100644
--- a/server/controllers/api/videos/abuse.ts
+++ b/server/controllers/api/videos/abuse.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { UserRight, VideoAbuseCreate, VideoAbuseState } from '../../../../shared' 2import { UserRight, VideoAbuseCreate, VideoAbuseState } from '../../../../shared'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { getFormattedObjects } from '../../../helpers/utils' 4import { getFormattedObjects, getServerActor } from '../../../helpers/utils'
5import { sequelizeTypescript } from '../../../initializers' 5import { sequelizeTypescript } from '../../../initializers'
6import { 6import {
7 asyncMiddleware, 7 asyncMiddleware,
@@ -62,7 +62,16 @@ export {
62// --------------------------------------------------------------------------- 62// ---------------------------------------------------------------------------
63 63
64async function listVideoAbuses (req: express.Request, res: express.Response) { 64async function listVideoAbuses (req: express.Request, res: express.Response) {
65 const resultList = await VideoAbuseModel.listForApi(req.query.start, req.query.count, req.query.sort) 65 const user = res.locals.oauth.token.user
66 const serverActor = await getServerActor()
67
68 const resultList = await VideoAbuseModel.listForApi({
69 start: req.query.start,
70 count: req.query.count,
71 sort: req.query.sort,
72 serverAccountId: serverActor.Account.id,
73 user
74 })
66 75
67 return res.json(getFormattedObjects(resultList.data, resultList.total)) 76 return res.json(getFormattedObjects(resultList.data, resultList.total))
68} 77}
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts
index 6ef1a915d..3636db18d 100644
--- a/server/models/video/video-abuse.ts
+++ b/server/models/video/video-abuse.ts
@@ -7,12 +7,13 @@ import {
7 isVideoAbuseStateValid 7 isVideoAbuseStateValid
8} from '../../helpers/custom-validators/video-abuses' 8} from '../../helpers/custom-validators/video-abuses'
9import { AccountModel } from '../account/account' 9import { AccountModel } from '../account/account'
10import { getSort, throwIfNotValid } from '../utils' 10import { buildBlockedAccountSQL, getSort, throwIfNotValid } from '../utils'
11import { VideoModel } from './video' 11import { VideoModel } from './video'
12import { VideoAbuseState } from '../../../shared' 12import { VideoAbuseState } from '../../../shared'
13import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants' 13import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants'
14import { MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models' 14import { MUserAccountId, MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models'
15import * as Bluebird from 'bluebird' 15import * as Bluebird from 'bluebird'
16import { literal, Op } from 'sequelize'
16 17
17@Table({ 18@Table({
18 tableName: 'videoAbuse', 19 tableName: 'videoAbuse',
@@ -85,11 +86,25 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
85 return VideoAbuseModel.findOne(query) 86 return VideoAbuseModel.findOne(query)
86 } 87 }
87 88
88 static listForApi (start: number, count: number, sort: string) { 89 static listForApi (parameters: {
90 start: number,
91 count: number,
92 sort: string,
93 serverAccountId: number
94 user?: MUserAccountId
95 }) {
96 const { start, count, sort, user, serverAccountId } = parameters
97 const userAccountId = user ? user.Account.id : undefined
98
89 const query = { 99 const query = {
90 offset: start, 100 offset: start,
91 limit: count, 101 limit: count,
92 order: getSort(sort), 102 order: getSort(sort),
103 where: {
104 reporterAccountId: {
105 [Op.notIn]: literal('(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')')
106 }
107 },
93 include: [ 108 include: [
94 { 109 {
95 model: AccountModel, 110 model: AccountModel,
diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts
index a2f3ee161..0cd6f22c7 100644
--- a/server/tests/api/videos/video-abuse.ts
+++ b/server/tests/api/videos/video-abuse.ts
@@ -17,6 +17,12 @@ import {
17} from '../../../../shared/extra-utils/index' 17} from '../../../../shared/extra-utils/index'
18import { doubleFollow } from '../../../../shared/extra-utils/server/follows' 18import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
19import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 19import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
20import {
21 addAccountToServerBlocklist,
22 addServerToServerBlocklist,
23 removeAccountFromServerBlocklist,
24 removeServerFromServerBlocklist
25} from '../../../../shared/extra-utils/users/blocklist'
20 26
21const expect = chai.expect 27const expect = chai.expect
22 28
@@ -163,13 +169,76 @@ describe('Test video abuses', function () {
163 expect(res.body.data[0].moderationComment).to.equal('It is valid') 169 expect(res.body.data[0].moderationComment).to.equal('It is valid')
164 }) 170 })
165 171
172 it('Should hide video abuses from blocked accounts', async function () {
173 this.timeout(10000)
174
175 {
176 await reportVideoAbuse(servers[1].url, servers[1].accessToken, servers[0].video.uuid, 'will mute this')
177 await waitJobs(servers)
178
179 const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
180 expect(res.body.total).to.equal(3)
181 }
182
183 const accountToBlock = 'root@localhost:' + servers[1].port
184
185 {
186 await addAccountToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, accountToBlock)
187
188 const res = await getVideoAbusesList(servers[ 0 ].url, servers[ 0 ].accessToken)
189 expect(res.body.total).to.equal(2)
190
191 const abuse = res.body.data.find(a => a.reason === 'will mute this')
192 expect(abuse).to.be.undefined
193 }
194
195 {
196 await removeAccountFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, accountToBlock)
197
198 const res = await getVideoAbusesList(servers[ 0 ].url, servers[ 0 ].accessToken)
199 expect(res.body.total).to.equal(3)
200 }
201 })
202
203 it('Should hide video abuses from blocked servers', async function () {
204 const serverToBlock = servers[1].host
205
206 {
207 await addServerToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, servers[1].host)
208
209 const res = await getVideoAbusesList(servers[ 0 ].url, servers[ 0 ].accessToken)
210 expect(res.body.total).to.equal(2)
211
212 const abuse = res.body.data.find(a => a.reason === 'will mute this')
213 expect(abuse).to.be.undefined
214 }
215
216 {
217 await removeServerFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, serverToBlock)
218
219 const res = await getVideoAbusesList(servers[ 0 ].url, servers[ 0 ].accessToken)
220 expect(res.body.total).to.equal(3)
221 }
222 })
223
166 it('Should delete the video abuse', async function () { 224 it('Should delete the video abuse', async function () {
225 this.timeout(10000)
226
167 await deleteVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id) 227 await deleteVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id)
168 228
169 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken) 229 await waitJobs(servers)
170 expect(res.body.total).to.equal(0) 230
171 expect(res.body.data).to.be.an('array') 231 {
172 expect(res.body.data.length).to.equal(0) 232 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
233 expect(res.body.total).to.equal(1)
234 expect(res.body.data.length).to.equal(1)
235 expect(res.body.data[0].id).to.not.equal(abuseServer2.id)
236 }
237
238 {
239 const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
240 expect(res.body.total).to.equal(3)
241 }
173 }) 242 })
174 243
175 after(async function () { 244 after(async function () {