mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
org user details apis
This commit is contained in:
@ -10,6 +10,7 @@ using Bit.Core.Domains;
|
||||
using Bit.Core.Enums;
|
||||
using System.Linq;
|
||||
using Bit.Core.Repositories;
|
||||
using System.Collections;
|
||||
|
||||
namespace Bit.Api.Controllers
|
||||
{
|
||||
@ -19,18 +20,18 @@ namespace Bit.Api.Controllers
|
||||
{
|
||||
private readonly IUserService _userService;
|
||||
private readonly ICipherService _cipherService;
|
||||
private readonly IOrganizationRepository _organizationRepository;
|
||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||
private readonly UserManager<User> _userManager;
|
||||
|
||||
public AccountsController(
|
||||
IUserService userService,
|
||||
ICipherService cipherService,
|
||||
IOrganizationRepository organizationRepository,
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
UserManager<User> userManager)
|
||||
{
|
||||
_userService = userService;
|
||||
_cipherService = cipherService;
|
||||
_organizationRepository = organizationRepository;
|
||||
_organizationUserRepository = organizationUserRepository;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
@ -159,11 +160,20 @@ namespace Bit.Api.Controllers
|
||||
public async Task<ProfileResponseModel> GetProfile()
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
var organizations = await _organizationRepository.GetManyByUserIdAsync(user.Id);
|
||||
var response = new ProfileResponseModel(user, organizations);
|
||||
var organizationUserDetails = await _organizationUserRepository.GetManyDetailsByUserAsync(user.Id);
|
||||
var response = new ProfileResponseModel(user, organizationUserDetails);
|
||||
return response;
|
||||
}
|
||||
|
||||
[HttpGet("organizations")]
|
||||
public async Task<ListResponseModel<ProfileOrganizationResponseModel>> GetOrganizations()
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User);
|
||||
var organizationUserDetails = await _organizationUserRepository.GetManyDetailsByUserAsync(userId.Value);
|
||||
var responseData = organizationUserDetails.Select(o => new ProfileOrganizationResponseModel(o));
|
||||
return new ListResponseModel<ProfileOrganizationResponseModel>(responseData);
|
||||
}
|
||||
|
||||
[HttpPut("profile")]
|
||||
[HttpPost("profile")]
|
||||
public async Task<ProfileResponseModel> PutProfile([FromBody]UpdateProfileRequestModel model)
|
||||
|
@ -46,7 +46,7 @@ namespace Bit.Api.Controllers
|
||||
[HttpGet("")]
|
||||
public async Task<ListResponseModel<OrganizationUserResponseModel>> Get(string orgId)
|
||||
{
|
||||
var organizationUsers = await _organizationUserRepository.GetManyDetailsByOrganizationsAsync(new Guid(orgId));
|
||||
var organizationUsers = await _organizationUserRepository.GetManyDetailsByOrganizationAsync(new Guid(orgId));
|
||||
var responses = organizationUsers.Select(o => new OrganizationUserResponseModel(o));
|
||||
return new ListResponseModel<OrganizationUserResponseModel>(responses);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ namespace Bit.Api.Models
|
||||
{
|
||||
public class OrganizationUserResponseModel : ResponseModel
|
||||
{
|
||||
public OrganizationUserResponseModel(OrganizationUserDetails organizationUser, string obj = "organizationUser")
|
||||
public OrganizationUserResponseModel(OrganizationUserUserDetails organizationUser, string obj = "organizationUser")
|
||||
: base(obj)
|
||||
{
|
||||
if(organizationUser == null)
|
||||
|
22
src/Api/Models/Response/ProfileOrganizationResponseModel.cs
Normal file
22
src/Api/Models/Response/ProfileOrganizationResponseModel.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class ProfileOrganizationResponseModel : ResponseModel
|
||||
{
|
||||
public ProfileOrganizationResponseModel(OrganizationUserOrganizationDetails organization)
|
||||
: base("profileOrganization")
|
||||
{
|
||||
Id = organization.OrganizationId.ToString();
|
||||
Name = organization.Name;
|
||||
Key = organization.Key;
|
||||
Status = organization.Status;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Key { get; set; }
|
||||
public OrganizationUserStatusType Status { get; set; }
|
||||
}
|
||||
}
|
@ -2,12 +2,14 @@
|
||||
using Bit.Core.Domains;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class ProfileResponseModel : ResponseModel
|
||||
{
|
||||
public ProfileResponseModel(User user, IEnumerable<Organization> organizations)
|
||||
public ProfileResponseModel(User user, IEnumerable<OrganizationUserOrganizationDetails> organizationsUserDetails)
|
||||
: base("profile")
|
||||
{
|
||||
if(user == null)
|
||||
@ -21,7 +23,7 @@ namespace Bit.Api.Models
|
||||
MasterPasswordHint = string.IsNullOrWhiteSpace(user.MasterPasswordHint) ? null : user.MasterPasswordHint;
|
||||
Culture = user.Culture;
|
||||
TwoFactorEnabled = user.TwoFactorEnabled;
|
||||
Organizations = organizations?.Select(o => new OrganizationResponseModel(o));
|
||||
Organizations = organizationsUserDetails?.Select(o => new ProfileOrganizationResponseModel(o));
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
@ -30,18 +32,6 @@ namespace Bit.Api.Models
|
||||
public string MasterPasswordHint { get; set; }
|
||||
public string Culture { get; set; }
|
||||
public bool TwoFactorEnabled { get; set; }
|
||||
public IEnumerable<OrganizationResponseModel> Organizations { get; set; }
|
||||
|
||||
public class OrganizationResponseModel
|
||||
{
|
||||
public OrganizationResponseModel(Organization organization)
|
||||
{
|
||||
Id = organization.Id.ToString();
|
||||
Name = organization.Name;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
public IEnumerable<ProfileOrganizationResponseModel> Organizations { get; set; }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user