diff options
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 11 | ||||
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 24 | ||||
-rw-r--r-- | server/models/video/video.ts | 2 | ||||
-rw-r--r-- | server/tests/api/check-params/videos-common-filters.ts | 73 | ||||
-rw-r--r-- | server/tests/api/videos/videos-common-filters.ts | 74 | ||||
-rw-r--r-- | shared/models/search/videos-common-query.model.ts | 6 | ||||
-rw-r--r-- | shared/models/search/videos-search-query.model.ts | 3 | ||||
-rw-r--r-- | shared/models/videos/index.ts | 1 | ||||
-rw-r--r-- | shared/models/videos/video-filter.type.ts | 1 |
9 files changed, 6 insertions, 189 deletions
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 91109217c..00c6deed4 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -1,7 +1,8 @@ | |||
1 | import { Response, Request, UploadFilesForCheck } from 'express' | 1 | import { Request, Response, UploadFilesForCheck } from 'express' |
2 | import { decode as magnetUriDecode } from 'magnet-uri' | 2 | import { decode as magnetUriDecode } from 'magnet-uri' |
3 | import validator from 'validator' | 3 | import validator from 'validator' |
4 | import { HttpStatusCode, VideoFilter, VideoInclude, VideoPrivacy, VideoRateType } from '@shared/models' | 4 | import { getVideoWithAttributes } from '@server/helpers/video' |
5 | import { HttpStatusCode, VideoInclude, VideoPrivacy, VideoRateType } from '@shared/models' | ||
5 | import { | 6 | import { |
6 | CONSTRAINTS_FIELDS, | 7 | CONSTRAINTS_FIELDS, |
7 | MIMETYPES, | 8 | MIMETYPES, |
@@ -13,14 +14,9 @@ import { | |||
13 | VIDEO_STATES | 14 | VIDEO_STATES |
14 | } from '../../initializers/constants' | 15 | } from '../../initializers/constants' |
15 | import { exists, isArray, isDateValid, isFileValid } from './misc' | 16 | import { exists, isArray, isDateValid, isFileValid } from './misc' |
16 | import { getVideoWithAttributes } from '@server/helpers/video' | ||
17 | 17 | ||
18 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS | 18 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS |
19 | 19 | ||
20 | function isVideoFilterValid (filter: VideoFilter) { | ||
21 | return filter === 'local' || filter === 'all-local' || filter === 'all' | ||
22 | } | ||
23 | |||
24 | function isVideoIncludeValid (include: VideoInclude) { | 20 | function isVideoIncludeValid (include: VideoInclude) { |
25 | return exists(include) && validator.isInt('' + include) | 21 | return exists(include) && validator.isInt('' + include) |
26 | } | 22 | } |
@@ -217,7 +213,6 @@ export { | |||
217 | isVideoFileSizeValid, | 213 | isVideoFileSizeValid, |
218 | isVideoImageValid, | 214 | isVideoImageValid, |
219 | isVideoSupportValid, | 215 | isVideoSupportValid, |
220 | isVideoFilterValid, | ||
221 | isPasswordValid, | 216 | isPasswordValid, |
222 | isValidPasswordProtectedPrivacy | 217 | isValidPasswordProtectedPrivacy |
223 | } | 218 | } |
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index aea3453b5..5a49779ed 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -7,8 +7,8 @@ import { uploadx } from '@server/lib/uploadx' | |||
7 | import { getServerActor } from '@server/models/application/application' | 7 | import { getServerActor } from '@server/models/application/application' |
8 | import { ExpressPromiseHandler } from '@server/types/express-handler' | 8 | import { ExpressPromiseHandler } from '@server/types/express-handler' |
9 | import { MUserAccountId, MVideoFullLight } from '@server/types/models' | 9 | import { MUserAccountId, MVideoFullLight } from '@server/types/models' |
10 | import { arrayify, getAllPrivacies } from '@shared/core-utils' | 10 | import { arrayify } from '@shared/core-utils' |
11 | import { HttpStatusCode, ServerErrorCode, UserRight, VideoInclude, VideoState } from '@shared/models' | 11 | import { HttpStatusCode, ServerErrorCode, UserRight, VideoState } from '@shared/models' |
12 | import { | 12 | import { |
13 | exists, | 13 | exists, |
14 | isBooleanValid, | 14 | isBooleanValid, |
@@ -26,7 +26,6 @@ import { | |||
26 | isValidPasswordProtectedPrivacy, | 26 | isValidPasswordProtectedPrivacy, |
27 | isVideoCategoryValid, | 27 | isVideoCategoryValid, |
28 | isVideoDescriptionValid, | 28 | isVideoDescriptionValid, |
29 | isVideoFilterValid, | ||
30 | isVideoImageValid, | 29 | isVideoImageValid, |
31 | isVideoIncludeValid, | 30 | isVideoIncludeValid, |
32 | isVideoLanguageValid, | 31 | isVideoLanguageValid, |
@@ -464,9 +463,6 @@ const commonVideosFiltersValidator = [ | |||
464 | .optional() | 463 | .optional() |
465 | .customSanitizer(toBooleanOrNull) | 464 | .customSanitizer(toBooleanOrNull) |
466 | .custom(isBooleanValid).withMessage('Should have a valid isLive boolean'), | 465 | .custom(isBooleanValid).withMessage('Should have a valid isLive boolean'), |
467 | query('filter') | ||
468 | .optional() | ||
469 | .custom(isVideoFilterValid), | ||
470 | query('include') | 466 | query('include') |
471 | .optional() | 467 | .optional() |
472 | .custom(isVideoIncludeValid), | 468 | .custom(isVideoIncludeValid), |
@@ -501,22 +497,6 @@ const commonVideosFiltersValidator = [ | |||
501 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 497 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
502 | if (areValidationErrors(req, res)) return | 498 | if (areValidationErrors(req, res)) return |
503 | 499 | ||
504 | // FIXME: deprecated in 4.0, to remove | ||
505 | { | ||
506 | if (req.query.filter === 'all-local') { | ||
507 | req.query.include = VideoInclude.NOT_PUBLISHED_STATE | ||
508 | req.query.isLocal = true | ||
509 | req.query.privacyOneOf = getAllPrivacies() | ||
510 | } else if (req.query.filter === 'all') { | ||
511 | req.query.include = VideoInclude.NOT_PUBLISHED_STATE | ||
512 | req.query.privacyOneOf = getAllPrivacies() | ||
513 | } else if (req.query.filter === 'local') { | ||
514 | req.query.isLocal = true | ||
515 | } | ||
516 | |||
517 | req.query.filter = undefined | ||
518 | } | ||
519 | |||
520 | const user = res.locals.oauth?.token.User | 500 | const user = res.locals.oauth?.token.User |
521 | 501 | ||
522 | if ((!user || user.hasRight(UserRight.SEE_ALL_VIDEOS) !== true)) { | 502 | if ((!user || user.hasRight(UserRight.SEE_ALL_VIDEOS) !== true)) { |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 2fe701436..73308182d 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -1639,7 +1639,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1639 | 1639 | ||
1640 | private static throwIfPrivateIncludeWithoutUser (include: VideoInclude, user: MUserAccountId) { | 1640 | private static throwIfPrivateIncludeWithoutUser (include: VideoInclude, user: MUserAccountId) { |
1641 | if (VideoModel.isPrivateInclude(include) && !user?.hasRight(UserRight.SEE_ALL_VIDEOS)) { | 1641 | if (VideoModel.isPrivateInclude(include) && !user?.hasRight(UserRight.SEE_ALL_VIDEOS)) { |
1642 | throw new Error('Try to filter all-local but user cannot see all videos') | 1642 | throw new Error('Try to include protected videos but user cannot see all videos') |
1643 | } | 1643 | } |
1644 | } | 1644 | } |
1645 | 1645 | ||
diff --git a/server/tests/api/check-params/videos-common-filters.ts b/server/tests/api/check-params/videos-common-filters.ts index 3e44e2f67..603f7f777 100644 --- a/server/tests/api/check-params/videos-common-filters.ts +++ b/server/tests/api/check-params/videos-common-filters.ts | |||
@@ -35,79 +35,6 @@ describe('Test video filters validators', function () { | |||
35 | moderatorAccessToken = await server.login.getAccessToken(moderator) | 35 | moderatorAccessToken = await server.login.getAccessToken(moderator) |
36 | }) | 36 | }) |
37 | 37 | ||
38 | describe('When setting a deprecated video filter', function () { | ||
39 | |||
40 | async function testEndpoints (token: string, filter: string, expectedStatus: HttpStatusCode) { | ||
41 | const paths = [ | ||
42 | '/api/v1/video-channels/root_channel/videos', | ||
43 | '/api/v1/accounts/root/videos', | ||
44 | '/api/v1/videos', | ||
45 | '/api/v1/search/videos', | ||
46 | '/api/v1/users/me/subscriptions/videos' | ||
47 | ] | ||
48 | |||
49 | for (const path of paths) { | ||
50 | await makeGetRequest({ | ||
51 | url: server.url, | ||
52 | path, | ||
53 | token, | ||
54 | query: { | ||
55 | filter | ||
56 | }, | ||
57 | expectedStatus | ||
58 | }) | ||
59 | } | ||
60 | } | ||
61 | |||
62 | it('Should fail with a bad filter', async function () { | ||
63 | await testEndpoints(server.accessToken, 'bad-filter', HttpStatusCode.BAD_REQUEST_400) | ||
64 | }) | ||
65 | |||
66 | it('Should succeed with a good filter', async function () { | ||
67 | await testEndpoints(server.accessToken, 'local', HttpStatusCode.OK_200) | ||
68 | }) | ||
69 | |||
70 | it('Should fail to list all-local/all with a simple user', async function () { | ||
71 | await testEndpoints(userAccessToken, 'all-local', HttpStatusCode.UNAUTHORIZED_401) | ||
72 | await testEndpoints(userAccessToken, 'all', HttpStatusCode.UNAUTHORIZED_401) | ||
73 | }) | ||
74 | |||
75 | it('Should succeed to list all-local/all with a moderator', async function () { | ||
76 | await testEndpoints(moderatorAccessToken, 'all-local', HttpStatusCode.OK_200) | ||
77 | await testEndpoints(moderatorAccessToken, 'all', HttpStatusCode.OK_200) | ||
78 | }) | ||
79 | |||
80 | it('Should succeed to list all-local/all with an admin', async function () { | ||
81 | await testEndpoints(server.accessToken, 'all-local', HttpStatusCode.OK_200) | ||
82 | await testEndpoints(server.accessToken, 'all', HttpStatusCode.OK_200) | ||
83 | }) | ||
84 | |||
85 | // Because we cannot authenticate the user on the RSS endpoint | ||
86 | it('Should fail on the feeds endpoint with the all-local/all filter', async function () { | ||
87 | for (const filter of [ 'all', 'all-local' ]) { | ||
88 | await makeGetRequest({ | ||
89 | url: server.url, | ||
90 | path: '/feeds/videos.json', | ||
91 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401, | ||
92 | query: { | ||
93 | filter | ||
94 | } | ||
95 | }) | ||
96 | } | ||
97 | }) | ||
98 | |||
99 | it('Should succeed on the feeds endpoint with the local filter', async function () { | ||
100 | await makeGetRequest({ | ||
101 | url: server.url, | ||
102 | path: '/feeds/videos.json', | ||
103 | expectedStatus: HttpStatusCode.OK_200, | ||
104 | query: { | ||
105 | filter: 'local' | ||
106 | } | ||
107 | }) | ||
108 | }) | ||
109 | }) | ||
110 | |||
111 | describe('When setting video filters', function () { | 38 | describe('When setting video filters', function () { |
112 | 39 | ||
113 | const validIncludes = [ | 40 | const validIncludes = [ |
diff --git a/server/tests/api/videos/videos-common-filters.ts b/server/tests/api/videos/videos-common-filters.ts index fac0f5dc5..48de7c537 100644 --- a/server/tests/api/videos/videos-common-filters.ts +++ b/server/tests/api/videos/videos-common-filters.ts | |||
@@ -74,80 +74,6 @@ describe('Test videos filter', function () { | |||
74 | ] | 74 | ] |
75 | }) | 75 | }) |
76 | 76 | ||
77 | describe('Check deprecated videos filter', function () { | ||
78 | |||
79 | async function getVideosNames (options: { | ||
80 | server: PeerTubeServer | ||
81 | token: string | ||
82 | filter: string | ||
83 | skipSubscription?: boolean | ||
84 | expectedStatus?: HttpStatusCode | ||
85 | }) { | ||
86 | const { server, token, filter, skipSubscription = false, expectedStatus = HttpStatusCode.OK_200 } = options | ||
87 | |||
88 | const videosResults: Video[][] = [] | ||
89 | |||
90 | for (const path of paths) { | ||
91 | if (skipSubscription && path === subscriptionVideosPath) continue | ||
92 | |||
93 | const res = await makeGetRequest({ | ||
94 | url: server.url, | ||
95 | path, | ||
96 | token, | ||
97 | query: { | ||
98 | sort: 'createdAt', | ||
99 | filter | ||
100 | }, | ||
101 | expectedStatus | ||
102 | }) | ||
103 | |||
104 | videosResults.push(res.body.data.map(v => v.name)) | ||
105 | } | ||
106 | |||
107 | return videosResults | ||
108 | } | ||
109 | |||
110 | it('Should display local videos', async function () { | ||
111 | for (const server of servers) { | ||
112 | const namesResults = await getVideosNames({ server, token: server.accessToken, filter: 'local' }) | ||
113 | for (const names of namesResults) { | ||
114 | expect(names).to.have.lengthOf(1) | ||
115 | expect(names[0]).to.equal('public ' + server.serverNumber) | ||
116 | } | ||
117 | } | ||
118 | }) | ||
119 | |||
120 | it('Should display all local 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 namesResults = await getVideosNames({ server, token, filter: 'all-local', skipSubscription: true }) | ||
125 | for (const names of namesResults) { | ||
126 | expect(names).to.have.lengthOf(3) | ||
127 | |||
128 | expect(names[0]).to.equal('public ' + server.serverNumber) | ||
129 | expect(names[1]).to.equal('unlisted ' + server.serverNumber) | ||
130 | expect(names[2]).to.equal('private ' + server.serverNumber) | ||
131 | } | ||
132 | } | ||
133 | } | ||
134 | }) | ||
135 | |||
136 | it('Should display all videos by the admin or the moderator', async function () { | ||
137 | for (const server of servers) { | ||
138 | for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) { | ||
139 | |||
140 | const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames({ server, token, filter: 'all' }) | ||
141 | expect(channelVideos).to.have.lengthOf(3) | ||
142 | expect(accountVideos).to.have.lengthOf(3) | ||
143 | |||
144 | expect(videos).to.have.lengthOf(5) | ||
145 | expect(searchVideos).to.have.lengthOf(5) | ||
146 | } | ||
147 | } | ||
148 | }) | ||
149 | }) | ||
150 | |||
151 | describe('Check videos filters', function () { | 77 | describe('Check videos filters', function () { |
152 | 78 | ||
153 | async function listVideos (options: { | 79 | async function listVideos (options: { |
diff --git a/shared/models/search/videos-common-query.model.ts b/shared/models/search/videos-common-query.model.ts index 2c52ca8cf..f783d7534 100644 --- a/shared/models/search/videos-common-query.model.ts +++ b/shared/models/search/videos-common-query.model.ts | |||
@@ -12,9 +12,6 @@ export interface VideosCommonQuery { | |||
12 | 12 | ||
13 | isLive?: boolean | 13 | isLive?: boolean |
14 | 14 | ||
15 | // FIXME: deprecated in 4.0 in favour of isLocal and include, to remove | ||
16 | filter?: never | ||
17 | |||
18 | isLocal?: boolean | 15 | isLocal?: boolean |
19 | include?: VideoInclude | 16 | include?: VideoInclude |
20 | 17 | ||
@@ -45,7 +42,4 @@ export interface VideosCommonQueryAfterSanitize extends VideosCommonQuery { | |||
45 | start: number | 42 | start: number |
46 | count: number | 43 | count: number |
47 | sort: string | 44 | sort: string |
48 | |||
49 | // FIXME: deprecated in 4.0, to remove | ||
50 | filter?: never | ||
51 | } | 45 | } |
diff --git a/shared/models/search/videos-search-query.model.ts b/shared/models/search/videos-search-query.model.ts index 447c72806..a5436879d 100644 --- a/shared/models/search/videos-search-query.model.ts +++ b/shared/models/search/videos-search-query.model.ts | |||
@@ -23,7 +23,4 @@ export interface VideosSearchQueryAfterSanitize extends VideosSearchQuery { | |||
23 | start: number | 23 | start: number |
24 | count: number | 24 | count: number |
25 | sort: string | 25 | sort: string |
26 | |||
27 | // FIXME: deprecated in 4.0, to remove | ||
28 | filter?: never | ||
29 | } | 26 | } |
diff --git a/shared/models/videos/index.ts b/shared/models/videos/index.ts index b3ce6ad3f..f8f1ce081 100644 --- a/shared/models/videos/index.ts +++ b/shared/models/videos/index.ts | |||
@@ -22,7 +22,6 @@ export * from './video-constant.model' | |||
22 | export * from './video-create.model' | 22 | export * from './video-create.model' |
23 | 23 | ||
24 | export * from './video-privacy.enum' | 24 | export * from './video-privacy.enum' |
25 | export * from './video-filter.type' | ||
26 | export * from './video-include.enum' | 25 | export * from './video-include.enum' |
27 | export * from './video-rate.type' | 26 | export * from './video-rate.type' |
28 | 27 | ||
diff --git a/shared/models/videos/video-filter.type.ts b/shared/models/videos/video-filter.type.ts deleted file mode 100644 index e641a401c..000000000 --- a/shared/models/videos/video-filter.type.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export type VideoFilter = 'local' | 'all-local' | 'all' | ||