1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 16:42:50 -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

@ -0,0 +1,8 @@
namespace Bit.Core.Enums
{
public enum SharePermissionType : byte
{
Reshare = 0,
Edit = 1
}
}

View File

@ -0,0 +1,11 @@
using Bit.Core.Domains;
namespace Bit.Core.Models.Data
{
public class CipherShare : Cipher
{
public string Key { get; internal set; }
public string Permissions { get; internal set; }
public Enums.ShareStatusType? Status { get; internal set; }
}
}

View File

@ -2,13 +2,16 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Bit.Core.Domains;
using Bit.Core.Models.Data;
namespace Bit.Core.Repositories
{
public interface ICipherRepository : IRepository<Cipher, Guid>
{
Task<Cipher> GetByIdAsync(Guid id, Guid userId);
Task<CipherShare> GetShareByIdAsync(Guid id, Guid userId);
Task<ICollection<Cipher>> GetManyByUserIdAsync(Guid userId);
Task<ICollection<CipherShare>> GetManyShareByUserIdAsync(Guid userId);
Task<ICollection<Cipher>> GetManyByTypeAndUserIdAsync(Enums.CipherType type, Guid userId);
Task<Tuple<ICollection<Cipher>, ICollection<Guid>>>
GetManySinceRevisionDateAndUserIdWithDeleteHistoryAsync(DateTime sinceRevisionDate, Guid userId);

View File

@ -7,6 +7,7 @@ using DataTableProxy;
using Bit.Core.Domains;
using System.Data;
using Dapper;
using Bit.Core.Models.Data;
namespace Bit.Core.Repositories.SqlServer
{
@ -31,6 +32,19 @@ namespace Bit.Core.Repositories.SqlServer
return cipher;
}
public async Task<CipherShare> GetShareByIdAsync(Guid id, Guid userId)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<CipherShare>(
$"[{Schema}].[CipherShare_ReadById]",
new { UserId = userId },
commandType: CommandType.StoredProcedure);
return results.FirstOrDefault(c => c.UserId == userId);
}
}
public async Task<ICollection<Cipher>> GetManyByUserIdAsync(Guid userId)
{
using(var connection = new SqlConnection(ConnectionString))
@ -44,6 +58,19 @@ namespace Bit.Core.Repositories.SqlServer
}
}
public async Task<ICollection<CipherShare>> GetManyShareByUserIdAsync(Guid userId)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<CipherShare>(
$"[{Schema}].[CipherShare_ReadByUserId]",
new { UserId = userId },
commandType: CommandType.StoredProcedure);
return results.ToList();
}
}
public async Task<ICollection<Cipher>> GetManyByTypeAndUserIdAsync(Enums.CipherType type, Guid userId)
{
using(var connection = new SqlConnection(ConnectionString))