aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/users/index.ts1
-rw-r--r--server/middlewares/validators/users.ts1
-rw-r--r--server/tests/api/check-params/users.ts9
-rw-r--r--server/tests/api/users/users.ts2
-rw-r--r--server/tests/utils/users/users.ts2
5 files changed, 15 insertions, 0 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index 9fcb8077f..87fab4a40 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -262,6 +262,7 @@ async function updateUser (req: express.Request, res: express.Response, next: ex
262 const roleChanged = body.role !== undefined && body.role !== userToUpdate.role 262 const roleChanged = body.role !== undefined && body.role !== userToUpdate.role
263 263
264 if (body.email !== undefined) userToUpdate.email = body.email 264 if (body.email !== undefined) userToUpdate.email = body.email
265 if (body.emailVerified !== undefined) userToUpdate.emailVerified = body.emailVerified
265 if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota 266 if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota
266 if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily 267 if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily
267 if (body.role !== undefined) userToUpdate.role = body.role 268 if (body.role !== undefined) userToUpdate.role = body.role
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index 61297120a..ccaf2eeb6 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -114,6 +114,7 @@ const deleteMeValidator = [
114const usersUpdateValidator = [ 114const usersUpdateValidator = [
115 param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), 115 param('id').isInt().not().isEmpty().withMessage('Should have a valid id'),
116 body('email').optional().isEmail().withMessage('Should have a valid email attribute'), 116 body('email').optional().isEmail().withMessage('Should have a valid email attribute'),
117 body('emailVerified').optional().isBoolean().withMessage('Should have a valid email verified attribute'),
117 body('videoQuota').optional().custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), 118 body('videoQuota').optional().custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'),
118 body('videoQuotaDaily').optional().custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), 119 body('videoQuotaDaily').optional().custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'),
119 body('role').optional().custom(isUserRoleValid).withMessage('Should have a valid role'), 120 body('role').optional().custom(isUserRoleValid).withMessage('Should have a valid role'),
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index ec46609a4..273be1679 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -428,6 +428,14 @@ describe('Test users API validators', function () {
428 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) 428 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
429 }) 429 })
430 430
431 it('Should fail with an invalid emailVerified attribute', async function () {
432 const fields = {
433 emailVerified: 'yes'
434 }
435
436 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
437 })
438
431 it('Should fail with an invalid videoQuota attribute', async function () { 439 it('Should fail with an invalid videoQuota attribute', async function () {
432 const fields = { 440 const fields = {
433 videoQuota: -90 441 videoQuota: -90
@@ -463,6 +471,7 @@ describe('Test users API validators', function () {
463 it('Should succeed with the correct params', async function () { 471 it('Should succeed with the correct params', async function () {
464 const fields = { 472 const fields = {
465 email: 'email@example.com', 473 email: 'email@example.com',
474 emailVerified: true,
466 videoQuota: 42, 475 videoQuota: 42,
467 role: UserRole.MODERATOR 476 role: UserRole.MODERATOR
468 } 477 }
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 513bca8a0..e7bb845b9 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -478,6 +478,7 @@ describe('Test users', function () {
478 userId, 478 userId,
479 accessToken, 479 accessToken,
480 email: 'updated2@example.com', 480 email: 'updated2@example.com',
481 emailVerified: true,
481 videoQuota: 42, 482 videoQuota: 42,
482 role: UserRole.MODERATOR 483 role: UserRole.MODERATOR
483 }) 484 })
@@ -487,6 +488,7 @@ describe('Test users', function () {
487 488
488 expect(user.username).to.equal('user_1') 489 expect(user.username).to.equal('user_1')
489 expect(user.email).to.equal('updated2@example.com') 490 expect(user.email).to.equal('updated2@example.com')
491 expect(user.emailVerified).to.be.true
490 expect(user.nsfwPolicy).to.equal('do_not_list') 492 expect(user.nsfwPolicy).to.equal('do_not_list')
491 expect(user.videoQuota).to.equal(42) 493 expect(user.videoQuota).to.equal(42)
492 expect(user.roleLabel).to.equal('Moderator') 494 expect(user.roleLabel).to.equal('Moderator')
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts
index 2c21a9ecf..f12992315 100644
--- a/server/tests/utils/users/users.ts
+++ b/server/tests/utils/users/users.ts
@@ -206,6 +206,7 @@ function updateUser (options: {
206 userId: number, 206 userId: number,
207 accessToken: string, 207 accessToken: string,
208 email?: string, 208 email?: string,
209 emailVerified?: boolean,
209 videoQuota?: number, 210 videoQuota?: number,
210 videoQuotaDaily?: number, 211 videoQuotaDaily?: number,
211 role?: UserRole 212 role?: UserRole
@@ -214,6 +215,7 @@ function updateUser (options: {
214 215
215 const toSend = {} 216 const toSend = {}
216 if (options.email !== undefined && options.email !== null) toSend['email'] = options.email 217 if (options.email !== undefined && options.email !== null) toSend['email'] = options.email
218 if (options.emailVerified !== undefined && options.emailVerified !== null) toSend['emailVerified'] = options.emailVerified
217 if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota 219 if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota
218 if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend['videoQuotaDaily'] = options.videoQuotaDaily 220 if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend['videoQuotaDaily'] = options.videoQuotaDaily
219 if (options.role !== undefined && options.role !== null) toSend['role'] = options.role 221 if (options.role !== undefined && options.role !== null) toSend['role'] = options.role