mirror of
https://github.com/bitwarden/server.git
synced 2025-04-08 22:58:11 -05:00
stub out fields and secure note models
This commit is contained in:
parent
d2405bc1cc
commit
27216efd1f
@ -4,6 +4,7 @@
|
|||||||
{
|
{
|
||||||
// Folder is deprecated
|
// Folder is deprecated
|
||||||
Folder = 0,
|
Folder = 0,
|
||||||
Login = 1
|
Login = 1,
|
||||||
|
SecureNote = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
9
src/Core/Enums/FieldType.cs
Normal file
9
src/Core/Enums/FieldType.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace Bit.Core.Enums
|
||||||
|
{
|
||||||
|
public enum FieldType : byte
|
||||||
|
{
|
||||||
|
Text = 0,
|
||||||
|
Password = 1,
|
||||||
|
Boolean = 2
|
||||||
|
}
|
||||||
|
}
|
7
src/Core/Enums/SecureNoteType.cs
Normal file
7
src/Core/Enums/SecureNoteType.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace Bit.Core.Enums
|
||||||
|
{
|
||||||
|
public enum SecureNoteType : byte
|
||||||
|
{
|
||||||
|
Generic = 0
|
||||||
|
}
|
||||||
|
}
|
11
src/Core/Models/Api/CipherDataModel.cs
Normal file
11
src/Core/Models/Api/CipherDataModel.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Bit.Core.Models.Api
|
||||||
|
{
|
||||||
|
public abstract class CipherDataModel
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Notes { get; set; }
|
||||||
|
public IEnumerable<FieldDataModel> Fields { get; set; }
|
||||||
|
}
|
||||||
|
}
|
14
src/Core/Models/Api/FieldDataModel.cs
Normal file
14
src/Core/Models/Api/FieldDataModel.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Bit.Core.Enums;
|
||||||
|
|
||||||
|
namespace Bit.Core.Models.Api
|
||||||
|
{
|
||||||
|
public class FieldDataModel
|
||||||
|
{
|
||||||
|
public FieldType Type { get; set; }
|
||||||
|
[StringLength(1000)]
|
||||||
|
public string Name { get; set; }
|
||||||
|
[StringLength(1000)]
|
||||||
|
public string Value { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -4,27 +4,31 @@ using Newtonsoft.Json;
|
|||||||
|
|
||||||
namespace Bit.Core.Models.Api
|
namespace Bit.Core.Models.Api
|
||||||
{
|
{
|
||||||
public class LoginDataModel
|
public class LoginDataModel : CipherDataModel
|
||||||
{
|
{
|
||||||
public LoginDataModel() { }
|
public LoginDataModel() { }
|
||||||
|
|
||||||
public LoginDataModel(LoginRequestModel login)
|
public LoginDataModel(LoginRequestModel login)
|
||||||
{
|
{
|
||||||
Name = login.Name;
|
Name = login.Name;
|
||||||
|
Notes = login.Notes;
|
||||||
|
Fields = login.Fields;
|
||||||
|
|
||||||
Uri = login.Uri;
|
Uri = login.Uri;
|
||||||
Username = login.Username;
|
Username = login.Username;
|
||||||
Password = login.Password;
|
Password = login.Password;
|
||||||
Notes = login.Notes;
|
|
||||||
Totp = login.Totp;
|
Totp = login.Totp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LoginDataModel(CipherRequestModel cipher)
|
public LoginDataModel(CipherRequestModel cipher)
|
||||||
{
|
{
|
||||||
Name = cipher.Name;
|
Name = cipher.Name;
|
||||||
|
Notes = cipher.Notes;
|
||||||
|
Fields = cipher.Fields;
|
||||||
|
|
||||||
Uri = cipher.Uri;
|
Uri = cipher.Uri;
|
||||||
Username = cipher.Username;
|
Username = cipher.Username;
|
||||||
Password = cipher.Password;
|
Password = cipher.Password;
|
||||||
Notes = cipher.Notes;
|
|
||||||
Totp = cipher.Totp;
|
Totp = cipher.Totp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,18 +42,18 @@ namespace Bit.Core.Models.Api
|
|||||||
var data = JsonConvert.DeserializeObject<LoginDataModel>(cipher.Data);
|
var data = JsonConvert.DeserializeObject<LoginDataModel>(cipher.Data);
|
||||||
|
|
||||||
Name = data.Name;
|
Name = data.Name;
|
||||||
|
Notes = data.Notes;
|
||||||
|
Fields = data.Fields;
|
||||||
|
|
||||||
Uri = data.Uri;
|
Uri = data.Uri;
|
||||||
Username = data.Username;
|
Username = data.Username;
|
||||||
Password = data.Password;
|
Password = data.Password;
|
||||||
Notes = data.Notes;
|
|
||||||
Totp = data.Totp;
|
Totp = data.Totp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name { get; set; }
|
|
||||||
public string Uri { get; set; }
|
public string Uri { get; set; }
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
public string Notes { get; set; }
|
|
||||||
public string Totp { get; set; }
|
public string Totp { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,16 +37,8 @@ namespace Bit.Core.Models.Api
|
|||||||
[EncryptedString]
|
[EncryptedString]
|
||||||
[StringLength(1000)]
|
[StringLength(1000)]
|
||||||
public string Totp { get; set; }
|
public string Totp { get; set; }
|
||||||
|
public IEnumerable<FieldDataModel> Fields { get; set; }
|
||||||
public virtual Cipher ToCipher(Guid userId)
|
public Dictionary<string, string> Attachments { get; set; }
|
||||||
{
|
|
||||||
return ToCipher(new Cipher
|
|
||||||
{
|
|
||||||
Id = new Guid(Id),
|
|
||||||
UserId = string.IsNullOrWhiteSpace(OrganizationId) ? (Guid?)userId : null,
|
|
||||||
Type = Type
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual Cipher ToCipher(Cipher existingCipher)
|
public virtual Cipher ToCipher(Cipher existingCipher)
|
||||||
{
|
{
|
||||||
@ -60,29 +52,23 @@ namespace Bit.Core.Models.Api
|
|||||||
throw new ArgumentException("Unsupported " + nameof(Type) + ".");
|
throw new ArgumentException("Unsupported " + nameof(Type) + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
return existingCipher;
|
if((Attachments?.Count ?? 0) == 0)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CipherAttachmentRequestModel : CipherRequestModel
|
|
||||||
{
|
|
||||||
public Dictionary<string, string> Attachments { get; set; }
|
|
||||||
|
|
||||||
public override Cipher ToCipher(Cipher existingCipher)
|
|
||||||
{
|
|
||||||
base.ToCipher(existingCipher);
|
|
||||||
|
|
||||||
var attachments = existingCipher.GetAttachments();
|
|
||||||
if((Attachments?.Count ?? 0) > 0 && (attachments?.Count ?? 0) > 0)
|
|
||||||
{
|
{
|
||||||
foreach(var attachment in existingCipher.GetAttachments().Where(a => Attachments.ContainsKey(a.Key)))
|
return existingCipher;
|
||||||
{
|
|
||||||
attachment.Value.FileName = Attachments[attachment.Key];
|
|
||||||
}
|
|
||||||
|
|
||||||
existingCipher.SetAttachments(attachments);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var attachments = existingCipher.GetAttachments();
|
||||||
|
if((attachments?.Count ?? 0) == 0)
|
||||||
|
{
|
||||||
|
return existingCipher;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(var attachment in attachments.Where(a => Attachments.ContainsKey(a.Key)))
|
||||||
|
{
|
||||||
|
attachment.Value.FileName = Attachments[attachment.Key];
|
||||||
|
}
|
||||||
|
|
||||||
|
existingCipher.SetAttachments(attachments);
|
||||||
return existingCipher;
|
return existingCipher;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,7 +78,7 @@ namespace Bit.Core.Models.Api
|
|||||||
[Required]
|
[Required]
|
||||||
public IEnumerable<string> CollectionIds { get; set; }
|
public IEnumerable<string> CollectionIds { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public CipherAttachmentRequestModel Cipher { get; set; }
|
public CipherRequestModel Cipher { get; set; }
|
||||||
|
|
||||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||||
{
|
{
|
||||||
|
@ -4,6 +4,7 @@ using Bit.Core.Utilities;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Core.Models.Data;
|
using Core.Models.Data;
|
||||||
using Bit.Core.Models.Table;
|
using Bit.Core.Models.Table;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Bit.Core.Models.Api
|
namespace Bit.Core.Models.Api
|
||||||
{
|
{
|
||||||
@ -33,6 +34,7 @@ namespace Bit.Core.Models.Api
|
|||||||
[EncryptedString]
|
[EncryptedString]
|
||||||
[StringLength(1000)]
|
[StringLength(1000)]
|
||||||
public string Totp { get; set; }
|
public string Totp { get; set; }
|
||||||
|
public IEnumerable<FieldDataModel> Fields { get; set; }
|
||||||
|
|
||||||
public CipherDetails ToCipherDetails(Guid userId)
|
public CipherDetails ToCipherDetails(Guid userId)
|
||||||
{
|
{
|
||||||
|
30
src/Core/Models/Api/SecureNoteModel.cs
Normal file
30
src/Core/Models/Api/SecureNoteModel.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using Bit.Core.Enums;
|
||||||
|
using Bit.Core.Models.Table;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Bit.Core.Models.Api
|
||||||
|
{
|
||||||
|
public class SecureNoteDataModel : CipherDataModel
|
||||||
|
{
|
||||||
|
public SecureNoteDataModel() { }
|
||||||
|
|
||||||
|
public SecureNoteDataModel(Cipher cipher)
|
||||||
|
{
|
||||||
|
if(cipher.Type != CipherType.SecureNote)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Cipher is not correct type.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = JsonConvert.DeserializeObject<SecureNoteDataModel>(cipher.Data);
|
||||||
|
|
||||||
|
Name = data.Name;
|
||||||
|
Notes = data.Notes;
|
||||||
|
Fields = data.Fields;
|
||||||
|
|
||||||
|
Type = data.Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SecureNoteType Type { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user