From 0aa52e170727ac6bdf441bcaa2353ae0b8a354ed Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 18 Nov 2020 15:29:38 +0100 Subject: Add ability to display all channel/account videos --- server/helpers/custom-validators/videos.ts | 2 +- server/middlewares/validators/videos/videos.ts | 5 ++++- server/models/video/video-query-builder.ts | 2 +- server/models/video/video.ts | 2 +- server/tests/api/check-params/videos-filter.ts | 29 +++++++++++++++----------- server/tests/api/videos/videos-filter.ts | 14 +++++++++++++ 6 files changed, 38 insertions(+), 16 deletions(-) (limited to 'server') diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index e99992236..8b309ae42 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -17,7 +17,7 @@ import * as magnetUtil from 'magnet-uri' const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS function isVideoFilterValid (filter: VideoFilter) { - return filter === 'local' || filter === 'all-local' + return filter === 'local' || filter === 'all-local' || filter === 'all' } function isVideoCategoryValid (value: any) { diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index ff90e347a..efab67a01 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -429,7 +429,10 @@ const commonVideosFiltersValidator = [ if (areValidationErrors(req, res)) return const user = res.locals.oauth ? res.locals.oauth.token.User : undefined - if (req.query.filter === 'all-local' && (!user || user.hasRight(UserRight.SEE_ALL_VIDEOS) === false)) { + if ( + (req.query.filter === 'all-local' || req.query.filter === 'all') && + (!user || user.hasRight(UserRight.SEE_ALL_VIDEOS) === false) + ) { res.status(401) .json({ error: 'You are not allowed to see all local videos.' }) diff --git a/server/models/video/video-query-builder.ts b/server/models/video/video-query-builder.ts index b14bb16d6..25d5042b7 100644 --- a/server/models/video/video-query-builder.ts +++ b/server/models/video/video-query-builder.ts @@ -89,7 +89,7 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions) } // Only list public/published videos - if (!options.filter || options.filter !== 'all-local') { + if (!options.filter || (options.filter !== 'all-local' && options.filter !== 'all')) { and.push( `("video"."state" = ${VideoState.PUBLISHED} OR ` + `("video"."state" = ${VideoState.TO_TRANSCODE} AND "video"."waitTranscoding" IS false))` diff --git a/server/models/video/video.ts b/server/models/video/video.ts index edf757697..f365d3d51 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -1085,7 +1085,7 @@ export class VideoModel extends Model { historyOfUser?: MUserId countVideos?: boolean }) { - if (options.filter && options.filter === 'all-local' && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) { + if ((options.filter === 'all-local' || options.filter === 'all') && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) { throw new Error('Try to filter all-local but no user has not the see all videos right') } diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts index ec8654db2..bf8248b0e 100644 --- a/server/tests/api/check-params/videos-filter.ts +++ b/server/tests/api/check-params/videos-filter.ts @@ -78,28 +78,33 @@ describe('Test videos filters', function () { await testEndpoints(server, server.accessToken, 'local', 200) }) - it('Should fail to list all-local with a simple user', async function () { + it('Should fail to list all-local/all with a simple user', async function () { await testEndpoints(server, userAccessToken, 'all-local', 401) + await testEndpoints(server, userAccessToken, 'all', 401) }) - it('Should succeed to list all-local with a moderator', async function () { + it('Should succeed to list all-local/all with a moderator', async function () { await testEndpoints(server, moderatorAccessToken, 'all-local', 200) + await testEndpoints(server, moderatorAccessToken, 'all', 200) }) - it('Should succeed to list all-local with an admin', async function () { + it('Should succeed to list all-local/all with an admin', async function () { await testEndpoints(server, server.accessToken, 'all-local', 200) + await testEndpoints(server, server.accessToken, 'all', 200) }) // Because we cannot authenticate the user on the RSS endpoint - it('Should fail on the feeds endpoint with the all-local filter', async function () { - await makeGetRequest({ - url: server.url, - path: '/feeds/videos.json', - statusCodeExpected: 401, - query: { - filter: 'all-local' - } - }) + it('Should fail on the feeds endpoint with the all-local/all filter', async function () { + for (const filter of [ 'all', 'all-local' ]) { + await makeGetRequest({ + url: server.url, + path: '/feeds/videos.json', + statusCodeExpected: 401, + query: { + filter + } + }) + } }) it('Should succeed on the feeds endpoint with the local filter', async function () { diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index 95e12e43c..6b9a4b6d4 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -116,6 +116,20 @@ describe('Test videos filter validator', function () { } } }) + + it('Should display all videos by the admin or the moderator', async function () { + for (const server of servers) { + for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) { + + const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames(server, token, 'all') + expect(channelVideos).to.have.lengthOf(3) + expect(accountVideos).to.have.lengthOf(3) + + expect(videos).to.have.lengthOf(5) + expect(searchVideos).to.have.lengthOf(5) + } + } + }) }) after(async function () { -- cgit v1.2.3