aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2021-01-19 13:43:33 +0100
committerGitHub <noreply@github.com>2021-01-19 13:43:33 +0100
commit370240824e2fb28b314255f6c23f5ea7d6b08625 (patch)
tree6d4350fd93ea0b960bd278a948cecbdfbd2b67d7 /server
parent2264c1ceedcf27998108b8f8b706e51ed910d4fb (diff)
downloadPeerTube-370240824e2fb28b314255f6c23f5ea7d6b08625.tar.gz
PeerTube-370240824e2fb28b314255f6c23f5ea7d6b08625.tar.zst
PeerTube-370240824e2fb28b314255f6c23f5ea7d6b08625.zip
Allow users/visitors to search through an account's videos (#3589)
* WIP: account search * add search to account view * add tests for account search
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/accounts.ts3
-rw-r--r--server/middlewares/validators/videos/videos.ts4
-rw-r--r--server/tests/api/users/users-multiple-servers.ts27
3 files changed, 29 insertions, 5 deletions
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts
index e807b4f44..e31924a94 100644
--- a/server/controllers/api/accounts.ts
+++ b/server/controllers/api/accounts.ts
@@ -175,7 +175,8 @@ async function listAccountVideos (req: express.Request, res: express.Response) {
175 withFiles: false, 175 withFiles: false,
176 accountId: account.id, 176 accountId: account.id,
177 user: res.locals.oauth ? res.locals.oauth.token.User : undefined, 177 user: res.locals.oauth ? res.locals.oauth.token.User : undefined,
178 countVideos 178 countVideos,
179 search: req.query.search
179 }, 'filter:api.accounts.videos.list.params') 180 }, 'filter:api.accounts.videos.list.params')
180 181
181 const resultList = await Hooks.wrapPromiseFun( 182 const resultList = await Hooks.wrapPromiseFun(
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts
index 8bc37b0ab..84e309bec 100644
--- a/server/middlewares/validators/videos/videos.ts
+++ b/server/middlewares/validators/videos/videos.ts
@@ -6,6 +6,7 @@ import { MVideoFullLight } from '@server/types/models'
6import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' 6import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
7import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model' 7import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model'
8import { 8import {
9 exists,
9 isBooleanValid, 10 isBooleanValid,
10 isDateValid, 11 isDateValid,
11 isFileFieldValid, 12 isFileFieldValid,
@@ -444,6 +445,9 @@ const commonVideosFiltersValidator = [
444 .optional() 445 .optional()
445 .customSanitizer(toBooleanOrNull) 446 .customSanitizer(toBooleanOrNull)
446 .custom(isBooleanValid).withMessage('Should have a valid skip count boolean'), 447 .custom(isBooleanValid).withMessage('Should have a valid skip count boolean'),
448 query('search')
449 .optional()
450 .custom(exists).withMessage('Should have a valid search'),
447 451
448 (req: express.Request, res: express.Response, next: express.NextFunction) => { 452 (req: express.Request, res: express.Response, next: express.NextFunction) => {
449 logger.debug('Checking commons video filters query', { parameters: req.query }) 453 logger.debug('Checking commons video filters query', { parameters: req.query })
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts
index 591ce4959..dcd03879b 100644
--- a/server/tests/api/users/users-multiple-servers.ts
+++ b/server/tests/api/users/users-multiple-servers.ts
@@ -34,7 +34,7 @@ describe('Test users with multiple servers', function () {
34 let userAvatarFilename: string 34 let userAvatarFilename: string
35 35
36 before(async function () { 36 before(async function () {
37 this.timeout(120000) 37 this.timeout(120_000)
38 38
39 servers = await flushAndRunMultipleServers(3) 39 servers = await flushAndRunMultipleServers(3)
40 40
@@ -92,7 +92,7 @@ describe('Test users with multiple servers', function () {
92 }) 92 })
93 93
94 it('Should be able to update my description', async function () { 94 it('Should be able to update my description', async function () {
95 this.timeout(10000) 95 this.timeout(10_000)
96 96
97 await updateMyUser({ 97 await updateMyUser({
98 url: servers[0].url, 98 url: servers[0].url,
@@ -109,7 +109,7 @@ describe('Test users with multiple servers', function () {
109 }) 109 })
110 110
111 it('Should be able to update my avatar', async function () { 111 it('Should be able to update my avatar', async function () {
112 this.timeout(10000) 112 this.timeout(10_000)
113 113
114 const fixture = 'avatar2.png' 114 const fixture = 'avatar2.png'
115 115
@@ -164,8 +164,27 @@ describe('Test users with multiple servers', function () {
164 } 164 }
165 }) 165 })
166 166
167 it('Should search through account videos', async function () {
168 this.timeout(10_000)
169
170 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'Kami no chikara' })
171
172 await waitJobs(servers)
173
174 for (const server of servers) {
175 const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5, undefined, {
176 search: 'Kami'
177 })
178
179 expect(res.body.total).to.equal(1)
180 expect(res.body.data).to.be.an('array')
181 expect(res.body.data).to.have.lengthOf(1)
182 expect(res.body.data[0].uuid).to.equal(resVideo.body.video.uuid)
183 }
184 })
185
167 it('Should remove the user', async function () { 186 it('Should remove the user', async function () {
168 this.timeout(10000) 187 this.timeout(10_000)
169 188
170 for (const server of servers) { 189 for (const server of servers) {
171 const resAccounts = await getAccountsList(server.url, '-createdAt') 190 const resAccounts = await getAccountsList(server.url, '-createdAt')