]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add ability to update plugin auth
authorChocobozzz <me@florianbigard.com>
Mon, 1 Feb 2021 14:39:13 +0000 (15:39 +0100)
committerChocobozzz <me@florianbigard.com>
Mon, 1 Feb 2021 14:39:13 +0000 (15:39 +0100)
client/src/app/+admin/users/user-edit/user-edit.component.html
client/src/app/+admin/users/user-edit/user-edit.ts
client/src/app/+admin/users/user-edit/user-update.component.ts
server/controllers/api/users/index.ts
server/middlewares/validators/users.ts
server/tests/api/users/users.ts
shared/extra-utils/users/users.ts
shared/models/users/user-update.model.ts
support/doc/api/openapi.yaml

index 78c92227f55e0b0880dd4da2efbfaaaf86ddb216..fb34d6b226367768b787bee24f2d9af603f05fcb 100644 (file)
         </div>
       </div>
 
+      <div class="form-group" *ngIf="!isCreation() && getAuthPlugins().length !== 0">
+        <label i18n for="pluginAuth">Auth plugin</label>
+
+        <div class="peertube-select-container">
+          <select id="pluginAuth" formControlName="pluginAuth" class="form-control">
+            <option [value]="null" i18n>None (local authentication)</option>
+            <option *ngFor="let authPlugin of getAuthPlugins()" [value]="authPlugin">{{ authPlugin }}</option>
+          </select>
+        </div>
+      </div>
+
       <div class="form-group">
         <my-peertube-checkbox
           inputName="byPassAutoBlock" formControlName="byPassAutoBlock"
index 1613bb0d1f921655b684cc91d44ec1c1b9ed911a..faa2f5ad88c8124562552b1c269b2c21d0c445a2 100644 (file)
@@ -42,6 +42,11 @@ export abstract class UserEdit extends FormReactive implements OnInit {
     return forAccount + forChannels
   }
 
+  getAuthPlugins () {
+    return this.serverConfig.plugin.registeredIdAndPassAuths.map(p => p.npmName)
+      .concat(this.serverConfig.plugin.registeredExternalAuths.map(p => p.npmName))
+  }
+
   isInBigView () {
     return this.screenService.getWindowInnerWidth() > 1600
   }
index e16f66a2baecace4875ee9f71d5dd0edbdb19886..281c3dcef359081483a6c4d7cfb0b3c4329f3d90 100644 (file)
@@ -53,7 +53,8 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
       role: USER_ROLE_VALIDATOR,
       videoQuota: USER_VIDEO_QUOTA_VALIDATOR,
       videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR,
-      byPassAutoBlock: null
+      byPassAutoBlock: null,
+      pluginAuth: null
     }, defaultValues)
 
     this.paramsSub = this.route.params.subscribe(routeParams => {
@@ -120,6 +121,7 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
       role: userJson.role.toString(),
       videoQuota: userJson.videoQuota,
       videoQuotaDaily: userJson.videoQuotaDaily,
+      pluginAuth: userJson.pluginAuth,
       byPassAutoBlock: userJson.adminFlags & UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
     })
   }
