From 6691c52280363fc42f7865230ebb3741f02fff23 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 22 Jul 2019 11:14:58 +0200 Subject: Add filter hooks tests --- server/controllers/api/videos/comment.ts | 2 +- server/controllers/api/videos/import.ts | 2 +- server/controllers/api/videos/index.ts | 36 ++++++++++++++++++++++---------- 3 files changed, 27 insertions(+), 13 deletions(-) (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index feda71bdd..39d521f5f 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts @@ -110,7 +110,7 @@ async function listVideoThreadComments (req: express.Request, res: express.Respo const apiOptions = await Hooks.wrapObject({ videoId: video.id, threadId: res.locals.videoCommentThread.id, - user: user + user }, 'filter:api.video-thread-comments.list.params') resultList = await Hooks.wrapPromiseFun( diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index dcba0e08f..47c6f122c 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -245,7 +245,7 @@ function insertIntoDB (parameters: { if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t) - await autoBlacklistVideoIfNeeded(video, user, t) + await autoBlacklistVideoIfNeeded({ video, user, isRemote: false, isNew: true, transaction: t }) // Set tags to the video if (tags) { diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 11e468df2..6a79a16c7 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -268,7 +268,13 @@ async function addVideo (req: express.Request, res: express.Response) { }, { transaction: t }) } - const videoWasAutoBlacklisted = await autoBlacklistVideoIfNeeded(video, res.locals.oauth.token.User, t) + const videoWasAutoBlacklisted = await autoBlacklistVideoIfNeeded({ + video, + user: res.locals.oauth.token.User, + isRemote: false, + isNew: true, + transaction: t + }) if (!videoWasAutoBlacklisted) await federateVideoIfNeeded(video, true, t) auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(videoCreated.toFormattedDetailsJSON())) @@ -336,16 +342,16 @@ async function updateVideo (req: express.Request, res: express.Response) { const sequelizeOptions = { transaction: t } const oldVideoChannel = videoInstance.VideoChannel - if (videoInfoToUpdate.name !== undefined) videoInstance.set('name', videoInfoToUpdate.name) - if (videoInfoToUpdate.category !== undefined) videoInstance.set('category', videoInfoToUpdate.category) - if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence) - if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language) - if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw) - if (videoInfoToUpdate.waitTranscoding !== undefined) videoInstance.set('waitTranscoding', videoInfoToUpdate.waitTranscoding) - if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support) - if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) - if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled) - if (videoInfoToUpdate.downloadEnabled !== undefined) videoInstance.set('downloadEnabled', videoInfoToUpdate.downloadEnabled) + if (videoInfoToUpdate.name !== undefined) videoInstance.name = videoInfoToUpdate.name + if (videoInfoToUpdate.category !== undefined) videoInstance.category = videoInfoToUpdate.category + if (videoInfoToUpdate.licence !== undefined) videoInstance.licence = videoInfoToUpdate.licence + if (videoInfoToUpdate.language !== undefined) videoInstance.language = videoInfoToUpdate.language + if (videoInfoToUpdate.nsfw !== undefined) videoInstance.nsfw = videoInfoToUpdate.nsfw + if (videoInfoToUpdate.waitTranscoding !== undefined) videoInstance.waitTranscoding = videoInfoToUpdate.waitTranscoding + if (videoInfoToUpdate.support !== undefined) videoInstance.support = videoInfoToUpdate.support + if (videoInfoToUpdate.description !== undefined) videoInstance.description = videoInfoToUpdate.description + if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.commentsEnabled = videoInfoToUpdate.commentsEnabled + if (videoInfoToUpdate.downloadEnabled !== undefined) videoInstance.downloadEnabled = videoInfoToUpdate.downloadEnabled if (videoInfoToUpdate.originallyPublishedAt !== undefined && videoInfoToUpdate.originallyPublishedAt !== null) { videoInstance.originallyPublishedAt = new Date(videoInfoToUpdate.originallyPublishedAt) @@ -398,6 +404,14 @@ async function updateVideo (req: express.Request, res: express.Response) { await ScheduleVideoUpdateModel.deleteByVideoId(videoInstanceUpdated.id, t) } + await autoBlacklistVideoIfNeeded({ + video: videoInstanceUpdated, + user: res.locals.oauth.token.User, + isRemote: false, + isNew: false, + transaction: t + }) + const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE // Don't send update if the video was unfederated -- cgit v1.2.3