From 527a52ac4295a072927ff46761766a8b181a7603 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Nov 2021 14:19:56 +0100 Subject: Add ability to filter out public videos from admin --- .../api/check-params/videos-common-filters.ts | 22 ++++++++++++++++++++-- server/tests/api/videos/videos-common-filters.ts | 8 +++++--- 2 files changed, 25 insertions(+), 5 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params/videos-common-filters.ts b/server/tests/api/check-params/videos-common-filters.ts index afe42b0d5..f2b5bee8e 100644 --- a/server/tests/api/check-params/videos-common-filters.ts +++ b/server/tests/api/check-params/videos-common-filters.ts @@ -9,7 +9,7 @@ import { setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' -import { HttpStatusCode, UserRole, VideoInclude } from '@shared/models' +import { HttpStatusCode, UserRole, VideoInclude, VideoPrivacy } from '@shared/models' describe('Test video filters validators', function () { let server: PeerTubeServer @@ -112,7 +112,7 @@ describe('Test video filters validators', function () { const validIncludes = [ VideoInclude.NONE, - VideoInclude.HIDDEN_PRIVACY, + VideoInclude.BLOCKED_OWNER, VideoInclude.NOT_PUBLISHED_STATE | VideoInclude.BLACKLISTED ] @@ -120,6 +120,7 @@ describe('Test video filters validators', function () { token?: string isLocal?: boolean include?: VideoInclude + privacyOneOf?: VideoPrivacy[] expectedStatus: HttpStatusCode }) { const paths = [ @@ -136,6 +137,7 @@ describe('Test video filters validators', function () { token: options.token || server.accessToken, query: { isLocal: options.isLocal, + privacyOneOf: options.privacyOneOf, include: options.include }, expectedStatus: options.expectedStatus @@ -143,6 +145,22 @@ describe('Test video filters validators', function () { } } + it('Should fail with a bad privacyOneOf', async function () { + await testEndpoints({ privacyOneOf: [ 'toto' ] as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + }) + + it('Should succeed with a good privacyOneOf', async function () { + await testEndpoints({ privacyOneOf: [ VideoPrivacy.INTERNAL ], expectedStatus: HttpStatusCode.OK_200 }) + }) + + it('Should fail to use privacyOneOf with a simple user', async function () { + await testEndpoints({ + privacyOneOf: [ VideoPrivacy.INTERNAL ], + token: userAccessToken, + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 + }) + }) + it('Should fail with a bad include', async function () { await testEndpoints({ include: 'toto' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) diff --git a/server/tests/api/videos/videos-common-filters.ts b/server/tests/api/videos/videos-common-filters.ts index 4f22d4ac3..ca5f42173 100644 --- a/server/tests/api/videos/videos-common-filters.ts +++ b/server/tests/api/videos/videos-common-filters.ts @@ -138,6 +138,7 @@ describe('Test videos filter', function () { hasWebtorrentFiles?: boolean hasHLSFiles?: boolean include?: VideoInclude + privacyOneOf?: VideoPrivacy[] category?: number tagsAllOf?: string[] token?: string @@ -148,7 +149,7 @@ describe('Test videos filter', function () { path: options.path, token: options.token ?? options.server.accessToken, query: { - ...pick(options, [ 'isLocal', 'include', 'category', 'tagsAllOf', 'hasWebtorrentFiles', 'hasHLSFiles' ]), + ...pick(options, [ 'isLocal', 'include', 'category', 'tagsAllOf', 'hasWebtorrentFiles', 'hasHLSFiles', 'privacyOneOf' ]), sort: 'createdAt' }, @@ -162,6 +163,7 @@ describe('Test videos filter', function () { server: PeerTubeServer isLocal?: boolean include?: VideoInclude + privacyOneOf?: VideoPrivacy[] token?: string expectedStatus?: HttpStatusCode }) { @@ -195,7 +197,7 @@ describe('Test videos filter', function () { server, token, isLocal: true, - include: VideoInclude.HIDDEN_PRIVACY + privacyOneOf: [ VideoPrivacy.UNLISTED, VideoPrivacy.PUBLIC, VideoPrivacy.PRIVATE ] }) for (const names of namesResults) { @@ -216,7 +218,7 @@ describe('Test videos filter', function () { const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames({ server, token, - include: VideoInclude.HIDDEN_PRIVACY + privacyOneOf: [ VideoPrivacy.UNLISTED, VideoPrivacy.PUBLIC, VideoPrivacy.PRIVATE ] }) expect(channelVideos).to.have.lengthOf(3) -- cgit v1.2.3