index c3190e731e8c25e9f694b228dc6194b187b2c80e..5911d1a0fed3c58efe4b8be4800d66131becbab8 100644 (file)
@@ -327,6 +327,7 @@ async function updateUser (req: express.Request, res: express.Response) {
   if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily
   if (body.role !== undefined) userToUpdate.role = body.role
   if (body.adminFlags !== undefined) userToUpdate.adminFlags = body.adminFlags
+  if (body.pluginAuth !== undefined) userToUpdate.pluginAuth = body.pluginAuth
 
   const user = await userToUpdate.save()
 
index 6b6e6c2df5696e07283747a6aaa3290117db09d0..345571e83718cf08663b1a4d26504fc3653ef7e8 100644 (file)
@@ -7,7 +7,7 @@ import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-code
 import { UserRole } from '../../../shared/models/users'
 import { UserRegister } from '../../../shared/models/users/user-register.model'
 import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor'
-import { isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc'
+import { exists, isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc'
 import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
 import {
   isNoInstanceConfigWarningModal,
@@ -201,6 +201,7 @@ const usersUpdateValidator = [
   body('emailVerified').optional().isBoolean().withMessage('Should have a valid email verified attribute'),
   body('videoQuota').optional().custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'),
   body('videoQuotaDaily').optional().custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'),
+  body('pluginAuth').optional(),
   body('role')
     .optional()
     .customSanitizer(toIntOrNull)
index cd928b9804d81b0b3cbb0c88275cae6e94031961..62a59033fe10ed39a27c3ba6c0f0078c1d56ef8f 100644 (file)
@@ -716,11 +716,12 @@ describe('Test users', function () {
         emailVerified: true,
         videoQuota: 42,
         role: UserRole.MODERATOR,
-        adminFlags: UserAdminFlag.NONE
+        adminFlags: UserAdminFlag.NONE,
+        pluginAuth: 'toto'
       })
 
       const res = await getUserInformation(server.url, accessToken, userId)
-      const user = res.body
+      const user = res.body as User
 
       expect(user.username).to.equal('user_1')
       expect(user.email).to.equal('updated2@example.com')
@@ -730,6 +731,15 @@ describe('Test users', function () {
       expect(user.roleLabel).to.equal('Moderator')
       expect(user.id).to.be.a('number')
       expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
+      expect(user.pluginAuth).to.equal('toto')
+    })
+
+    it('Should reset the auth plugin', async function () {
+      await updateUser({ url: server.url, userId, accessToken, pluginAuth: null })
+
+      const res = await getUserInformation(server.url, accessToken, userId)
+      const user = res.body as User
+      expect(user.pluginAuth).to.be.null
     })
 
     it('Should have removed the user token', async function () {
index c683dcdd12cedfabada121e1863ddb12900b683c..db532dbb0272b0735941c4508c20b56c0ff2d912 100644 (file)
@@ -288,6 +288,7 @@ function updateUser (options: {
   videoQuotaDaily?: number
   password?: string
   adminFlags?: UserAdminFlag
+  pluginAuth?: string
   role?: UserRole
 }) {
   const path = '/api/v1/users/' + options.userId
@@ -300,6 +301,7 @@ function updateUser (options: {
   if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend['videoQuotaDaily'] = options.videoQuotaDaily
   if (options.role !== undefined && options.role !== null) toSend['role'] = options.role
   if (options.adminFlags !== undefined && options.adminFlags !== null) toSend['adminFlags'] = options.adminFlags
+  if (options.pluginAuth !== undefined) toSend['pluginAuth'] = options.pluginAuth
 
   return makePutBodyRequest({
     url: options.url,
index fa43487ac5c801f6e7dac2de11effd4c00ff49d7..1587385453f6f62fac8ec96157efcf4f89a92e21 100644 (file)
@@ -9,4 +9,5 @@ export interface UserUpdate {
   videoQuotaDaily?: number
   role?: UserRole
   adminFlags?: UserAdminFlag
+  pluginAuth?: string
 }
index b05a113cadcf9293dbaffe0b91ea2d4f1b2d4b11..49616bcaa76643a68441d67f70f93d0df1ab0215 100644 (file)
@@ -3898,6 +3898,13 @@ components:
         - 2
       description: 'The user role (Admin = `0`, Moderator = `1`, User = `2`)'
       example: 2
+    UserAdminFlags:
+      type: integer
+      enum:
+        - 0
+        - 1
+      description: 'Admin flags for the user (None = `0`, Bypass video blacklist = `1`)'
+      example: 1
 
     VideoStateConstant:
       properties:
@@ -5022,6 +5029,9 @@ components:
           type: string
           format: email
           description: The user email
+        pluginAuth:
+          type: string
+          description: Auth plugin to use to authenticate the user
         theme:
           type: string
           description: Theme enabled by this user
@@ -5099,8 +5109,13 @@ components:
         videoQuotaDaily:
           type: integer
           description: The user daily video quota
+        channelName:
+          type: string
+          description: The user default channel username
         role:
           $ref: '#/components/schemas/UserRole'
+        adminFlags:
+          $ref: '#/components/schemas/UserAdminFlags'
       required:
         - username
         - password
@@ -5117,20 +5132,26 @@ components:
           type: string
           format: email
           description: The updated email of the user
+        emailVerified:
+          type: boolean
+          description: Set the email as verified
         videoQuota:
           type: integer
           description: The updated video quota of the user
         videoQuotaDaily:
           type: integer
           description: The updated daily video quota of the user
+        pluginAuth:
+          type: string
+          nullable: true
+          description: The auth plugin to use to authenticate the user
+          example: 'peertube-plugin-auth-saml2'
         role:
           $ref: '#/components/schemas/UserRole'
+        adminFlags:
+          $ref: '#/components/schemas/UserAdminFlags'
       required:
         - id
-        - email
-        - videoQuota
-        - videoQuotaDaily
-        - role
     UpdateMe:
       properties:
         password: