From 45f1bd72a08998c60a9dd68ff069cea9de39161c Mon Sep 17 00:00:00 2001 From: John Livingston <38844060+JohnXLivingston@users.noreply.github.com> Date: Mon, 17 Feb 2020 10:16:52 +0100 Subject: [PATCH] Creating a user with an empty password will send an email to let him set his password (#2479) * Creating a user with an empty password will send an email to let him set his password * Consideration of Chocobozzz's comments * Tips for optional password * API documentation * Fix circular imports * Tests --- .../users/user-edit/user-create.component.ts | 10 ++- .../users/user-edit/user-edit.component.html | 7 ++ .../users/user-edit/user-update.component.ts | 4 + client/src/app/+admin/users/users.routes.ts | 4 + .../user-validators.service.ts | 12 +++ server/controllers/api/users/index.ts | 16 +++- server/helpers/custom-validators/users.ts | 10 +++ server/initializers/constants.ts | 2 + server/lib/emailer.ts | 16 ++++ server/lib/redis.ts | 9 +++ server/middlewares/validators/users.ts | 3 +- server/tests/api/check-params/users.ts | 48 +++++++++++- server/tests/api/server/email.ts | 76 ++++++++++++++++--- support/doc/api/openapi.yaml | 2 +- 14 files changed, 201 insertions(+), 18 deletions(-) diff --git a/client/src/app/+admin/users/user-edit/user-create.component.ts b/client/src/app/+admin/users/user-edit/user-create.component.ts index e726ec4d7..1769c0de0 100644 --- a/client/src/app/+admin/users/user-edit/user-create.component.ts +++ b/client/src/app/+admin/users/user-edit/user-create.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from '@angular/core' -import { Router } from '@angular/router' +import { Router, ActivatedRoute } from '@angular/router' import { AuthService, Notifier, ServerService } from '@app/core' import { UserCreate, UserRole } from '../../../../../../shared' import { UserEdit } from './user-edit' @@ -23,6 +23,7 @@ export class UserCreateComponent extends UserEdit implements OnInit { protected configService: ConfigService, protected auth: AuthService, private userValidatorsService: UserValidatorsService, + private route: ActivatedRoute, private router: Router, private notifier: Notifier, private userService: UserService, @@ -45,7 +46,7 @@ export class UserCreateComponent extends UserEdit implements OnInit { this.buildForm({ username: this.userValidatorsService.USER_USERNAME, email: this.userValidatorsService.USER_EMAIL, - password: this.userValidatorsService.USER_PASSWORD, + password: this.isPasswordOptional() ? this.userValidatorsService.USER_PASSWORD_OPTIONAL : this.userValidatorsService.USER_PASSWORD, role: this.userValidatorsService.USER_ROLE, videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA, videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY, @@ -78,6 +79,11 @@ export class UserCreateComponent extends UserEdit implements OnInit { return true } + isPasswordOptional () { + const serverConfig = this.route.snapshot.data.serverConfig + return serverConfig.email.enabled + } + getFormButtonTitle () { return this.i18n('Create user') } 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.html index 4ff4d0d12..2aca5ddca 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 @@ -29,6 +29,13 @@
+ + + + If you leave the password empty, an email will be sent to the user. + + +