mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 00:52:49 -05:00
cipher details create/update
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Utilities;
|
||||
using Bit.Core.Models.Table;
|
||||
using Newtonsoft.Json;
|
||||
using Core.Models.Data;
|
||||
|
||||
@ -29,15 +28,15 @@ namespace Bit.Core.Models.Api
|
||||
[StringLength(10000)]
|
||||
public string Notes { get; set; }
|
||||
|
||||
public CipherDetails ToCipher(Guid userId)
|
||||
public CipherDetails ToCipherDetails(Guid userId)
|
||||
{
|
||||
return ToCipher(new CipherDetails
|
||||
return ToCipherDetails(new CipherDetails
|
||||
{
|
||||
UserId = userId
|
||||
});
|
||||
}
|
||||
|
||||
public CipherDetails ToCipher(CipherDetails existingLogin)
|
||||
public CipherDetails ToCipherDetails(CipherDetails existingLogin)
|
||||
{
|
||||
existingLogin.FolderId = string.IsNullOrWhiteSpace(FolderId) ? null : (Guid?)new Guid(FolderId);
|
||||
existingLogin.Favorite = Favorite;
|
||||
|
@ -20,7 +20,7 @@ namespace Bit.Core.Models.Api
|
||||
throw new ArgumentNullException(nameof(deletedIds));
|
||||
}
|
||||
|
||||
Revised = revisedCiphers.Select(c => new CipherResponseModel(c));
|
||||
//Revised = revisedCiphers.Select(c => new CipherResponseModel(c));
|
||||
Deleted = deletedIds.Select(id => id.ToString());
|
||||
}
|
||||
|
||||
|
@ -1,32 +1,10 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
using Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class CipherResponseModel : ResponseModel
|
||||
{
|
||||
public CipherResponseModel(Cipher cipher, string obj = "cipher")
|
||||
: base(obj)
|
||||
{
|
||||
if(cipher == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(cipher));
|
||||
}
|
||||
|
||||
Id = cipher.Id.ToString();
|
||||
Type = cipher.Type;
|
||||
RevisionDate = cipher.RevisionDate;
|
||||
|
||||
switch(cipher.Type)
|
||||
{
|
||||
case Enums.CipherType.Login:
|
||||
Data = new LoginDataModel(cipher);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Unsupported " + nameof(Type) + ".");
|
||||
}
|
||||
}
|
||||
public CipherResponseModel(CipherDetails cipher, string obj = "cipher")
|
||||
: base(obj)
|
||||
{
|
||||
@ -38,6 +16,8 @@ namespace Bit.Core.Models.Api
|
||||
Id = cipher.Id.ToString();
|
||||
Type = cipher.Type;
|
||||
RevisionDate = cipher.RevisionDate;
|
||||
FolderId = cipher.FolderId?.ToString();
|
||||
Favorite = cipher.Favorite;
|
||||
|
||||
switch(cipher.Type)
|
||||
{
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using Core.Models.Data;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
@ -41,8 +40,5 @@ namespace Bit.Core.Models.Api
|
||||
public string Password { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public DateTime RevisionDate { get; set; }
|
||||
|
||||
// Expandables
|
||||
public FolderResponseModel Folder { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,9 @@ namespace Bit.Core.Repositories
|
||||
Task<ICollection<CipherDetails>> GetManyByTypeAndUserIdAsync(Enums.CipherType type, Guid userId);
|
||||
Task<Tuple<ICollection<CipherDetails>, ICollection<Guid>>> GetManySinceRevisionDateAndUserIdWithDeleteHistoryAsync(
|
||||
DateTime sinceRevisionDate, Guid userId);
|
||||
Task CreateAsync(CipherDetails cipher);
|
||||
Task ReplaceAsync(CipherDetails cipher);
|
||||
Task UpsertAsync(CipherDetails cipher);
|
||||
Task UpdateUserEmailPasswordAndCiphersAsync(User user, IEnumerable<Cipher> ciphers);
|
||||
Task CreateAsync(IEnumerable<Cipher> ciphers);
|
||||
}
|
||||
|
@ -85,6 +85,41 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateAsync(CipherDetails cipher)
|
||||
{
|
||||
cipher.SetNewId();
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[CipherDetails_Create]",
|
||||
cipher,
|
||||
commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ReplaceAsync(CipherDetails obj)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteAsync(
|
||||
$"[{Schema}].[CipherDetails_Update]",
|
||||
obj,
|
||||
commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpsertAsync(CipherDetails cipher)
|
||||
{
|
||||
if(cipher.Id.Equals(default(Guid)))
|
||||
{
|
||||
await CreateAsync(cipher);
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplaceAsync(cipher);
|
||||
}
|
||||
}
|
||||
|
||||
public Task UpdateUserEmailPasswordAndCiphersAsync(User user, IEnumerable<Cipher> ciphers)
|
||||
{
|
||||
if(ciphers.Count() == 0)
|
||||
|
@ -7,7 +7,7 @@ namespace Bit.Core.Services
|
||||
{
|
||||
public interface ICipherService
|
||||
{
|
||||
Task SaveAsync(Cipher cipher);
|
||||
Task SaveAsync(CipherDetails cipher);
|
||||
Task DeleteAsync(Cipher cipher);
|
||||
Task SaveFolderAsync(Folder folder);
|
||||
Task DeleteFolderAsync(Folder folder);
|
||||
|
@ -27,7 +27,7 @@ namespace Bit.Core.Services
|
||||
_pushService = pushService;
|
||||
}
|
||||
|
||||
public async Task SaveAsync(Cipher cipher)
|
||||
public async Task SaveAsync(CipherDetails cipher)
|
||||
{
|
||||
if(cipher.Id == default(Guid))
|
||||
{
|
||||
|
Reference in New Issue
Block a user