1
0
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:
Kyle Spearrin 2017-03-11 15:34:57 -05:00
parent 732e0d8984
commit 4a9206b992
5 changed files with 35 additions and 6 deletions

View File

@ -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("")]

View File

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

View File

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

View File

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

View File

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