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

apis for creating ciphers with org & collections

This commit is contained in:
Kyle Spearrin
2018-10-19 12:07:31 -04:00
parent e3f94bb67b
commit 96b492fa07
12 changed files with 437 additions and 61 deletions

View File

@ -101,6 +101,21 @@ namespace Bit.Core.Repositories.SqlServer
}
}
public async Task CreateAsync(Cipher cipher, IEnumerable<Guid> collectionIds)
{
cipher.SetNewId();
var objWithCollections = JsonConvert.DeserializeObject<CipherWithCollections>(
JsonConvert.SerializeObject(cipher));
objWithCollections.CollectionIds = collectionIds.ToGuidIdArrayTVP();
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.ExecuteAsync(
$"[{Schema}].[Cipher_CreateWithCollections]",
objWithCollections,
commandType: CommandType.StoredProcedure);
}
}
public async Task CreateAsync(CipherDetails cipher)
{
cipher.SetNewId();
@ -113,6 +128,21 @@ namespace Bit.Core.Repositories.SqlServer
}
}
public async Task CreateAsync(CipherDetails cipher, IEnumerable<Guid> collectionIds)
{
cipher.SetNewId();
var objWithCollections = JsonConvert.DeserializeObject<CipherDetailsWithCollections>(
JsonConvert.SerializeObject(cipher));
objWithCollections.CollectionIds = collectionIds.ToGuidIdArrayTVP();
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.ExecuteAsync(
$"[{Schema}].[CipherDetails_CreateWithCollections]",
objWithCollections,
commandType: CommandType.StoredProcedure);
}
}
public async Task ReplaceAsync(CipherDetails obj)
{
using(var connection = new SqlConnection(ConnectionString))
@ -715,6 +745,11 @@ namespace Bit.Core.Repositories.SqlServer
return collectionCiphersTable;
}
public class CipherDetailsWithCollections : CipherDetails
{
public DataTable CollectionIds { get; set; }
}
public class CipherWithCollections : Cipher
{
public DataTable CollectionIds { get; set; }