Support refusing remote comments
This commit is contained in:
parent
b569b2c607
commit
b2a70e3ca2
|
@ -109,8 +109,10 @@ async function processCreateVideoComment (activity: ActivityCreate, byActor: MAc
|
||||||
let video: MVideoAccountLightBlacklistAllFiles
|
let video: MVideoAccountLightBlacklistAllFiles
|
||||||
let created: boolean
|
let created: boolean
|
||||||
let comment: MCommentOwnerVideo
|
let comment: MCommentOwnerVideo
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resolveThreadResult = await resolveThread({ url: commentObject.id, isVideo: false })
|
const resolveThreadResult = await resolveThread({ url: commentObject.id, isVideo: false })
|
||||||
|
if (!resolveThreadResult) return // Comment not accepted
|
||||||
|
|
||||||
video = resolveThreadResult.video
|
video = resolveThreadResult.video
|
||||||
created = resolveThreadResult.commentCreated
|
created = resolveThreadResult.commentCreated
|
||||||
|
|
|
@ -4,7 +4,9 @@ import { logger } from '../../helpers/logger'
|
||||||
import { doJSONRequest } from '../../helpers/requests'
|
import { doJSONRequest } from '../../helpers/requests'
|
||||||
import { ACTIVITY_PUB, CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants'
|
import { ACTIVITY_PUB, CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants'
|
||||||
import { VideoCommentModel } from '../../models/video/video-comment'
|
import { VideoCommentModel } from '../../models/video/video-comment'
|
||||||
import { MCommentOwner, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../types/models/video'
|
import { MComment, MCommentOwner, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../types/models/video'
|
||||||
|
import { isRemoteVideoCommentAccepted } from '../moderation'
|
||||||
|
import { Hooks } from '../plugins/hooks'
|
||||||
import { getOrCreateAPActor } from './actors'
|
import { getOrCreateAPActor } from './actors'
|
||||||
import { checkUrlsSameHost } from './url'
|
import { checkUrlsSameHost } from './url'
|
||||||
import { getOrCreateAPVideo } from './videos'
|
import { getOrCreateAPVideo } from './videos'
|
||||||
|
@ -103,6 +105,10 @@ async function tryToResolveThreadFromVideo (params: ResolveThreadParams) {
|
||||||
firstReply.changed('updatedAt', true)
|
firstReply.changed('updatedAt', true)
|
||||||
firstReply.Video = video
|
firstReply.Video = video
|
||||||
|
|
||||||
|
if (await isRemoteCommentAccepted(firstReply) !== true) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
comments[comments.length - 1] = await firstReply.save()
|
comments[comments.length - 1] = await firstReply.save()
|
||||||
|
|
||||||
for (let i = comments.length - 2; i >= 0; i--) {
|
for (let i = comments.length - 2; i >= 0; i--) {
|
||||||
|
@ -113,6 +119,10 @@ async function tryToResolveThreadFromVideo (params: ResolveThreadParams) {
|
||||||
comment.changed('updatedAt', true)
|
comment.changed('updatedAt', true)
|
||||||
comment.Video = video
|
comment.Video = video
|
||||||
|
|
||||||
|
if (await isRemoteCommentAccepted(comment) !== true) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
comments[i] = await comment.save()
|
comments[i] = await comment.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,3 +179,26 @@ async function resolveRemoteParentComment (params: ResolveThreadParams) {
|
||||||
commentCreated: true
|
commentCreated: true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function isRemoteCommentAccepted (comment: MComment) {
|
||||||
|
// Already created
|
||||||
|
if (comment.id) return true
|
||||||
|
|
||||||
|
const acceptParameters = {
|
||||||
|
comment
|
||||||
|
}
|
||||||
|
|
||||||
|
const acceptedResult = await Hooks.wrapFun(
|
||||||
|
isRemoteVideoCommentAccepted,
|
||||||
|
acceptParameters,
|
||||||
|
'filter:activity-pub.remote-video-comment.create.accept.result'
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!acceptedResult || acceptedResult.accepted !== true) {
|
||||||
|
logger.info('Refused to create a remote comment.', { acceptedResult, acceptParameters })
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
|
@ -13,18 +13,15 @@ import {
|
||||||
MAbuseFull,
|
MAbuseFull,
|
||||||
MAccountDefault,
|
MAccountDefault,
|
||||||
MAccountLight,
|
MAccountLight,
|
||||||
|
MComment,
|
||||||
MCommentAbuseAccountVideo,
|
MCommentAbuseAccountVideo,
|
||||||
MCommentOwnerVideo,
|
MCommentOwnerVideo,
|
||||||
MUser,
|
MUser,
|
||||||
MVideoAbuseVideoFull,
|
MVideoAbuseVideoFull,
|
||||||
MVideoAccountLightBlacklistAllFiles
|
MVideoAccountLightBlacklistAllFiles
|
||||||
} from '@server/types/models'
|
} from '@server/types/models'
|
||||||
import { ActivityCreate } from '../../shared/models/activitypub'
|
|
||||||
import { VideoObject } from '../../shared/models/activitypub/objects'
|
|
||||||
import { VideoCommentObject } from '../../shared/models/activitypub/objects/video-comment-object'
|
|
||||||
import { LiveVideoCreate, VideoCreate, VideoImportCreate } from '../../shared/models/videos'
|
import { LiveVideoCreate, VideoCreate, VideoImportCreate } from '../../shared/models/videos'
|
||||||
import { VideoCommentCreate } from '../../shared/models/videos/comment'
|
import { VideoCommentCreate } from '../../shared/models/videos/comment'
|
||||||
import { ActorModel } from '../models/actor/actor'
|
|
||||||
import { UserModel } from '../models/user/user'
|
import { UserModel } from '../models/user/user'
|
||||||
import { VideoModel } from '../models/video/video'
|
import { VideoModel } from '../models/video/video'
|
||||||
import { VideoCommentModel } from '../models/video/video-comment'
|
import { VideoCommentModel } from '../models/video/video-comment'
|
||||||
|
@ -36,7 +33,9 @@ export type AcceptResult = {
|
||||||
errorMessage?: string
|
errorMessage?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can be filtered by plugins
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Stub function that can be filtered by plugins
|
||||||
function isLocalVideoAccepted (object: {
|
function isLocalVideoAccepted (object: {
|
||||||
videoBody: VideoCreate
|
videoBody: VideoCreate
|
||||||
videoFile: VideoUploadFile
|
videoFile: VideoUploadFile
|
||||||
|
@ -45,6 +44,9 @@ function isLocalVideoAccepted (object: {
|
||||||
return { accepted: true }
|
return { accepted: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Stub function that can be filtered by plugins
|
||||||
function isLocalLiveVideoAccepted (object: {
|
function isLocalLiveVideoAccepted (object: {
|
||||||
liveVideoBody: LiveVideoCreate
|
liveVideoBody: LiveVideoCreate
|
||||||
user: UserModel
|
user: UserModel
|
||||||
|
@ -52,6 +54,9 @@ function isLocalLiveVideoAccepted (object: {
|
||||||
return { accepted: true }
|
return { accepted: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Stub function that can be filtered by plugins
|
||||||
function isLocalVideoThreadAccepted (_object: {
|
function isLocalVideoThreadAccepted (_object: {
|
||||||
commentBody: VideoCommentCreate
|
commentBody: VideoCommentCreate
|
||||||
video: VideoModel
|
video: VideoModel
|
||||||
|
@ -60,6 +65,7 @@ function isLocalVideoThreadAccepted (_object: {
|
||||||
return { accepted: true }
|
return { accepted: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stub function that can be filtered by plugins
|
||||||
function isLocalVideoCommentReplyAccepted (_object: {
|
function isLocalVideoCommentReplyAccepted (_object: {
|
||||||
commentBody: VideoCommentCreate
|
commentBody: VideoCommentCreate
|
||||||
parentComment: VideoCommentModel
|
parentComment: VideoCommentModel
|
||||||
|
@ -69,22 +75,18 @@ function isLocalVideoCommentReplyAccepted (_object: {
|
||||||
return { accepted: true }
|
return { accepted: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRemoteVideoAccepted (_object: {
|
// ---------------------------------------------------------------------------
|
||||||
activity: ActivityCreate
|
|
||||||
videoAP: VideoObject
|
|
||||||
byActor: ActorModel
|
|
||||||
}): AcceptResult {
|
|
||||||
return { accepted: true }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Stub function that can be filtered by plugins
|
||||||
function isRemoteVideoCommentAccepted (_object: {
|
function isRemoteVideoCommentAccepted (_object: {
|
||||||
activity: ActivityCreate
|
comment: MComment
|
||||||
commentAP: VideoCommentObject
|
|
||||||
byActor: ActorModel
|
|
||||||
}): AcceptResult {
|
}): AcceptResult {
|
||||||
return { accepted: true }
|
return { accepted: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Stub function that can be filtered by plugins
|
||||||
function isPreImportVideoAccepted (object: {
|
function isPreImportVideoAccepted (object: {
|
||||||
videoImportBody: VideoImportCreate
|
videoImportBody: VideoImportCreate
|
||||||
user: MUser
|
user: MUser
|
||||||
|
@ -92,6 +94,7 @@ function isPreImportVideoAccepted (object: {
|
||||||
return { accepted: true }
|
return { accepted: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stub function that can be filtered by plugins
|
||||||
function isPostImportVideoAccepted (object: {
|
function isPostImportVideoAccepted (object: {
|
||||||
videoFilePath: PathLike
|
videoFilePath: PathLike
|
||||||
videoFile: VideoFileModel
|
videoFile: VideoFileModel
|
||||||
|
@ -100,6 +103,8 @@ function isPostImportVideoAccepted (object: {
|
||||||
return { accepted: true }
|
return { accepted: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
async function createVideoAbuse (options: {
|
async function createVideoAbuse (options: {
|
||||||
baseAbuse: FilteredModelAttributes<AbuseModel>
|
baseAbuse: FilteredModelAttributes<AbuseModel>
|
||||||
videoInstance: MVideoAccountLightBlacklistAllFiles
|
videoInstance: MVideoAccountLightBlacklistAllFiles
|
||||||
|
@ -189,12 +194,13 @@ function createAccountAbuse (options: {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
export {
|
export {
|
||||||
isLocalLiveVideoAccepted,
|
isLocalLiveVideoAccepted,
|
||||||
|
|
||||||
isLocalVideoAccepted,
|
isLocalVideoAccepted,
|
||||||
isLocalVideoThreadAccepted,
|
isLocalVideoThreadAccepted,
|
||||||
isRemoteVideoAccepted,
|
|
||||||
isRemoteVideoCommentAccepted,
|
isRemoteVideoCommentAccepted,
|
||||||
isLocalVideoCommentReplyAccepted,
|
isLocalVideoCommentReplyAccepted,
|
||||||
isPreImportVideoAccepted,
|
isPreImportVideoAccepted,
|
||||||
|
|
|
@ -178,6 +178,8 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
registerHook({
|
registerHook({
|
||||||
target: 'filter:api.video-thread.create.accept.result',
|
target: 'filter:api.video-thread.create.accept.result',
|
||||||
handler: ({ accepted }, { commentBody }) => checkCommentBadWord(accepted, commentBody)
|
handler: ({ accepted }, { commentBody }) => checkCommentBadWord(accepted, commentBody)
|
||||||
|
@ -188,6 +190,13 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
|
||||||
handler: ({ accepted }, { commentBody }) => checkCommentBadWord(accepted, commentBody)
|
handler: ({ accepted }, { commentBody }) => checkCommentBadWord(accepted, commentBody)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
registerHook({
|
||||||
|
target: 'filter:activity-pub.remote-video-comment.create.accept.result',
|
||||||
|
handler: ({ accepted }, { comment }) => checkCommentBadWord(accepted, comment)
|
||||||
|
})
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
registerHook({
|
registerHook({
|
||||||
target: 'filter:api.video-threads.list.params',
|
target: 'filter:api.video-threads.list.params',
|
||||||
handler: obj => addToCount(obj)
|
handler: obj => addToCount(obj)
|
||||||
|
|
|
@ -64,6 +64,8 @@ describe('Test plugin filter hooks', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('Videos', function () {
|
||||||
|
|
||||||
it('Should run filter:api.videos.list.params', async function () {
|
it('Should run filter:api.videos.list.params', async function () {
|
||||||
const { data } = await servers[0].videos.list({ start: 0, count: 2 })
|
const { data } = await servers[0].videos.list({ start: 0, count: 2 })
|
||||||
|
|
||||||
|
@ -144,6 +146,9 @@ describe('Test plugin filter hooks', function () {
|
||||||
const video = await servers[0].videos.get({ id: videoUUID })
|
const video = await servers[0].videos.get({ id: videoUUID })
|
||||||
expect(video.name).to.contain('<3')
|
expect(video.name).to.contain('<3')
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Video/live/import accept', function () {
|
||||||
|
|
||||||
it('Should run filter:api.video.upload.accept.result', async function () {
|
it('Should run filter:api.video.upload.accept.result', async function () {
|
||||||
await servers[0].videos.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
|
await servers[0].videos.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
|
||||||
|
@ -235,6 +240,9 @@ describe('Test plugin filter hooks', function () {
|
||||||
expect(videoImport.state.label).to.equal('Rejected')
|
expect(videoImport.state.label).to.equal('Rejected')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Video comments accept', function () {
|
||||||
|
|
||||||
it('Should run filter:api.video-thread.create.accept.result', async function () {
|
it('Should run filter:api.video-thread.create.accept.result', async function () {
|
||||||
await servers[0].comments.createThread({
|
await servers[0].comments.createThread({
|
||||||
|
@ -262,6 +270,54 @@ describe('Test plugin filter hooks', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should run filter:activity-pub.remote-video-comment.create.accept.result on a thread creation', async function () {
|
||||||
|
this.timeout(30000)
|
||||||
|
|
||||||
|
await servers[1].comments.createThread({ videoId: videoUUID, text: 'comment with bad word' })
|
||||||
|
|
||||||
|
await waitJobs(servers)
|
||||||
|
|
||||||
|
{
|
||||||
|
const thread = await servers[0].comments.listThreads({ videoId: videoUUID })
|
||||||
|
expect(thread.data).to.have.lengthOf(1)
|
||||||
|
expect(thread.data[0].text).to.not.include(' bad ')
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const thread = await servers[1].comments.listThreads({ videoId: videoUUID })
|
||||||
|
expect(thread.data).to.have.lengthOf(2)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should run filter:activity-pub.remote-video-comment.create.accept.result on a reply creation', async function () {
|
||||||
|
this.timeout(30000)
|
||||||
|
|
||||||
|
const { data } = await servers[1].comments.listThreads({ videoId: videoUUID })
|
||||||
|
const threadIdServer2 = data.find(t => t.text === 'thread').id
|
||||||
|
|
||||||
|
await servers[1].comments.addReply({
|
||||||
|
videoId: videoUUID,
|
||||||
|
toCommentId: threadIdServer2,
|
||||||
|
text: 'comment with bad word'
|
||||||
|
})
|
||||||
|
|
||||||
|
await waitJobs(servers)
|
||||||
|
|
||||||
|
{
|
||||||
|
const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId })
|
||||||
|
expect(tree.children).to.have.lengthOf(1)
|
||||||
|
expect(tree.children[0].comment.text).to.not.include(' bad ')
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const tree = await servers[1].comments.getThread({ videoId: videoUUID, threadId: threadIdServer2 })
|
||||||
|
expect(tree.children).to.have.lengthOf(2)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Video comments', function () {
|
||||||
|
|
||||||
it('Should run filter:api.video-threads.list.params', async function () {
|
it('Should run filter:api.video-threads.list.params', async function () {
|
||||||
const { data } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
|
const { data } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
|
||||||
|
|
||||||
|
@ -291,6 +347,7 @@ describe('Test plugin filter hooks', function () {
|
||||||
await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.params', 3)
|
await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.params', 3)
|
||||||
await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.result', 3)
|
await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.result', 3)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('filter:video.auto-blacklist.result', function () {
|
describe('filter:video.auto-blacklist.result', function () {
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,9 @@ export const serverFilterHookObject = {
|
||||||
'filter:job-queue.process.result': true,
|
'filter:job-queue.process.result': true,
|
||||||
|
|
||||||
'filter:transcoding.manual.resolutions-to-transcode.result': true,
|
'filter:transcoding.manual.resolutions-to-transcode.result': true,
|
||||||
'filter:transcoding.auto.resolutions-to-transcode.result': true
|
'filter:transcoding.auto.resolutions-to-transcode.result': true,
|
||||||
|
|
||||||
|
'filter:activity-pub.remote-video-comment.create.accept.result': true
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ServerFilterHookName = keyof typeof serverFilterHookObject
|
export type ServerFilterHookName = keyof typeof serverFilterHookObject
|
||||||
|
|
Loading…
Reference in New Issue
Block a user