ActivityPub-federated video streaming platform using P2P directly in your web browser
Add ability to update plugin auth
Chocobozzz6d989edc66e7
diff --git a/client/src/app/+admin/users/user-edit/user-edit.component.html b/client/src/app/+admin/users/user-edit/user-edit.component.htmlindex 78c92227f5..fb34d6b226 100644--- a/client/src/app/+admin/users/user-edit/user-edit.component.html+++ b/client/src/app/+admin/users/user-edit/user-edit.component.html@@ -174,6 +174,17 @@</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-checkboxinputName="byPassAutoBlock" formControlName="byPassAutoBlock"diff --git a/client/src/app/+admin/users/user-edit/user-edit.ts b/client/src/app/+admin/users/user-edit/user-edit.tsindex 1613bb0d1f..faa2f5ad88 100644--- a/client/src/app/+admin/users/user-edit/user-edit.ts+++ b/client/src/app/+admin/users/user-edit/user-edit.ts@@ -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}diff --git a/client/src/app/+admin/users/user-edit/user-update.component.ts b/client/src/app/+admin/users/user-edit/user-update.component.tsindex e16f66a2ba..281c3dcef3 100644--- a/client/src/app/+admin/users/user-edit/user-update.component.ts+++ b/client/src/app/+admin/users/user-edit/user-update.component.ts@@ -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})}diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.tsindex c3190e731e..5911d1a0fe 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) {if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDailyif (body.role !== undefined) userToUpdate.role = body.roleif (body.adminFlags !== undefined) userToUpdate.adminFlags = body.adminFlags+ if (body.pluginAuth !== undefined) userToUpdate.pluginAuth = body.pluginAuthconst user = await userToUpdate.save()diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.tsindex 6b6e6c2df5..345571e837 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-codeimport { 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)diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.tsindex cd928b9804..62a59033fe 100644--- a/server/tests/api/users/users.ts+++ b/server/tests/api/users/users.ts@@ -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 Userexpect(user.username).to.equal('user_1')expect(user.email).to.equal('[email protected]')@@ -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 () {diff --git a/shared/extra-utils/users/users.ts b/shared/extra-utils/users/users.tsindex c683dcdd12..db532dbb02 100644--- a/shared/extra-utils/users/users.ts+++ b/shared/extra-utils/users/users.ts@@ -288,6 +288,7 @@ function updateUser (options: {videoQuotaDaily?: numberpassword?: stringadminFlags?: UserAdminFlag+ pluginAuth?: stringrole?: 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.videoQuotaDailyif (options.role !== undefined && options.role !== null) toSend['role'] = options.roleif (options.adminFlags !== undefined && options.adminFlags !== null) toSend['adminFlags'] = options.adminFlags+ if (options.pluginAuth !== undefined) toSend['pluginAuth'] = options.pluginAuthreturn makePutBodyRequest({url: options.url,diff --git a/shared/models/users/user-update.model.ts b/shared/models/users/user-update.model.tsindex fa43487ac5..1587385453 100644--- a/shared/models/users/user-update.model.ts+++ b/shared/models/users/user-update.model.ts@@ -9,4 +9,5 @@ export interface UserUpdate {videoQuotaDaily?: numberrole?: UserRoleadminFlags?: UserAdminFlag+ pluginAuth?: string}diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yamlindex b05a113cad..49616bcaa7 100644--- a/support/doc/api/openapi.yaml+++ b/support/doc/api/openapi.yaml@@ -3898,6 +3898,13 @@ components:- 2description: '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: 1VideoStateConstant:properties:@@ -5022,6 +5029,9 @@ components:type: stringformat: emaildescription: The user email+ pluginAuth:+ type: string+ description: Auth plugin to use to authenticate the usertheme:type: stringdescription: Theme enabled by this user@@ -5099,8 +5109,13 @@ components:videoQuotaDaily:type: integerdescription: The user daily video quota+ channelName:+ type: string+ description: The user default channel usernamerole:$ref: '#/components/schemas/UserRole'+ adminFlags:+ $ref: '#/components/schemas/UserAdminFlags'required:- username- password@@ -5117,20 +5132,26 @@ components:type: stringformat: emaildescription: The updated email of the user+ emailVerified:+ type: boolean+ description: Set the email as verifiedvideoQuota:type: integerdescription: The updated video quota of the uservideoQuotaDaily:type: integerdescription: 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- - videoQuota- - videoQuotaDaily- - roleUpdateMe:properties:password: