mirror of
https://github.com/bitwarden/server.git
synced 2024-11-25 12:45:18 +01:00
cipher details with subvaults api
This commit is contained in:
parent
854c4f7871
commit
7d9a2cdd95
@ -44,6 +44,21 @@ namespace Bit.Api.Controllers
|
||||
return new CipherResponseModel(cipher);
|
||||
}
|
||||
|
||||
[HttpGet("{id}/full-details")]
|
||||
public async Task<CipherFullDetailsResponseModel> GetDetails(string id)
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
var cipherId = new Guid(id);
|
||||
var cipher = await _cipherRepository.GetFullDetailsByIdAsync(cipherId, userId);
|
||||
if(cipher == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
var subvaultCiphers = await _subvaultCipherRepository.GetManyByUserIdCipherIdAsync(userId, cipherId);
|
||||
return new CipherFullDetailsResponseModel(cipher, subvaultCiphers);
|
||||
}
|
||||
|
||||
[HttpGet("")]
|
||||
public async Task<ListResponseModel<CipherResponseModel>> Get()
|
||||
{
|
||||
@ -53,7 +68,7 @@ namespace Bit.Api.Controllers
|
||||
return new ListResponseModel<CipherResponseModel>(responses);
|
||||
}
|
||||
|
||||
[HttpGet("subvaults")]
|
||||
[HttpGet("details")]
|
||||
public async Task<ListResponseModel<CipherDetailsResponseModel>> GetSubvaults()
|
||||
{
|
||||
var userId = _userService.GetProperUserId(User).Value;
|
||||
|
@ -45,8 +45,8 @@ namespace Bit.Core.Models.Api
|
||||
public class CipherDetailsResponseModel : CipherResponseModel
|
||||
{
|
||||
public CipherDetailsResponseModel(CipherDetails cipher,
|
||||
IDictionary<Guid, IGrouping<Guid, SubvaultCipher>> subvaultCiphers)
|
||||
: base(cipher, "cipherDetails")
|
||||
IDictionary<Guid, IGrouping<Guid, SubvaultCipher>> subvaultCiphers, string obj = "cipherDetails")
|
||||
: base(cipher, obj)
|
||||
{
|
||||
if(subvaultCiphers.ContainsKey(cipher.Id))
|
||||
{
|
||||
@ -58,6 +58,24 @@ namespace Bit.Core.Models.Api
|
||||
}
|
||||
}
|
||||
|
||||
public CipherDetailsResponseModel(CipherDetails cipher, IEnumerable<SubvaultCipher> subvaultCiphers,
|
||||
string obj = "cipherDetails")
|
||||
: base(cipher, obj)
|
||||
{
|
||||
SubvaultIds = subvaultCiphers.Select(s => s.SubvaultId);
|
||||
}
|
||||
|
||||
public IEnumerable<Guid> SubvaultIds { get; set; }
|
||||
}
|
||||
|
||||
public class CipherFullDetailsResponseModel : CipherDetailsResponseModel
|
||||
{
|
||||
public CipherFullDetailsResponseModel(CipherFullDetails cipher, IEnumerable<SubvaultCipher> subvaultCiphers)
|
||||
: base(cipher, subvaultCiphers, "cipherFullDetails")
|
||||
{
|
||||
Edit = cipher.Edit;
|
||||
}
|
||||
|
||||
public bool Edit { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -8,5 +8,6 @@ namespace Bit.Core.Repositories
|
||||
public interface ISubvaultCipherRepository
|
||||
{
|
||||
Task<ICollection<SubvaultCipher>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<SubvaultCipher>> GetManyByUserIdCipherIdAsync(Guid userId, Guid cipherId);
|
||||
}
|
||||
}
|
||||
|
@ -31,5 +31,18 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<SubvaultCipher>> GetManyByUserIdCipherIdAsync(Guid userId, Guid cipherId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<SubvaultCipher>(
|
||||
$"[dbo].[SubvaultCipher_ReadByUserIdCipherId]",
|
||||
new { UserId = userId, CipherId = cipherId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -182,5 +182,6 @@
|
||||
<Build Include="dbo\Stored Procedures\OrganizationUserUserDetails_ReadByOrganizationId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Subvault_ReadByOrganizationIdAdminUserId.sql" />
|
||||
<Build Include="dbo\User Defined Types\GuidIdArray.sql" />
|
||||
<Build Include="dbo\Stored Procedures\SubvaultCipher_ReadByCipherId.sql" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -0,0 +1,20 @@
|
||||
CREATE PROCEDURE [dbo].[SubvaultCipher_ReadByUserIdCipherId]
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@CipherId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
SC.*
|
||||
FROM
|
||||
[dbo].[SubvaultCipher] SC
|
||||
INNER JOIN
|
||||
[dbo].[SubvaultUser] SU ON SU.[SubvaultId] = SC.[SubvaultId]
|
||||
INNER JOIN
|
||||
[dbo].[OrganizationUser] OU ON OU.[Id] = SU.[OrganizationUserId]
|
||||
WHERE
|
||||
SC.[CipherId] = @CipherId
|
||||
AND OU.[UserId] = @UserId
|
||||
AND OU.[Status] = 2 -- Confirmed
|
||||
END
|
Loading…
Reference in New Issue
Block a user