aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/helpers/custom-validators/videos.ts2
-rw-r--r--server/middlewares/validators/videos/videos.ts5
-rw-r--r--server/models/video/video-query-builder.ts2
-rw-r--r--server/models/video/video.ts2
-rw-r--r--server/tests/api/check-params/videos-filter.ts29
-rw-r--r--server/tests/api/videos/videos-filter.ts14
6 files changed, 38 insertions, 16 deletions
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'
17const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS 17const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
18 18
19function isVideoFilterValid (filter: VideoFilter) { 19function isVideoFilterValid (filter: VideoFilter) {
20 return filter === 'local' || filter === 'all-local' 20 return filter === 'local' || filter === 'all-local' || filter === 'all'
21} 21}
22 22
23function isVideoCategoryValid (value: any) { 23function 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 = [
429 if (areValidationErrors(req, res)) return 429 if (areValidationErrors(req, res)) return
430 430
431 const user = res.locals.oauth ? res.locals.oauth.token.User : undefined 431 const user = res.locals.oauth ? res.locals.oauth.token.User : undefined
432 if (req.query.filter === 'all-local' && (!user || user.hasRight(UserRight.SEE_ALL_VIDEOS) === false)) { 432 if (
433 (req.query.filter === 'all-local' || req.query.filter === 'all') &&
434 (!user || user.hasRight(UserRight.SEE_ALL_VIDEOS) === false)
435 ) {
433 res.status(401) 436 res.status(401)
434 .json({ error: 'You are not allowed to see all local videos.' }) 437 .json({ error: 'You are not allowed to see all local videos.' })
435 438
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)
89 } 89 }
90 90
91 // Only list public/published videos 91 // Only list public/published videos
92 if (!options.filter || options.filter !== 'all-local') { 92 if (!options.filter || (options.filter !== 'all-local' && options.filter !== 'all')) {
93 and.push( 93 and.push(
94 `("video"."state" = ${VideoState.PUBLISHED} OR ` + 94 `("video"."state" = ${VideoState.PUBLISHED} OR ` +
95 `("video"."state" = ${VideoState.TO_TRANSCODE} AND "video"."waitTranscoding" IS false))` 95 `("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<VideoModel> {
1085 historyOfUser?: MUserId 1085 historyOfUser?: MUserId
1086 countVideos?: boolean 1086 countVideos?: boolean
1087 }) { 1087 }) {
1088 if (options.filter && options.filter === 'all-local' && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) { 1088 if ((options.filter === 'all-local' || options.filter === 'all') && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) {
1089 throw new Error('Try to filter all-local but no user has not the see all videos right') 1089 throw new Error('Try to filter all-local but no user has not the see all videos right')
1090 } 1090 }
1091 1091
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 () {
78 await testEndpoints(server, server.accessToken, 'local', 200) 78 await testEndpoints(server, server.accessToken, 'local', 200)
79 }) 79 })
80 80
81 it('Should fail to list all-local with a simple user', async function () { 81 it('Should fail to list all-local/all with a simple user', async function () {
82 await testEndpoints(server, userAccessToken, 'all-local', 401) 82 await testEndpoints(server, userAccessToken, 'all-local', 401)
83 await testEndpoints(server, userAccessToken, 'all', 401)
83 }) 84 })
84 85
85 it('Should succeed to list all-local with a moderator', async function () { 86 it('Should succeed to list all-local/all with a moderator', async function () {
86 await testEndpoints(server, moderatorAccessToken, 'all-local', 200) 87 await testEndpoints(server, moderatorAccessToken, 'all-local', 200)
88 await testEndpoints(server, moderatorAccessToken, 'all', 200)
87 }) 89 })
88 90
89 it('Should succeed to list all-local with an admin', async function () { 91 it('Should succeed to list all-local/all with an admin', async function () {
90 await testEndpoints(server, server.accessToken, 'all-local', 200) 92 await testEndpoints(server, server.accessToken, 'all-local', 200)
93 await testEndpoints(server, server.accessToken, 'all', 200)
91 }) 94 })
92 95
93 // Because we cannot authenticate the user on the RSS endpoint 96 // Because we cannot authenticate the user on the RSS endpoint
94 it('Should fail on the feeds endpoint with the all-local filter', async function () { 97 it('Should fail on the feeds endpoint with the all-local/all filter', async function () {
95 await makeGetRequest({ 98 for (const filter of [ 'all', 'all-local' ]) {
96 url: server.url, 99 await makeGetRequest({
97 path: '/feeds/videos.json', 100 url: server.url,
98 statusCodeExpected: 401, 101 path: '/feeds/videos.json',
99 query: { 102 statusCodeExpected: 401,
100 filter: 'all-local' 103 query: {
101 } 104 filter
102 }) 105 }
106 })
107 }
103 }) 108 })
104 109
105 it('Should succeed on the feeds endpoint with the local filter', async function () { 110 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 () {
116 } 116 }
117 } 117 }
118 }) 118 })
119
120 it('Should display all videos by the admin or the moderator', async function () {
121 for (const server of servers) {
122 for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) {
123
124 const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames(server, token, 'all')
125 expect(channelVideos).to.have.lengthOf(3)
126 expect(accountVideos).to.have.lengthOf(3)
127
128 expect(videos).to.have.lengthOf(5)
129 expect(searchVideos).to.have.lengthOf(5)
130 }
131 }
132 })
119 }) 133 })
120 134
121 after(async function () { 135 after(async function () {