mirror of
https://github.com/bitwarden/mobile
synced 2025-12-29 22:53:34 +00:00
In-app vault export support (#729)
* First pass at vault export UI * Password validation via cryptoService * Export service framework * support for constructing json export data * Support for constructing csv export data * Cleanup and simplification * Completion of vault export feature * Formatting and simplification * Use dialog instead of toast for invalid master password entry
This commit is contained in:
97
src/Core/Models/Export/Cipher.cs
Normal file
97
src/Core/Models/Export/Cipher.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.View;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Core.Models.Export
|
||||
{
|
||||
public class Cipher
|
||||
{
|
||||
public Cipher() { }
|
||||
|
||||
public Cipher(CipherView obj)
|
||||
{
|
||||
OrganizationId = obj.OrganizationId;
|
||||
FolderId = obj.FolderId;
|
||||
Type = obj.Type;
|
||||
Name = obj.Name;
|
||||
Notes = obj.Notes;
|
||||
Favorite = obj.Favorite;
|
||||
|
||||
Fields = obj.Fields?.Select(f => new Field(f)).ToList();
|
||||
|
||||
switch(obj.Type)
|
||||
{
|
||||
case CipherType.Login:
|
||||
Login = new Login(obj.Login);
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
SecureNote = new SecureNote(obj.SecureNote);
|
||||
break;
|
||||
case CipherType.Card:
|
||||
Card = new Card(obj.Card);
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
Identity = new Identity(obj.Identity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public string OrganizationId { get; set; }
|
||||
public string FolderId { get; set; }
|
||||
public CipherType Type { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public bool Favorite { get; set; }
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public List<Field> Fields { get; set; }
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public Login Login { get; set; }
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public SecureNote SecureNote { get; set; }
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public Card Card { get; set; }
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public Identity Identity { get; set; }
|
||||
|
||||
public CipherView ToView(Cipher req, CipherView view = null)
|
||||
{
|
||||
if(view == null)
|
||||
{
|
||||
view = new CipherView();
|
||||
}
|
||||
|
||||
view.Type = req.Type;
|
||||
view.FolderId = req.FolderId;
|
||||
if(view.OrganizationId == null)
|
||||
{
|
||||
view.OrganizationId = req.OrganizationId;
|
||||
}
|
||||
|
||||
view.Name = req.Name;
|
||||
view.Notes = req.Notes;
|
||||
view.Favorite = req.Favorite;
|
||||
|
||||
view.Fields = req.Fields?.Select(f => Field.ToView(f)).ToList();
|
||||
|
||||
switch(req.Type)
|
||||
{
|
||||
case CipherType.Login:
|
||||
view.Login = Login.ToView(req.Login);
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
view.SecureNote = SecureNote.ToView(req.SecureNote);
|
||||
break;
|
||||
case CipherType.Card:
|
||||
view.Card = Card.ToView(req.Card);
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
view.Identity = Identity.ToView(req.Identity);
|
||||
break;
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user