2016-06-07 20:05:27 -04:00
|
|
|
|
using System;
|
2017-03-18 11:58:02 -04:00
|
|
|
|
using Core.Models.Data;
|
2017-03-21 00:04:39 -04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Bit.Core.Models.Table;
|
|
|
|
|
|
using System.Linq;
|
2016-06-07 20:05:27 -04:00
|
|
|
|
|
2017-03-08 21:55:08 -05:00
|
|
|
|
namespace Bit.Core.Models.Api
|
2016-06-07 20:05:27 -04:00
|
|
|
|
{
|
2017-04-17 17:01:23 -04:00
|
|
|
|
public class CipherMiniResponseModel : ResponseModel
|
2016-06-07 20:05:27 -04:00
|
|
|
|
{
|
2017-04-17 17:01:23 -04:00
|
|
|
|
public CipherMiniResponseModel(Cipher cipher, string obj = "cipherMini")
|
2017-03-18 11:58:02 -04:00
|
|
|
|
: base(obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(cipher == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new ArgumentNullException(nameof(cipher));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Id = cipher.Id.ToString();
|
|
|
|
|
|
Type = cipher.Type;
|
|
|
|
|
|
RevisionDate = cipher.RevisionDate;
|
2017-03-21 00:04:39 -04:00
|
|
|
|
OrganizationId = cipher.OrganizationId?.ToString();
|
2017-03-18 11:58:02 -04:00
|
|
|
|
|
|
|
|
|
|
switch(cipher.Type)
|
|
|
|
|
|
{
|
|
|
|
|
|
case Enums.CipherType.Login:
|
2017-01-02 21:52:13 -05:00
|
|
|
|
Data = new LoginDataModel(cipher);
|
2016-06-08 22:00:31 -04:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new ArgumentException("Unsupported " + nameof(Type) + ".");
|
|
|
|
|
|
}
|
2016-06-07 20:05:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-19 16:47:12 -04:00
|
|
|
|
[Obsolete]
|
|
|
|
|
|
public CipherMiniResponseModel(Folder folder, string obj = "cipherMini")
|
|
|
|
|
|
: base(obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(folder == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new ArgumentNullException(nameof(folder));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Id = folder.Id.ToString();
|
|
|
|
|
|
Type = Enums.CipherType.Folder;
|
|
|
|
|
|
RevisionDate = folder.RevisionDate;
|
|
|
|
|
|
Data = new FolderDataModel(folder);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-07 20:05:27 -04:00
|
|
|
|
public string Id { get; set; }
|
2017-03-21 00:04:39 -04:00
|
|
|
|
public string OrganizationId { get; set; }
|
2017-03-18 11:58:02 -04:00
|
|
|
|
public Enums.CipherType Type { get; set; }
|
2016-06-08 22:00:31 -04:00
|
|
|
|
public dynamic Data { get; set; }
|
|
|
|
|
|
public DateTime RevisionDate { get; set; }
|
2016-06-07 20:05:27 -04:00
|
|
|
|
}
|
2017-03-21 00:04:39 -04:00
|
|
|
|
|
2017-04-17 17:01:23 -04:00
|
|
|
|
public class CipherResponseModel : CipherMiniResponseModel
|
|
|
|
|
|
{
|
|
|
|
|
|
public CipherResponseModel(CipherDetails cipher, string obj = "cipher")
|
|
|
|
|
|
: base(cipher, obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
FolderId = cipher.FolderId?.ToString();
|
|
|
|
|
|
Favorite = cipher.Favorite;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-19 16:47:12 -04:00
|
|
|
|
[Obsolete]
|
|
|
|
|
|
public CipherResponseModel(Folder folder, string obj = "cipher")
|
|
|
|
|
|
: base(folder, obj)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
2017-04-17 17:01:23 -04:00
|
|
|
|
public string FolderId { get; set; }
|
|
|
|
|
|
public bool Favorite { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-03-21 00:04:39 -04:00
|
|
|
|
public class CipherDetailsResponseModel : CipherResponseModel
|
|
|
|
|
|
{
|
2017-03-24 09:42:06 -04:00
|
|
|
|
public CipherDetailsResponseModel(CipherDetails cipher,
|
2017-04-27 09:19:30 -04:00
|
|
|
|
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphers, string obj = "cipherDetails")
|
2017-04-04 17:22:47 -04:00
|
|
|
|
: base(cipher, obj)
|
2017-03-21 00:04:39 -04:00
|
|
|
|
{
|
2017-04-27 09:19:30 -04:00
|
|
|
|
if(collectionCiphers.ContainsKey(cipher.Id))
|
2017-03-24 09:42:06 -04:00
|
|
|
|
{
|
2017-04-27 09:39:21 -04:00
|
|
|
|
CollectionIds = collectionCiphers[cipher.Id].Select(c => c.CollectionId);
|
2017-03-24 09:42:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-04-27 09:19:30 -04:00
|
|
|
|
CollectionIds = new Guid[] { };
|
2017-03-24 09:42:06 -04:00
|
|
|
|
}
|
2017-03-21 00:04:39 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-27 09:19:30 -04:00
|
|
|
|
public CipherDetailsResponseModel(CipherDetails cipher, IEnumerable<CollectionCipher> collectionCiphers,
|
2017-04-04 17:22:47 -04:00
|
|
|
|
string obj = "cipherDetails")
|
|
|
|
|
|
: base(cipher, obj)
|
|
|
|
|
|
{
|
2017-04-27 09:39:21 -04:00
|
|
|
|
CollectionIds = collectionCiphers.Select(c => c.CollectionId);
|
2017-04-04 17:22:47 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-27 09:19:30 -04:00
|
|
|
|
public IEnumerable<Guid> CollectionIds { get; set; }
|
2017-03-21 00:04:39 -04:00
|
|
|
|
}
|
2017-04-04 17:22:47 -04:00
|
|
|
|
|
2017-04-17 17:01:23 -04:00
|
|
|
|
public class CipherMiniDetailsResponseModel : CipherMiniResponseModel
|
|
|
|
|
|
{
|
|
|
|
|
|
public CipherMiniDetailsResponseModel(Cipher cipher,
|
2017-04-27 09:19:30 -04:00
|
|
|
|
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphers, string obj = "cipherMiniDetails")
|
2017-04-17 17:01:23 -04:00
|
|
|
|
: base(cipher, obj)
|
|
|
|
|
|
{
|
2017-04-27 09:19:30 -04:00
|
|
|
|
if(collectionCiphers.ContainsKey(cipher.Id))
|
2017-04-17 17:01:23 -04:00
|
|
|
|
{
|
2017-04-27 09:39:21 -04:00
|
|
|
|
CollectionIds = collectionCiphers[cipher.Id].Select(c => c.CollectionId);
|
2017-04-17 17:01:23 -04:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-04-27 09:19:30 -04:00
|
|
|
|
CollectionIds = new Guid[] { };
|
2017-04-17 17:01:23 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-27 09:19:30 -04:00
|
|
|
|
public IEnumerable<Guid> CollectionIds { get; set; }
|
2017-04-17 17:01:23 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-04 17:22:47 -04:00
|
|
|
|
public class CipherFullDetailsResponseModel : CipherDetailsResponseModel
|
|
|
|
|
|
{
|
2017-04-27 09:19:30 -04:00
|
|
|
|
public CipherFullDetailsResponseModel(CipherFullDetails cipher, IEnumerable<CollectionCipher> collectionCiphers)
|
|
|
|
|
|
: base(cipher, collectionCiphers, "cipherFullDetails")
|
2017-04-04 17:22:47 -04:00
|
|
|
|
{
|
|
|
|
|
|
Edit = cipher.Edit;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool Edit { get; set; }
|
|
|
|
|
|
}
|
2016-06-07 20:05:27 -04:00
|
|
|
|
}
|