From 49653c3388a278575edae08af43b476f1cfacb7b Mon Sep 17 00:00:00 2001 From: rockstardev <5191402+rockstardev@users.noreply.github.com> Date: Fri, 23 May 2025 22:50:15 -0500 Subject: [PATCH 1/2] Adding flag on Greenfield create user call to skip email invitation --- .../Models/CreateApplicationUserRequest.cs | 5 +++++ .../GreenField/GreenfieldUsersController.cs | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/BTCPayServer.Client/Models/CreateApplicationUserRequest.cs b/BTCPayServer.Client/Models/CreateApplicationUserRequest.cs index 0980f9373..f1e4e29bd 100644 --- a/BTCPayServer.Client/Models/CreateApplicationUserRequest.cs +++ b/BTCPayServer.Client/Models/CreateApplicationUserRequest.cs @@ -26,5 +26,10 @@ namespace BTCPayServer.Client.Models /// Whether this user is an administrator. If left null and there are no admins in the system, the user will be created as an admin. /// public bool? IsAdministrator { get; set; } + + /// + /// Flag to specify if email invitation should be sent to the user. https://github.com/btcpayserver/btcpayserver/issues/6406#issuecomment-2886252217 + /// + public bool? SkipEmailInvite { get; set; } } } diff --git a/BTCPayServer/Controllers/GreenField/GreenfieldUsersController.cs b/BTCPayServer/Controllers/GreenField/GreenfieldUsersController.cs index b389307a0..4acf0ca7f 100644 --- a/BTCPayServer/Controllers/GreenField/GreenfieldUsersController.cs +++ b/BTCPayServer/Controllers/GreenField/GreenfieldUsersController.cs @@ -249,7 +249,7 @@ namespace BTCPayServer.Controllers.Greenfield { var user = await _userManager.GetUserAsync(User); if (user is null) return this.UserNotFound(); - + UploadImageResultModel? upload = null; if (file is null) ModelState.AddModelError(nameof(file), "Invalid file"); @@ -286,7 +286,7 @@ namespace BTCPayServer.Controllers.Greenfield { var user = await _userManager.GetUserAsync(User); if (user is null) return this.UserNotFound(); - + var blob = user.GetBlob() ?? new UserBlob(); if (!string.IsNullOrEmpty(blob.ImageUrl)) { @@ -315,10 +315,10 @@ namespace BTCPayServer.Controllers.Greenfield ModelState.AddModelError(nameof(request.Email), "Email is missing"); if (!MailboxAddressValidator.IsMailboxAddress(request.Email)) ModelState.AddModelError(nameof(request.Email), "Invalid email"); - + if (!ModelState.IsValid) return this.CreateValidationError(ModelState); - + if (User.Identity is null) throw new JsonHttpException(this.StatusCode(401)); var anyAdmin = (await _userManager.GetUsersInRoleAsync(Roles.ServerAdmin)).Any(); @@ -358,6 +358,9 @@ namespace BTCPayServer.Controllers.Greenfield Created = DateTimeOffset.UtcNow, Approved = isAdmin // auto-approve first admin and users created by an admin }; + if (request.SkipEmailInvite == true) + user.RequiresEmailConfirmation = false; + var blob = user.GetBlob() ?? new(); blob.Name = request.Name; blob.ImageUrl = request.ImageUrl; From 5b2b6d69942890abbda90f415675b1279cbaec34 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Wed, 28 May 2025 13:59:16 +0200 Subject: [PATCH 2/2] Update email invite flag --- BTCPayServer.Client/Models/CreateApplicationUserRequest.cs | 4 ++-- .../Controllers/GreenField/GreenfieldUsersController.cs | 4 +--- BTCPayServer/wwwroot/swagger/v1/swagger.template.users.json | 6 ++++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/BTCPayServer.Client/Models/CreateApplicationUserRequest.cs b/BTCPayServer.Client/Models/CreateApplicationUserRequest.cs index f1e4e29bd..c6b79e5f8 100644 --- a/BTCPayServer.Client/Models/CreateApplicationUserRequest.cs +++ b/BTCPayServer.Client/Models/CreateApplicationUserRequest.cs @@ -28,8 +28,8 @@ namespace BTCPayServer.Client.Models public bool? IsAdministrator { get; set; } /// - /// Flag to specify if email invitation should be sent to the user. https://github.com/btcpayserver/btcpayserver/issues/6406#issuecomment-2886252217 + /// Flag to specify if an email invitation should be sent to the user. /// - public bool? SkipEmailInvite { get; set; } + public bool? SendInvitationEmail { get; set; } = true; } } diff --git a/BTCPayServer/Controllers/GreenField/GreenfieldUsersController.cs b/BTCPayServer/Controllers/GreenField/GreenfieldUsersController.cs index 4acf0ca7f..6e9de580c 100644 --- a/BTCPayServer/Controllers/GreenField/GreenfieldUsersController.cs +++ b/BTCPayServer/Controllers/GreenField/GreenfieldUsersController.cs @@ -358,8 +358,6 @@ namespace BTCPayServer.Controllers.Greenfield Created = DateTimeOffset.UtcNow, Approved = isAdmin // auto-approve first admin and users created by an admin }; - if (request.SkipEmailInvite == true) - user.RequiresEmailConfirmation = false; var blob = user.GetBlob() ?? new(); blob.Name = request.Name; @@ -418,7 +416,7 @@ namespace BTCPayServer.Controllers.Greenfield var currentUser = await _userManager.GetUserAsync(User); var userEvent = currentUser switch { - { } invitedBy => await UserEvent.Invited.Create(user, invitedBy, _callbackGenerator, Request, true), + { } invitedBy => await UserEvent.Invited.Create(user, invitedBy, _callbackGenerator, Request, request.SendInvitationEmail is not false), _ => await UserEvent.Registered.Create(user, _callbackGenerator, Request) }; _eventAggregator.Publish(userEvent); diff --git a/BTCPayServer/wwwroot/swagger/v1/swagger.template.users.json b/BTCPayServer/wwwroot/swagger/v1/swagger.template.users.json index d07ca68f5..1ae38b02e 100644 --- a/BTCPayServer/wwwroot/swagger/v1/swagger.template.users.json +++ b/BTCPayServer/wwwroot/swagger/v1/swagger.template.users.json @@ -271,6 +271,12 @@ "description": "Make this user administrator (only if you have the `unrestricted` permission of a server administrator)", "nullable": true, "default": false + }, + "sendInvitationEmail": { + "type": "boolean", + "description": "Flag to specify if an email invitation should be sent to the user", + "nullable": true, + "default": true } } }