Introduce blacklist command

pull/4271/head
Chocobozzz 2021-07-08 11:17:55 +02:00
parent a1637fa1e2
commit e3d15a6a9a
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
13 changed files with 173 additions and 226 deletions

View File

@ -1,32 +1,28 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha' import 'mocha'
import { expect } from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
import { import {
BlacklistCommand,
checkBadCountPagination,
checkBadSortPagination,
checkBadStartPagination,
cleanupTests, cleanupTests,
createUser, createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getBlacklistedVideosList,
getVideo, getVideo,
getVideoWithToken, getVideoWithToken,
makePostBodyRequest, makePostBodyRequest,
makePutBodyRequest, makePutBodyRequest,
removeVideoFromBlacklist,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideo, uploadVideo,
userLogin, userLogin,
waitJobs waitJobs
} from '../../../../shared/extra-utils' } from '@shared/extra-utils'
import { import { VideoBlacklistType, VideoDetails } from '@shared/models'
checkBadCountPagination,
checkBadSortPagination,
checkBadStartPagination
} from '../../../../shared/extra-utils/requests/check-api-params'
import { VideoBlacklistType, VideoDetails } from '../../../../shared/models/videos'
import { expect } from 'chai'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
describe('Test video blacklist API validators', function () { describe('Test video blacklist API validators', function () {
let servers: ServerInfo[] let servers: ServerInfo[]
@ -34,6 +30,7 @@ describe('Test video blacklist API validators', function () {
let remoteVideoUUID: string let remoteVideoUUID: string
let userAccessToken1 = '' let userAccessToken1 = ''
let userAccessToken2 = '' let userAccessToken2 = ''
let command: BlacklistCommand
// --------------------------------------------------------------- // ---------------------------------------------------------------
@ -75,6 +72,8 @@ describe('Test video blacklist API validators', function () {
} }
await waitJobs(servers) await waitJobs(servers)
command = servers[0].blacklistCommand
}) })
describe('When adding a video in blacklist', function () { describe('When adding a video in blacklist', function () {
@ -234,25 +233,26 @@ describe('Test video blacklist API validators', function () {
}) })
describe('When removing a video in blacklist', function () { describe('When removing a video in blacklist', function () {
it('Should fail with a non authenticated user', async function () { it('Should fail with a non authenticated user', async function () {
await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401) await command.remove({ token: 'fake token', videoId: servers[0].video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should fail with a non admin user', async function () { it('Should fail with a non admin user', async function () {
await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403) await command.remove({ token: userAccessToken2, videoId: servers[0].video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
}) })
it('Should fail with an incorrect id', async function () { it('Should fail with an incorrect id', async function () {
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) await command.remove({ videoId: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
}) })
it('Should fail with a not blacklisted video', async function () { it('Should fail with a not blacklisted video', async function () {
// The video was not added to the blacklist so it should fail // The video was not added to the blacklist so it should fail
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, HttpStatusCode.NOT_FOUND_404) await command.remove({ videoId: notBlacklistedVideoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
}) })
it('Should succeed with the correct params', async function () { it('Should succeed with the correct params', async function () {
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.NO_CONTENT_204) await command.remove({ videoId: servers[0].video.uuid, expectedStatus: HttpStatusCode.NO_CONTENT_204 })
}) })
}) })
@ -260,11 +260,11 @@ describe('Test video blacklist API validators', function () {
const basePath = '/api/v1/videos/blacklist/' const basePath = '/api/v1/videos/blacklist/'
it('Should fail with a non authenticated user', async function () { it('Should fail with a non authenticated user', async function () {
await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: HttpStatusCode.UNAUTHORIZED_401 }) await servers[0].blacklistCommand.list({ token: 'fake token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
}) })
it('Should fail with a non admin user', async function () { it('Should fail with a non admin user', async function () {
await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: HttpStatusCode.FORBIDDEN_403 }) await servers[0].blacklistCommand.list({ token: userAccessToken2, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
}) })
it('Should fail with a bad start pagination', async function () { it('Should fail with a bad start pagination', async function () {
@ -280,16 +280,11 @@ describe('Test video blacklist API validators', function () {
}) })
it('Should fail with an invalid type', async function () { it('Should fail with an invalid type', async function () {
await getBlacklistedVideosList({ await servers[0].blacklistCommand.list({ type: 0, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
url: servers[0].url,
token: servers[0].accessToken,
type: 0,
specialStatus: HttpStatusCode.BAD_REQUEST_400
})
}) })
it('Should succeed with the correct parameters', async function () { it('Should succeed with the correct parameters', async function () {
await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: VideoBlacklistType.MANUAL }) await servers[0].blacklistCommand.list({ type: VideoBlacklistType.MANUAL })
}) })
}) })

View File

@ -6,7 +6,6 @@ import { FfmpegCommand } from 'fluent-ffmpeg'
import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
addVideoToBlacklist,
checkLiveCleanup, checkLiveCleanup,
cleanupTests, cleanupTests,
ConfigCommand, ConfigCommand,
@ -172,7 +171,7 @@ describe('Save replay setting', function () {
await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
await Promise.all([ await Promise.all([
addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true), servers[0].blacklistCommand.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }),
testFfmpegStreamError(ffmpegCommand, true) testFfmpegStreamError(ffmpegCommand, true)
]) ])
@ -280,7 +279,7 @@ describe('Save replay setting', function () {
await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
await Promise.all([ await Promise.all([
addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true), servers[0].blacklistCommand.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }),
testFfmpegStreamError(ffmpegCommand, true) testFfmpegStreamError(ffmpegCommand, true)
]) ])

View File

@ -7,7 +7,6 @@ import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-
import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
addVideoToBlacklist,
buildServerDirectory, buildServerDirectory,
checkLiveCleanup, checkLiveCleanup,
checkLiveSegmentHash, checkLiveSegmentHash,
@ -347,7 +346,7 @@ describe('Test live', function () {
liveVideo = await createLiveWrapper() liveVideo = await createLiveWrapper()
await addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideo.uuid) await servers[0].blacklistCommand.add({ videoId: liveVideo.uuid })
const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey) const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey)
await testFfmpegStreamError(command, true) await testFfmpegStreamError(command, true)

View File

@ -4,22 +4,19 @@ import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { orderBy } from 'lodash' import { orderBy } from 'lodash'
import { import {
addVideoToBlacklist, BlacklistCommand,
cleanupTests, cleanupTests,
createUser, createUser,
doubleFollow, doubleFollow,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getBlacklistedVideosList,
getMyUserInformation, getMyUserInformation,
getMyVideos, getMyVideos,
getVideosList, getVideosList,
killallServers, killallServers,
removeVideoFromBlacklist,
reRunServer, reRunServer,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
updateVideo, updateVideo,
updateVideoBlacklist,
uploadVideo, uploadVideo,
userLogin, userLogin,
waitJobs waitJobs
@ -32,13 +29,14 @@ const expect = chai.expect
describe('Test video blacklist', function () { describe('Test video blacklist', function () {
let servers: ServerInfo[] = [] let servers: ServerInfo[] = []
let videoId: number let videoId: number
let command: BlacklistCommand
async function blacklistVideosOnServer (server: ServerInfo) { async function blacklistVideosOnServer (server: ServerInfo) {
const res = await getVideosList(server.url) const res = await getVideosList(server.url)
const videos = res.body.data const videos = res.body.data
for (const video of videos) { for (const video of videos) {
await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason') await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' })
} }
} }
@ -61,6 +59,8 @@ describe('Test video blacklist', function () {
// Wait videos propagation, server 2 has transcoding enabled // Wait videos propagation, server 2 has transcoding enabled
await waitJobs(servers) await waitJobs(servers)
command = servers[0].blacklistCommand
// Blacklist the two videos on server 1 // Blacklist the two videos on server 1
await blacklistVideosOnServer(servers[0]) await blacklistVideosOnServer(servers[0])
}) })
@ -77,7 +77,7 @@ describe('Test video blacklist', function () {
} }
{ {
const body = await servers[0].searchCommand.searchVideos({ search: 'name' }) const body = await servers[0].searchCommand.searchVideos({ search: 'video' })
expect(body.total).to.equal(0) expect(body.total).to.equal(0)
expect(body.data).to.be.an('array') expect(body.data).to.be.an('array')
@ -95,7 +95,7 @@ describe('Test video blacklist', function () {
} }
{ {
const body = await servers[1].searchCommand.searchVideos({ search: 'name' }) const body = await servers[1].searchCommand.searchVideos({ search: 'video' })
expect(body.total).to.equal(2) expect(body.total).to.equal(2)
expect(body.data).to.be.an('array') expect(body.data).to.be.an('array')
@ -106,11 +106,10 @@ describe('Test video blacklist', function () {
describe('When listing manually blacklisted videos', function () { describe('When listing manually blacklisted videos', function () {
it('Should display all the blacklisted videos', async function () { it('Should display all the blacklisted videos', async function () {
const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken }) const body = await command.list()
expect(body.total).to.equal(2)
expect(res.body.total).to.equal(2) const blacklistedVideos = body.data
const blacklistedVideos = res.body.data
expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos).to.be.an('array')
expect(blacklistedVideos.length).to.equal(2) expect(blacklistedVideos.length).to.equal(2)
@ -121,79 +120,66 @@ describe('Test video blacklist', function () {
}) })
it('Should display all the blacklisted videos when applying manual type filter', async function () { it('Should display all the blacklisted videos when applying manual type filter', async function () {
const res = await getBlacklistedVideosList({ const body = await command.list({ type: VideoBlacklistType.MANUAL })
url: servers[0].url, expect(body.total).to.equal(2)
token: servers[0].accessToken,
type: VideoBlacklistType.MANUAL
})
expect(res.body.total).to.equal(2) const blacklistedVideos = body.data
const blacklistedVideos = res.body.data
expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos).to.be.an('array')
expect(blacklistedVideos.length).to.equal(2) expect(blacklistedVideos.length).to.equal(2)
}) })
it('Should display nothing when applying automatic type filter', async function () { it('Should display nothing when applying automatic type filter', async function () {
const res = await getBlacklistedVideosList({ const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
url: servers[0].url, expect(body.total).to.equal(0)
token: servers[0].accessToken,
type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
})
expect(res.body.total).to.equal(0) const blacklistedVideos = body.data
const blacklistedVideos = res.body.data
expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos).to.be.an('array')
expect(blacklistedVideos.length).to.equal(0) expect(blacklistedVideos.length).to.equal(0)
}) })
it('Should get the correct sort when sorting by descending id', async function () { it('Should get the correct sort when sorting by descending id', async function () {
const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-id' }) const body = await command.list({ sort: '-id' })
expect(res.body.total).to.equal(2) expect(body.total).to.equal(2)
const blacklistedVideos = res.body.data const blacklistedVideos = body.data
expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos).to.be.an('array')
expect(blacklistedVideos.length).to.equal(2) expect(blacklistedVideos.length).to.equal(2)
const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ]) const result = orderBy(body.data, [ 'id' ], [ 'desc' ])
expect(blacklistedVideos).to.deep.equal(result) expect(blacklistedVideos).to.deep.equal(result)
}) })
it('Should get the correct sort when sorting by descending video name', async function () { it('Should get the correct sort when sorting by descending video name', async function () {
const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) const body = await command.list({ sort: '-name' })
expect(res.body.total).to.equal(2) expect(body.total).to.equal(2)
const blacklistedVideos = res.body.data const blacklistedVideos = body.data
expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos).to.be.an('array')
expect(blacklistedVideos.length).to.equal(2) expect(blacklistedVideos.length).to.equal(2)
const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ]) const result = orderBy(body.data, [ 'name' ], [ 'desc' ])
expect(blacklistedVideos).to.deep.equal(result) expect(blacklistedVideos).to.deep.equal(result)
}) })
it('Should get the correct sort when sorting by ascending creation date', async function () { it('Should get the correct sort when sorting by ascending creation date', async function () {
const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' }) const body = await command.list({ sort: 'createdAt' })
expect(res.body.total).to.equal(2) expect(body.total).to.equal(2)
const blacklistedVideos = res.body.data const blacklistedVideos = body.data
expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos).to.be.an('array')
expect(blacklistedVideos.length).to.equal(2) expect(blacklistedVideos.length).to.equal(2)
const result = orderBy(res.body.data, [ 'createdAt' ]) const result = orderBy(body.data, [ 'createdAt' ])
expect(blacklistedVideos).to.deep.equal(result) expect(blacklistedVideos).to.deep.equal(result)
}) })
}) })
describe('When updating blacklisted videos', function () { describe('When updating blacklisted videos', function () {
it('Should change the reason', async function () { it('Should change the reason', async function () {
await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') await command.update({ videoId, reason: 'my super reason updated' })
const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) const body = await command.list({ sort: '-name' })
const video = res.body.data.find(b => b.video.id === videoId) const video = body.data.find(b => b.video.id === videoId)
expect(video.reason).to.equal('my super reason updated') expect(video.reason).to.equal('my super reason updated')
}) })
@ -228,12 +214,12 @@ describe('Test video blacklist', function () {
it('Should remove a video from the blacklist on server 1', async function () { it('Should remove a video from the blacklist on server 1', async function () {
// Get one video in the blacklist // Get one video in the blacklist
const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) const body = await command.list({ sort: '-name' })
videoToRemove = res.body.data[0] videoToRemove = body.data[0]
blacklist = res.body.data.slice(1) blacklist = body.data.slice(1)
// Remove it // Remove it
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id) await command.remove({ videoId: videoToRemove.video.id })
}) })
it('Should have the ex-blacklisted video in videos list on server 1', async function () { it('Should have the ex-blacklisted video in videos list on server 1', async function () {
@ -249,10 +235,10 @@ describe('Test video blacklist', function () {
}) })
it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) const body = await command.list({ sort: '-name' })
expect(res.body.total).to.equal(1) expect(body.total).to.equal(1)
const videos = res.body.data const videos = body.data
expect(videos).to.be.an('array') expect(videos).to.be.an('array')
expect(videos.length).to.equal(1) expect(videos.length).to.equal(1)
expect(videos).to.deep.equal(blacklist) expect(videos).to.deep.equal(blacklist)
@ -281,7 +267,7 @@ describe('Test video blacklist', function () {
it('Should blacklist video 3 and keep it federated', async function () { it('Should blacklist video 3 and keep it federated', async function () {
this.timeout(10000) this.timeout(10000)
await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video3UUID, 'super reason', false) await command.add({ videoId: video3UUID, reason: 'super reason', unfederate: false })
await waitJobs(servers) await waitJobs(servers)
@ -299,7 +285,7 @@ describe('Test video blacklist', function () {
it('Should unfederate the video', async function () { it('Should unfederate the video', async function () {
this.timeout(10000) this.timeout(10000)
await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video4UUID, 'super reason', true) await command.add({ videoId: video4UUID, reason: 'super reason', unfederate: true })
await waitJobs(servers) await waitJobs(servers)
@ -323,9 +309,9 @@ describe('Test video blacklist', function () {
}) })
it('Should have the correct video blacklist unfederate attribute', async function () { it('Should have the correct video blacklist unfederate attribute', async function () {
const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' }) const body = await command.list({ sort: 'createdAt' })
const blacklistedVideos: VideoBlacklist[] = res.body.data const blacklistedVideos = body.data
const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID)
const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID) const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID)
@ -336,7 +322,7 @@ describe('Test video blacklist', function () {
it('Should remove the video from blacklist and refederate the video', async function () { it('Should remove the video from blacklist and refederate the video', async function () {
this.timeout(10000) this.timeout(10000)
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video4UUID) await command.remove({ videoId: video4UUID })
await waitJobs(servers) await waitJobs(servers)
@ -407,14 +393,9 @@ describe('Test video blacklist', function () {
it('Should auto blacklist a video on upload', async function () { it('Should auto blacklist a video on upload', async function () {
await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' })
const res = await getBlacklistedVideosList({ const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
url: servers[0].url, expect(body.total).to.equal(1)
token: servers[0].accessToken, expect(body.data[0].video.name).to.equal('blacklisted')
type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
})
expect(res.body.total).to.equal(1)
expect(res.body.data[0].video.name).to.equal('blacklisted')
}) })
it('Should auto blacklist a video on URL import', async function () { it('Should auto blacklist a video on URL import', async function () {
@ -427,15 +408,9 @@ describe('Test video blacklist', function () {
} }
await importVideo(servers[0].url, userWithoutFlag, attributes) await importVideo(servers[0].url, userWithoutFlag, attributes)
const res = await getBlacklistedVideosList({ const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
url: servers[0].url, expect(body.total).to.equal(2)
token: servers[0].accessToken, expect(body.data[1].video.name).to.equal('URL import')
sort: 'createdAt',
type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
})
expect(res.body.total).to.equal(2)
expect(res.body.data[1].video.name).to.equal('URL import')
}) })
it('Should auto blacklist a video on torrent import', async function () { it('Should auto blacklist a video on torrent import', async function () {
@ -446,27 +421,16 @@ describe('Test video blacklist', function () {
} }
await importVideo(servers[0].url, userWithoutFlag, attributes) await importVideo(servers[0].url, userWithoutFlag, attributes)
const res = await getBlacklistedVideosList({ const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
url: servers[0].url, expect(body.total).to.equal(3)
token: servers[0].accessToken, expect(body.data[2].video.name).to.equal('Torrent import')
sort: 'createdAt',
type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
})
expect(res.body.total).to.equal(3)
expect(res.body.data[2].video.name).to.equal('Torrent import')
}) })
it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () {
await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' })
const res = await getBlacklistedVideosList({ const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
url: servers[0].url, expect(body.total).to.equal(3)
token: servers[0].accessToken,
type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
})
expect(res.body.total).to.equal(3)
}) })
}) })

View File

@ -4,7 +4,6 @@ import 'mocha'
import { buildUUID } from '@server/helpers/uuid' import { buildUUID } from '@server/helpers/uuid'
import { import {
addVideoCommentThread, addVideoCommentThread,
addVideoToBlacklist,
checkAbuseStateChange, checkAbuseStateChange,
checkAutoInstanceFollowing, checkAutoInstanceFollowing,
CheckerBaseParams, CheckerBaseParams,
@ -28,7 +27,6 @@ import {
MockSmtpServer, MockSmtpServer,
prepareNotificationsTest, prepareNotificationsTest,
registerUser, registerUser,
removeVideoFromBlacklist,
ServerInfo, ServerInfo,
uploadVideo, uploadVideo,
wait, wait,
@ -297,7 +295,7 @@ describe('Test moderation notifications', function () {
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
const uuid = resVideo.body.video.uuid const uuid = resVideo.body.video.uuid
await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) await servers[0].blacklistCommand.add({ videoId: uuid })
await waitJobs(servers) await waitJobs(servers)
await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist') await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
@ -310,10 +308,10 @@ describe('Test moderation notifications', function () {
const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name })
const uuid = resVideo.body.video.uuid const uuid = resVideo.body.video.uuid
await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) await servers[0].blacklistCommand.add({ videoId: uuid })
await waitJobs(servers) await waitJobs(servers)
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) await servers[0].blacklistCommand.remove({ videoId: uuid })
await waitJobs(servers) await waitJobs(servers)
await wait(500) await wait(500)
@ -517,7 +515,7 @@ describe('Test moderation notifications', function () {
it('Should send video published and unblacklist after video unblacklisted', async function () { it('Should send video published and unblacklist after video unblacklisted', async function () {
this.timeout(40000) this.timeout(40000)
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID) await servers[0].blacklistCommand.remove({ videoId: videoUUID })
await waitJobs(servers) await waitJobs(servers)
@ -554,7 +552,7 @@ describe('Test moderation notifications', function () {
const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) const resVideo = await uploadVideo(servers[0].url, userAccessToken, data)
const uuid = resVideo.body.video.uuid const uuid = resVideo.body.video.uuid
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) await servers[0].blacklistCommand.remove({ videoId: uuid })
await waitJobs(servers) await waitJobs(servers)
await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist') await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')

View File

@ -4,14 +4,12 @@ import 'mocha'
import * as chai from 'chai' import * as chai from 'chai'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { import {
addVideoToBlacklist,
askResetPassword, askResetPassword,
askSendVerifyEmail, askSendVerifyEmail,
blockUser, blockUser,
cleanupTests, cleanupTests,
createUser, createUser,
flushAndRunServer, flushAndRunServer,
removeVideoFromBlacklist,
resetPassword, resetPassword,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
@ -248,7 +246,7 @@ describe('Test emails', function () {
this.timeout(10000) this.timeout(10000)
const reason = 'my super reason' const reason = 'my super reason'
await addVideoToBlacklist(server.url, server.accessToken, videoUserUUID, reason) await server.blacklistCommand.add({ videoId: videoUserUUID, reason })
await waitJobs(server) await waitJobs(server)
expect(emails).to.have.lengthOf(6) expect(emails).to.have.lengthOf(6)
@ -266,7 +264,7 @@ describe('Test emails', function () {
it('Should send the notification email', async function () { it('Should send the notification email', async function () {
this.timeout(10000) this.timeout(10000)
await removeVideoFromBlacklist(server.url, server.accessToken, videoUserUUID) await server.blacklistCommand.remove({ videoId: videoUserUUID })
await waitJobs(server) await waitJobs(server)
expect(emails).to.have.lengthOf(7) expect(emails).to.have.lengthOf(7)

View File

@ -11,7 +11,6 @@ import {
createUser, createUser,
deleteMe, deleteMe,
flushAndRunServer, flushAndRunServer,
getBlacklistedVideosList,
getMyUserInformation, getMyUserInformation,
getMyUserVideoQuotaUsed, getMyUserVideoQuotaUsed,
getMyUserVideoRating, getMyUserVideoRating,
@ -808,7 +807,7 @@ describe('Test users', function () {
describe('Video blacklists', function () { describe('Video blacklists', function () {
it('Should be able to list video blacklist by a moderator', async function () { it('Should be able to list video blacklist by a moderator', async function () {
await getBlacklistedVideosList({ url: server.url, token: accessTokenUser }) await server.blacklistCommand.list({ token: accessTokenUser })
}) })
}) })

View File

@ -6,7 +6,6 @@ import { HttpStatusCode } from '@shared/core-utils'
import { import {
addVideoChannel, addVideoChannel,
addVideoInPlaylist, addVideoInPlaylist,
addVideoToBlacklist,
checkPlaylistFilesWereRemoved, checkPlaylistFilesWereRemoved,
cleanupTests, cleanupTests,
createUser, createUser,
@ -28,7 +27,6 @@ import {
getVideoPlaylistsList, getVideoPlaylistsList,
getVideoPlaylistWithToken, getVideoPlaylistWithToken,
removeUser, removeUser,
removeVideoFromBlacklist,
removeVideoFromPlaylist, removeVideoFromPlaylist,
reorderVideosPlaylist, reorderVideosPlaylist,
ServerInfo, ServerInfo,
@ -728,7 +726,7 @@ describe('Test video playlists', function () {
const position = 1 const position = 1
{ {
await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video1, 'reason', true) await servers[0].blacklistCommand.add({ videoId: video1, reason: 'reason', unfederate: true })
await waitJobs(servers) await waitJobs(servers)
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)
@ -738,7 +736,7 @@ describe('Test video playlists', function () {
} }
{ {
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video1) await servers[0].blacklistCommand.remove({ videoId: video1 })
await waitJobs(servers) await waitJobs(servers)
await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3)

View File

@ -2,13 +2,11 @@
import 'mocha' import 'mocha'
import { expect } from 'chai' import { expect } from 'chai'
import { Video, VideoBlacklist } from '@shared/models' import { Video } from '@shared/models'
import { import {
doubleFollow, doubleFollow,
getBlacklistedVideosList,
getVideosList, getVideosList,
MockBlocklist, MockBlocklist,
removeVideoFromBlacklist,
setAccessTokensToServers, setAccessTokensToServers,
uploadVideoAndGetId, uploadVideoAndGetId,
wait wait
@ -97,10 +95,9 @@ describe('Official plugin auto-block videos', function () {
}) })
it('Should have video in blacklists', async function () { it('Should have video in blacklists', async function () {
const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken }) const body = await servers[0].blacklistCommand.list()
const videoBlacklists = res.body.data as VideoBlacklist[]
const videoBlacklists = body.data
expect(videoBlacklists).to.have.lengthOf(1) expect(videoBlacklists).to.have.lengthOf(1)
expect(videoBlacklists[0].reason).to.contains('Automatically blocked from auto block plugin') expect(videoBlacklists[0].reason).to.contains('Automatically blocked from auto block plugin')
expect(videoBlacklists[0].video.name).to.equal(server2Videos[0].name) expect(videoBlacklists[0].video.name).to.equal(server2Videos[0].name)
@ -163,7 +160,7 @@ describe('Official plugin auto-block videos', function () {
await check(servers[0], video.uuid, false) await check(servers[0], video.uuid, false)
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video.uuid) await servers[0].blacklistCommand.remove({ videoId: video.uuid })
await check(servers[0], video.uuid, true) await check(servers[0], video.uuid, true)

View File

@ -18,7 +18,7 @@ import { makeGetRequest } from '../requests/requests'
import { SearchCommand } from '../search' import { SearchCommand } from '../search'
import { SocketIOCommand } from '../socket' import { SocketIOCommand } from '../socket'
import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users'
import { LiveCommand, ServicesCommand } from '../videos' import { LiveCommand, ServicesCommand, BlacklistCommand } from '../videos'
import { ConfigCommand } from './config-command' import { ConfigCommand } from './config-command'
import { ContactFormCommand } from './contact-form-command' import { ContactFormCommand } from './contact-form-command'
import { DebugCommand } from './debug-command' import { DebugCommand } from './debug-command'
@ -102,6 +102,7 @@ interface ServerInfo {
subscriptionsCommand?: SubscriptionsCommand subscriptionsCommand?: SubscriptionsCommand
liveCommand?: LiveCommand liveCommand?: LiveCommand
servicesCommand?: ServicesCommand servicesCommand?: ServicesCommand
blacklistCommand?: BlacklistCommand
} }
function parallelTests () { function parallelTests () {
@ -329,6 +330,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
server.subscriptionsCommand = new SubscriptionsCommand(server) server.subscriptionsCommand = new SubscriptionsCommand(server)
server.liveCommand = new LiveCommand(server) server.liveCommand = new LiveCommand(server)
server.servicesCommand = new ServicesCommand(server) server.servicesCommand = new ServicesCommand(server)
server.blacklistCommand = new BlacklistCommand(server)
res(server) res(server)
}) })

View File

@ -0,0 +1,77 @@
import { ResultList } from '@shared/models'
import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
import { VideoBlacklist, VideoBlacklistType } from '../../models/videos'
import { AbstractCommand, OverrideCommandOptions } from '../shared'
export class BlacklistCommand extends AbstractCommand {
add (options: OverrideCommandOptions & {
videoId: number | string
reason?: string
unfederate?: boolean
}) {
const { videoId, reason, unfederate } = options
const path = '/api/v1/videos/' + videoId + '/blacklist'
return this.postBodyRequest({
...options,
path,
fields: { reason, unfederate },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
update (options: OverrideCommandOptions & {
videoId: number | string
reason?: string
}) {
const { videoId, reason } = options
const path = '/api/v1/videos/' + videoId + '/blacklist'
return this.putBodyRequest({
...options,
path,
fields: { reason },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
remove (options: OverrideCommandOptions & {
videoId: number | string
}) {
const { videoId } = options
const path = '/api/v1/videos/' + videoId + '/blacklist'
return this.deleteRequest({
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
list (options: OverrideCommandOptions & {
sort?: string
type?: VideoBlacklistType
} = {}) {
const { sort, type } = options
const path = '/api/v1/videos/blacklist/'
const query = { sort, type }
return this.getRequestBody<ResultList<VideoBlacklist>>({
...options,
path,
query,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
}

View File

@ -1,7 +1,7 @@
export * from './blacklist-command'
export * from './live-command' export * from './live-command'
export * from './live' export * from './live'
export * from './services-command' export * from './services-command'
export * from './video-blacklist'
export * from './video-captions' export * from './video-captions'
export * from './video-change-ownership' export * from './video-change-ownership'
export * from './video-channels' export * from './video-channels'

View File

@ -1,79 +0,0 @@
import * as request from 'supertest'
import { VideoBlacklistType } from '../../models/videos'
import { makeGetRequest } from '..'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
function addVideoToBlacklist (
url: string,
token: string,
videoId: number | string,
reason?: string,
unfederate?: boolean,
specialStatus = HttpStatusCode.NO_CONTENT_204
) {
const path = '/api/v1/videos/' + videoId + '/blacklist'
return request(url)
.post(path)
.send({ reason, unfederate })
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + token)
.expect(specialStatus)
}
function updateVideoBlacklist (
url: string,
token: string,
videoId: number,
reason?: string,
specialStatus = HttpStatusCode.NO_CONTENT_204
) {
const path = '/api/v1/videos/' + videoId + '/blacklist'
return request(url)
.put(path)
.send({ reason })
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + token)
.expect(specialStatus)
}
function removeVideoFromBlacklist (url: string, token: string, videoId: number | string, specialStatus = HttpStatusCode.NO_CONTENT_204) {
const path = '/api/v1/videos/' + videoId + '/blacklist'
return request(url)
.delete(path)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + token)
.expect(specialStatus)
}
function getBlacklistedVideosList (parameters: {
url: string
token: string
sort?: string
type?: VideoBlacklistType
specialStatus?: HttpStatusCode
}) {
const { url, token, sort, type, specialStatus = HttpStatusCode.OK_200 } = parameters
const path = '/api/v1/videos/blacklist/'
const query = { sort, type }
return makeGetRequest({
url,
path,
query,
token,
statusCodeExpected: specialStatus
})
}
// ---------------------------------------------------------------------------
export {
addVideoToBlacklist,
removeVideoFromBlacklist,
getBlacklistedVideosList,
updateVideoBlacklist
}