1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 08:02:49 -05:00

return share information with cipher API response

This commit is contained in:
Kyle Spearrin
2017-02-21 22:52:02 -05:00
parent 8051995cc7
commit 900e71d4dd
11 changed files with 123 additions and 15 deletions

View File

@ -31,27 +31,28 @@ namespace Bit.Api.Controllers
}
[HttpGet("{id}")]
public async Task<CipherResponseModel> Get(string id)
public async Task<CipherShareResponseModel> Get(string id)
{
var userId = _userService.GetProperUserId(User).Value;
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
var cipher = await _cipherRepository.GetShareByIdAsync(new Guid(id), userId);
if(cipher == null)
{
throw new NotFoundException();
}
return new CipherResponseModel(cipher, userId);
return new CipherShareResponseModel(cipher, userId);
}
[HttpGet("")]
public async Task<ListResponseModel<CipherResponseModel>> Get()
public async Task<ListResponseModel<CipherShareResponseModel>> Get()
{
var userId = _userService.GetProperUserId(User).Value;
var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId);
var responses = ciphers.Select(c => new CipherResponseModel(c, userId));
return new ListResponseModel<CipherResponseModel>(responses);
var ciphers = await _cipherRepository.GetManyShareByUserIdAsync(userId);
var responses = ciphers.Select(c => new CipherShareResponseModel(c, userId));
return new ListResponseModel<CipherShareResponseModel>(responses);
}
[Obsolete]
[HttpGet("history")]
public async Task<CipherHistoryResponseModel> Get(DateTime since)
{

View File

@ -118,13 +118,16 @@ namespace Bit.Api.IdentityServer
claims.Add(new Claim("device", device.Identifier));
}
var customResponse = new Dictionary<string, object>();
if(!string.IsNullOrWhiteSpace(user.PrivateKey))
{
customResponse.Add("EncryptedPrivateKey", user.PrivateKey);
}
context.Result = new GrantValidationResult(user.Id.ToString(), "Application",
identityProvider: "bitwarden",
claims: claims.Count > 0 ? claims : null,
customResponse: new Dictionary<string, object>
{
{ "EncryptedPrivateKey", user.PrivateKey }
});
customResponse: customResponse);
}
private void BuildTwoFactorResult(User user, ResourceOwnerPasswordValidationContext context)

View File

@ -1,15 +1,15 @@
using System;
using Bit.Core.Domains;
using Bit.Core.Models.Data;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Linq;
namespace Bit.Api.Models
{
public class CipherResponseModel : ResponseModel
{
public CipherResponseModel(Cipher cipher, Guid userId)
: base("cipher")
public CipherResponseModel(Cipher cipher, Guid userId, string obj = "cipher")
: base(obj)
{
if(cipher == null)
{
@ -40,7 +40,22 @@ namespace Bit.Api.Models
public Core.Enums.CipherType Type { get; set; }
public bool Favorite { get; set; }
public dynamic Data { get; set; }
public string Key { get; set; }
public DateTime RevisionDate { get; set; }
}
public class CipherShareResponseModel : CipherResponseModel
{
public CipherShareResponseModel(CipherShare cipherShare, Guid userId)
: base(cipherShare, userId, "cipherShare")
{
Key = cipherShare.Key;
Permissions = cipherShare.Permissions == null ? null :
JsonConvert.DeserializeObject<IEnumerable<Core.Enums.SharePermissionType>>(cipherShare.Permissions);
Status = cipherShare.Status;
}
public string Key { get; set; }
public IEnumerable<Core.Enums.SharePermissionType> Permissions { get; set; }
public Core.Enums.ShareStatusType? Status { get; set; }
}
}