From 18a86d3f12ac19e459c9cd3bb9123859d880e590 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 12 Jul 2017 15:16:36 -0400 Subject: [PATCH] model adjustments --- src/App/App.csproj | 5 +- src/App/Models/Api/LoginDataModel.cs | 1 + .../Models/Api/Response/AttachmentResponse.cs | 11 +++++ .../Api/Response/CipherHistoryResponse.cs | 10 ---- src/App/Models/Api/Response/CipherResponse.cs | 4 ++ src/App/Models/Api/Response/LoginResponse.cs | 5 ++ .../Response/ProfileOrganizationResponse.cs | 6 +++ .../Models/Api/Response/ProfileResponse.cs | 2 + src/App/Models/Attachment.cs | 40 ++++++++++++++++ src/App/Models/Cipher.cs | 10 ---- src/App/Models/Data/AttachmentData.cs | 47 +++++++++++++++++++ src/App/Models/Data/LoginData.cs | 12 +++++ src/App/Models/Folder.cs | 5 +- src/App/Models/Login.cs | 20 +++++++- 14 files changed, 153 insertions(+), 25 deletions(-) create mode 100644 src/App/Models/Api/Response/AttachmentResponse.cs delete mode 100644 src/App/Models/Api/Response/CipherHistoryResponse.cs create mode 100644 src/App/Models/Attachment.cs delete mode 100644 src/App/Models/Cipher.cs create mode 100644 src/App/Models/Data/AttachmentData.cs diff --git a/src/App/App.csproj b/src/App/App.csproj index 0d829ff2e..6b450e941 100644 --- a/src/App/App.csproj +++ b/src/App/App.csproj @@ -103,7 +103,7 @@ - + @@ -116,8 +116,9 @@ - + + diff --git a/src/App/Models/Api/LoginDataModel.cs b/src/App/Models/Api/LoginDataModel.cs index 1f9723f2a..2791257b1 100644 --- a/src/App/Models/Api/LoginDataModel.cs +++ b/src/App/Models/Api/LoginDataModel.cs @@ -7,5 +7,6 @@ public string Username { get; set; } public string Password { get; set; } public string Notes { get; set; } + public string Totp { get; set; } } } diff --git a/src/App/Models/Api/Response/AttachmentResponse.cs b/src/App/Models/Api/Response/AttachmentResponse.cs new file mode 100644 index 000000000..8695ec2f8 --- /dev/null +++ b/src/App/Models/Api/Response/AttachmentResponse.cs @@ -0,0 +1,11 @@ +namespace Bit.App.Models.Api +{ + public class AttachmentResponse + { + public string Id { get; set; } + public string Url { get; set; } + public string FileName { get; set; } + public string Size { get; set; } + public string SizeName { get; set; } + } +} diff --git a/src/App/Models/Api/Response/CipherHistoryResponse.cs b/src/App/Models/Api/Response/CipherHistoryResponse.cs deleted file mode 100644 index ef7bd4aa0..000000000 --- a/src/App/Models/Api/Response/CipherHistoryResponse.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; - -namespace Bit.App.Models.Api -{ - public class CipherHistoryResponse - { - public IEnumerable Revised { get; set; } - public IEnumerable Deleted { get; set; } - } -} diff --git a/src/App/Models/Api/Response/CipherResponse.cs b/src/App/Models/Api/Response/CipherResponse.cs index d198faa7e..6b420403d 100644 --- a/src/App/Models/Api/Response/CipherResponse.cs +++ b/src/App/Models/Api/Response/CipherResponse.cs @@ -1,6 +1,7 @@ using Bit.App.Enums; using System; using Newtonsoft.Json.Linq; +using System.Collections.Generic; namespace Bit.App.Models.Api { @@ -12,7 +13,10 @@ namespace Bit.App.Models.Api public string OrganizationId { get; set; } public CipherType Type { get; set; } public bool Favorite { get; set; } + public bool Edit { get; set; } + public bool OrganizationUseTotp { get; set; } public JObject Data { get; set; } + public IEnumerable Attachments { get; set; } public DateTime RevisionDate { get; set; } } } diff --git a/src/App/Models/Api/Response/LoginResponse.cs b/src/App/Models/Api/Response/LoginResponse.cs index 3ef616181..18a0cf20e 100644 --- a/src/App/Models/Api/Response/LoginResponse.cs +++ b/src/App/Models/Api/Response/LoginResponse.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace Bit.App.Models.Api { @@ -13,7 +14,11 @@ namespace Bit.App.Models.Api public string Username { get; set; } public string Password { get; set; } public string Notes { get; set; } + public string Totp { get; set; } public bool Favorite { get; set; } + public bool Edit { get; set; } + public bool OrganizationUseTotp { get; set; } + public IEnumerable Attachments { get; set; } public DateTime RevisionDate { get; set; } } } diff --git a/src/App/Models/Api/Response/ProfileOrganizationResponse.cs b/src/App/Models/Api/Response/ProfileOrganizationResponse.cs index 0d406931c..33f25c277 100644 --- a/src/App/Models/Api/Response/ProfileOrganizationResponse.cs +++ b/src/App/Models/Api/Response/ProfileOrganizationResponse.cs @@ -6,6 +6,12 @@ namespace Bit.App.Models.Api { public string Id { get; set; } public string Name { get; set; } + public bool UseGroups { get; set; } + public bool UseDirectory { get; set; } + public bool UseTotp { get; set; } + public int Seats { get; set; } + public int MaxCollections { get; set; } + public short? MaxStorageGb { get; set; } public string Key { get; set; } public OrganizationUserStatusType Status { get; set; } public OrganizationUserType Type { get; set; } diff --git a/src/App/Models/Api/Response/ProfileResponse.cs b/src/App/Models/Api/Response/ProfileResponse.cs index 7370d0e5b..257e9fad9 100644 --- a/src/App/Models/Api/Response/ProfileResponse.cs +++ b/src/App/Models/Api/Response/ProfileResponse.cs @@ -7,6 +7,8 @@ namespace Bit.App.Models.Api public string Id { get; set; } public string Name { get; set; } public string Email { get; set; } + public bool EmailVerified { get; set; } + public bool Premium { get; set; } public string MasterPasswordHint { get; set; } public string Culture { get; set; } public bool TwoFactorEnabled { get; set; } diff --git a/src/App/Models/Attachment.cs b/src/App/Models/Attachment.cs new file mode 100644 index 000000000..003bdeac3 --- /dev/null +++ b/src/App/Models/Attachment.cs @@ -0,0 +1,40 @@ +using Bit.App.Models.Api; +using Bit.App.Models.Data; + +namespace Bit.App.Models +{ + public class Attachment + { + public Attachment() + { } + + public Attachment(AttachmentData data) + { + Id = data.Id; + Url = data.Url; + FileName = data.FileName; + Size = data.Size; + SizeName = data.SizeName; + } + + public Attachment(AttachmentResponse response) + { + Id = response.Id; + Url = response.Url; + FileName = response.FileName; + Size = response.Size; + SizeName = response.SizeName; + } + + public string Id { get; set; } + public string Url { get; set; } + public string FileName { get; set; } + public string Size { get; set; } + public string SizeName { get; set; } + + public AttachmentData ToAttachmentData(string loginId) + { + return new AttachmentData(this, loginId); + } + } +} diff --git a/src/App/Models/Cipher.cs b/src/App/Models/Cipher.cs deleted file mode 100644 index 1d276ed6d..000000000 --- a/src/App/Models/Cipher.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace Bit.App.Models -{ - public abstract class Cipher - { - public string Id { get; set; } - public CipherString Name { get; set; } - } -} diff --git a/src/App/Models/Data/AttachmentData.cs b/src/App/Models/Data/AttachmentData.cs new file mode 100644 index 000000000..1e9f2d649 --- /dev/null +++ b/src/App/Models/Data/AttachmentData.cs @@ -0,0 +1,47 @@ +using SQLite; +using Bit.App.Abstractions; +using Bit.App.Models.Api; + +namespace Bit.App.Models.Data +{ + [Table("Attachment")] + public class AttachmentData : IDataObject + { + public AttachmentData() + { } + + public AttachmentData(Attachment attachment, string loginId) + { + Id = attachment.Id; + LoginId = loginId; + Url = attachment.Url; + FileName = attachment.FileName; + Size = attachment.Size; + SizeName = attachment.SizeName; + } + + public AttachmentData(AttachmentResponse response, string loginId) + { + Id = response.Id; + LoginId = loginId; + Url = response.Url; + FileName = response.FileName; + Size = response.Size; + SizeName = response.SizeName; + } + + [PrimaryKey] + public string Id { get; set; } + [Indexed] + public string LoginId { get; set; } + public string Url { get; set; } + public string FileName { get; set; } + public string Size { get; set; } + public string SizeName { get; set; } + + public Attachment ToAttachment() + { + return new Attachment(this); + } + } +} diff --git a/src/App/Models/Data/LoginData.cs b/src/App/Models/Data/LoginData.cs index d4fcf324a..688c13385 100644 --- a/src/App/Models/Data/LoginData.cs +++ b/src/App/Models/Data/LoginData.cs @@ -22,7 +22,10 @@ namespace Bit.App.Models.Data Username = login.Username?.EncryptedString; Password = login.Password?.EncryptedString; Notes = login.Notes?.EncryptedString; + Totp = login?.Notes?.EncryptedString; Favorite = login.Favorite; + Edit = login.Edit; + OrganizationUseTotp = login.OrganizationUseTotp; } public LoginData(LoginResponse login, string userId) @@ -36,8 +39,11 @@ namespace Bit.App.Models.Data Username = login.Username; Password = login.Password; Notes = login.Notes; + Totp = login.Totp; Favorite = login.Favorite; RevisionDateTime = login.RevisionDate; + Edit = login.Edit; + OrganizationUseTotp = login.OrganizationUseTotp; } public LoginData(CipherResponse cipher, string userId) @@ -58,7 +64,10 @@ namespace Bit.App.Models.Data Username = data.Username; Password = data.Password; Notes = data.Notes; + Totp = data.Totp; Favorite = cipher.Favorite; + Edit = cipher.Edit; + OrganizationUseTotp = cipher.OrganizationUseTotp; RevisionDateTime = cipher.RevisionDate; } @@ -73,7 +82,10 @@ namespace Bit.App.Models.Data public string Username { get; set; } public string Password { get; set; } public string Notes { get; set; } + public string Totp { get; set; } public bool Favorite { get; set; } + public bool Edit { get; set; } + public bool OrganizationUseTotp { get; set; } public DateTime RevisionDateTime { get; set; } = DateTime.UtcNow; public Login ToLogin() diff --git a/src/App/Models/Folder.cs b/src/App/Models/Folder.cs index c37d5258c..a40d00b37 100644 --- a/src/App/Models/Folder.cs +++ b/src/App/Models/Folder.cs @@ -3,7 +3,7 @@ using Bit.App.Models.Api; namespace Bit.App.Models { - public class Folder : Cipher + public class Folder { public Folder() { } @@ -20,6 +20,9 @@ namespace Bit.App.Models Name = response.Name != null ? new CipherString(response.Name) : null; } + public string Id { get; set; } + public CipherString Name { get; set; } + public FolderRequest ToFolderRequest() { return new FolderRequest(this); diff --git a/src/App/Models/Login.cs b/src/App/Models/Login.cs index 6d381aa6e..46f08a8aa 100644 --- a/src/App/Models/Login.cs +++ b/src/App/Models/Login.cs @@ -1,14 +1,16 @@ using Bit.App.Models.Api; using Bit.App.Models.Data; +using System.Collections.Generic; +using System.Linq; namespace Bit.App.Models { - public class Login : Cipher + public class Login { public Login() { } - public Login(LoginData data) + public Login(LoginData data, IEnumerable attachments = null) { Id = data.Id; UserId = data.UserId; @@ -19,7 +21,11 @@ namespace Bit.App.Models Username = data.Username != null ? new CipherString(data.Username) : null; Password = data.Password != null ? new CipherString(data.Password) : null; Notes = data.Notes != null ? new CipherString(data.Notes) : null; + Totp = data.Totp != null ? new CipherString(data.Totp) : null; Favorite = data.Favorite; + Edit = data.Edit; + OrganizationUseTotp = data.OrganizationUseTotp; + Attachments = attachments?.Select(a => new Attachment(a)); } public Login(LoginResponse response) @@ -33,17 +39,27 @@ namespace Bit.App.Models Username = response.Username != null ? new CipherString(response.Username) : null; Password = response.Password != null ? new CipherString(response.Password) : null; Notes = response.Notes != null ? new CipherString(response.Notes) : null; + Totp = response.Totp != null ? new CipherString(response.Totp) : null; Favorite = response.Favorite; + Edit = response.Edit; + OrganizationUseTotp = response.OrganizationUseTotp; + Attachments = response.Attachments?.Select(a => new Attachment(a)); } + public string Id { get; set; } public string UserId { get; set; } public string OrganizationId { get; set; } public string FolderId { get; set; } + public CipherString Name { get; set; } public CipherString Uri { get; set; } public CipherString Username { get; set; } public CipherString Password { get; set; } public CipherString Notes { get; set; } + public CipherString Totp { get; set; } public bool Favorite { get; set; } + public bool Edit { get; set; } + public bool OrganizationUseTotp { get; set; } + public IEnumerable Attachments { get; set; } public LoginRequest ToLoginRequest() {