Merge pull request #6752 from btcpayserver/bugfix/flag-skip-email

Adding flag on Greenfield API Create User method to skip email invitation
This commit is contained in:
rockstardev
2025-05-29 12:04:38 -05:00
committed by GitHub
3 changed files with 17 additions and 5 deletions

View File

@@ -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.
/// </summary>
public bool? IsAdministrator { get; set; }
/// <summary>
/// Flag to specify if an email invitation should be sent to the user.
/// </summary>
public bool? SendInvitationEmail { get; set; } = true;
}
}

View File

@@ -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,7 @@ namespace BTCPayServer.Controllers.Greenfield
Created = DateTimeOffset.UtcNow,
Approved = isAdmin // auto-approve first admin and users created by an admin
};
var blob = user.GetBlob() ?? new();
blob.Name = request.Name;
blob.ImageUrl = request.ImageUrl;
@@ -415,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);

View File

@@ -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
}
}
}