mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 16:42:50 -05:00
apis for org vault listing
This commit is contained in:
@ -6,9 +6,9 @@ using System.Linq;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class CipherResponseModel : ResponseModel
|
||||
public class CipherMiniResponseModel : ResponseModel
|
||||
{
|
||||
public CipherResponseModel(CipherDetails cipher, string obj = "cipher")
|
||||
public CipherMiniResponseModel(Cipher cipher, string obj = "cipherMini")
|
||||
: base(obj)
|
||||
{
|
||||
if(cipher == null)
|
||||
@ -20,8 +20,6 @@ namespace Bit.Core.Models.Api
|
||||
Type = cipher.Type;
|
||||
RevisionDate = cipher.RevisionDate;
|
||||
OrganizationId = cipher.OrganizationId?.ToString();
|
||||
FolderId = cipher.FolderId?.ToString();
|
||||
Favorite = cipher.Favorite;
|
||||
|
||||
switch(cipher.Type)
|
||||
{
|
||||
@ -35,13 +33,24 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public string Id { get; set; }
|
||||
public string OrganizationId { get; set; }
|
||||
public string FolderId { get; set; }
|
||||
public Enums.CipherType Type { get; set; }
|
||||
public bool Favorite { get; set; }
|
||||
public dynamic Data { get; set; }
|
||||
public DateTime RevisionDate { get; set; }
|
||||
}
|
||||
|
||||
public class CipherResponseModel : CipherMiniResponseModel
|
||||
{
|
||||
public CipherResponseModel(CipherDetails cipher, string obj = "cipher")
|
||||
: base(cipher, obj)
|
||||
{
|
||||
FolderId = cipher.FolderId?.ToString();
|
||||
Favorite = cipher.Favorite;
|
||||
}
|
||||
|
||||
public string FolderId { get; set; }
|
||||
public bool Favorite { get; set; }
|
||||
}
|
||||
|
||||
public class CipherDetailsResponseModel : CipherResponseModel
|
||||
{
|
||||
public CipherDetailsResponseModel(CipherDetails cipher,
|
||||
@ -68,6 +77,25 @@ namespace Bit.Core.Models.Api
|
||||
public IEnumerable<Guid> SubvaultIds { get; set; }
|
||||
}
|
||||
|
||||
public class CipherMiniDetailsResponseModel : CipherMiniResponseModel
|
||||
{
|
||||
public CipherMiniDetailsResponseModel(Cipher cipher,
|
||||
IDictionary<Guid, IGrouping<Guid, SubvaultCipher>> subvaultCiphers, string obj = "cipherMiniDetails")
|
||||
: base(cipher, obj)
|
||||
{
|
||||
if(subvaultCiphers.ContainsKey(cipher.Id))
|
||||
{
|
||||
SubvaultIds = subvaultCiphers[cipher.Id].Select(s => s.SubvaultId);
|
||||
}
|
||||
else
|
||||
{
|
||||
SubvaultIds = new Guid[] { };
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Guid> SubvaultIds { get; set; }
|
||||
}
|
||||
|
||||
public class CipherFullDetailsResponseModel : CipherDetailsResponseModel
|
||||
{
|
||||
public CipherFullDetailsResponseModel(CipherFullDetails cipher, IEnumerable<SubvaultCipher> subvaultCiphers)
|
||||
|
@ -12,6 +12,7 @@ namespace Bit.Core.Repositories
|
||||
Task<CipherFullDetails> GetFullDetailsByIdAsync(Guid id, Guid userId);
|
||||
Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<CipherDetails>> GetManyByUserIdHasSubvaultsAsync(Guid userId);
|
||||
Task<ICollection<Cipher>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<ICollection<CipherDetails>> GetManyByTypeAndUserIdAsync(Enums.CipherType type, Guid userId);
|
||||
Task CreateAsync(CipherDetails cipher);
|
||||
Task ReplaceAsync(CipherDetails cipher);
|
||||
|
@ -8,6 +8,7 @@ namespace Bit.Core.Repositories
|
||||
public interface ISubvaultCipherRepository
|
||||
{
|
||||
Task<ICollection<SubvaultCipher>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<SubvaultCipher>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<ICollection<SubvaultCipher>> GetManyByUserIdCipherIdAsync(Guid userId, Guid cipherId);
|
||||
Task UpdateSubvaultsAsync(Guid cipherId, Guid userId, IEnumerable<Guid> subvaultIds);
|
||||
}
|
||||
|
@ -76,6 +76,19 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<Cipher>> GetManyByOrganizationIdAsync(Guid organizationId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<Cipher>(
|
||||
$"[{Schema}].[Cipher_ReadByOrganizationId]",
|
||||
new { OrganizationId = organizationId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<CipherDetails>> GetManyByTypeAndUserIdAsync(Enums.CipherType type, Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
|
@ -33,6 +33,19 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<SubvaultCipher>> GetManyByOrganizationIdAsync(Guid organizationId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<SubvaultCipher>(
|
||||
"[dbo].[SubvaultCipher_ReadByOrganizationId]",
|
||||
new { OrganizationId = organizationId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<SubvaultCipher>> GetManyByUserIdCipherIdAsync(Guid userId, Guid cipherId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
|
Reference in New Issue
Block a user