From 4b67ba027eb1f527f01ce5598e16d054290d33ab Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 15 Apr 2019 08:42:50 -0400 Subject: [PATCH] collection and folder models --- src/Core/Models/Domain/Collection.cs | 41 ++++++++++++++++++++++++++ src/Core/Models/Domain/Folder.cs | 32 ++++++++++++++++++++ src/Core/Models/View/CollectionView.cs | 19 ++++++++++-- src/Core/Models/View/FolderView.cs | 17 ++++++++--- 4 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 src/Core/Models/Domain/Collection.cs create mode 100644 src/Core/Models/Domain/Folder.cs diff --git a/src/Core/Models/Domain/Collection.cs b/src/Core/Models/Domain/Collection.cs new file mode 100644 index 000000000..b917c2207 --- /dev/null +++ b/src/Core/Models/Domain/Collection.cs @@ -0,0 +1,41 @@ +using Bit.Core.Models.Data; +using Bit.Core.Models.View; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Bit.Core.Models.Domain +{ + public class Collection : Domain + { + public Collection() { } + + public Collection(CollectionData obj, bool alreadyEncrypted = false) + { + BuildDomainModel(this, obj, new HashSet + { + "Id", + "OrganizationId", + "Name", + "ExternalId", + "ReadOnly" + }, alreadyEncrypted, new HashSet + { + "Id", + "OrganizationId", + "ExternalId", + "ReadOnly" + }); + } + + public string Id { get; set; } + public string OrganizationId { get; set; } + public CipherString Name { get; set; } + public string ExternalId { get; set; } + public bool ReadOnly { get; set; } + + public Task DecryptAsync(string orgId) + { + return DecryptObjAsync(new CollectionView(this), this, new HashSet { "Name" }, orgId); + } + } +} diff --git a/src/Core/Models/Domain/Folder.cs b/src/Core/Models/Domain/Folder.cs new file mode 100644 index 000000000..8bf6dd374 --- /dev/null +++ b/src/Core/Models/Domain/Folder.cs @@ -0,0 +1,32 @@ +using Bit.Core.Models.Data; +using Bit.Core.Models.View; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Bit.Core.Models.Domain +{ + public class Folder : Domain + { + public Folder() { } + + public Folder(FolderData obj, bool alreadyEncrypted = false) + { + BuildDomainModel(this, obj, new HashSet + { + "Id", + "Name" + }, alreadyEncrypted, new HashSet { "Id" }); + RevisionDate = obj.RevisionDate; + } + + public string Id { get; set; } + public CipherString Name { get; set; } + public DateTime RevisionDate { get; set; } + + public Task DecryptAsync(string orgId) + { + return DecryptObjAsync(new FolderView(this), this, new HashSet { "Name" }, orgId); + } + } +} diff --git a/src/Core/Models/View/CollectionView.cs b/src/Core/Models/View/CollectionView.cs index 177d4e3fb..4f90c20b8 100644 --- a/src/Core/Models/View/CollectionView.cs +++ b/src/Core/Models/View/CollectionView.cs @@ -1,10 +1,23 @@ -using System; +using Bit.Core.Models.Domain; namespace Bit.Core.Models.View { - public class CollectionView + public class CollectionView : View { - public Guid OrganizationId { get; set; } + public CollectionView() { } + + public CollectionView(Collection c) + { + Id = c.Id; + OrganizationId = c.OrganizationId; + ReadOnly = c.ReadOnly; + ExternalId = c.ExternalId; + } + + public string Id { get; set; } + public string OrganizationId { get; set; } public string Name { get; set; } + public string ExternalId { get; set; } + public bool ReadOnly { get; set; } } } diff --git a/src/Core/Models/View/FolderView.cs b/src/Core/Models/View/FolderView.cs index dadae8c95..c6adf5756 100644 --- a/src/Core/Models/View/FolderView.cs +++ b/src/Core/Models/View/FolderView.cs @@ -1,11 +1,20 @@ -using System; -using System.Collections.Generic; -using System.Text; +using Bit.Core.Models.Domain; +using System; namespace Bit.Core.Models.View { - public class FolderView + public class FolderView : View { + public FolderView() { } + + public FolderView(Folder f) + { + Id = f.Id; + RevisionDate = f.RevisionDate; + } + + public string Id { get; set; } public string Name { get; set; } + public DateTime RevisionDate { get; set; } } }