Add ability to search by host in server

pull/4283/head
Chocobozzz 2021-07-27 09:07:38 +02:00
parent 5d0095fde1
commit 29837f8885
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
18 changed files with 513 additions and 354 deletions

View File

@ -47,11 +47,7 @@ export class UserNotification implements UserNotificationServer {
comment?: {
threadId: number
video: {
id: number
uuid: string
name: string
}
video: VideoInfo
}
account?: ActorInfo

View File

@ -1,7 +1,7 @@
import { Subject } from 'rxjs'
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
import { ComponentPagination, hasMoreItems, Notifier } from '@app/core'
import { UserNotificationType, AbuseState } from '@shared/models'
import { AbuseState } from '@shared/models'
import { UserNotification } from './user-notification.model'
import { UserNotificationService } from './user-notification.service'

View File

@ -536,6 +536,7 @@ export class PeerTubeEmbed {
videoCaptions,
inactivityTimeout: 2500,
videoViewUrl: this.getVideoUrl(videoInfo.uuid) + '/views',
videoShortUUID: videoInfo.shortUUID,
videoUUID: videoInfo.uuid,
isLive: videoInfo.isLive,

View File

@ -1,6 +1,7 @@
import * as express from 'express'
import { query } from 'express-validator'
import { isSearchTargetValid } from '@server/helpers/custom-validators/search'
import { isHostValid } from '@server/helpers/custom-validators/servers'
import { isDateValid } from '../../helpers/custom-validators/misc'
import { logger } from '../../helpers/logger'
import { areValidationErrors } from './shared'
@ -8,6 +9,10 @@ import { areValidationErrors } from './shared'
const videosSearchValidator = [
query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
query('host')
.optional()
.custom(isHostValid).withMessage('Should have a valid host'),
query('startDate')
.optional()
.custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),

View File

@ -1,5 +1,6 @@
import { FindOptions, ModelIndexesOptions, Op, WhereOptions } from 'sequelize'
import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
import { uuidToShort } from '@server/helpers/uuid'
import { UserNotificationIncludes, UserNotificationModelForApi } from '@server/types/models/user'
import { AttributesOnly } from '@shared/core-utils'
import { UserNotification, UserNotificationType } from '../../../shared'
@ -615,6 +616,7 @@ export class UserNotificationModel extends Model<Partial<AttributesOnly<UserNoti
return {
id: video.id,
uuid: video.uuid,
shortUUID: uuidToShort(video.uuid),
name: video.name
}
}
@ -628,6 +630,7 @@ export class UserNotificationModel extends Model<Partial<AttributesOnly<UserNoti
? {
id: abuse.VideoCommentAbuse.VideoComment.Video.id,
name: abuse.VideoCommentAbuse.VideoComment.Video.name,
shortUUID: uuidToShort(abuse.VideoCommentAbuse.VideoComment.Video.uuid),
uuid: abuse.VideoCommentAbuse.VideoComment.Video.uuid
}
: undefined

View File

@ -1,6 +1,7 @@
import { Sequelize } from 'sequelize'
import validator from 'validator'
import { exists } from '@server/helpers/custom-validators/misc'
import { WEBSERVER } from '@server/initializers/constants'
import { buildDirectionAndField, createSafeIn } from '@server/models/utils'
import { MUserAccountId, MUserId } from '@server/types/models'
import { VideoFilter, VideoPrivacy, VideoState } from '@shared/models'
@ -25,6 +26,7 @@ export type BuildVideosListQueryOptions = {
nsfw?: boolean
filter?: VideoFilter
host?: string
isLive?: boolean
categoryOneOf?: number[]
@ -131,6 +133,10 @@ export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder {
this.whereOnlyLocal()
}
if (options.host) {
this.whereHost(options.host)
}
if (options.accountId) {
this.whereAccountId(options.accountId)
}
@ -291,6 +297,19 @@ export class VideosIdListQueryBuilder extends AbstractVideosQueryBuilder {
this.and.push('"video"."remote" IS FALSE')
}
private whereHost (host: string) {
// Local instance
if (host === WEBSERVER.HOST) {
this.and.push('"accountActor"."serverId" IS NULL')
return
}
this.joins.push('INNER JOIN "server" ON "server"."id" = "accountActor"."serverId"')
this.and.push('"server"."host" = :host')
this.replacements.host = host
}
private whereAccountId (accountId: number) {
this.and.push('"account"."id" = :accountId')
this.replacements.accountId = accountId

View File

@ -20,7 +20,7 @@ import {
import { setAsUpdated } from '@server/helpers/database-utils'
import { buildUUID, uuidToShort } from '@server/helpers/uuid'
import { MAccountId, MChannelId } from '@server/types/models'
import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistLink, buildPlaylistWatchPath } from '@shared/core-utils'
import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistWatchPath } from '@shared/core-utils'
import { ActivityIconObject } from '../../../shared/models/activitypub/objects'
import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object'
import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'

View File

@ -26,7 +26,7 @@ import {
} from 'sequelize-typescript'
import { setAsUpdated } from '@server/helpers/database-utils'
import { buildNSFWFilter } from '@server/helpers/express-utils'
import { shortToUUID } from '@server/helpers/uuid'
import { uuidToShort } from '@server/helpers/uuid'
import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video'
import { LiveManager } from '@server/lib/live/live-manager'
import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths'
@ -1113,6 +1113,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
static async searchAndPopulateAccountAndServer (options: {
includeLocalVideos: boolean
search?: string
host?: string
start?: number
count?: number
sort?: string
@ -1151,6 +1152,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
user: options.user,
filter: options.filter,
host: options.host,
start: options.start,
count: options.count,
@ -1579,7 +1581,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
}
getWatchStaticPath () {
return buildVideoWatchPath({ shortUUID: shortToUUID(this.uuid) })
return buildVideoWatchPath({ shortUUID: uuidToShort(this.uuid) })
}
getEmbedStaticPath () {

View File

@ -70,7 +70,7 @@ describe('Test admin notifications', function () {
joinPeerTubeServer.setLatestVersion('1.4.2')
await wait(3000)
await checkNewPeerTubeVersion(baseParams, '1.4.2', 'absence')
await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '1.4.2', checkType: 'absence' })
})
it('Should send a notification to admins on new plugin version', async function () {
@ -79,7 +79,7 @@ describe('Test admin notifications', function () {
joinPeerTubeServer.setLatestVersion('15.4.2')
await wait(3000)
await checkNewPeerTubeVersion(baseParams, '15.4.2', 'presence')
await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.2', checkType: 'presence' })
})
it('Should not send the same notification to admins', async function () {
@ -101,7 +101,7 @@ describe('Test admin notifications', function () {
joinPeerTubeServer.setLatestVersion('15.4.3')
await wait(3000)
await checkNewPeerTubeVersion(baseParams, '15.4.3', 'presence')
await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.3', checkType: 'presence' })
expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
})
})
@ -112,7 +112,7 @@ describe('Test admin notifications', function () {
this.timeout(30000)
await wait(6000)
await checkNewPluginVersion(baseParams, PluginType.PLUGIN, 'hello-world', 'absence')
await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'absence' })
})
it('Should send a notification to admins on new plugin version', async function () {
@ -122,7 +122,7 @@ describe('Test admin notifications', function () {
await server.sql.setPluginLatestVersion('hello-world', '0.0.1')
await wait(6000)
await checkNewPluginVersion(baseParams, PluginType.PLUGIN, 'hello-world', 'presence')
await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'presence' })
})
it('Should not send the same notification to admins', async function () {

View File

@ -52,25 +52,25 @@ describe('Test comments notifications', function () {
it('Should not send a new comment notification after a comment on another video', async function () {
this.timeout(20000)
const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
const commentId = created.id
await waitJobs(servers)
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
})
it('Should not send a new comment notification if I comment my own video', async function () {
this.timeout(20000)
const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
const created = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: 'comment' })
const commentId = created.id
await waitJobs(servers)
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
})
it('Should not send a new comment notification if the account is muted', async function () {
@ -78,13 +78,13 @@ describe('Test comments notifications', function () {
await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
const commentId = created.id
await waitJobs(servers)
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
})
@ -92,19 +92,19 @@ describe('Test comments notifications', function () {
it('Should send a new comment notification after a local comment on my video', async function () {
this.timeout(20000)
const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
const commentId = created.id
await waitJobs(servers)
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
})
it('Should send a new comment notification after a remote comment on my video', async function () {
this.timeout(20000)
const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
await waitJobs(servers)
@ -116,26 +116,26 @@ describe('Test comments notifications', function () {
expect(data).to.have.lengthOf(1)
const commentId = data[0].id
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
})
it('Should send a new comment notification after a local reply on my video', async function () {
this.timeout(20000)
const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
await waitJobs(servers)
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
})
it('Should send a new comment notification after a remote reply on my video', async function () {
this.timeout(20000)
const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
await waitJobs(servers)
{
@ -155,7 +155,7 @@ describe('Test comments notifications', function () {
expect(tree.children).to.have.lengthOf(1)
const commentId = tree.children[0].comment.id
await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
})
it('Should convert markdown in comment to html', async function () {
@ -174,6 +174,7 @@ describe('Test comments notifications', function () {
describe('Mention notifications', function () {
let baseParams: CheckerBaseParams
const byAccountDisplayName = 'super root name'
before(async () => {
baseParams = {
@ -190,23 +191,23 @@ describe('Test comments notifications', function () {
it('Should not send a new mention comment notification if I mention the video owner', async function () {
this.timeout(10000)
const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
await waitJobs(servers)
await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
})
it('Should not send a new mention comment notification if I mention myself', async function () {
this.timeout(10000)
const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
const { id: commentId } = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
await waitJobs(servers)
await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
})
it('Should not send a new mention notification if the account is muted', async function () {
@ -214,12 +215,12 @@ describe('Test comments notifications', function () {
await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
await waitJobs(servers)
await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
})
@ -227,35 +228,37 @@ describe('Test comments notifications', function () {
it('Should not send a new mention notification if the remote account mention a local account', async function () {
this.timeout(20000)
const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
await waitJobs(servers)
const { id: threadId } = await servers[1].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
await waitJobs(servers)
await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
const byAccountDisplayName = 'super root 2 name'
await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'absence' })
})
it('Should send a new mention notification after local comments', async function () {
this.timeout(10000)
const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
await waitJobs(servers)
await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'presence' })
const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' })
await waitJobs(servers)
await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
})
it('Should send a new mention notification after remote comments', async function () {
this.timeout(20000)
const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
await waitJobs(servers)
@ -267,20 +270,21 @@ describe('Test comments notifications', function () {
const { data } = await servers[0].comments.listThreads({ videoId: uuid })
expect(data).to.have.lengthOf(1)
const server1ThreadId = data[0].id
await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
const byAccountDisplayName = 'super root 2 name'
const threadId = data[0].id
await checkCommentMention({ ...baseParams, shortUUID, commentId: threadId, threadId, byAccountDisplayName, checkType: 'presence' })
const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}`
await servers[1].comments.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 })
await waitJobs(servers)
const tree = await servers[0].comments.getThread({ videoId: uuid, threadId: server1ThreadId })
const tree = await servers[0].comments.getThread({ videoId: uuid, threadId })
expect(tree.children).to.have.lengthOf(1)
const commentId = tree.children[0].comment.id
await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
})
it('Should convert markdown in comment to html', async function () {

View File

@ -67,7 +67,7 @@ describe('Test moderation notifications', function () {
await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' })
await waitJobs(servers)
await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence')
await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
})
it('Should send a notification to moderators on remote video abuse', async function () {
@ -82,7 +82,7 @@ describe('Test moderation notifications', function () {
await servers[1].abuses.report({ videoId, reason: 'super reason' })
await waitJobs(servers)
await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence')
await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
})
it('Should send a notification to moderators on local comment abuse', async function () {
@ -101,7 +101,7 @@ describe('Test moderation notifications', function () {
await servers[0].abuses.report({ commentId: comment.id, reason: 'super reason' })
await waitJobs(servers)
await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence')
await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
})
it('Should send a notification to moderators on remote comment abuse', async function () {
@ -123,7 +123,7 @@ describe('Test moderation notifications', function () {
await servers[1].abuses.report({ commentId, reason: 'super reason' })
await waitJobs(servers)
await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence')
await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
})
it('Should send a notification to moderators on local account abuse', async function () {
@ -136,7 +136,7 @@ describe('Test moderation notifications', function () {
await servers[0].abuses.report({ accountId, reason: 'super reason' })
await waitJobs(servers)
await checkNewAccountAbuseForModerators(baseParams, username, 'presence')
await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' })
})
it('Should send a notification to moderators on remote account abuse', async function () {
@ -152,7 +152,7 @@ describe('Test moderation notifications', function () {
await servers[1].abuses.report({ accountId: account.id, reason: 'super reason' })
await waitJobs(servers)
await checkNewAccountAbuseForModerators(baseParams, username, 'presence')
await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' })
})
})
@ -181,7 +181,7 @@ describe('Test moderation notifications', function () {
await servers[0].abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } })
await waitJobs(servers)
await checkAbuseStateChange(baseParams, abuseId, AbuseState.ACCEPTED, 'presence')
await checkAbuseStateChange({ ...baseParams, abuseId, state: AbuseState.ACCEPTED, checkType: 'presence' })
})
it('Should send a notification to reporter if the abuse has been rejected', async function () {
@ -190,7 +190,7 @@ describe('Test moderation notifications', function () {
await servers[0].abuses.update({ abuseId, body: { state: AbuseState.REJECTED } })
await waitJobs(servers)
await checkAbuseStateChange(baseParams, abuseId, AbuseState.REJECTED, 'presence')
await checkAbuseStateChange({ ...baseParams, abuseId, state: AbuseState.REJECTED, checkType: 'presence' })
})
})
@ -236,7 +236,7 @@ describe('Test moderation notifications', function () {
await servers[0].abuses.addMessage({ abuseId, message })
await waitJobs(servers)
await checkNewAbuseMessage(baseParamsUser, abuseId, message, 'user_1@example.com', 'presence')
await checkNewAbuseMessage({ ...baseParamsUser, abuseId, message, toEmail: 'user_1@example.com', checkType: 'presence' })
})
it('Should not send a notification to the admin if sent by the admin', async function () {
@ -246,7 +246,8 @@ describe('Test moderation notifications', function () {
await servers[0].abuses.addMessage({ abuseId, message })
await waitJobs(servers)
await checkNewAbuseMessage(baseParamsAdmin, abuseId, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'absence')
const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com'
await checkNewAbuseMessage({ ...baseParamsAdmin, abuseId, message, toEmail, checkType: 'absence' })
})
it('Should send a notification to moderators', async function () {
@ -256,7 +257,8 @@ describe('Test moderation notifications', function () {
await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message })
await waitJobs(servers)
await checkNewAbuseMessage(baseParamsAdmin, abuseId2, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'presence')
const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com'
await checkNewAbuseMessage({ ...baseParamsAdmin, abuseId: abuseId2, message, toEmail, checkType: 'presence' })
})
it('Should not send a notification to reporter if sent by the reporter', async function () {
@ -266,7 +268,8 @@ describe('Test moderation notifications', function () {
await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message })
await waitJobs(servers)
await checkNewAbuseMessage(baseParamsUser, abuseId2, message, 'user_1@example.com', 'absence')
const toEmail = 'user_1@example.com'
await checkNewAbuseMessage({ ...baseParamsUser, abuseId: abuseId2, message, toEmail, checkType: 'absence' })
})
})
@ -286,19 +289,19 @@ describe('Test moderation notifications', function () {
this.timeout(10000)
const name = 'video for abuse ' + buildUUID()
const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
await servers[0].blacklist.add({ videoId: uuid })
await waitJobs(servers)
await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
await checkNewBlacklistOnMyVideo({ ...baseParams, shortUUID, videoName: name, blacklistType: 'blacklist' })
})
it('Should send a notification to video owner on unblacklist', async function () {
this.timeout(10000)
const name = 'video for abuse ' + buildUUID()
const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
await servers[0].blacklist.add({ videoId: uuid })
@ -307,7 +310,7 @@ describe('Test moderation notifications', function () {
await waitJobs(servers)
await wait(500)
await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist')
await checkNewBlacklistOnMyVideo({ ...baseParams, shortUUID, videoName: name, blacklistType: 'unblacklist' })
})
})
@ -330,10 +333,10 @@ describe('Test moderation notifications', function () {
await waitJobs(servers)
await checkUserRegistered(baseParams, 'user_45', 'presence')
await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' })
const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
await checkUserRegistered({ ...baseParams, ...userOverride }, 'user_45', 'absence')
await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' })
})
})
@ -372,10 +375,10 @@ describe('Test moderation notifications', function () {
await waitJobs(servers)
await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence')
await checkNewInstanceFollower({ ...baseParams, followerHost: 'localhost:' + servers[2].port, checkType: 'presence' })
const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
await checkNewInstanceFollower({ ...baseParams, ...userOverride }, 'localhost:' + servers[2].port, 'absence')
await checkNewInstanceFollower({ ...baseParams, ...userOverride, followerHost: 'localhost:' + servers[2].port, checkType: 'absence' })
})
it('Should send a notification on auto follow back', async function () {
@ -399,10 +402,10 @@ describe('Test moderation notifications', function () {
const followerHost = servers[0].host
const followingHost = servers[2].host
await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence')
await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' })
const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
await checkAutoInstanceFollowing({ ...baseParams, ...userOverride }, followerHost, followingHost, 'absence')
await checkAutoInstanceFollowing({ ...baseParams, ...userOverride, followerHost, followingHost, checkType: 'absence' })
config.followings.instance.autoFollowBack.enabled = false
await servers[0].config.updateCustomSubConfig({ newConfig: config })
@ -421,7 +424,7 @@ describe('Test moderation notifications', function () {
const followerHost = servers[0].host
const followingHost = servers[1].host
await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence')
await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' })
config.followings.instance.autoFollowIndex.enabled = false
await servers[0].config.updateCustomSubConfig({ newConfig: config })
@ -433,7 +436,8 @@ describe('Test moderation notifications', function () {
let userBaseParams: CheckerBaseParams
let adminBaseParamsServer1: CheckerBaseParams
let adminBaseParamsServer2: CheckerBaseParams
let videoUUID: string
let uuid: string
let shortUUID: string
let videoName: string
let currentCustomConfig: CustomConfig
@ -480,36 +484,36 @@ describe('Test moderation notifications', function () {
await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
})
it('Should send notification to moderators on new video with auto-blacklist', async function () {
this.timeout(40000)
videoName = 'video with auto-blacklist ' + buildUUID()
const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: videoName } })
videoUUID = uuid
const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: videoName } })
shortUUID = video.shortUUID
uuid = video.uuid
await waitJobs(servers)
await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
await checkVideoAutoBlacklistForModerators({ ...adminBaseParamsServer1, shortUUID, videoName, checkType: 'presence' })
})
it('Should not send video publish notification if auto-blacklisted', async function () {
await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence')
await checkVideoIsPublished({ ...userBaseParams, videoName, shortUUID, checkType: 'absence' })
})
it('Should not send a local user subscription notification if auto-blacklisted', async function () {
await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence')
await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'absence' })
})
it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence')
await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'absence' })
})
it('Should send video published and unblacklist after video unblacklisted', async function () {
this.timeout(40000)
await servers[0].blacklist.remove({ videoId: videoUUID })
await servers[0].blacklist.remove({ videoId: uuid })
await waitJobs(servers)
@ -520,11 +524,11 @@ describe('Test moderation notifications', function () {
})
it('Should send a local user subscription notification after removed from blacklist', async function () {
await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence')
await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'presence' })
})
it('Should send a remote user subscription notification after removed from blacklist', async function () {
await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence')
await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'presence' })
})
it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
@ -543,19 +547,19 @@ describe('Test moderation notifications', function () {
}
}
const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes })
const { shortUUID, uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes })
await servers[0].blacklist.remove({ videoId: uuid })
await waitJobs(servers)
await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
await checkNewBlacklistOnMyVideo({ ...userBaseParams, shortUUID, videoName: name, blacklistType: 'unblacklist' })
// FIXME: Can't test absence as two notifications sent to same user and util only checks last one
// One notification might be better anyways
// await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName: name, shortUUID, checkType: 'absence' })
await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName: name, shortUUID, checkType: 'absence' })
})
it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
@ -575,12 +579,12 @@ describe('Test moderation notifications', function () {
}
}
const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes })
const { shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes })
await wait(6000)
await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence')
await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence')
await checkVideoIsPublished({ ...userBaseParams, videoName: name, shortUUID, checkType: 'absence' })
await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName: name, shortUUID, checkType: 'absence' })
await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName: name, shortUUID, checkType: 'absence' })
})
it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
@ -589,10 +593,10 @@ describe('Test moderation notifications', function () {
const name = 'video without auto-blacklist ' + buildUUID()
// admin with blacklist right will not be auto-blacklisted
const { uuid } = await servers[0].videos.upload({ attributes: { name } })
const { shortUUID } = await servers[0].videos.upload({ attributes: { name } })
await waitJobs(servers)
await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
await checkVideoAutoBlacklistForModerators({ ...adminBaseParamsServer1, shortUUID, videoName: name, checkType: 'absence' })
})
after(async () => {

View File

@ -111,10 +111,10 @@ describe('Test notifications API', function () {
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
}
const { name, uuid } = await server.videos.randomUpload()
const { name, shortUUID } = await server.videos.randomUpload()
const check = { web: true, mail: true }
await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' })
})
it('Should only have web notifications', async function () {
@ -130,16 +130,16 @@ describe('Test notifications API', function () {
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
}
const { name, uuid } = await server.videos.randomUpload()
const { name, shortUUID } = await server.videos.randomUpload()
{
const check = { mail: true, web: false }
await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' })
}
{
const check = { mail: false, web: true }
await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence')
await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'presence' })
}
})
@ -156,16 +156,16 @@ describe('Test notifications API', function () {
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
}
const { name, uuid } = await server.videos.randomUpload()
const { name, shortUUID } = await server.videos.randomUpload()
{
const check = { mail: false, web: true }
await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'absence' })
}
{
const check = { mail: true, web: false }
await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence')
await checkNewVideoFromSubscription({ ...baseParams, check, videoName: name, shortUUID, checkType: 'presence' })
}
})
@ -187,9 +187,9 @@ describe('Test notifications API', function () {
)
}
const { name, uuid } = await server.videos.randomUpload()
const { name, shortUUID } = await server.videos.randomUpload()
await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
})
})

View File

@ -74,8 +74,8 @@ describe('Test user notifications', function () {
await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
await waitJobs(servers)
const { name, uuid } = await uploadRandomVideoOnServers(servers, 1)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
})
it('Should send a new video notification from a remote account', async function () {
@ -84,8 +84,8 @@ describe('Test user notifications', function () {
await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port })
await waitJobs(servers)
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2)
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
})
it('Should send a new video notification on a scheduled publication', async function () {
@ -101,10 +101,10 @@ describe('Test user notifications', function () {
privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
}
}
const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
await wait(6000)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
})
it('Should send a new video notification on a remote scheduled publication', async function () {
@ -120,11 +120,11 @@ describe('Test user notifications', function () {
privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
}
}
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
await waitJobs(servers)
await wait(6000)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
})
it('Should not send a notification before the video is published', async function () {
@ -139,61 +139,61 @@ describe('Test user notifications', function () {
privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
}
}
const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
await wait(6000)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
})
it('Should send a new video notification when a video becomes public', async function () {
this.timeout(50000)
const data = { privacy: VideoPrivacy.PRIVATE }
const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
await waitJobs(servers)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
})
it('Should send a new video notification when a remote video becomes public', async function () {
this.timeout(50000)
const data = { privacy: VideoPrivacy.PRIVATE }
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
await waitJobs(servers)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence')
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
})
it('Should not send a new video notification when a video becomes unlisted', async function () {
this.timeout(50000)
const data = { privacy: VideoPrivacy.PRIVATE }
const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data)
const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data)
await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
})
it('Should not send a new video notification when a remote video becomes unlisted', async function () {
this.timeout(50000)
const data = { privacy: VideoPrivacy.PRIVATE }
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } })
await waitJobs(servers)
await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence')
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
})
it('Should send a new video notification after a video import', async function () {
@ -211,7 +211,7 @@ describe('Test user notifications', function () {
await waitJobs(servers)
await checkNewVideoFromSubscription(baseParams, name, video.uuid, 'presence')
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
})
})
@ -230,10 +230,10 @@ describe('Test user notifications', function () {
it('Should not send a notification if transcoding is not enabled', async function () {
this.timeout(50000)
const { name, uuid } = await uploadRandomVideoOnServers(servers, 1)
const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1)
await waitJobs(servers)
await checkVideoIsPublished(baseParams, name, uuid, 'absence')
await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
})
it('Should not send a notification if the wait transcoding is false', async function () {
@ -251,19 +251,19 @@ describe('Test user notifications', function () {
it('Should send a notification even if the video is not transcoded in other resolutions', async function () {
this.timeout(50000)
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' })
await waitJobs(servers)
await checkVideoIsPublished(baseParams, name, uuid, 'presence')
await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
})
it('Should send a notification with a transcoded video', async function () {
this.timeout(50000)
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true })
await waitJobs(servers)
await checkVideoIsPublished(baseParams, name, uuid, 'presence')
await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
})
it('Should send a notification when an imported video is transcoded', async function () {
@ -281,7 +281,7 @@ describe('Test user notifications', function () {
const { video } = await servers[1].imports.importVideo({ attributes })
await waitJobs(servers)
await checkVideoIsPublished(baseParams, name, video.uuid, 'presence')
await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
})
it('Should send a notification when the scheduled update has been proceeded', async function () {
@ -297,10 +297,10 @@ describe('Test user notifications', function () {
privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
}
}
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
await wait(6000)
await checkVideoIsPublished(baseParams, name, uuid, 'presence')
await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
})
it('Should not send a notification before the video is published', async function () {
@ -315,10 +315,10 @@ describe('Test user notifications', function () {
privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
}
}
const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data)
const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 2, data)
await wait(6000)
await checkVideoIsPublished(baseParams, name, uuid, 'absence')
await checkVideoIsPublished({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
})
})
@ -345,10 +345,12 @@ describe('Test user notifications', function () {
privacy: VideoPrivacy.PRIVATE,
targetUrl: FIXTURE_URLS.badVideo
}
const { video } = await servers[0].imports.importVideo({ attributes })
const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
await waitJobs(servers)
await checkMyVideoImportIsFinished(baseParams, name, video.uuid, FIXTURE_URLS.badVideo, false, 'presence')
const url = FIXTURE_URLS.badVideo
await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: false, checkType: 'presence' })
})
it('Should send a notification when the video import succeeded', async function () {
@ -362,10 +364,12 @@ describe('Test user notifications', function () {
privacy: VideoPrivacy.PRIVATE,
targetUrl: FIXTURE_URLS.goodVideo
}
const { video } = await servers[0].imports.importVideo({ attributes })
const { video: { shortUUID } } = await servers[0].imports.importVideo({ attributes })
await waitJobs(servers)
await checkMyVideoImportIsFinished(baseParams, name, video.uuid, FIXTURE_URLS.goodVideo, true, 'presence')
const url = FIXTURE_URLS.goodVideo
await checkMyVideoImportIsFinished({ ...baseParams, videoName: name, shortUUID, url, success: true, checkType: 'presence' })
})
})
@ -404,7 +408,14 @@ describe('Test user notifications', function () {
await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
await waitJobs(servers)
await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence')
await checkNewActorFollow({
...baseParams,
followType: 'channel',
followerName: 'root',
followerDisplayName: 'super root name',
followingDisplayName: myChannelName,
checkType: 'presence'
})
await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
})
@ -415,7 +426,14 @@ describe('Test user notifications', function () {
await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
await waitJobs(servers)
await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence')
await checkNewActorFollow({
...baseParams,
followType: 'channel',
followerName: 'root',
followerDisplayName: 'super root 2 name',
followingDisplayName: myChannelName,
checkType: 'presence'
})
await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
})

View File

@ -5,6 +5,7 @@ import * as chai from 'chai'
import {
cleanupTests,
createSingleServer,
doubleFollow,
PeerTubeServer,
SearchCommand,
setAccessTokensToServers,
@ -17,19 +18,21 @@ import { VideoPrivacy } from '@shared/models'
const expect = chai.expect
describe('Test videos search', function () {
let server: PeerTubeServer = null
let server: PeerTubeServer
let remoteServer: PeerTubeServer
let startDate: string
let videoUUID: string
let command: SearchCommand
before(async function () {
this.timeout(60000)
this.timeout(120000)
server = await createSingleServer(1)
remoteServer = await createSingleServer(2)
await setAccessTokensToServers([ server ])
await setDefaultVideoChannel([ server ])
await setAccessTokensToServers([ server, remoteServer ])
await setDefaultVideoChannel([ server, remoteServer ])
{
const attributes1 = {
@ -131,6 +134,13 @@ describe('Test videos search', function () {
await server.videos.upload({ attributes: { ...attributes1, category: 2 } })
}
{
await remoteServer.videos.upload({ attributes: { name: 'remote video 1' } })
await remoteServer.videos.upload({ attributes: { name: 'remote video 2' } })
}
await doubleFollow(server, remoteServer)
command = server.search
})
@ -469,8 +479,30 @@ describe('Test videos search', function () {
expect(body.data[0].name).to.equal('1111 2222 3333 - 3')
})
it('Should search by host', async function () {
{
const body = await command.advancedVideoSearch({ search: { search: '6666 7777 8888', host: server.host } })
expect(body.total).to.equal(1)
expect(body.data[0].name).to.equal('6666 7777 8888')
}
{
const body = await command.advancedVideoSearch({ search: { search: '1111', host: 'example.com' } })
expect(body.total).to.equal(0)
expect(body.data).to.have.lengthOf(0)
}
{
const body = await command.advancedVideoSearch({ search: { search: 'remote', host: remoteServer.host } })
expect(body.total).to.equal(2)
expect(body.data).to.have.lengthOf(2)
expect(body.data[0].name).to.equal('remote video 1')
expect(body.data[1].name).to.equal('remote video 2')
}
})
it('Should search by live', async function () {
this.timeout(30000)
this.timeout(60000)
{
const newConfig = {

View File

@ -13,7 +13,7 @@ describe('Test emails', function () {
let userId2: number
let userAccessToken: string
let videoUUID: string
let videoShortUUID: string
let videoId: number
let videoUserUUID: string
@ -59,8 +59,8 @@ describe('Test emails', function () {
const attributes = {
name: 'my super name'
}
const { uuid, id } = await server.videos.upload({ attributes })
videoUUID = uuid
const { shortUUID, id } = await server.videos.upload({ attributes })
videoShortUUID = shortUUID
videoId = id
}
})
@ -180,6 +180,7 @@ describe('Test emails', function () {
})
describe('When creating an abuse', function () {
it('Should send the notification email', async function () {
this.timeout(10000)
@ -195,7 +196,7 @@ describe('Test emails', function () {
expect(email['from'][0]['address']).equal('test-admin@localhost')
expect(email['to'][0]['address']).equal('admin' + server.internalServerNumber + '@example.com')
expect(email['subject']).contains('abuse')
expect(email['text']).contains(videoUUID)
expect(email['text']).contains(videoShortUUID)
})
})

View File

@ -10,6 +10,16 @@ import { doubleFollow } from '../server/follows'
import { createMultipleServers } from '../server/servers'
import { setAccessTokensToServers } from './login'
type CheckerBaseParams = {
server: PeerTubeServer
emails: any[]
socketNotifications: UserNotification[]
token: string
check?: { web: boolean, mail: boolean }
}
type CheckerType = 'presence' | 'absence'
function getAllNotificationsSettings (): UserNotificationSetting {
return {
newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
@ -31,101 +41,20 @@ function getAllNotificationsSettings (): UserNotificationSetting {
}
}
type CheckerBaseParams = {
server: PeerTubeServer
emails: any[]
socketNotifications: UserNotification[]
token: string
check?: { web: boolean, mail: boolean }
}
type CheckerType = 'presence' | 'absence'
async function checkNotification (
base: CheckerBaseParams,
notificationChecker: (notification: UserNotification, type: CheckerType) => void,
emailNotificationFinder: (email: object) => boolean,
async function checkNewVideoFromSubscription (options: CheckerBaseParams & {
videoName: string
shortUUID: string
checkType: CheckerType
) {
const check = base.check || { web: true, mail: true }
if (check.web) {
const notification = await base.server.notifications.getLastest({ token: base.token })
if (notification || checkType !== 'absence') {
notificationChecker(notification, checkType)
}
const socketNotification = base.socketNotifications.find(n => {
try {
notificationChecker(n, 'presence')
return true
} catch {
return false
}
})
if (checkType === 'presence') {
const obj = inspect(base.socketNotifications, { depth: 5 })
expect(socketNotification, 'The socket notification is absent when it should be present. ' + obj).to.not.be.undefined
} else {
const obj = inspect(socketNotification, { depth: 5 })
expect(socketNotification, 'The socket notification is present when it should not be present. ' + obj).to.be.undefined
}
}
if (check.mail) {
// Last email
const email = base.emails
.slice()
.reverse()
.find(e => emailNotificationFinder(e))
if (checkType === 'presence') {
const emails = base.emails.map(e => e.text)
expect(email, 'The email is absent when is should be present. ' + inspect(emails)).to.not.be.undefined
} else {
expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined
}
}
}
function checkVideo (video: any, videoName?: string, videoUUID?: string) {
if (videoName) {
expect(video.name).to.be.a('string')
expect(video.name).to.not.be.empty
expect(video.name).to.equal(videoName)
}
if (videoUUID) {
expect(video.uuid).to.be.a('string')
expect(video.uuid).to.not.be.empty
expect(video.uuid).to.equal(videoUUID)
}
expect(video.id).to.be.a('number')
}
function checkActor (actor: any) {
expect(actor.displayName).to.be.a('string')
expect(actor.displayName).to.not.be.empty
expect(actor.host).to.not.be.undefined
}
function checkComment (comment: any, commentId: number, threadId: number) {
expect(comment.id).to.equal(commentId)
expect(comment.threadId).to.equal(threadId)
}
async function checkNewVideoFromSubscription (base: CheckerBaseParams, videoName: string, videoUUID: string, type: CheckerType) {
}) {
const { videoName, shortUUID } = options
const notificationType = UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
checkVideo(notification.video, videoName, videoUUID)
checkVideo(notification.video, videoName, shortUUID)
checkActor(notification.video.channel)
} else {
expect(notification).to.satisfy((n: UserNotification) => {
@ -136,21 +65,26 @@ async function checkNewVideoFromSubscription (base: CheckerBaseParams, videoName
function emailNotificationFinder (email: object) {
const text = email['text']
return text.indexOf(videoUUID) !== -1 && text.indexOf('Your subscription') !== -1
return text.indexOf(shortUUID) !== -1 && text.indexOf('Your subscription') !== -1
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function checkVideoIsPublished (base: CheckerBaseParams, videoName: string, videoUUID: string, type: CheckerType) {
async function checkVideoIsPublished (options: CheckerBaseParams & {
videoName: string
shortUUID: string
checkType: CheckerType
}) {
const { videoName, shortUUID } = options
const notificationType = UserNotificationType.MY_VIDEO_PUBLISHED
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
checkVideo(notification.video, videoName, videoUUID)
checkVideo(notification.video, videoName, shortUUID)
checkActor(notification.video.channel)
} else {
expect(notification.video).to.satisfy(v => v === undefined || v.name !== videoName)
@ -159,30 +93,31 @@ async function checkVideoIsPublished (base: CheckerBaseParams, videoName: string
function emailNotificationFinder (email: object) {
const text: string = email['text']
return text.includes(videoUUID) && text.includes('Your video')
return text.includes(shortUUID) && text.includes('Your video')
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function checkMyVideoImportIsFinished (
base: CheckerBaseParams,
videoName: string,
videoUUID: string,
url: string,
success: boolean,
type: CheckerType
) {
async function checkMyVideoImportIsFinished (options: CheckerBaseParams & {
videoName: string
shortUUID: string
url: string
success: boolean
checkType: CheckerType
}) {
const { videoName, shortUUID, url, success } = options
const notificationType = success ? UserNotificationType.MY_VIDEO_IMPORT_SUCCESS : UserNotificationType.MY_VIDEO_IMPORT_ERROR
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
expect(notification.videoImport.targetUrl).to.equal(url)
if (success) checkVideo(notification.videoImport.video, videoName, videoUUID)
if (success) checkVideo(notification.videoImport.video, videoName, shortUUID)
} else {
expect(notification.videoImport).to.satisfy(i => i === undefined || i.targetUrl !== url)
}
@ -195,14 +130,18 @@ async function checkMyVideoImportIsFinished (
return text.includes(url) && text.includes(toFind)
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function checkUserRegistered (base: CheckerBaseParams, username: string, type: CheckerType) {
async function checkUserRegistered (options: CheckerBaseParams & {
username: string
checkType: CheckerType
}) {
const { username } = options
const notificationType = UserNotificationType.NEW_USER_REGISTRATION
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
@ -219,21 +158,21 @@ async function checkUserRegistered (base: CheckerBaseParams, username: string, t
return text.includes(' registered.') && text.includes(username)
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function checkNewActorFollow (
base: CheckerBaseParams,
followType: 'channel' | 'account',
followerName: string,
followerDisplayName: string,
followingDisplayName: string,
type: CheckerType
) {
async function checkNewActorFollow (options: CheckerBaseParams & {
followType: 'channel' | 'account'
followerName: string
followerDisplayName: string
followingDisplayName: string
checkType: CheckerType
}) {
const { followType, followerName, followerDisplayName, followingDisplayName } = options
const notificationType = UserNotificationType.NEW_FOLLOW
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
@ -259,14 +198,18 @@ async function checkNewActorFollow (
return text.includes(followType) && text.includes(followingDisplayName) && text.includes(followerDisplayName)
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function checkNewInstanceFollower (base: CheckerBaseParams, followerHost: string, type: CheckerType) {
async function checkNewInstanceFollower (options: CheckerBaseParams & {
followerHost: string
checkType: CheckerType
}) {
const { followerHost } = options
const notificationType = UserNotificationType.NEW_INSTANCE_FOLLOWER
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
@ -288,14 +231,19 @@ async function checkNewInstanceFollower (base: CheckerBaseParams, followerHost:
return text.includes('instance has a new follower') && text.includes(followerHost)
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function checkAutoInstanceFollowing (base: CheckerBaseParams, followerHost: string, followingHost: string, type: CheckerType) {
async function checkAutoInstanceFollowing (options: CheckerBaseParams & {
followerHost: string
followingHost: string
checkType: CheckerType
}) {
const { followerHost, followingHost } = options
const notificationType = UserNotificationType.AUTO_INSTANCE_FOLLOWING
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
@ -319,21 +267,21 @@ async function checkAutoInstanceFollowing (base: CheckerBaseParams, followerHost
return text.includes(' automatically followed a new instance') && text.includes(followingHost)
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function checkCommentMention (
base: CheckerBaseParams,
uuid: string,
commentId: number,
threadId: number,
byAccountDisplayName: string,
type: CheckerType
) {
async function checkCommentMention (options: CheckerBaseParams & {
shortUUID: string
commentId: number
threadId: number
byAccountDisplayName: string
checkType: CheckerType
}) {
const { shortUUID, commentId, threadId, byAccountDisplayName } = options
const notificationType = UserNotificationType.COMMENT_MENTION
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
@ -341,7 +289,7 @@ async function checkCommentMention (
checkActor(notification.comment.account)
expect(notification.comment.account.displayName).to.equal(byAccountDisplayName)
checkVideo(notification.comment.video, undefined, uuid)
checkVideo(notification.comment.video, undefined, shortUUID)
} else {
expect(notification).to.satisfy(n => n.type !== notificationType || n.comment.id !== commentId)
}
@ -350,25 +298,31 @@ async function checkCommentMention (
function emailNotificationFinder (email: object) {
const text: string = email['text']
return text.includes(' mentioned ') && text.includes(uuid) && text.includes(byAccountDisplayName)
return text.includes(' mentioned ') && text.includes(shortUUID) && text.includes(byAccountDisplayName)
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
let lastEmailCount = 0
async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string, commentId: number, threadId: number, type: CheckerType) {
async function checkNewCommentOnMyVideo (options: CheckerBaseParams & {
shortUUID: string
commentId: number
threadId: number
checkType: CheckerType
}) {
const { server, shortUUID, commentId, threadId, checkType, emails } = options
const notificationType = UserNotificationType.NEW_COMMENT_ON_MY_VIDEO
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
checkComment(notification.comment, commentId, threadId)
checkActor(notification.comment.account)
checkVideo(notification.comment.video, undefined, uuid)
checkVideo(notification.comment.video, undefined, shortUUID)
} else {
expect(notification).to.satisfy((n: UserNotification) => {
return n === undefined || n.comment === undefined || n.comment.id !== commentId
@ -376,51 +330,62 @@ async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string,
}
}
const commentUrl = `http://localhost:${base.server.port}/w/${uuid};threadId=${threadId}`
const commentUrl = `http://localhost:${server.port}/w/${shortUUID};threadId=${threadId}`
function emailNotificationFinder (email: object) {
return email['text'].indexOf(commentUrl) !== -1
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
if (type === 'presence') {
if (checkType === 'presence') {
// We cannot detect email duplicates, so check we received another email
expect(base.emails).to.have.length.above(lastEmailCount)
lastEmailCount = base.emails.length
expect(emails).to.have.length.above(lastEmailCount)
lastEmailCount = emails.length
}
}
async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
async function checkNewVideoAbuseForModerators (options: CheckerBaseParams & {
shortUUID: string
videoName: string
checkType: CheckerType
}) {
const { shortUUID, videoName } = options
const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
expect(notification.abuse.id).to.be.a('number')
checkVideo(notification.abuse.video, videoName, videoUUID)
checkVideo(notification.abuse.video, videoName, shortUUID)
} else {
expect(notification).to.satisfy((n: UserNotification) => {
return n === undefined || n.abuse === undefined || n.abuse.video.uuid !== videoUUID
return n === undefined || n.abuse === undefined || n.abuse.video.shortUUID !== shortUUID
})
}
}
function emailNotificationFinder (email: object) {
const text = email['text']
return text.indexOf(videoUUID) !== -1 && text.indexOf('abuse') !== -1
return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function checkNewAbuseMessage (base: CheckerBaseParams, abuseId: number, message: string, toEmail: string, type: CheckerType) {
async function checkNewAbuseMessage (options: CheckerBaseParams & {
abuseId: number
message: string
toEmail: string
checkType: CheckerType
}) {
const { abuseId, message, toEmail } = options
const notificationType = UserNotificationType.ABUSE_NEW_MESSAGE
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
@ -439,14 +404,19 @@ async function checkNewAbuseMessage (base: CheckerBaseParams, abuseId: number, m
return text.indexOf(message) !== -1 && to.length !== 0
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function checkAbuseStateChange (base: CheckerBaseParams, abuseId: number, state: AbuseState, type: CheckerType) {
async function checkAbuseStateChange (options: CheckerBaseParams & {
abuseId: number
state: AbuseState
checkType: CheckerType
}) {
const { abuseId, state } = options
const notificationType = UserNotificationType.ABUSE_STATE_CHANGE
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
@ -469,39 +439,48 @@ async function checkAbuseStateChange (base: CheckerBaseParams, abuseId: number,
return text.indexOf(contains) !== -1
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function checkNewCommentAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
async function checkNewCommentAbuseForModerators (options: CheckerBaseParams & {
shortUUID: string
videoName: string
checkType: CheckerType
}) {
const { shortUUID, videoName } = options
const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
expect(notification.abuse.id).to.be.a('number')
checkVideo(notification.abuse.comment.video, videoName, videoUUID)
checkVideo(notification.abuse.comment.video, videoName, shortUUID)
} else {
expect(notification).to.satisfy((n: UserNotification) => {
return n === undefined || n.abuse === undefined || n.abuse.comment.video.uuid !== videoUUID
return n === undefined || n.abuse === undefined || n.abuse.comment.video.shortUUID !== shortUUID
})
}
}
function emailNotificationFinder (email: object) {
const text = email['text']
return text.indexOf(videoUUID) !== -1 && text.indexOf('abuse') !== -1
return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function checkNewAccountAbuseForModerators (base: CheckerBaseParams, displayName: string, type: CheckerType) {
async function checkNewAccountAbuseForModerators (options: CheckerBaseParams & {
displayName: string
checkType: CheckerType
}) {
const { displayName } = options
const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
@ -519,40 +498,45 @@ async function checkNewAccountAbuseForModerators (base: CheckerBaseParams, displ
return text.indexOf(displayName) !== -1 && text.indexOf('abuse') !== -1
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
async function checkVideoAutoBlacklistForModerators (options: CheckerBaseParams & {
shortUUID: string
videoName: string
checkType: CheckerType
}) {
const { shortUUID, videoName } = options
const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
expect(notification.videoBlacklist.video.id).to.be.a('number')
checkVideo(notification.videoBlacklist.video, videoName, videoUUID)
checkVideo(notification.videoBlacklist.video, videoName, shortUUID)
} else {
expect(notification).to.satisfy((n: UserNotification) => {
return n === undefined || n.video === undefined || n.video.uuid !== videoUUID
return n === undefined || n.video === undefined || n.video.shortUUID !== shortUUID
})
}
}
function emailNotificationFinder (email: object) {
const text = email['text']
return text.indexOf(videoUUID) !== -1 && email['text'].indexOf('video-auto-blacklist/list') !== -1
return text.indexOf(shortUUID) !== -1 && email['text'].indexOf('video-auto-blacklist/list') !== -1
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function checkNewBlacklistOnMyVideo (
base: CheckerBaseParams,
videoUUID: string,
videoName: string,
async function checkNewBlacklistOnMyVideo (options: CheckerBaseParams & {
shortUUID: string
videoName: string
blacklistType: 'blacklist' | 'unblacklist'
) {
}) {
const { videoName, shortUUID, blacklistType } = options
const notificationType = blacklistType === 'blacklist'
? UserNotificationType.BLACKLIST_ON_MY_VIDEO
: UserNotificationType.UNBLACKLIST_ON_MY_VIDEO
@ -563,22 +547,30 @@ async function checkNewBlacklistOnMyVideo (
const video = blacklistType === 'blacklist' ? notification.videoBlacklist.video : notification.video
checkVideo(video, videoName, videoUUID)
checkVideo(video, videoName, shortUUID)
}
function emailNotificationFinder (email: object) {
const text = email['text']
return text.indexOf(videoUUID) !== -1 && text.indexOf(' ' + blacklistType) !== -1
const blacklistText = blacklistType === 'blacklist'
? 'blacklisted'
: 'unblacklisted'
return text.includes(shortUUID) && text.includes(blacklistText)
}
await checkNotification(base, notificationChecker, emailNotificationFinder, 'presence')
await checkNotification({ ...options, notificationChecker, emailNotificationFinder, checkType: 'presence' })
}
async function checkNewPeerTubeVersion (base: CheckerBaseParams, latestVersion: string, type: CheckerType) {
async function checkNewPeerTubeVersion (options: CheckerBaseParams & {
latestVersion: string
checkType: CheckerType
}) {
const { latestVersion } = options
const notificationType = UserNotificationType.NEW_PEERTUBE_VERSION
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
@ -597,14 +589,19 @@ async function checkNewPeerTubeVersion (base: CheckerBaseParams, latestVersion:
return text.includes(latestVersion)
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function checkNewPluginVersion (base: CheckerBaseParams, pluginType: PluginType, pluginName: string, type: CheckerType) {
async function checkNewPluginVersion (options: CheckerBaseParams & {
pluginType: PluginType
pluginName: string
checkType: CheckerType
}) {
const { pluginName, pluginType } = options
const notificationType = UserNotificationType.NEW_PLUGIN_VERSION
function notificationChecker (notification: UserNotification, type: CheckerType) {
if (type === 'presence') {
function notificationChecker (notification: UserNotification, checkType: CheckerType) {
if (checkType === 'presence') {
expect(notification).to.not.be.undefined
expect(notification.type).to.equal(notificationType)
@ -623,7 +620,7 @@ async function checkNewPluginVersion (base: CheckerBaseParams, pluginType: Plugi
return text.includes(pluginName)
}
await checkNotification(base, notificationChecker, emailNotificationFinder, type)
await checkNotification({ ...options, notificationChecker, emailNotificationFinder })
}
async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: any = {}) {
@ -697,7 +694,6 @@ export {
CheckerBaseParams,
CheckerType,
checkNotification,
checkMyVideoImportIsFinished,
checkUserRegistered,
checkAutoInstanceFollowing,
@ -718,3 +714,82 @@ export {
checkNewPeerTubeVersion,
checkNewPluginVersion
}
// ---------------------------------------------------------------------------
async function checkNotification (options: CheckerBaseParams & {
notificationChecker: (notification: UserNotification, checkType: CheckerType) => void
emailNotificationFinder: (email: object) => boolean
checkType: CheckerType
}) {
const { server, token, checkType, notificationChecker, emailNotificationFinder, socketNotifications, emails } = options
const check = options.check || { web: true, mail: true }
if (check.web) {
const notification = await server.notifications.getLastest({ token: token })
if (notification || checkType !== 'absence') {
notificationChecker(notification, checkType)
}
const socketNotification = socketNotifications.find(n => {
try {
notificationChecker(n, 'presence')
return true
} catch {
return false
}
})
if (checkType === 'presence') {
const obj = inspect(socketNotifications, { depth: 5 })
expect(socketNotification, 'The socket notification is absent when it should be present. ' + obj).to.not.be.undefined
} else {
const obj = inspect(socketNotification, { depth: 5 })
expect(socketNotification, 'The socket notification is present when it should not be present. ' + obj).to.be.undefined
}
}
if (check.mail) {
// Last email
const email = emails
.slice()
.reverse()
.find(e => emailNotificationFinder(e))
if (checkType === 'presence') {
const texts = emails.map(e => e.text)
expect(email, 'The email is absent when is should be present. ' + inspect(texts)).to.not.be.undefined
} else {
expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined
}
}
}
function checkVideo (video: any, videoName?: string, shortUUID?: string) {
if (videoName) {
expect(video.name).to.be.a('string')
expect(video.name).to.not.be.empty
expect(video.name).to.equal(videoName)
}
if (shortUUID) {
expect(video.shortUUID).to.be.a('string')
expect(video.shortUUID).to.not.be.empty
expect(video.shortUUID).to.equal(shortUUID)
}
expect(video.id).to.be.a('number')
}
function checkActor (actor: any) {
expect(actor.displayName).to.be.a('string')
expect(actor.displayName).to.not.be.empty
expect(actor.host).to.not.be.undefined
}
function checkComment (comment: any, commentId: number, threadId: number) {
expect(comment.id).to.equal(commentId)
expect(comment.threadId).to.equal(threadId)
}

View File

@ -4,6 +4,8 @@ import { VideosCommonQuery } from './videos-common-query.model'
export interface VideosSearchQuery extends SearchTargetQuery, VideosCommonQuery {
search?: string
host?: string
startDate?: string // ISO 8601
endDate?: string // ISO 8601

View File

@ -36,6 +36,7 @@ export const enum UserNotificationType {
export interface VideoInfo {
id: number
uuid: string
shortUUID: string
name: string
}
@ -82,11 +83,7 @@ export interface UserNotification {
comment?: {
threadId: number
video: {
id: number
uuid: string
name: string
}
video: VideoInfo
}
account?: ActorInfo