mirror of
https://github.com/bitwarden/server.git
synced 2025-01-22 21:51:22 +01:00
get subvaults for organization user
This commit is contained in:
parent
732e0d8984
commit
4a9206b992
@ -17,22 +17,25 @@ namespace Bit.Api.Controllers
|
||||
private readonly IOrganizationRepository _organizationRepository;
|
||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||
private readonly IOrganizationService _organizationService;
|
||||
private readonly ISubvaultRepository _subvaultRepository;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
public OrganizationUsersController(
|
||||
IOrganizationRepository organizationRepository,
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
IOrganizationService organizationService,
|
||||
ISubvaultRepository subvaultRepository,
|
||||
IUserService userService)
|
||||
{
|
||||
_organizationRepository = organizationRepository;
|
||||
_organizationUserRepository = organizationUserRepository;
|
||||
_organizationService = organizationService;
|
||||
_subvaultRepository = subvaultRepository;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<OrganizationUserResponseModel> Get(string orgId, string id)
|
||||
public async Task<OrganizationUserDetailsResponseModel> Get(string orgId, string id)
|
||||
{
|
||||
var organizationUser = await _organizationUserRepository.GetDetailsByIdAsync(new Guid(id));
|
||||
if(organizationUser == null)
|
||||
@ -40,7 +43,7 @@ namespace Bit.Api.Controllers
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
return new OrganizationUserResponseModel(organizationUser);
|
||||
return new OrganizationUserDetailsResponseModel(organizationUser.Item1, organizationUser.Item2);
|
||||
}
|
||||
|
||||
[HttpGet("")]
|
||||
|
@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Data;
|
||||
using System.Collections.Generic;
|
||||
using Bit.Core.Models.Table;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
@ -29,4 +32,16 @@ namespace Bit.Core.Models.Api
|
||||
public OrganizationUserType Type { get; set; }
|
||||
public OrganizationUserStatusType Status { get; set; }
|
||||
}
|
||||
|
||||
public class OrganizationUserDetailsResponseModel : OrganizationUserResponseModel
|
||||
{
|
||||
public OrganizationUserDetailsResponseModel(OrganizationUserUserDetails organizationUser,
|
||||
IEnumerable<Subvault> subvaults)
|
||||
: base(organizationUser, "organizationUserDetails")
|
||||
{
|
||||
Subvaults = new ListResponseModel<SubvaultResponseModel>(subvaults.Select(s => new SubvaultResponseModel(s)));
|
||||
}
|
||||
|
||||
public ListResponseModel<SubvaultResponseModel> Subvaults { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace Bit.Core.Repositories
|
||||
public interface IOrganizationUserRepository : IRepository<OrganizationUser, Guid>
|
||||
{
|
||||
Task<OrganizationUser> GetByOrganizationAsync(Guid organizationId, Guid userId);
|
||||
Task<OrganizationUserUserDetails> GetDetailsByIdAsync(Guid id);
|
||||
Task<Tuple<OrganizationUserUserDetails, ICollection<Subvault>>> GetDetailsByIdAsync(Guid id);
|
||||
Task<ICollection<OrganizationUserUserDetails>> GetManyDetailsByOrganizationAsync(Guid organizationId);
|
||||
Task<ICollection<OrganizationUserOrganizationDetails>> GetManyDetailsByUserAsync(Guid userId);
|
||||
}
|
||||
|
@ -33,16 +33,18 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OrganizationUserUserDetails> GetDetailsByIdAsync(Guid id)
|
||||
public async Task<Tuple<OrganizationUserUserDetails, ICollection<Subvault>>> GetDetailsByIdAsync(Guid id)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<OrganizationUserUserDetails>(
|
||||
var results = await connection.QueryMultipleAsync(
|
||||
"[dbo].[OrganizationUserUserDetails_ReadById]",
|
||||
new { Id = id },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.SingleOrDefault();
|
||||
var user = (await results.ReadAsync<OrganizationUserUserDetails>()).SingleOrDefault();
|
||||
var subvaults = (await results.ReadAsync<Subvault>()).ToList();
|
||||
return new Tuple<OrganizationUserUserDetails, ICollection<Subvault>>(user, subvaults);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,4 +10,13 @@ BEGIN
|
||||
[dbo].[OrganizationUserUserDetailsView]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
SELECT
|
||||
S.*
|
||||
FROM
|
||||
[dbo].[SubvaultView] S
|
||||
INNER JOIN
|
||||
[dbo].[SubvaultUser] SU ON SU.[SubvaultId] = S.[Id]
|
||||
WHERE
|
||||
SU.[OrganizationUserId] = @Id
|
||||
END
|
Loading…
Reference in New Issue
Block a user