diff --git a/BTCPayServer.Client/Models/ApplicationUserData.cs b/BTCPayServer.Client/Models/ApplicationUserData.cs
index 2ef97a166..25715ae12 100644
--- a/BTCPayServer.Client/Models/ApplicationUserData.cs
+++ b/BTCPayServer.Client/Models/ApplicationUserData.cs
@@ -21,5 +21,10 @@ namespace BTCPayServer.Client.Models
/// whether the user needed to verify their email on account creation
///
public bool RequiresEmailConfirmation { get; set; }
+
+ ///
+ /// the roles of the user
+ ///
+ public string[] Roles { get; set; }
}
}
diff --git a/BTCPayServer.Tests/GreenfieldAPITests.cs b/BTCPayServer.Tests/GreenfieldAPITests.cs
index 2d4030460..ac1d0054c 100644
--- a/BTCPayServer.Tests/GreenfieldAPITests.cs
+++ b/BTCPayServer.Tests/GreenfieldAPITests.cs
@@ -148,10 +148,13 @@ namespace BTCPayServer.Tests
// We have no admin, so it should work
var user1 = await unauthClient.CreateUser(
new CreateApplicationUserRequest() { Email = "test@gmail.com", Password = "abceudhqw" });
+ Assert.Empty(user1.Roles);
+
// We have no admin, so it should work
var user2 = await unauthClient.CreateUser(
new CreateApplicationUserRequest() { Email = "test2@gmail.com", Password = "abceudhqw" });
-
+ Assert.Empty(user2.Roles);
+
// Duplicate email
await AssertValidationError(new[] { "Email" },
async () => await unauthClient.CreateUser(
@@ -164,7 +167,8 @@ namespace BTCPayServer.Tests
Password = "abceudhqw",
IsAdministrator = true
});
-
+ Assert.Contains("ServerAdmin", admin.Roles);
+
// Creating a new user without proper creds is now impossible (unauthorized)
// Because if registration are locked and that an admin exists, we don't accept unauthenticated connection
await AssertHttpError(401,
@@ -560,6 +564,7 @@ namespace BTCPayServer.Tests
Assert.NotNull(apiKeyProfileUserData);
Assert.Equal(apiKeyProfileUserData.Id, user.UserId);
Assert.Equal(apiKeyProfileUserData.Email, user.RegisterDetails.Email);
+ Assert.Contains("ServerAdmin", apiKeyProfileUserData.Roles);
await Assert.ThrowsAsync(async () => await clientInsufficient.GetCurrentUser());
await clientServer.GetCurrentUser();
diff --git a/BTCPayServer/Controllers/GreenField/UsersController.cs b/BTCPayServer/Controllers/GreenField/UsersController.cs
index 350b7cf02..dba0672c0 100644
--- a/BTCPayServer/Controllers/GreenField/UsersController.cs
+++ b/BTCPayServer/Controllers/GreenField/UsersController.cs
@@ -58,7 +58,7 @@ namespace BTCPayServer.Controllers.GreenField
public async Task> GetCurrentUser()
{
var user = await _userManager.GetUserAsync(User);
- return FromModel(user);
+ return await FromModel(user);
}
[AllowAnonymous]
@@ -152,17 +152,20 @@ namespace BTCPayServer.Controllers.GreenField
}
}
_eventAggregator.Publish(new UserRegisteredEvent() { RequestUri = Request.GetAbsoluteRootUri(), User = user, Admin = request.IsAdministrator is true });
- return CreatedAtAction(string.Empty, user);
+ var model = await FromModel(user);
+ return CreatedAtAction(string.Empty, model);
}
- private static ApplicationUserData FromModel(ApplicationUser data)
+ private async Task FromModel(ApplicationUser data)
{
+ var roles = (await _userManager.GetRolesAsync(data)).ToArray();
return new ApplicationUserData()
{
Id = data.Id,
Email = data.Email,
EmailConfirmed = data.EmailConfirmed,
- RequiresEmailConfirmation = data.RequiresEmailConfirmation
+ RequiresEmailConfirmation = data.RequiresEmailConfirmation,
+ Roles = roles
};
}
}
diff --git a/BTCPayServer/wwwroot/swagger/v1/swagger.template.users.json b/BTCPayServer/wwwroot/swagger/v1/swagger.template.users.json
index 6fbe758f6..ce2180dd8 100644
--- a/BTCPayServer/wwwroot/swagger/v1/swagger.template.users.json
+++ b/BTCPayServer/wwwroot/swagger/v1/swagger.template.users.json
@@ -117,12 +117,12 @@
"properties": {
"id": {
"type": "string",
- "description": "The id of the new user",
+ "description": "The id of the user",
"nullable": false
},
"email": {
"type": "string",
- "description": "The email of the new user",
+ "description": "The email of the user",
"nullable": false
},
"emailConfirmed": {
@@ -132,6 +132,14 @@
"requiresEmailConfirmation": {
"type": "boolean",
"description": "True if the email requires email confirmation to log in"
+ },
+ "roles": {
+ "type": "array",
+ "nullable": false,
+ "items": {
+ "type": "string"
+ },
+ "description": "The roles of the user"
}
}
}