Add ability to unfederate a local video (on blacklist)
This commit is contained in:
parent
93f85e90ff
commit
5abb9fbbd1
21 changed files with 456 additions and 318 deletions
|
@ -7,6 +7,7 @@
|
||||||
<th style="width: 40px"></th>
|
<th style="width: 40px"></th>
|
||||||
<th i18n pSortableColumn="name">Video name <p-sortIcon field="name"></p-sortIcon></th>
|
<th i18n pSortableColumn="name">Video name <p-sortIcon field="name"></p-sortIcon></th>
|
||||||
<th i18n>Sensitive</th>
|
<th i18n>Sensitive</th>
|
||||||
|
<th i18n>Unfederated</th>
|
||||||
<th i18n pSortableColumn="createdAt">Date <p-sortIcon field="createdAt"></p-sortIcon></th>
|
<th i18n pSortableColumn="createdAt">Date <p-sortIcon field="createdAt"></p-sortIcon></th>
|
||||||
<th style="width: 120px;"></th>
|
<th style="width: 120px;"></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -26,7 +27,8 @@
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td>{{ videoBlacklist.video.nsfw }}</td>
|
<td>{{ booleanToText(videoBlacklist.video.nsfw) }}</td>
|
||||||
|
<td>{{ booleanToText(videoBlacklist.unfederated) }}</td>
|
||||||
<td>{{ videoBlacklist.createdAt }}</td>
|
<td>{{ videoBlacklist.createdAt }}</td>
|
||||||
|
|
||||||
<td class="action-cell">
|
<td class="action-cell">
|
||||||
|
@ -37,7 +39,7 @@
|
||||||
|
|
||||||
<ng-template pTemplate="rowexpansion" let-videoBlacklist>
|
<ng-template pTemplate="rowexpansion" let-videoBlacklist>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="moderation-expanded" colspan="5">
|
<td class="moderation-expanded" colspan="6">
|
||||||
<span i18n class="moderation-expanded-label">Blacklist reason:</span>
|
<span i18n class="moderation-expanded-label">Blacklist reason:</span>
|
||||||
<span class="moderation-expanded-text">{{ videoBlacklist.reason }}</span>
|
<span class="moderation-expanded-text">{{ videoBlacklist.reason }}</span>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -46,6 +46,12 @@ export class VideoBlacklistListComponent extends RestTable implements OnInit {
|
||||||
return Video.buildClientUrl(videoBlacklist.video.uuid)
|
return Video.buildClientUrl(videoBlacklist.video.uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
booleanToText (value: boolean) {
|
||||||
|
if (value === true) return this.i18n('yes')
|
||||||
|
|
||||||
|
return this.i18n('no')
|
||||||
|
}
|
||||||
|
|
||||||
async removeVideoFromBlacklist (entry: VideoBlacklist) {
|
async removeVideoFromBlacklist (entry: VideoBlacklist) {
|
||||||
const confirmMessage = this.i18n(
|
const confirmMessage = this.i18n(
|
||||||
'Do you really want to remove this video from the blacklist? It will be available again in the videos list.'
|
'Do you really want to remove this video from the blacklist? It will be available again in the videos list.'
|
||||||
|
|
|
@ -65,7 +65,9 @@
|
||||||
<span i18n *ngIf="user.blocked" class="banned-info">(banned)</span>
|
<span i18n *ngIf="user.blocked" class="banned-info">(banned)</span>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td *ngIf="!requiresEmailVerification || user.blocked; else emailWithVerificationStatus">{{ user.email }}</td>
|
<td *ngIf="!requiresEmailVerification || user.blocked; else emailWithVerificationStatus">{{ user.email }}</td>
|
||||||
|
|
||||||
<ng-template #emailWithVerificationStatus>
|
<ng-template #emailWithVerificationStatus>
|
||||||
<td *ngIf="user.emailVerified === false; else emailVerifiedNotFalse" i18n-title title="User's email must be verified to login">
|
<td *ngIf="user.emailVerified === false; else emailVerifiedNotFalse" i18n-title title="User's email must be verified to login">
|
||||||
<em>? {{ user.email }}</em>
|
<em>? {{ user.email }}</em>
|
||||||
|
@ -76,6 +78,7 @@
|
||||||
</td>
|
</td>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
<td>{{ user.videoQuotaUsed }} / {{ user.videoQuota }}</td>
|
<td>{{ user.videoQuotaUsed }} / {{ user.videoQuota }}</td>
|
||||||
<td>{{ user.roleLabel }}</td>
|
<td>{{ user.roleLabel }}</td>
|
||||||
<td>{{ user.createdAt }}</td>
|
<td>{{ user.createdAt }}</td>
|
||||||
|
|
|
@ -36,8 +36,11 @@ export class VideoBlacklistService {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
blacklistVideo (videoId: number, reason?: string) {
|
blacklistVideo (videoId: number, reason: string, unfederate: boolean) {
|
||||||
const body = reason ? { reason } : {}
|
const body = {
|
||||||
|
unfederate,
|
||||||
|
reason
|
||||||
|
}
|
||||||
|
|
||||||
return this.authHttp.post(VideoBlacklistService.BASE_VIDEOS_URL + videoId + '/blacklist', body)
|
return this.authHttp.post(VideoBlacklistService.BASE_VIDEOS_URL + videoId + '/blacklist', body)
|
||||||
.pipe(
|
.pipe(
|
||||||
|
|
|
@ -15,6 +15,13 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group" *ngIf="video.isLocal">
|
||||||
|
<my-peertube-checkbox
|
||||||
|
inputName="unfederate" formControlName="unfederate"
|
||||||
|
i18n-labelText labelText="Unfederate the video (ask for its deletion from the remote instances)"
|
||||||
|
></my-peertube-checkbox>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group inputs">
|
<div class="form-group inputs">
|
||||||
<span i18n class="action-button action-button-cancel" (click)="hide()">
|
<span i18n class="action-button action-button-cancel" (click)="hide()">
|
||||||
Cancel
|
Cancel
|
||||||
|
|
|
@ -34,9 +34,12 @@ export class VideoBlacklistComponent extends FormReactive implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit () {
|
ngOnInit () {
|
||||||
|
const defaultValues = { unfederate: 'true' }
|
||||||
|
|
||||||
this.buildForm({
|
this.buildForm({
|
||||||
reason: this.videoBlacklistValidatorsService.VIDEO_BLACKLIST_REASON
|
reason: this.videoBlacklistValidatorsService.VIDEO_BLACKLIST_REASON,
|
||||||
})
|
unfederate: null
|
||||||
|
}, defaultValues)
|
||||||
}
|
}
|
||||||
|
|
||||||
show () {
|
show () {
|
||||||
|
@ -50,8 +53,9 @@ export class VideoBlacklistComponent extends FormReactive implements OnInit {
|
||||||
|
|
||||||
blacklist () {
|
blacklist () {
|
||||||
const reason = this.form.value[ 'reason' ] || undefined
|
const reason = this.form.value[ 'reason' ] || undefined
|
||||||
|
const unfederate = this.video.isLocal ? this.form.value[ 'unfederate' ] : undefined
|
||||||
|
|
||||||
this.videoBlacklistService.blacklistVideo(this.video.id, reason)
|
this.videoBlacklistService.blacklistVideo(this.video.id, reason, unfederate)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
() => {
|
() => {
|
||||||
this.notifier.success(this.i18n('Video blacklisted.'))
|
this.notifier.success(this.i18n('Video blacklisted.'))
|
||||||
|
|
|
@ -18,6 +18,8 @@ import { VideoBlacklistModel } from '../../../models/video/video-blacklist'
|
||||||
import { sequelizeTypescript } from '../../../initializers'
|
import { sequelizeTypescript } from '../../../initializers'
|
||||||
import { Notifier } from '../../../lib/notifier'
|
import { Notifier } from '../../../lib/notifier'
|
||||||
import { VideoModel } from '../../../models/video/video'
|
import { VideoModel } from '../../../models/video/video'
|
||||||
|
import { sendCreateVideo, sendDeleteVideo, sendUpdateVideo } from '../../../lib/activitypub/send'
|
||||||
|
import { federateVideoIfNeeded } from '../../../lib/activitypub'
|
||||||
|
|
||||||
const blacklistRouter = express.Router()
|
const blacklistRouter = express.Router()
|
||||||
|
|
||||||
|
@ -66,12 +68,17 @@ async function addVideoToBlacklist (req: express.Request, res: express.Response)
|
||||||
|
|
||||||
const toCreate = {
|
const toCreate = {
|
||||||
videoId: videoInstance.id,
|
videoId: videoInstance.id,
|
||||||
|
unfederated: body.unfederate === true,
|
||||||
reason: body.reason
|
reason: body.reason
|
||||||
}
|
}
|
||||||
|
|
||||||
const blacklist = await VideoBlacklistModel.create(toCreate)
|
const blacklist = await VideoBlacklistModel.create(toCreate)
|
||||||
blacklist.Video = videoInstance
|
blacklist.Video = videoInstance
|
||||||
|
|
||||||
|
if (body.unfederate === true) {
|
||||||
|
await sendDeleteVideo(videoInstance, undefined)
|
||||||
|
}
|
||||||
|
|
||||||
Notifier.Instance.notifyOnVideoBlacklist(blacklist)
|
Notifier.Instance.notifyOnVideoBlacklist(blacklist)
|
||||||
|
|
||||||
logger.info('Video %s blacklisted.', res.locals.video.uuid)
|
logger.info('Video %s blacklisted.', res.locals.video.uuid)
|
||||||
|
@ -101,8 +108,14 @@ async function removeVideoFromBlacklistController (req: express.Request, res: ex
|
||||||
const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel
|
const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel
|
||||||
const video: VideoModel = res.locals.video
|
const video: VideoModel = res.locals.video
|
||||||
|
|
||||||
await sequelizeTypescript.transaction(t => {
|
await sequelizeTypescript.transaction(async t => {
|
||||||
return videoBlacklist.destroy({ transaction: t })
|
const unfederated = videoBlacklist.unfederated
|
||||||
|
await videoBlacklist.destroy({ transaction: t })
|
||||||
|
|
||||||
|
// Re federate the video
|
||||||
|
if (unfederated === true) {
|
||||||
|
await federateVideoIfNeeded(video, true, t)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
Notifier.Instance.notifyOnVideoUnblacklist(video)
|
Notifier.Instance.notifyOnVideoUnblacklist(video)
|
||||||
|
|
|
@ -364,7 +364,11 @@ async function updateVideo (req: express.Request, res: express.Response) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE
|
const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE
|
||||||
await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
|
|
||||||
|
// Don't send update if the video was unfederated
|
||||||
|
if (!videoInstanceUpdated.VideoBlacklist || videoInstanceUpdated.VideoBlacklist.unfederated === false) {
|
||||||
|
await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
|
||||||
|
}
|
||||||
|
|
||||||
auditLogger.update(
|
auditLogger.update(
|
||||||
getAuditIdFromRes(res),
|
getAuditIdFromRes(res),
|
||||||
|
|
|
@ -16,7 +16,7 @@ let config: IConfig = require('config')
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
const LAST_MIGRATION_VERSION = 315
|
const LAST_MIGRATION_VERSION = 320
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
27
server/initializers/migrations/0320-blacklist-unfederate.ts
Normal file
27
server/initializers/migrations/0320-blacklist-unfederate.ts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import * as Sequelize from 'sequelize'
|
||||||
|
|
||||||
|
async function up (utils: {
|
||||||
|
transaction: Sequelize.Transaction,
|
||||||
|
queryInterface: Sequelize.QueryInterface,
|
||||||
|
sequelize: Sequelize.Sequelize
|
||||||
|
}): Promise<void> {
|
||||||
|
|
||||||
|
{
|
||||||
|
const data = {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: false
|
||||||
|
}
|
||||||
|
|
||||||
|
await utils.queryInterface.addColumn('videoBlacklist', 'unfederated', data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function down (options) {
|
||||||
|
throw new Error('Not implemented.')
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
up,
|
||||||
|
down
|
||||||
|
}
|
|
@ -78,7 +78,7 @@ async function shareByServer (video: VideoModel, t: Transaction) {
|
||||||
const serverActor = await getServerActor()
|
const serverActor = await getServerActor()
|
||||||
|
|
||||||
const serverShareUrl = getVideoAnnounceActivityPubUrl(serverActor, video)
|
const serverShareUrl = getVideoAnnounceActivityPubUrl(serverActor, video)
|
||||||
return VideoShareModel.findOrCreate({
|
const [ serverShare ] = await VideoShareModel.findOrCreate({
|
||||||
defaults: {
|
defaults: {
|
||||||
actorId: serverActor.id,
|
actorId: serverActor.id,
|
||||||
videoId: video.id,
|
videoId: video.id,
|
||||||
|
@ -88,16 +88,14 @@ async function shareByServer (video: VideoModel, t: Transaction) {
|
||||||
url: serverShareUrl
|
url: serverShareUrl
|
||||||
},
|
},
|
||||||
transaction: t
|
transaction: t
|
||||||
}).then(([ serverShare, created ]) => {
|
|
||||||
if (created) return sendVideoAnnounce(serverActor, serverShare, video, t)
|
|
||||||
|
|
||||||
return undefined
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return sendVideoAnnounce(serverActor, serverShare, video, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function shareByVideoChannel (video: VideoModel, t: Transaction) {
|
async function shareByVideoChannel (video: VideoModel, t: Transaction) {
|
||||||
const videoChannelShareUrl = getVideoAnnounceActivityPubUrl(video.VideoChannel.Actor, video)
|
const videoChannelShareUrl = getVideoAnnounceActivityPubUrl(video.VideoChannel.Actor, video)
|
||||||
return VideoShareModel.findOrCreate({
|
const [ videoChannelShare ] = await VideoShareModel.findOrCreate({
|
||||||
defaults: {
|
defaults: {
|
||||||
actorId: video.VideoChannel.actorId,
|
actorId: video.VideoChannel.actorId,
|
||||||
videoId: video.id,
|
videoId: video.id,
|
||||||
|
@ -107,11 +105,9 @@ async function shareByVideoChannel (video: VideoModel, t: Transaction) {
|
||||||
url: videoChannelShareUrl
|
url: videoChannelShareUrl
|
||||||
},
|
},
|
||||||
transaction: t
|
transaction: t
|
||||||
}).then(([ videoChannelShare, created ]) => {
|
|
||||||
if (created) return sendVideoAnnounce(video.VideoChannel.Actor, videoChannelShare, video, t)
|
|
||||||
|
|
||||||
return undefined
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return sendVideoAnnounce(video.VideoChannel.Actor, videoChannelShare, video, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function undoShareByVideoChannel (video: VideoModel, oldVideoChannel: VideoChannelModel, t: Transaction) {
|
async function undoShareByVideoChannel (video: VideoModel, oldVideoChannel: VideoChannelModel, t: Transaction) {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { body, param } from 'express-validator/check'
|
import { body, param } from 'express-validator/check'
|
||||||
import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
|
import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
|
||||||
import { isVideoExist } from '../../../helpers/custom-validators/videos'
|
import { isVideoExist } from '../../../helpers/custom-validators/videos'
|
||||||
import { logger } from '../../../helpers/logger'
|
import { logger } from '../../../helpers/logger'
|
||||||
import { areValidationErrors } from '../utils'
|
import { areValidationErrors } from '../utils'
|
||||||
import { isVideoBlacklistExist, isVideoBlacklistReasonValid } from '../../../helpers/custom-validators/video-blacklist'
|
import { isVideoBlacklistExist, isVideoBlacklistReasonValid } from '../../../helpers/custom-validators/video-blacklist'
|
||||||
|
import { VideoModel } from '../../../models/video/video'
|
||||||
|
|
||||||
const videosBlacklistRemoveValidator = [
|
const videosBlacklistRemoveValidator = [
|
||||||
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
|
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
|
||||||
|
@ -22,6 +23,10 @@ const videosBlacklistRemoveValidator = [
|
||||||
|
|
||||||
const videosBlacklistAddValidator = [
|
const videosBlacklistAddValidator = [
|
||||||
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
|
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
|
||||||
|
body('unfederate')
|
||||||
|
.optional()
|
||||||
|
.toBoolean()
|
||||||
|
.custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'),
|
||||||
body('reason')
|
body('reason')
|
||||||
.optional()
|
.optional()
|
||||||
.custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),
|
.custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'),
|
||||||
|
@ -32,6 +37,14 @@ const videosBlacklistAddValidator = [
|
||||||
if (areValidationErrors(req, res)) return
|
if (areValidationErrors(req, res)) return
|
||||||
if (!await isVideoExist(req.params.videoId, res)) return
|
if (!await isVideoExist(req.params.videoId, res)) return
|
||||||
|
|
||||||
|
const video: VideoModel = res.locals.video
|
||||||
|
if (req.body.unfederate === true && video.remote === true) {
|
||||||
|
return res
|
||||||
|
.status(409)
|
||||||
|
.send({ error: 'You cannot unfederate a remote video.' })
|
||||||
|
.end()
|
||||||
|
}
|
||||||
|
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,21 +1,7 @@
|
||||||
import {
|
import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
|
||||||
AfterCreate,
|
|
||||||
AfterDestroy,
|
|
||||||
AllowNull,
|
|
||||||
BelongsTo,
|
|
||||||
Column,
|
|
||||||
CreatedAt,
|
|
||||||
DataType,
|
|
||||||
ForeignKey,
|
|
||||||
Is,
|
|
||||||
Model,
|
|
||||||
Table,
|
|
||||||
UpdatedAt
|
|
||||||
} from 'sequelize-typescript'
|
|
||||||
import { getSortOnModel, SortType, throwIfNotValid } from '../utils'
|
import { getSortOnModel, SortType, throwIfNotValid } from '../utils'
|
||||||
import { VideoModel } from './video'
|
import { VideoModel } from './video'
|
||||||
import { isVideoBlacklistReasonValid } from '../../helpers/custom-validators/video-blacklist'
|
import { isVideoBlacklistReasonValid } from '../../helpers/custom-validators/video-blacklist'
|
||||||
import { Emailer } from '../../lib/emailer'
|
|
||||||
import { VideoBlacklist } from '../../../shared/models/videos'
|
import { VideoBlacklist } from '../../../shared/models/videos'
|
||||||
import { CONSTRAINTS_FIELDS } from '../../initializers'
|
import { CONSTRAINTS_FIELDS } from '../../initializers'
|
||||||
|
|
||||||
|
@ -35,6 +21,10 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
|
||||||
@Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_BLACKLIST.REASON.max))
|
@Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_BLACKLIST.REASON.max))
|
||||||
reason: string
|
reason: string
|
||||||
|
|
||||||
|
@AllowNull(false)
|
||||||
|
@Column
|
||||||
|
unfederated: boolean
|
||||||
|
|
||||||
@CreatedAt
|
@CreatedAt
|
||||||
createdAt: Date
|
createdAt: Date
|
||||||
|
|
||||||
|
@ -93,6 +83,7 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
|
||||||
createdAt: this.createdAt,
|
createdAt: this.createdAt,
|
||||||
updatedAt: this.updatedAt,
|
updatedAt: this.updatedAt,
|
||||||
reason: this.reason,
|
reason: this.reason,
|
||||||
|
unfederated: this.unfederated,
|
||||||
|
|
||||||
video: {
|
video: {
|
||||||
id: video.id,
|
id: video.id,
|
||||||
|
|
|
@ -4,17 +4,20 @@ import 'mocha'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createUser,
|
createUser,
|
||||||
|
doubleFollow,
|
||||||
|
flushAndRunMultipleServers,
|
||||||
flushTests,
|
flushTests,
|
||||||
getBlacklistedVideosList, getVideo, getVideoWithToken,
|
getBlacklistedVideosList,
|
||||||
|
getVideo,
|
||||||
|
getVideoWithToken,
|
||||||
killallServers,
|
killallServers,
|
||||||
makePostBodyRequest,
|
makePostBodyRequest,
|
||||||
makePutBodyRequest,
|
makePutBodyRequest,
|
||||||
removeVideoFromBlacklist,
|
removeVideoFromBlacklist,
|
||||||
runServer,
|
|
||||||
ServerInfo,
|
ServerInfo,
|
||||||
setAccessTokensToServers,
|
setAccessTokensToServers,
|
||||||
uploadVideo,
|
uploadVideo,
|
||||||
userLogin
|
userLogin, waitJobs
|
||||||
} from '../../../../shared/utils'
|
} from '../../../../shared/utils'
|
||||||
import {
|
import {
|
||||||
checkBadCountPagination,
|
checkBadCountPagination,
|
||||||
|
@ -25,8 +28,9 @@ import { VideoDetails } from '../../../../shared/models/videos'
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
|
|
||||||
describe('Test video blacklist API validators', function () {
|
describe('Test video blacklist API validators', function () {
|
||||||
let server: ServerInfo
|
let servers: ServerInfo[]
|
||||||
let notBlacklistedVideoId: number
|
let notBlacklistedVideoId: number
|
||||||
|
let remoteVideoUUID: string
|
||||||
let userAccessToken1 = ''
|
let userAccessToken1 = ''
|
||||||
let userAccessToken2 = ''
|
let userAccessToken2 = ''
|
||||||
|
|
||||||
|
@ -36,75 +40,89 @@ describe('Test video blacklist API validators', function () {
|
||||||
this.timeout(120000)
|
this.timeout(120000)
|
||||||
|
|
||||||
await flushTests()
|
await flushTests()
|
||||||
|
servers = await flushAndRunMultipleServers(2)
|
||||||
|
|
||||||
server = await runServer(1)
|
await setAccessTokensToServers(servers)
|
||||||
|
await doubleFollow(servers[0], servers[1])
|
||||||
await setAccessTokensToServers([ server ])
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const username = 'user1'
|
const username = 'user1'
|
||||||
const password = 'my super password'
|
const password = 'my super password'
|
||||||
await createUser(server.url, server.accessToken, username, password)
|
await createUser(servers[0].url, servers[0].accessToken, username, password)
|
||||||
userAccessToken1 = await userLogin(server, { username, password })
|
userAccessToken1 = await userLogin(servers[0], { username, password })
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const username = 'user2'
|
const username = 'user2'
|
||||||
const password = 'my super password'
|
const password = 'my super password'
|
||||||
await createUser(server.url, server.accessToken, username, password)
|
await createUser(servers[0].url, servers[0].accessToken, username, password)
|
||||||
userAccessToken2 = await userLogin(server, { username, password })
|
userAccessToken2 = await userLogin(servers[0], { username, password })
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const res = await uploadVideo(server.url, userAccessToken1, {})
|
const res = await uploadVideo(servers[0].url, userAccessToken1, {})
|
||||||
server.video = res.body.video
|
servers[0].video = res.body.video
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const res = await uploadVideo(server.url, server.accessToken, {})
|
const res = await uploadVideo(servers[0].url, servers[0].accessToken, {})
|
||||||
notBlacklistedVideoId = res.body.video.uuid
|
notBlacklistedVideoId = res.body.video.uuid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const res = await uploadVideo(servers[1].url, servers[1].accessToken, {})
|
||||||
|
remoteVideoUUID = res.body.video.uuid
|
||||||
|
}
|
||||||
|
|
||||||
|
await waitJobs(servers)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('When adding a video in blacklist', function () {
|
describe('When adding a video in blacklist', function () {
|
||||||
const basePath = '/api/v1/videos/'
|
const basePath = '/api/v1/videos/'
|
||||||
|
|
||||||
it('Should fail with nothing', async function () {
|
it('Should fail with nothing', async function () {
|
||||||
const path = basePath + server.video + '/blacklist'
|
const path = basePath + servers[0].video + '/blacklist'
|
||||||
const fields = {}
|
const fields = {}
|
||||||
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with a wrong video', async function () {
|
it('Should fail with a wrong video', async function () {
|
||||||
const wrongPath = '/api/v1/videos/blabla/blacklist'
|
const wrongPath = '/api/v1/videos/blabla/blacklist'
|
||||||
const fields = {}
|
const fields = {}
|
||||||
await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
|
await makePostBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with a non authenticated user', async function () {
|
it('Should fail with a non authenticated user', async function () {
|
||||||
const path = basePath + server.video + '/blacklist'
|
const path = basePath + servers[0].video + '/blacklist'
|
||||||
const fields = {}
|
const fields = {}
|
||||||
await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
|
await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with a non admin user', async function () {
|
it('Should fail with a non admin user', async function () {
|
||||||
const path = basePath + server.video + '/blacklist'
|
const path = basePath + servers[0].video + '/blacklist'
|
||||||
const fields = {}
|
const fields = {}
|
||||||
await makePostBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
|
await makePostBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with an invalid reason', async function () {
|
it('Should fail with an invalid reason', async function () {
|
||||||
const path = basePath + server.video.uuid + '/blacklist'
|
const path = basePath + servers[0].video.uuid + '/blacklist'
|
||||||
const fields = { reason: 'a'.repeat(305) }
|
const fields = { reason: 'a'.repeat(305) }
|
||||||
|
|
||||||
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should fail to unfederate a remote video', async function () {
|
||||||
|
const path = basePath + remoteVideoUUID + '/blacklist'
|
||||||
|
const fields = { unfederate: true }
|
||||||
|
|
||||||
|
await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 409 })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should succeed with the correct params', async function () {
|
it('Should succeed with the correct params', async function () {
|
||||||
const path = basePath + server.video.uuid + '/blacklist'
|
const path = basePath + servers[0].video.uuid + '/blacklist'
|
||||||
const fields = { }
|
const fields = { }
|
||||||
|
|
||||||
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
|
await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -114,61 +132,61 @@ describe('Test video blacklist API validators', function () {
|
||||||
it('Should fail with a wrong video', async function () {
|
it('Should fail with a wrong video', async function () {
|
||||||
const wrongPath = '/api/v1/videos/blabla/blacklist'
|
const wrongPath = '/api/v1/videos/blabla/blacklist'
|
||||||
const fields = {}
|
const fields = {}
|
||||||
await makePutBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
|
await makePutBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with a video not blacklisted', async function () {
|
it('Should fail with a video not blacklisted', async function () {
|
||||||
const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
|
const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
|
||||||
const fields = {}
|
const fields = {}
|
||||||
await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
|
await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 404 })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with a non authenticated user', async function () {
|
it('Should fail with a non authenticated user', async function () {
|
||||||
const path = basePath + server.video + '/blacklist'
|
const path = basePath + servers[0].video + '/blacklist'
|
||||||
const fields = {}
|
const fields = {}
|
||||||
await makePutBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
|
await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with a non admin user', async function () {
|
it('Should fail with a non admin user', async function () {
|
||||||
const path = basePath + server.video + '/blacklist'
|
const path = basePath + servers[0].video + '/blacklist'
|
||||||
const fields = {}
|
const fields = {}
|
||||||
await makePutBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
|
await makePutBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with an invalid reason', async function () {
|
it('Should fail with an invalid reason', async function () {
|
||||||
const path = basePath + server.video.uuid + '/blacklist'
|
const path = basePath + servers[0].video.uuid + '/blacklist'
|
||||||
const fields = { reason: 'a'.repeat(305) }
|
const fields = { reason: 'a'.repeat(305) }
|
||||||
|
|
||||||
await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should succeed with the correct params', async function () {
|
it('Should succeed with the correct params', async function () {
|
||||||
const path = basePath + server.video.uuid + '/blacklist'
|
const path = basePath + servers[0].video.uuid + '/blacklist'
|
||||||
const fields = { reason: 'hello' }
|
const fields = { reason: 'hello' }
|
||||||
|
|
||||||
await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
|
await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('When getting blacklisted video', function () {
|
describe('When getting blacklisted video', function () {
|
||||||
|
|
||||||
it('Should fail with a non authenticated user', async function () {
|
it('Should fail with a non authenticated user', async function () {
|
||||||
await getVideo(server.url, server.video.uuid, 401)
|
await getVideo(servers[0].url, servers[0].video.uuid, 401)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with another user', async function () {
|
it('Should fail with another user', async function () {
|
||||||
await getVideoWithToken(server.url, userAccessToken2, server.video.uuid, 403)
|
await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should succeed with the owner authenticated user', async function () {
|
it('Should succeed with the owner authenticated user', async function () {
|
||||||
const res = await getVideoWithToken(server.url, userAccessToken1, server.video.uuid, 200)
|
const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, 200)
|
||||||
const video: VideoDetails = res.body
|
const video: VideoDetails = res.body
|
||||||
|
|
||||||
expect(video.blacklisted).to.be.true
|
expect(video.blacklisted).to.be.true
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should succeed with an admin', async function () {
|
it('Should succeed with an admin', async function () {
|
||||||
const res = await getVideoWithToken(server.url, server.accessToken, server.video.uuid, 200)
|
const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 200)
|
||||||
const video: VideoDetails = res.body
|
const video: VideoDetails = res.body
|
||||||
|
|
||||||
expect(video.blacklisted).to.be.true
|
expect(video.blacklisted).to.be.true
|
||||||
|
@ -177,24 +195,24 @@ 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(server.url, 'fake token', server.video.uuid, 401)
|
await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, 401)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with a non admin user', async function () {
|
it('Should fail with a non admin user', async function () {
|
||||||
await removeVideoFromBlacklist(server.url, userAccessToken2, server.video.uuid, 403)
|
await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with an incorrect id', async function () {
|
it('Should fail with an incorrect id', async function () {
|
||||||
await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400)
|
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', 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(server.url, server.accessToken, notBlacklistedVideoId, 404)
|
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, 404)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should succeed with the correct params', async function () {
|
it('Should succeed with the correct params', async function () {
|
||||||
await removeVideoFromBlacklist(server.url, server.accessToken, server.video.uuid, 204)
|
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 204)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -202,28 +220,28 @@ 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(server.url, 'fake token', 401)
|
await getBlacklistedVideosList(servers[0].url, 'fake token', 401)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with a non admin user', async function () {
|
it('Should fail with a non admin user', async function () {
|
||||||
await getBlacklistedVideosList(server.url, userAccessToken2, 403)
|
await getBlacklistedVideosList(servers[0].url, userAccessToken2, 403)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with a bad start pagination', async function () {
|
it('Should fail with a bad start pagination', async function () {
|
||||||
await checkBadStartPagination(server.url, basePath, server.accessToken)
|
await checkBadStartPagination(servers[0].url, basePath, servers[0].accessToken)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with a bad count pagination', async function () {
|
it('Should fail with a bad count pagination', async function () {
|
||||||
await checkBadCountPagination(server.url, basePath, server.accessToken)
|
await checkBadCountPagination(servers[0].url, basePath, servers[0].accessToken)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with an incorrect sort', async function () {
|
it('Should fail with an incorrect sort', async function () {
|
||||||
await checkBadSortPagination(server.url, basePath, server.accessToken)
|
await checkBadSortPagination(servers[0].url, basePath, servers[0].accessToken)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
after(async function () {
|
after(async function () {
|
||||||
killallServers([ server ])
|
killallServers(servers)
|
||||||
|
|
||||||
// Keep the logs if the test failed
|
// Keep the logs if the test failed
|
||||||
if (this['ok']) {
|
if (this['ok']) {
|
||||||
|
|
|
@ -3,7 +3,6 @@ import './services'
|
||||||
import './single-server'
|
import './single-server'
|
||||||
import './video-abuse'
|
import './video-abuse'
|
||||||
import './video-blacklist'
|
import './video-blacklist'
|
||||||
import './video-blacklist-management'
|
|
||||||
import './video-captions'
|
import './video-captions'
|
||||||
import './video-change-ownership'
|
import './video-change-ownership'
|
||||||
import './video-channels'
|
import './video-channels'
|
||||||
|
|
|
@ -1,192 +0,0 @@
|
||||||
/* tslint:disable:no-unused-expression */
|
|
||||||
|
|
||||||
import * as chai from 'chai'
|
|
||||||
import { orderBy } from 'lodash'
|
|
||||||
import 'mocha'
|
|
||||||
import {
|
|
||||||
addVideoToBlacklist,
|
|
||||||
flushAndRunMultipleServers,
|
|
||||||
getBlacklistedVideosList,
|
|
||||||
getMyVideos,
|
|
||||||
getSortedBlacklistedVideosList,
|
|
||||||
getVideosList,
|
|
||||||
killallServers,
|
|
||||||
removeVideoFromBlacklist,
|
|
||||||
ServerInfo,
|
|
||||||
setAccessTokensToServers,
|
|
||||||
updateVideoBlacklist,
|
|
||||||
uploadVideo
|
|
||||||
} from '../../../../shared/utils/index'
|
|
||||||
import { doubleFollow } from '../../../../shared/utils/server/follows'
|
|
||||||
import { waitJobs } from '../../../../shared/utils/server/jobs'
|
|
||||||
import { VideoAbuse } from '../../../../shared/models/videos'
|
|
||||||
|
|
||||||
const expect = chai.expect
|
|
||||||
|
|
||||||
describe('Test video blacklist management', function () {
|
|
||||||
let servers: ServerInfo[] = []
|
|
||||||
let videoId: number
|
|
||||||
|
|
||||||
async function blacklistVideosOnServer (server: ServerInfo) {
|
|
||||||
const res = await getVideosList(server.url)
|
|
||||||
|
|
||||||
const videos = res.body.data
|
|
||||||
for (let video of videos) {
|
|
||||||
await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
before(async function () {
|
|
||||||
this.timeout(50000)
|
|
||||||
|
|
||||||
// Run servers
|
|
||||||
servers = await flushAndRunMultipleServers(2)
|
|
||||||
|
|
||||||
// Get the access tokens
|
|
||||||
await setAccessTokensToServers(servers)
|
|
||||||
|
|
||||||
// Server 1 and server 2 follow each other
|
|
||||||
await doubleFollow(servers[0], servers[1])
|
|
||||||
|
|
||||||
// Upload 2 videos on server 2
|
|
||||||
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' })
|
|
||||||
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' })
|
|
||||||
|
|
||||||
// Wait videos propagation, server 2 has transcoding enabled
|
|
||||||
await waitJobs(servers)
|
|
||||||
|
|
||||||
// Blacklist the two videos on server 1
|
|
||||||
await blacklistVideosOnServer(servers[0])
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('When listing blacklisted videos', function () {
|
|
||||||
it('Should display all the blacklisted videos', async function () {
|
|
||||||
const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken)
|
|
||||||
|
|
||||||
expect(res.body.total).to.equal(2)
|
|
||||||
|
|
||||||
const blacklistedVideos = res.body.data
|
|
||||||
expect(blacklistedVideos).to.be.an('array')
|
|
||||||
expect(blacklistedVideos.length).to.equal(2)
|
|
||||||
|
|
||||||
for (const blacklistedVideo of blacklistedVideos) {
|
|
||||||
expect(blacklistedVideo.reason).to.equal('super reason')
|
|
||||||
videoId = blacklistedVideo.video.id
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Should get the correct sort when sorting by descending id', async function () {
|
|
||||||
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id')
|
|
||||||
expect(res.body.total).to.equal(2)
|
|
||||||
|
|
||||||
const blacklistedVideos = res.body.data
|
|
||||||
expect(blacklistedVideos).to.be.an('array')
|
|
||||||
expect(blacklistedVideos.length).to.equal(2)
|
|
||||||
|
|
||||||
const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ])
|
|
||||||
|
|
||||||
expect(blacklistedVideos).to.deep.equal(result)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Should get the correct sort when sorting by descending video name', async function () {
|
|
||||||
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
|
|
||||||
expect(res.body.total).to.equal(2)
|
|
||||||
|
|
||||||
const blacklistedVideos = res.body.data
|
|
||||||
expect(blacklistedVideos).to.be.an('array')
|
|
||||||
expect(blacklistedVideos.length).to.equal(2)
|
|
||||||
|
|
||||||
const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ])
|
|
||||||
|
|
||||||
expect(blacklistedVideos).to.deep.equal(result)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Should get the correct sort when sorting by ascending creation date', async function () {
|
|
||||||
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
|
|
||||||
expect(res.body.total).to.equal(2)
|
|
||||||
|
|
||||||
const blacklistedVideos = res.body.data
|
|
||||||
expect(blacklistedVideos).to.be.an('array')
|
|
||||||
expect(blacklistedVideos.length).to.equal(2)
|
|
||||||
|
|
||||||
const result = orderBy(res.body.data, [ 'createdAt' ])
|
|
||||||
|
|
||||||
expect(blacklistedVideos).to.deep.equal(result)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('When updating blacklisted videos', function () {
|
|
||||||
it('Should change the reason', async function () {
|
|
||||||
await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated')
|
|
||||||
|
|
||||||
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
|
|
||||||
const video = res.body.data.find(b => b.video.id === videoId)
|
|
||||||
|
|
||||||
expect(video.reason).to.equal('my super reason updated')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('When listing my videos', function () {
|
|
||||||
it('Should display blacklisted videos', async function () {
|
|
||||||
await blacklistVideosOnServer(servers[1])
|
|
||||||
|
|
||||||
const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5)
|
|
||||||
|
|
||||||
expect(res.body.total).to.equal(2)
|
|
||||||
expect(res.body.data).to.have.lengthOf(2)
|
|
||||||
|
|
||||||
for (const video of res.body.data) {
|
|
||||||
expect(video.blacklisted).to.be.true
|
|
||||||
expect(video.blacklistedReason).to.equal('super reason')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('When removing a blacklisted video', function () {
|
|
||||||
let videoToRemove: VideoAbuse
|
|
||||||
let blacklist = []
|
|
||||||
|
|
||||||
it('Should not have any video in videos list on server 1', async function () {
|
|
||||||
const res = await getVideosList(servers[0].url)
|
|
||||||
expect(res.body.total).to.equal(0)
|
|
||||||
expect(res.body.data).to.be.an('array')
|
|
||||||
expect(res.body.data.length).to.equal(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Should remove a video from the blacklist on server 1', async function () {
|
|
||||||
// Get one video in the blacklist
|
|
||||||
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
|
|
||||||
videoToRemove = res.body.data[0]
|
|
||||||
blacklist = res.body.data.slice(1)
|
|
||||||
|
|
||||||
// Remove it
|
|
||||||
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Should have the ex-blacklisted video in videos list on server 1', async function () {
|
|
||||||
const res = await getVideosList(servers[0].url)
|
|
||||||
expect(res.body.total).to.equal(1)
|
|
||||||
|
|
||||||
const videos = res.body.data
|
|
||||||
expect(videos).to.be.an('array')
|
|
||||||
expect(videos.length).to.equal(1)
|
|
||||||
|
|
||||||
expect(videos[0].name).to.equal(videoToRemove.video.name)
|
|
||||||
expect(videos[0].id).to.equal(videoToRemove.video.id)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
|
|
||||||
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
|
|
||||||
expect(res.body.total).to.equal(1)
|
|
||||||
|
|
||||||
const videos = res.body.data
|
|
||||||
expect(videos).to.be.an('array')
|
|
||||||
expect(videos.length).to.equal(1)
|
|
||||||
expect(videos).to.deep.equal(blacklist)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
after(async function () {
|
|
||||||
killallServers(servers)
|
|
||||||
})
|
|
||||||
})
|
|
|
@ -1,24 +1,43 @@
|
||||||
/* tslint:disable:no-unused-expression */
|
/* tslint:disable:no-unused-expression */
|
||||||
|
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
|
import { orderBy } from 'lodash'
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import {
|
import {
|
||||||
addVideoToBlacklist,
|
addVideoToBlacklist,
|
||||||
flushAndRunMultipleServers,
|
flushAndRunMultipleServers,
|
||||||
|
getBlacklistedVideosList,
|
||||||
|
getMyVideos,
|
||||||
|
getSortedBlacklistedVideosList,
|
||||||
getVideosList,
|
getVideosList,
|
||||||
killallServers,
|
killallServers,
|
||||||
|
removeVideoFromBlacklist,
|
||||||
searchVideo,
|
searchVideo,
|
||||||
ServerInfo,
|
ServerInfo,
|
||||||
setAccessTokensToServers,
|
setAccessTokensToServers,
|
||||||
uploadVideo
|
updateVideo,
|
||||||
|
updateVideoBlacklist,
|
||||||
|
uploadVideo,
|
||||||
|
viewVideo
|
||||||
} from '../../../../shared/utils/index'
|
} from '../../../../shared/utils/index'
|
||||||
import { doubleFollow } from '../../../../shared/utils/server/follows'
|
import { doubleFollow } from '../../../../shared/utils/server/follows'
|
||||||
import { waitJobs } from '../../../../shared/utils/server/jobs'
|
import { waitJobs } from '../../../../shared/utils/server/jobs'
|
||||||
|
import { VideoBlacklist } from '../../../../shared/models/videos'
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
describe('Test video blacklists', function () {
|
describe('Test video blacklist management', function () {
|
||||||
let servers: ServerInfo[] = []
|
let servers: ServerInfo[] = []
|
||||||
|
let videoId: number
|
||||||
|
|
||||||
|
async function blacklistVideosOnServer (server: ServerInfo) {
|
||||||
|
const res = await getVideosList(server.url)
|
||||||
|
|
||||||
|
const videos = res.body.data
|
||||||
|
for (let video of videos) {
|
||||||
|
await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.timeout(50000)
|
this.timeout(50000)
|
||||||
|
@ -32,58 +51,270 @@ describe('Test video blacklists', function () {
|
||||||
// Server 1 and server 2 follow each other
|
// Server 1 and server 2 follow each other
|
||||||
await doubleFollow(servers[0], servers[1])
|
await doubleFollow(servers[0], servers[1])
|
||||||
|
|
||||||
// Upload a video on server 2
|
// Upload 2 videos on server 2
|
||||||
const videoAttributes = {
|
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' })
|
||||||
name: 'my super name for server 2',
|
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' })
|
||||||
description: 'my super description for server 2'
|
|
||||||
}
|
|
||||||
await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
|
|
||||||
|
|
||||||
// Wait videos propagation, server 2 has transcoding enabled
|
// Wait videos propagation, server 2 has transcoding enabled
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
||||||
const res = await getVideosList(servers[0].url)
|
// Blacklist the two videos on server 1
|
||||||
const videos = res.body.data
|
await blacklistVideosOnServer(servers[0])
|
||||||
|
|
||||||
expect(videos.length).to.equal(1)
|
|
||||||
|
|
||||||
servers[0].remoteVideo = videos.find(video => video.name === 'my super name for server 2')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should blacklist a remote video on server 1', async function () {
|
describe('When listing/searching videos', function () {
|
||||||
await addVideoToBlacklist(servers[0].url, servers[0].accessToken, servers[0].remoteVideo.id)
|
|
||||||
|
it('Should not have the video blacklisted in videos list/search on server 1', async function () {
|
||||||
|
{
|
||||||
|
const res = await getVideosList(servers[ 0 ].url)
|
||||||
|
|
||||||
|
expect(res.body.total).to.equal(0)
|
||||||
|
expect(res.body.data).to.be.an('array')
|
||||||
|
expect(res.body.data.length).to.equal(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const res = await searchVideo(servers[ 0 ].url, 'name')
|
||||||
|
|
||||||
|
expect(res.body.total).to.equal(0)
|
||||||
|
expect(res.body.data).to.be.an('array')
|
||||||
|
expect(res.body.data.length).to.equal(0)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should have the blacklisted video in videos list/search on server 2', async function () {
|
||||||
|
{
|
||||||
|
const res = await getVideosList(servers[ 1 ].url)
|
||||||
|
|
||||||
|
expect(res.body.total).to.equal(2)
|
||||||
|
expect(res.body.data).to.be.an('array')
|
||||||
|
expect(res.body.data.length).to.equal(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const res = await searchVideo(servers[ 1 ].url, 'video')
|
||||||
|
|
||||||
|
expect(res.body.total).to.equal(2)
|
||||||
|
expect(res.body.data).to.be.an('array')
|
||||||
|
expect(res.body.data.length).to.equal(2)
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not have the video blacklisted in videos list on server 1', async function () {
|
describe('When listing blacklisted videos', function () {
|
||||||
const res = await getVideosList(servers[0].url)
|
it('Should display all the blacklisted videos', async function () {
|
||||||
|
const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken)
|
||||||
|
|
||||||
expect(res.body.total).to.equal(0)
|
expect(res.body.total).to.equal(2)
|
||||||
expect(res.body.data).to.be.an('array')
|
|
||||||
expect(res.body.data.length).to.equal(0)
|
const blacklistedVideos = res.body.data
|
||||||
|
expect(blacklistedVideos).to.be.an('array')
|
||||||
|
expect(blacklistedVideos.length).to.equal(2)
|
||||||
|
|
||||||
|
for (const blacklistedVideo of blacklistedVideos) {
|
||||||
|
expect(blacklistedVideo.reason).to.equal('super reason')
|
||||||
|
videoId = blacklistedVideo.video.id
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should get the correct sort when sorting by descending id', async function () {
|
||||||
|
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id')
|
||||||
|
expect(res.body.total).to.equal(2)
|
||||||
|
|
||||||
|
const blacklistedVideos = res.body.data
|
||||||
|
expect(blacklistedVideos).to.be.an('array')
|
||||||
|
expect(blacklistedVideos.length).to.equal(2)
|
||||||
|
|
||||||
|
const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ])
|
||||||
|
|
||||||
|
expect(blacklistedVideos).to.deep.equal(result)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should get the correct sort when sorting by descending video name', async function () {
|
||||||
|
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
|
||||||
|
expect(res.body.total).to.equal(2)
|
||||||
|
|
||||||
|
const blacklistedVideos = res.body.data
|
||||||
|
expect(blacklistedVideos).to.be.an('array')
|
||||||
|
expect(blacklistedVideos.length).to.equal(2)
|
||||||
|
|
||||||
|
const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ])
|
||||||
|
|
||||||
|
expect(blacklistedVideos).to.deep.equal(result)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should get the correct sort when sorting by ascending creation date', async function () {
|
||||||
|
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
|
||||||
|
expect(res.body.total).to.equal(2)
|
||||||
|
|
||||||
|
const blacklistedVideos = res.body.data
|
||||||
|
expect(blacklistedVideos).to.be.an('array')
|
||||||
|
expect(blacklistedVideos.length).to.equal(2)
|
||||||
|
|
||||||
|
const result = orderBy(res.body.data, [ 'createdAt' ])
|
||||||
|
|
||||||
|
expect(blacklistedVideos).to.deep.equal(result)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not have the video blacklisted in videos search on server 1', async function () {
|
describe('When updating blacklisted videos', function () {
|
||||||
const res = await searchVideo(servers[0].url, 'name')
|
it('Should change the reason', async function () {
|
||||||
|
await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated')
|
||||||
|
|
||||||
expect(res.body.total).to.equal(0)
|
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
|
||||||
expect(res.body.data).to.be.an('array')
|
const video = res.body.data.find(b => b.video.id === videoId)
|
||||||
expect(res.body.data.length).to.equal(0)
|
|
||||||
|
expect(video.reason).to.equal('my super reason updated')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have the blacklisted video in videos list on server 2', async function () {
|
describe('When listing my videos', function () {
|
||||||
const res = await getVideosList(servers[1].url)
|
it('Should display blacklisted videos', async function () {
|
||||||
|
await blacklistVideosOnServer(servers[1])
|
||||||
|
|
||||||
expect(res.body.total).to.equal(1)
|
const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5)
|
||||||
expect(res.body.data).to.be.an('array')
|
|
||||||
expect(res.body.data.length).to.equal(1)
|
expect(res.body.total).to.equal(2)
|
||||||
|
expect(res.body.data).to.have.lengthOf(2)
|
||||||
|
|
||||||
|
for (const video of res.body.data) {
|
||||||
|
expect(video.blacklisted).to.be.true
|
||||||
|
expect(video.blacklistedReason).to.equal('super reason')
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have the video blacklisted in videos search on server 2', async function () {
|
describe('When removing a blacklisted video', function () {
|
||||||
const res = await searchVideo(servers[1].url, 'name')
|
let videoToRemove: VideoBlacklist
|
||||||
|
let blacklist = []
|
||||||
|
|
||||||
|
it('Should not have any video in videos list on server 1', async function () {
|
||||||
|
const res = await getVideosList(servers[0].url)
|
||||||
|
expect(res.body.total).to.equal(0)
|
||||||
|
expect(res.body.data).to.be.an('array')
|
||||||
|
expect(res.body.data.length).to.equal(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should remove a video from the blacklist on server 1', async function () {
|
||||||
|
// Get one video in the blacklist
|
||||||
|
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
|
||||||
|
videoToRemove = res.body.data[0]
|
||||||
|
blacklist = res.body.data.slice(1)
|
||||||
|
|
||||||
|
// Remove it
|
||||||
|
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should have the ex-blacklisted video in videos list on server 1', async function () {
|
||||||
|
const res = await getVideosList(servers[0].url)
|
||||||
|
expect(res.body.total).to.equal(1)
|
||||||
|
|
||||||
|
const videos = res.body.data
|
||||||
|
expect(videos).to.be.an('array')
|
||||||
|
expect(videos.length).to.equal(1)
|
||||||
|
|
||||||
|
expect(videos[0].name).to.equal(videoToRemove.video.name)
|
||||||
|
expect(videos[0].id).to.equal(videoToRemove.video.id)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
|
||||||
|
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
|
||||||
|
expect(res.body.total).to.equal(1)
|
||||||
|
|
||||||
|
const videos = res.body.data
|
||||||
|
expect(videos).to.be.an('array')
|
||||||
|
expect(videos.length).to.equal(1)
|
||||||
|
expect(videos).to.deep.equal(blacklist)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('When blacklisting local videos', function () {
|
||||||
|
let video3UUID: string
|
||||||
|
let video4UUID: string
|
||||||
|
|
||||||
|
before(async function () {
|
||||||
|
this.timeout(10000)
|
||||||
|
|
||||||
|
{
|
||||||
|
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' })
|
||||||
|
video3UUID = res.body.video.uuid
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'Video 4' })
|
||||||
|
video4UUID = res.body.video.uuid
|
||||||
|
}
|
||||||
|
|
||||||
|
await waitJobs(servers)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should blacklist video 3 and keep it federated', async function () {
|
||||||
|
this.timeout(10000)
|
||||||
|
|
||||||
|
await addVideoToBlacklist(servers[ 0 ].url, servers[ 0 ].accessToken, video3UUID, 'super reason', false)
|
||||||
|
|
||||||
|
await waitJobs(servers)
|
||||||
|
|
||||||
|
{
|
||||||
|
const res = await getVideosList(servers[ 0 ].url)
|
||||||
|
expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const res = await getVideosList(servers[ 1 ].url)
|
||||||
|
expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should unfederate the video', async function () {
|
||||||
|
this.timeout(10000)
|
||||||
|
|
||||||
|
await addVideoToBlacklist(servers[ 0 ].url, servers[ 0 ].accessToken, video4UUID, 'super reason', true)
|
||||||
|
|
||||||
|
await waitJobs(servers)
|
||||||
|
|
||||||
|
for (const server of servers) {
|
||||||
|
const res = await getVideosList(server.url)
|
||||||
|
expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should have the video unfederated even after an Update AP message', async function () {
|
||||||
|
this.timeout(10000)
|
||||||
|
|
||||||
|
await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, video4UUID, { description: 'super description' })
|
||||||
|
|
||||||
|
await waitJobs(servers)
|
||||||
|
|
||||||
|
for (const server of servers) {
|
||||||
|
const res = await getVideosList(server.url)
|
||||||
|
expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should have the correct video blacklist unfederate attribute', async function () {
|
||||||
|
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
|
||||||
|
|
||||||
|
const blacklistedVideos: VideoBlacklist[] = res.body.data
|
||||||
|
const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID)
|
||||||
|
const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID)
|
||||||
|
|
||||||
|
expect(video3Blacklisted.unfederated).to.be.false
|
||||||
|
expect(video4Blacklisted.unfederated).to.be.true
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should remove the video from blacklist and refederate the video', async function () {
|
||||||
|
this.timeout(10000)
|
||||||
|
|
||||||
|
await removeVideoFromBlacklist(servers[ 0 ].url, servers[ 0 ].accessToken, video4UUID)
|
||||||
|
|
||||||
|
await waitJobs(servers)
|
||||||
|
|
||||||
|
for (const server of servers) {
|
||||||
|
const res = await getVideosList(server.url)
|
||||||
|
expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
expect(res.body.total).to.equal(1)
|
|
||||||
expect(res.body.data).to.be.an('array')
|
|
||||||
expect(res.body.data.length).to.equal(1)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
after(async function () {
|
after(async function () {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
export interface VideoBlacklistCreate {
|
export interface VideoBlacklistCreate {
|
||||||
reason?: string
|
reason?: string
|
||||||
|
unfederate?: boolean
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ export interface VideoBlacklist {
|
||||||
id: number
|
id: number
|
||||||
createdAt: Date
|
createdAt: Date
|
||||||
updatedAt: Date
|
updatedAt: Date
|
||||||
|
unfederated: boolean
|
||||||
reason?: string
|
reason?: string
|
||||||
|
|
||||||
video: {
|
video: {
|
||||||
|
|
|
@ -145,8 +145,12 @@ function runServer (serverNumber: number, configOverride?: Object, args = []) {
|
||||||
if (dontContinue === true) return
|
if (dontContinue === true) return
|
||||||
|
|
||||||
server.app.stdout.removeListener('data', onStdout)
|
server.app.stdout.removeListener('data', onStdout)
|
||||||
|
|
||||||
|
process.on('exit', () => process.kill(server.app.pid))
|
||||||
|
|
||||||
res(server)
|
res(server)
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
import * as request from 'supertest'
|
import * as request from 'supertest'
|
||||||
|
|
||||||
function addVideoToBlacklist (url: string, token: string, videoId: number | string, reason?: string, specialStatus = 204) {
|
function addVideoToBlacklist (
|
||||||
|
url: string,
|
||||||
|
token: string,
|
||||||
|
videoId: number | string,
|
||||||
|
reason?: string,
|
||||||
|
unfederate?: boolean,
|
||||||
|
specialStatus = 204
|
||||||
|
) {
|
||||||
const path = '/api/v1/videos/' + videoId + '/blacklist'
|
const path = '/api/v1/videos/' + videoId + '/blacklist'
|
||||||
|
|
||||||
return request(url)
|
return request(url)
|
||||||
.post(path)
|
.post(path)
|
||||||
.send({ reason })
|
.send({ reason, unfederate })
|
||||||
.set('Accept', 'application/json')
|
.set('Accept', 'application/json')
|
||||||
.set('Authorization', 'Bearer ' + token)
|
.set('Authorization', 'Bearer ' + token)
|
||||||
.expect(specialStatus)
|
.expect(specialStatus)
|
||||||
|
|
Loading…
Reference in a new issue