mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
Greenfield: Expand user data (#6649)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -84,7 +85,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
var user = await _userManager.FindByIdOrEmail(idOrEmail);
|
||||
if (user != null)
|
||||
{
|
||||
return Ok(await FromModel(user));
|
||||
return Ok(await ForAPI(user));
|
||||
}
|
||||
return this.UserNotFound();
|
||||
}
|
||||
@@ -128,7 +129,13 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
[HttpGet("~/api/v1/users/")]
|
||||
public async Task<ActionResult<ApplicationUserData[]>> GetUsers()
|
||||
{
|
||||
return Ok(await _userService.GetUsersWithRoles());
|
||||
var usersWithRoles = await _userService.GetUsersWithRoles();
|
||||
List<ApplicationUserData> users = [];
|
||||
foreach (var user in usersWithRoles)
|
||||
{
|
||||
users.Add(await UserService.ForAPI<ApplicationUserData>(user.User, user.Roles, _callbackGenerator, _uriResolver, Request));
|
||||
}
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
[Authorize(Policy = Policies.CanViewProfile, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
@@ -136,7 +143,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
public async Task<ActionResult<ApplicationUserData>> GetCurrentUser()
|
||||
{
|
||||
var user = await _userManager.GetUserAsync(User);
|
||||
return await FromModel(user!);
|
||||
return await ForAPI(user!);
|
||||
}
|
||||
|
||||
[Authorize(Policy = Policies.CanModifyProfile, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
@@ -232,7 +239,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
if (!ModelState.IsValid)
|
||||
return this.CreateValidationError(ModelState);
|
||||
|
||||
var model = await FromModel(user);
|
||||
var model = await ForAPI(user);
|
||||
return Ok(model);
|
||||
}
|
||||
|
||||
@@ -264,7 +271,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
user.SetBlob(blob);
|
||||
await _userManager.UpdateAsync(user);
|
||||
_eventAggregator.Publish(new UserEvent.Updated(user));
|
||||
var model = await FromModel(user);
|
||||
var model = await ForAPI(user);
|
||||
return Ok(model);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -414,7 +421,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
};
|
||||
_eventAggregator.Publish(userEvent);
|
||||
|
||||
var model = await FromModel(user);
|
||||
var model = await ForAPI(user);
|
||||
return CreatedAtAction(string.Empty, model);
|
||||
}
|
||||
|
||||
@@ -449,14 +456,11 @@ namespace BTCPayServer.Controllers.Greenfield
|
||||
return Ok();
|
||||
}
|
||||
|
||||
private async Task<ApplicationUserData> FromModel(ApplicationUser data)
|
||||
private async Task<ApplicationUserData> ForAPI(ApplicationUser data)
|
||||
{
|
||||
var roles = (await _userManager.GetRolesAsync(data)).ToArray();
|
||||
var model = UserService.FromModel(data, roles);
|
||||
model.ImageUrl = string.IsNullOrEmpty(model.ImageUrl)
|
||||
? null
|
||||
: await _uriResolver.Resolve(Request.GetAbsoluteRootUri(), UnresolvedUri.Create(model.ImageUrl));
|
||||
return model;
|
||||
var blob = data.GetBlob();
|
||||
return await UserService.ForAPI<ApplicationUserData>(data, roles, _callbackGenerator, _uriResolver, Request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user