aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-01 15:39:13 +0100
committerChocobozzz <me@florianbigard.com>2021-02-01 15:39:13 +0100
commit6d989edc66e7b541fcf97c2a4a6f91cbf960060a (patch)
tree9c72977cf05eee2b3a84dd1867ec60ef491b0900 /server
parentcb5c2abc99c2e222fe18621f79cb68b805678e15 (diff)
downloadPeerTube-6d989edc66e7b541fcf97c2a4a6f91cbf960060a.tar.gz
PeerTube-6d989edc66e7b541fcf97c2a4a6f91cbf960060a.tar.zst
PeerTube-6d989edc66e7b541fcf97c2a4a6f91cbf960060a.zip
Add ability to update plugin auth
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/users/index.ts1
-rw-r--r--server/middlewares/validators/users.ts3
-rw-r--r--server/tests/api/users/users.ts14
3 files changed, 15 insertions, 3 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index c3190e731..5911d1a0f 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -327,6 +327,7 @@ async function updateUser (req: express.Request, res: express.Response) {
327 if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily 327 if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily
328 if (body.role !== undefined) userToUpdate.role = body.role 328 if (body.role !== undefined) userToUpdate.role = body.role
329 if (body.adminFlags !== undefined) userToUpdate.adminFlags = body.adminFlags 329 if (body.adminFlags !== undefined) userToUpdate.adminFlags = body.adminFlags
330 if (body.pluginAuth !== undefined) userToUpdate.pluginAuth = body.pluginAuth
330 331
331 const user = await userToUpdate.save() 332 const user = await userToUpdate.save()
332 333
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index 6b6e6c2df..345571e83 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -7,7 +7,7 @@ import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-code
7import { UserRole } from '../../../shared/models/users' 7import { UserRole } from '../../../shared/models/users'
8import { UserRegister } from '../../../shared/models/users/user-register.model' 8import { UserRegister } from '../../../shared/models/users/user-register.model'
9import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' 9import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor'
10import { isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' 10import { exists, isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc'
11import { isThemeNameValid } from '../../helpers/custom-validators/plugins' 11import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
12import { 12import {
13 isNoInstanceConfigWarningModal, 13 isNoInstanceConfigWarningModal,
@@ -201,6 +201,7 @@ const usersUpdateValidator = [
201 body('emailVerified').optional().isBoolean().withMessage('Should have a valid email verified attribute'), 201 body('emailVerified').optional().isBoolean().withMessage('Should have a valid email verified attribute'),
202 body('videoQuota').optional().custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), 202 body('videoQuota').optional().custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'),
203 body('videoQuotaDaily').optional().custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), 203 body('videoQuotaDaily').optional().custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'),
204 body('pluginAuth').optional(),
204 body('role') 205 body('role')
205 .optional() 206 .optional()
206 .customSanitizer(toIntOrNull) 207 .customSanitizer(toIntOrNull)
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index cd928b980..62a59033f 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -716,11 +716,12 @@ describe('Test users', function () {
716 emailVerified: true, 716 emailVerified: true,
717 videoQuota: 42, 717 videoQuota: 42,
718 role: UserRole.MODERATOR, 718 role: UserRole.MODERATOR,
719 adminFlags: UserAdminFlag.NONE 719 adminFlags: UserAdminFlag.NONE,
720 pluginAuth: 'toto'
720 }) 721 })
721 722
722 const res = await getUserInformation(server.url, accessToken, userId) 723 const res = await getUserInformation(server.url, accessToken, userId)
723 const user = res.body 724 const user = res.body as User
724 725
725 expect(user.username).to.equal('user_1') 726 expect(user.username).to.equal('user_1')
726 expect(user.email).to.equal('updated2@example.com') 727 expect(user.email).to.equal('updated2@example.com')
@@ -730,6 +731,15 @@ describe('Test users', function () {
730 expect(user.roleLabel).to.equal('Moderator') 731 expect(user.roleLabel).to.equal('Moderator')
731 expect(user.id).to.be.a('number') 732 expect(user.id).to.be.a('number')
732 expect(user.adminFlags).to.equal(UserAdminFlag.NONE) 733 expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
734 expect(user.pluginAuth).to.equal('toto')
735 })
736
737 it('Should reset the auth plugin', async function () {
738 await updateUser({ url: server.url, userId, accessToken, pluginAuth: null })
739
740 const res = await getUserInformation(server.url, accessToken, userId)
741 const user = res.body as User
742 expect(user.pluginAuth).to.be.null
733 }) 743 })
734 744
735 it('Should have removed the user token', async function () { 745 it('Should have removed the user token', async function () {