1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

Deleted date on Cipher table, related sprocs and repositories updated

This commit is contained in:
Chad Scharf
2020-03-26 19:32:37 -04:00
parent a74df16848
commit bc46eccf70
13 changed files with 601 additions and 44 deletions

View File

@ -10,10 +10,10 @@ namespace Bit.Core.Repositories
public interface ICipherRepository : IRepository<Cipher, Guid>
{
Task<CipherDetails> GetByIdAsync(Guid id, Guid userId);
Task<CipherOrganizationDetails> GetOrganizationDetailsByIdAsync(Guid id);
Task<CipherOrganizationDetails> GetOrganizationDetailsByIdAsync(Guid id, bool deleted = false);
Task<bool> GetCanEditByIdAsync(Guid userId, Guid cipherId);
Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId, bool withOrganizations = true);
Task<ICollection<Cipher>> GetManyByOrganizationIdAsync(Guid organizationId);
Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId, bool withOrganizations = true, bool deleted = false);
Task<ICollection<Cipher>> GetManyByOrganizationIdAsync(Guid organizationId, bool deleted = false);
Task CreateAsync(Cipher cipher, IEnumerable<Guid> collectionIds);
Task CreateAsync(CipherDetails cipher);
Task CreateAsync(CipherDetails cipher, IEnumerable<Guid> collectionIds);
@ -23,7 +23,8 @@ namespace Bit.Core.Repositories
Task UpdatePartialAsync(Guid id, Guid userId, Guid? folderId, bool favorite);
Task UpdateAttachmentAsync(CipherAttachment attachment);
Task DeleteAttachmentAsync(Guid cipherId, string attachmentId);
Task DeleteAsync(IEnumerable<Guid> ids, Guid userId);
Task DeleteAsync(Cipher obj, bool permanent = false);
Task DeleteAsync(IEnumerable<Guid> ids, Guid userId, bool permanent = false);
Task MoveAsync(IEnumerable<Guid> ids, Guid? folderId, Guid userId);
Task DeleteByUserIdAsync(Guid userId);
Task DeleteByOrganizationIdAsync(Guid organizationId);

View File

@ -36,13 +36,13 @@ namespace Bit.Core.Repositories.SqlServer
}
}
public async Task<CipherOrganizationDetails> GetOrganizationDetailsByIdAsync(Guid id)
public async Task<CipherOrganizationDetails> GetOrganizationDetailsByIdAsync(Guid id, bool deleted = false)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<CipherDetails>(
$"[{Schema}].[CipherOrganizationDetails_ReadById]",
new { Id = id },
new { Id = id, Deleted = deleted },
commandType: CommandType.StoredProcedure);
return results.FirstOrDefault();
@ -62,7 +62,7 @@ namespace Bit.Core.Repositories.SqlServer
}
}
public async Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId, bool withOrganizations = true)
public async Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId, bool withOrganizations = true, bool deleted = false)
{
string sprocName = null;
if(withOrganizations)
@ -78,7 +78,7 @@ namespace Bit.Core.Repositories.SqlServer
{
var results = await connection.QueryAsync<CipherDetails>(
sprocName,
new { UserId = userId },
new { UserId = userId, Deleted = deleted },
commandType: CommandType.StoredProcedure);
return results
@ -88,13 +88,13 @@ namespace Bit.Core.Repositories.SqlServer
}
}
public async Task<ICollection<Cipher>> GetManyByOrganizationIdAsync(Guid organizationId)
public async Task<ICollection<Cipher>> GetManyByOrganizationIdAsync(Guid organizationId, bool deleted = false)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<Cipher>(
$"[{Schema}].[Cipher_ReadByOrganizationId]",
new { OrganizationId = organizationId },
new { OrganizationId = organizationId, Deleted = deleted },
commandType: CommandType.StoredProcedure);
return results.ToList();
@ -215,13 +215,24 @@ namespace Bit.Core.Repositories.SqlServer
}
}
public async Task DeleteAsync(IEnumerable<Guid> ids, Guid userId)
public async Task DeleteAsync(Cipher obj, bool permanent = false)
{
using (var connection = new SqlConnection(ConnectionString))
{
var results = await connection.ExecuteAsync(
$"[{Schema}].[Cipher_DeleteById]",
new { obj.Id, Permanent = permanent },
commandType: CommandType.StoredProcedure);
}
}
public async Task DeleteAsync(IEnumerable<Guid> ids, Guid userId, bool permanent = false)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.ExecuteAsync(
$"[{Schema}].[Cipher_Delete]",
new { Ids = ids.ToGuidIdArrayTVP(), UserId = userId },
new { Ids = ids.ToGuidIdArrayTVP(), UserId = userId, Permanent = permanent },
commandType: CommandType.StoredProcedure);
}
}