1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-05 18:12:48 -05:00

Run formatting (#2230)

This commit is contained in:
Justin Baur
2022-08-29 16:06:55 -04:00
committed by GitHub
parent 9b7aef0763
commit 7f5f010e1e
1205 changed files with 73813 additions and 75022 deletions

View File

@ -1,33 +1,32 @@
using Bit.Core.Entities;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class ApiKeyResponseModel : ResponseModel
{
public class ApiKeyResponseModel : ResponseModel
public ApiKeyResponseModel(OrganizationApiKey organizationApiKey, string obj = "apiKey")
: base(obj)
{
public ApiKeyResponseModel(OrganizationApiKey organizationApiKey, string obj = "apiKey")
: base(obj)
if (organizationApiKey == null)
{
if (organizationApiKey == null)
{
throw new ArgumentNullException(nameof(organizationApiKey));
}
ApiKey = organizationApiKey.ApiKey;
RevisionDate = organizationApiKey.RevisionDate;
throw new ArgumentNullException(nameof(organizationApiKey));
}
public ApiKeyResponseModel(User user, string obj = "apiKey")
: base(obj)
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
ApiKey = user.ApiKey;
RevisionDate = user.RevisionDate;
}
public string ApiKey { get; set; }
public DateTime RevisionDate { get; set; }
ApiKey = organizationApiKey.ApiKey;
RevisionDate = organizationApiKey.RevisionDate;
}
public ApiKeyResponseModel(User user, string obj = "apiKey")
: base(obj)
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
ApiKey = user.ApiKey;
RevisionDate = user.RevisionDate;
}
public string ApiKey { get; set; }
public DateTime RevisionDate { get; set; }
}

View File

@ -5,49 +5,48 @@ using Bit.Core.Models.Data;
using Bit.Core.Settings;
using Bit.Core.Utilities;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class AttachmentResponseModel : ResponseModel
{
public class AttachmentResponseModel : ResponseModel
public AttachmentResponseModel(AttachmentResponseData data) : base("attachment")
{
public AttachmentResponseModel(AttachmentResponseData data) : base("attachment")
Id = data.Id;
Url = data.Url;
FileName = data.Data.FileName;
Key = data.Data.Key;
Size = data.Data.Size;
SizeName = CoreHelpers.ReadableBytesSize(data.Data.Size);
}
public AttachmentResponseModel(string id, CipherAttachment.MetaData data, Cipher cipher,
IGlobalSettings globalSettings)
: base("attachment")
{
Id = id;
Url = $"{globalSettings.Attachment.BaseUrl}/{cipher.Id}/{id}";
FileName = data.FileName;
Key = data.Key;
Size = data.Size;
SizeName = CoreHelpers.ReadableBytesSize(data.Size);
}
public string Id { get; set; }
public string Url { get; set; }
public string FileName { get; set; }
public string Key { get; set; }
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)]
public long Size { get; set; }
public string SizeName { get; set; }
public static IEnumerable<AttachmentResponseModel> FromCipher(Cipher cipher, IGlobalSettings globalSettings)
{
var attachments = cipher.GetAttachments();
if (attachments == null)
{
Id = data.Id;
Url = data.Url;
FileName = data.Data.FileName;
Key = data.Data.Key;
Size = data.Data.Size;
SizeName = CoreHelpers.ReadableBytesSize(data.Data.Size);
return null;
}
public AttachmentResponseModel(string id, CipherAttachment.MetaData data, Cipher cipher,
IGlobalSettings globalSettings)
: base("attachment")
{
Id = id;
Url = $"{globalSettings.Attachment.BaseUrl}/{cipher.Id}/{id}";
FileName = data.FileName;
Key = data.Key;
Size = data.Size;
SizeName = CoreHelpers.ReadableBytesSize(data.Size);
}
public string Id { get; set; }
public string Url { get; set; }
public string FileName { get; set; }
public string Key { get; set; }
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)]
public long Size { get; set; }
public string SizeName { get; set; }
public static IEnumerable<AttachmentResponseModel> FromCipher(Cipher cipher, IGlobalSettings globalSettings)
{
var attachments = cipher.GetAttachments();
if (attachments == null)
{
return null;
}
return attachments.Select(a => new AttachmentResponseModel(a.Key, a.Value, cipher, globalSettings));
}
return attachments.Select(a => new AttachmentResponseModel(a.Key, a.Value, cipher, globalSettings));
}
}

View File

@ -1,16 +1,15 @@
using Bit.Core.Enums;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response
{
public class AttachmentUploadDataResponseModel : ResponseModel
{
public string AttachmentId { get; set; }
public string Url { get; set; }
public FileUploadType FileUploadType { get; set; }
public CipherResponseModel CipherResponse { get; set; }
public CipherMiniResponseModel CipherMiniResponse { get; set; }
namespace Bit.Api.Models.Response;
public AttachmentUploadDataResponseModel() : base("attachment-fileUpload") { }
}
public class AttachmentUploadDataResponseModel : ResponseModel
{
public string AttachmentId { get; set; }
public string Url { get; set; }
public FileUploadType FileUploadType { get; set; }
public CipherResponseModel CipherResponse { get; set; }
public CipherMiniResponseModel CipherMiniResponse { get; set; }
public AttachmentUploadDataResponseModel() : base("attachment-fileUpload") { }
}

View File

@ -1,17 +1,16 @@
using Bit.Core.Models.Api;
using Bit.Core.Models.Business;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class BillingHistoryResponseModel : ResponseModel
{
public class BillingHistoryResponseModel : ResponseModel
public BillingHistoryResponseModel(BillingInfo billing)
: base("billingHistory")
{
public BillingHistoryResponseModel(BillingInfo billing)
: base("billingHistory")
{
Transactions = billing.Transactions?.Select(t => new BillingTransaction(t));
Invoices = billing.Invoices?.Select(i => new BillingInvoice(i));
}
public IEnumerable<BillingInvoice> Invoices { get; set; }
public IEnumerable<BillingTransaction> Transactions { get; set; }
Transactions = billing.Transactions?.Select(t => new BillingTransaction(t));
Invoices = billing.Invoices?.Select(i => new BillingInvoice(i));
}
public IEnumerable<BillingInvoice> Invoices { get; set; }
public IEnumerable<BillingTransaction> Transactions { get; set; }
}

View File

@ -1,18 +1,17 @@
using Bit.Core.Models.Api;
using Bit.Core.Models.Business;
namespace Bit.Api.Models.Response
{
public class BillingPaymentResponseModel : ResponseModel
{
public BillingPaymentResponseModel(BillingInfo billing)
: base("billingPayment")
{
Balance = billing.Balance;
PaymentSource = billing.PaymentSource != null ? new BillingSource(billing.PaymentSource) : null;
}
namespace Bit.Api.Models.Response;
public decimal Balance { get; set; }
public BillingSource PaymentSource { get; set; }
public class BillingPaymentResponseModel : ResponseModel
{
public BillingPaymentResponseModel(BillingInfo billing)
: base("billingPayment")
{
Balance = billing.Balance;
PaymentSource = billing.PaymentSource != null ? new BillingSource(billing.PaymentSource) : null;
}
public decimal Balance { get; set; }
public BillingSource PaymentSource { get; set; }
}

View File

@ -2,82 +2,81 @@
using Bit.Core.Models.Api;
using Bit.Core.Models.Business;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class BillingResponseModel : ResponseModel
{
public class BillingResponseModel : ResponseModel
public BillingResponseModel(BillingInfo billing)
: base("billing")
{
public BillingResponseModel(BillingInfo billing)
: base("billing")
{
Balance = billing.Balance;
PaymentSource = billing.PaymentSource != null ? new BillingSource(billing.PaymentSource) : null;
Transactions = billing.Transactions?.Select(t => new BillingTransaction(t));
Invoices = billing.Invoices?.Select(i => new BillingInvoice(i));
}
public decimal Balance { get; set; }
public BillingSource PaymentSource { get; set; }
public IEnumerable<BillingInvoice> Invoices { get; set; }
public IEnumerable<BillingTransaction> Transactions { get; set; }
Balance = billing.Balance;
PaymentSource = billing.PaymentSource != null ? new BillingSource(billing.PaymentSource) : null;
Transactions = billing.Transactions?.Select(t => new BillingTransaction(t));
Invoices = billing.Invoices?.Select(i => new BillingInvoice(i));
}
public class BillingSource
{
public BillingSource(BillingInfo.BillingSource source)
{
Type = source.Type;
CardBrand = source.CardBrand;
Description = source.Description;
NeedsVerification = source.NeedsVerification;
}
public PaymentMethodType Type { get; set; }
public string CardBrand { get; set; }
public string Description { get; set; }
public bool NeedsVerification { get; set; }
}
public class BillingInvoice
{
public BillingInvoice(BillingInfo.BillingInvoice inv)
{
Amount = inv.Amount;
Date = inv.Date;
Url = inv.Url;
PdfUrl = inv.PdfUrl;
Number = inv.Number;
Paid = inv.Paid;
}
public decimal Amount { get; set; }
public DateTime? Date { get; set; }
public string Url { get; set; }
public string PdfUrl { get; set; }
public string Number { get; set; }
public bool Paid { get; set; }
}
public class BillingTransaction
{
public BillingTransaction(BillingInfo.BillingTransaction transaction)
{
CreatedDate = transaction.CreatedDate;
Amount = transaction.Amount;
Refunded = transaction.Refunded;
RefundedAmount = transaction.RefundedAmount;
PartiallyRefunded = transaction.PartiallyRefunded;
Type = transaction.Type;
PaymentMethodType = transaction.PaymentMethodType;
Details = transaction.Details;
}
public DateTime CreatedDate { get; set; }
public decimal Amount { get; set; }
public bool? Refunded { get; set; }
public bool? PartiallyRefunded { get; set; }
public decimal? RefundedAmount { get; set; }
public TransactionType Type { get; set; }
public PaymentMethodType? PaymentMethodType { get; set; }
public string Details { get; set; }
}
public decimal Balance { get; set; }
public BillingSource PaymentSource { get; set; }
public IEnumerable<BillingInvoice> Invoices { get; set; }
public IEnumerable<BillingTransaction> Transactions { get; set; }
}
public class BillingSource
{
public BillingSource(BillingInfo.BillingSource source)
{
Type = source.Type;
CardBrand = source.CardBrand;
Description = source.Description;
NeedsVerification = source.NeedsVerification;
}
public PaymentMethodType Type { get; set; }
public string CardBrand { get; set; }
public string Description { get; set; }
public bool NeedsVerification { get; set; }
}
public class BillingInvoice
{
public BillingInvoice(BillingInfo.BillingInvoice inv)
{
Amount = inv.Amount;
Date = inv.Date;
Url = inv.Url;
PdfUrl = inv.PdfUrl;
Number = inv.Number;
Paid = inv.Paid;
}
public decimal Amount { get; set; }
public DateTime? Date { get; set; }
public string Url { get; set; }
public string PdfUrl { get; set; }
public string Number { get; set; }
public bool Paid { get; set; }
}
public class BillingTransaction
{
public BillingTransaction(BillingInfo.BillingTransaction transaction)
{
CreatedDate = transaction.CreatedDate;
Amount = transaction.Amount;
Refunded = transaction.Refunded;
RefundedAmount = transaction.RefundedAmount;
PartiallyRefunded = transaction.PartiallyRefunded;
Type = transaction.Type;
PaymentMethodType = transaction.PaymentMethodType;
Details = transaction.Details;
}
public DateTime CreatedDate { get; set; }
public decimal Amount { get; set; }
public bool? Refunded { get; set; }
public bool? PartiallyRefunded { get; set; }
public decimal? RefundedAmount { get; set; }
public TransactionType Type { get; set; }
public PaymentMethodType? PaymentMethodType { get; set; }
public string Details { get; set; }
}

View File

@ -6,142 +6,141 @@ using Bit.Core.Models.Data;
using Bit.Core.Settings;
using Core.Models.Data;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class CipherMiniResponseModel : ResponseModel
{
public class CipherMiniResponseModel : ResponseModel
public CipherMiniResponseModel(Cipher cipher, IGlobalSettings globalSettings, bool orgUseTotp, string obj = "cipherMini")
: base(obj)
{
public CipherMiniResponseModel(Cipher cipher, IGlobalSettings globalSettings, bool orgUseTotp, string obj = "cipherMini")
: base(obj)
if (cipher == null)
{
if (cipher == null)
{
throw new ArgumentNullException(nameof(cipher));
}
Id = cipher.Id.ToString();
Type = cipher.Type;
CipherData cipherData;
switch (cipher.Type)
{
case CipherType.Login:
var loginData = JsonSerializer.Deserialize<CipherLoginData>(cipher.Data);
cipherData = loginData;
Data = loginData;
Login = new CipherLoginModel(loginData);
break;
case CipherType.SecureNote:
var secureNoteData = JsonSerializer.Deserialize<CipherSecureNoteData>(cipher.Data);
Data = secureNoteData;
cipherData = secureNoteData;
SecureNote = new CipherSecureNoteModel(secureNoteData);
break;
case CipherType.Card:
var cardData = JsonSerializer.Deserialize<CipherCardData>(cipher.Data);
Data = cardData;
cipherData = cardData;
Card = new CipherCardModel(cardData);
break;
case CipherType.Identity:
var identityData = JsonSerializer.Deserialize<CipherIdentityData>(cipher.Data);
Data = identityData;
cipherData = identityData;
Identity = new CipherIdentityModel(identityData);
break;
default:
throw new ArgumentException("Unsupported " + nameof(Type) + ".");
}
Name = cipherData.Name;
Notes = cipherData.Notes;
Fields = cipherData.Fields?.Select(f => new CipherFieldModel(f));
PasswordHistory = cipherData.PasswordHistory?.Select(ph => new CipherPasswordHistoryModel(ph));
RevisionDate = cipher.RevisionDate;
OrganizationId = cipher.OrganizationId?.ToString();
Attachments = AttachmentResponseModel.FromCipher(cipher, globalSettings);
OrganizationUseTotp = orgUseTotp;
DeletedDate = cipher.DeletedDate;
Reprompt = cipher.Reprompt.GetValueOrDefault(CipherRepromptType.None);
throw new ArgumentNullException(nameof(cipher));
}
public string Id { get; set; }
public string OrganizationId { get; set; }
public CipherType Type { get; set; }
public dynamic Data { get; set; }
public string Name { get; set; }
public string Notes { get; set; }
public CipherLoginModel Login { get; set; }
public CipherCardModel Card { get; set; }
public CipherIdentityModel Identity { get; set; }
public CipherSecureNoteModel SecureNote { get; set; }
public IEnumerable<CipherFieldModel> Fields { get; set; }
public IEnumerable<CipherPasswordHistoryModel> PasswordHistory { get; set; }
public IEnumerable<AttachmentResponseModel> Attachments { get; set; }
public bool OrganizationUseTotp { get; set; }
public DateTime RevisionDate { get; set; }
public DateTime? DeletedDate { get; set; }
public CipherRepromptType Reprompt { get; set; }
Id = cipher.Id.ToString();
Type = cipher.Type;
CipherData cipherData;
switch (cipher.Type)
{
case CipherType.Login:
var loginData = JsonSerializer.Deserialize<CipherLoginData>(cipher.Data);
cipherData = loginData;
Data = loginData;
Login = new CipherLoginModel(loginData);
break;
case CipherType.SecureNote:
var secureNoteData = JsonSerializer.Deserialize<CipherSecureNoteData>(cipher.Data);
Data = secureNoteData;
cipherData = secureNoteData;
SecureNote = new CipherSecureNoteModel(secureNoteData);
break;
case CipherType.Card:
var cardData = JsonSerializer.Deserialize<CipherCardData>(cipher.Data);
Data = cardData;
cipherData = cardData;
Card = new CipherCardModel(cardData);
break;
case CipherType.Identity:
var identityData = JsonSerializer.Deserialize<CipherIdentityData>(cipher.Data);
Data = identityData;
cipherData = identityData;
Identity = new CipherIdentityModel(identityData);
break;
default:
throw new ArgumentException("Unsupported " + nameof(Type) + ".");
}
Name = cipherData.Name;
Notes = cipherData.Notes;
Fields = cipherData.Fields?.Select(f => new CipherFieldModel(f));
PasswordHistory = cipherData.PasswordHistory?.Select(ph => new CipherPasswordHistoryModel(ph));
RevisionDate = cipher.RevisionDate;
OrganizationId = cipher.OrganizationId?.ToString();
Attachments = AttachmentResponseModel.FromCipher(cipher, globalSettings);
OrganizationUseTotp = orgUseTotp;
DeletedDate = cipher.DeletedDate;
Reprompt = cipher.Reprompt.GetValueOrDefault(CipherRepromptType.None);
}
public class CipherResponseModel : CipherMiniResponseModel
{
public CipherResponseModel(CipherDetails cipher, IGlobalSettings globalSettings, string obj = "cipher")
: base(cipher, globalSettings, cipher.OrganizationUseTotp, obj)
{
FolderId = cipher.FolderId?.ToString();
Favorite = cipher.Favorite;
Edit = cipher.Edit;
ViewPassword = cipher.ViewPassword;
}
public string FolderId { get; set; }
public bool Favorite { get; set; }
public bool Edit { get; set; }
public bool ViewPassword { get; set; }
}
public class CipherDetailsResponseModel : CipherResponseModel
{
public CipherDetailsResponseModel(CipherDetails cipher, GlobalSettings globalSettings,
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphers, string obj = "cipherDetails")
: base(cipher, globalSettings, obj)
{
if (collectionCiphers?.ContainsKey(cipher.Id) ?? false)
{
CollectionIds = collectionCiphers[cipher.Id].Select(c => c.CollectionId);
}
else
{
CollectionIds = new Guid[] { };
}
}
public CipherDetailsResponseModel(CipherDetails cipher, GlobalSettings globalSettings,
IEnumerable<CollectionCipher> collectionCiphers, string obj = "cipherDetails")
: base(cipher, globalSettings, obj)
{
CollectionIds = collectionCiphers?.Select(c => c.CollectionId) ?? new List<Guid>();
}
public IEnumerable<Guid> CollectionIds { get; set; }
}
public class CipherMiniDetailsResponseModel : CipherMiniResponseModel
{
public CipherMiniDetailsResponseModel(Cipher cipher, GlobalSettings globalSettings,
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphers, bool orgUseTotp, string obj = "cipherMiniDetails")
: base(cipher, globalSettings, orgUseTotp, obj)
{
if (collectionCiphers?.ContainsKey(cipher.Id) ?? false)
{
CollectionIds = collectionCiphers[cipher.Id].Select(c => c.CollectionId);
}
else
{
CollectionIds = new Guid[] { };
}
}
public IEnumerable<Guid> CollectionIds { get; set; }
}
public string Id { get; set; }
public string OrganizationId { get; set; }
public CipherType Type { get; set; }
public dynamic Data { get; set; }
public string Name { get; set; }
public string Notes { get; set; }
public CipherLoginModel Login { get; set; }
public CipherCardModel Card { get; set; }
public CipherIdentityModel Identity { get; set; }
public CipherSecureNoteModel SecureNote { get; set; }
public IEnumerable<CipherFieldModel> Fields { get; set; }
public IEnumerable<CipherPasswordHistoryModel> PasswordHistory { get; set; }
public IEnumerable<AttachmentResponseModel> Attachments { get; set; }
public bool OrganizationUseTotp { get; set; }
public DateTime RevisionDate { get; set; }
public DateTime? DeletedDate { get; set; }
public CipherRepromptType Reprompt { get; set; }
}
public class CipherResponseModel : CipherMiniResponseModel
{
public CipherResponseModel(CipherDetails cipher, IGlobalSettings globalSettings, string obj = "cipher")
: base(cipher, globalSettings, cipher.OrganizationUseTotp, obj)
{
FolderId = cipher.FolderId?.ToString();
Favorite = cipher.Favorite;
Edit = cipher.Edit;
ViewPassword = cipher.ViewPassword;
}
public string FolderId { get; set; }
public bool Favorite { get; set; }
public bool Edit { get; set; }
public bool ViewPassword { get; set; }
}
public class CipherDetailsResponseModel : CipherResponseModel
{
public CipherDetailsResponseModel(CipherDetails cipher, GlobalSettings globalSettings,
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphers, string obj = "cipherDetails")
: base(cipher, globalSettings, obj)
{
if (collectionCiphers?.ContainsKey(cipher.Id) ?? false)
{
CollectionIds = collectionCiphers[cipher.Id].Select(c => c.CollectionId);
}
else
{
CollectionIds = new Guid[] { };
}
}
public CipherDetailsResponseModel(CipherDetails cipher, GlobalSettings globalSettings,
IEnumerable<CollectionCipher> collectionCiphers, string obj = "cipherDetails")
: base(cipher, globalSettings, obj)
{
CollectionIds = collectionCiphers?.Select(c => c.CollectionId) ?? new List<Guid>();
}
public IEnumerable<Guid> CollectionIds { get; set; }
}
public class CipherMiniDetailsResponseModel : CipherMiniResponseModel
{
public CipherMiniDetailsResponseModel(Cipher cipher, GlobalSettings globalSettings,
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphers, bool orgUseTotp, string obj = "cipherMiniDetails")
: base(cipher, globalSettings, orgUseTotp, obj)
{
if (collectionCiphers?.ContainsKey(cipher.Id) ?? false)
{
CollectionIds = collectionCiphers[cipher.Id].Select(c => c.CollectionId);
}
else
{
CollectionIds = new Guid[] { };
}
}
public IEnumerable<Guid> CollectionIds { get; set; }
}

View File

@ -2,51 +2,50 @@
using Bit.Core.Models.Api;
using Bit.Core.Models.Data;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class CollectionResponseModel : ResponseModel
{
public class CollectionResponseModel : ResponseModel
public CollectionResponseModel(Collection collection, string obj = "collection")
: base(obj)
{
public CollectionResponseModel(Collection collection, string obj = "collection")
: base(obj)
if (collection == null)
{
if (collection == null)
{
throw new ArgumentNullException(nameof(collection));
}
Id = collection.Id.ToString();
OrganizationId = collection.OrganizationId.ToString();
Name = collection.Name;
ExternalId = collection.ExternalId;
throw new ArgumentNullException(nameof(collection));
}
public string Id { get; set; }
public string OrganizationId { get; set; }
public string Name { get; set; }
public string ExternalId { get; set; }
Id = collection.Id.ToString();
OrganizationId = collection.OrganizationId.ToString();
Name = collection.Name;
ExternalId = collection.ExternalId;
}
public class CollectionDetailsResponseModel : CollectionResponseModel
{
public CollectionDetailsResponseModel(CollectionDetails collectionDetails)
: base(collectionDetails, "collectionDetails")
{
ReadOnly = collectionDetails.ReadOnly;
HidePasswords = collectionDetails.HidePasswords;
}
public bool ReadOnly { get; set; }
public bool HidePasswords { get; set; }
}
public class CollectionGroupDetailsResponseModel : CollectionResponseModel
{
public CollectionGroupDetailsResponseModel(Collection collection, IEnumerable<SelectionReadOnly> groups)
: base(collection, "collectionGroupDetails")
{
Groups = groups.Select(g => new SelectionReadOnlyResponseModel(g));
}
public IEnumerable<SelectionReadOnlyResponseModel> Groups { get; set; }
}
public string Id { get; set; }
public string OrganizationId { get; set; }
public string Name { get; set; }
public string ExternalId { get; set; }
}
public class CollectionDetailsResponseModel : CollectionResponseModel
{
public CollectionDetailsResponseModel(CollectionDetails collectionDetails)
: base(collectionDetails, "collectionDetails")
{
ReadOnly = collectionDetails.ReadOnly;
HidePasswords = collectionDetails.HidePasswords;
}
public bool ReadOnly { get; set; }
public bool HidePasswords { get; set; }
}
public class CollectionGroupDetailsResponseModel : CollectionResponseModel
{
public CollectionGroupDetailsResponseModel(Collection collection, IEnumerable<SelectionReadOnly> groups)
: base(collection, "collectionGroupDetails")
{
Groups = groups.Select(g => new SelectionReadOnlyResponseModel(g));
}
public IEnumerable<SelectionReadOnlyResponseModel> Groups { get; set; }
}

View File

@ -2,29 +2,28 @@
using Bit.Core.Enums;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response
{
public class DeviceResponseModel : ResponseModel
{
public DeviceResponseModel(Device device)
: base("device")
{
if (device == null)
{
throw new ArgumentNullException(nameof(device));
}
namespace Bit.Api.Models.Response;
Id = device.Id.ToString();
Name = device.Name;
Type = device.Type;
Identifier = device.Identifier;
CreationDate = device.CreationDate;
public class DeviceResponseModel : ResponseModel
{
public DeviceResponseModel(Device device)
: base("device")
{
if (device == null)
{
throw new ArgumentNullException(nameof(device));
}
public string Id { get; set; }
public string Name { get; set; }
public DeviceType Type { get; set; }
public string Identifier { get; set; }
public DateTime CreationDate { get; set; }
Id = device.Id.ToString();
Name = device.Name;
Type = device.Type;
Identifier = device.Identifier;
CreationDate = device.CreationDate;
}
public string Id { get; set; }
public string Name { get; set; }
public DeviceType Type { get; set; }
public string Identifier { get; set; }
public DateTime CreationDate { get; set; }
}

View File

@ -1,17 +1,16 @@
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response
{
public class DeviceVerificationResponseModel : ResponseModel
{
public DeviceVerificationResponseModel(bool isDeviceVerificationSectionEnabled, bool unknownDeviceVerificationEnabled)
: base("deviceVerificationSettings")
{
IsDeviceVerificationSectionEnabled = isDeviceVerificationSectionEnabled;
UnknownDeviceVerificationEnabled = unknownDeviceVerificationEnabled;
}
namespace Bit.Api.Models.Response;
public bool IsDeviceVerificationSectionEnabled { get; }
public bool UnknownDeviceVerificationEnabled { get; }
public class DeviceVerificationResponseModel : ResponseModel
{
public DeviceVerificationResponseModel(bool isDeviceVerificationSectionEnabled, bool unknownDeviceVerificationEnabled)
: base("deviceVerificationSettings")
{
IsDeviceVerificationSectionEnabled = isDeviceVerificationSectionEnabled;
UnknownDeviceVerificationEnabled = unknownDeviceVerificationEnabled;
}
public bool IsDeviceVerificationSectionEnabled { get; }
public bool UnknownDeviceVerificationEnabled { get; }
}

View File

@ -3,54 +3,53 @@ using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class DomainsResponseModel : ResponseModel
{
public class DomainsResponseModel : ResponseModel
public DomainsResponseModel(User user, bool excluded = true)
: base("domains")
{
public DomainsResponseModel(User user, bool excluded = true)
: base("domains")
if (user == null)
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
EquivalentDomains = user.EquivalentDomains != null ?
JsonSerializer.Deserialize<List<List<string>>>(user.EquivalentDomains) : null;
var excludedGlobalEquivalentDomains = user.ExcludedGlobalEquivalentDomains != null ?
JsonSerializer.Deserialize<List<GlobalEquivalentDomainsType>>(user.ExcludedGlobalEquivalentDomains) :
new List<GlobalEquivalentDomainsType>();
var globalDomains = new List<GlobalDomains>();
var domainsToInclude = excluded ? Core.Utilities.StaticStore.GlobalDomains :
Core.Utilities.StaticStore.GlobalDomains.Where(d => !excludedGlobalEquivalentDomains.Contains(d.Key));
foreach (var domain in domainsToInclude)
{
globalDomains.Add(new GlobalDomains(domain.Key, domain.Value, excludedGlobalEquivalentDomains, excluded));
}
GlobalEquivalentDomains = !globalDomains.Any() ? null : globalDomains;
throw new ArgumentNullException(nameof(user));
}
public IEnumerable<IEnumerable<string>> EquivalentDomains { get; set; }
public IEnumerable<GlobalDomains> GlobalEquivalentDomains { get; set; }
EquivalentDomains = user.EquivalentDomains != null ?
JsonSerializer.Deserialize<List<List<string>>>(user.EquivalentDomains) : null;
public class GlobalDomains
var excludedGlobalEquivalentDomains = user.ExcludedGlobalEquivalentDomains != null ?
JsonSerializer.Deserialize<List<GlobalEquivalentDomainsType>>(user.ExcludedGlobalEquivalentDomains) :
new List<GlobalEquivalentDomainsType>();
var globalDomains = new List<GlobalDomains>();
var domainsToInclude = excluded ? Core.Utilities.StaticStore.GlobalDomains :
Core.Utilities.StaticStore.GlobalDomains.Where(d => !excludedGlobalEquivalentDomains.Contains(d.Key));
foreach (var domain in domainsToInclude)
{
public GlobalDomains(
GlobalEquivalentDomainsType globalDomain,
IEnumerable<string> domains,
IEnumerable<GlobalEquivalentDomainsType> excludedDomains,
bool excluded)
{
Type = globalDomain;
Domains = domains;
Excluded = excluded && (excludedDomains?.Contains(globalDomain) ?? false);
}
public GlobalEquivalentDomainsType Type { get; set; }
public IEnumerable<string> Domains { get; set; }
public bool Excluded { get; set; }
globalDomains.Add(new GlobalDomains(domain.Key, domain.Value, excludedGlobalEquivalentDomains, excluded));
}
GlobalEquivalentDomains = !globalDomains.Any() ? null : globalDomains;
}
public IEnumerable<IEnumerable<string>> EquivalentDomains { get; set; }
public IEnumerable<GlobalDomains> GlobalEquivalentDomains { get; set; }
public class GlobalDomains
{
public GlobalDomains(
GlobalEquivalentDomainsType globalDomain,
IEnumerable<string> domains,
IEnumerable<GlobalEquivalentDomainsType> excludedDomains,
bool excluded)
{
Type = globalDomain;
Domains = domains;
Excluded = excluded && (excludedDomains?.Contains(globalDomain) ?? false);
}
public GlobalEquivalentDomainsType Type { get; set; }
public IEnumerable<string> Domains { get; set; }
public bool Excluded { get; set; }
}
}

View File

@ -5,114 +5,113 @@ using Bit.Core.Models.Data;
using Bit.Core.Settings;
using Core.Models.Data;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class EmergencyAccessResponseModel : ResponseModel
{
public class EmergencyAccessResponseModel : ResponseModel
public EmergencyAccessResponseModel(EmergencyAccess emergencyAccess, string obj = "emergencyAccess") : base(obj)
{
public EmergencyAccessResponseModel(EmergencyAccess emergencyAccess, string obj = "emergencyAccess") : base(obj)
if (emergencyAccess == null)
{
if (emergencyAccess == null)
{
throw new ArgumentNullException(nameof(emergencyAccess));
}
Id = emergencyAccess.Id.ToString();
Status = emergencyAccess.Status;
Type = emergencyAccess.Type;
WaitTimeDays = emergencyAccess.WaitTimeDays;
throw new ArgumentNullException(nameof(emergencyAccess));
}
public EmergencyAccessResponseModel(EmergencyAccessDetails emergencyAccess, string obj = "emergencyAccess") : base(obj)
{
if (emergencyAccess == null)
{
throw new ArgumentNullException(nameof(emergencyAccess));
}
Id = emergencyAccess.Id.ToString();
Status = emergencyAccess.Status;
Type = emergencyAccess.Type;
WaitTimeDays = emergencyAccess.WaitTimeDays;
}
public string Id { get; private set; }
public EmergencyAccessStatusType Status { get; private set; }
public EmergencyAccessType Type { get; private set; }
public int WaitTimeDays { get; private set; }
Id = emergencyAccess.Id.ToString();
Status = emergencyAccess.Status;
Type = emergencyAccess.Type;
WaitTimeDays = emergencyAccess.WaitTimeDays;
}
public class EmergencyAccessGranteeDetailsResponseModel : EmergencyAccessResponseModel
public EmergencyAccessResponseModel(EmergencyAccessDetails emergencyAccess, string obj = "emergencyAccess") : base(obj)
{
public EmergencyAccessGranteeDetailsResponseModel(EmergencyAccessDetails emergencyAccess)
: base(emergencyAccess, "emergencyAccessGranteeDetails")
if (emergencyAccess == null)
{
if (emergencyAccess == null)
{
throw new ArgumentNullException(nameof(emergencyAccess));
}
GranteeId = emergencyAccess.GranteeId.ToString();
Email = emergencyAccess.GranteeEmail;
Name = emergencyAccess.GranteeName;
throw new ArgumentNullException(nameof(emergencyAccess));
}
public string GranteeId { get; private set; }
public string Name { get; private set; }
public string Email { get; private set; }
Id = emergencyAccess.Id.ToString();
Status = emergencyAccess.Status;
Type = emergencyAccess.Type;
WaitTimeDays = emergencyAccess.WaitTimeDays;
}
public class EmergencyAccessGrantorDetailsResponseModel : EmergencyAccessResponseModel
{
public EmergencyAccessGrantorDetailsResponseModel(EmergencyAccessDetails emergencyAccess)
: base(emergencyAccess, "emergencyAccessGrantorDetails")
{
if (emergencyAccess == null)
{
throw new ArgumentNullException(nameof(emergencyAccess));
}
GrantorId = emergencyAccess.GrantorId.ToString();
Email = emergencyAccess.GrantorEmail;
Name = emergencyAccess.GrantorName;
}
public string GrantorId { get; private set; }
public string Name { get; private set; }
public string Email { get; private set; }
}
public class EmergencyAccessTakeoverResponseModel : ResponseModel
{
public EmergencyAccessTakeoverResponseModel(EmergencyAccess emergencyAccess, User grantor, string obj = "emergencyAccessTakeover") : base(obj)
{
if (emergencyAccess == null)
{
throw new ArgumentNullException(nameof(emergencyAccess));
}
KeyEncrypted = emergencyAccess.KeyEncrypted;
Kdf = grantor.Kdf;
KdfIterations = grantor.KdfIterations;
}
public int KdfIterations { get; private set; }
public KdfType Kdf { get; private set; }
public string KeyEncrypted { get; private set; }
}
public class EmergencyAccessViewResponseModel : ResponseModel
{
public EmergencyAccessViewResponseModel(
IGlobalSettings globalSettings,
EmergencyAccess emergencyAccess,
IEnumerable<CipherDetails> ciphers)
: base("emergencyAccessView")
{
KeyEncrypted = emergencyAccess.KeyEncrypted;
Ciphers = ciphers.Select(c => new CipherResponseModel(c, globalSettings));
}
public string KeyEncrypted { get; set; }
public IEnumerable<CipherResponseModel> Ciphers { get; set; }
}
public string Id { get; private set; }
public EmergencyAccessStatusType Status { get; private set; }
public EmergencyAccessType Type { get; private set; }
public int WaitTimeDays { get; private set; }
}
public class EmergencyAccessGranteeDetailsResponseModel : EmergencyAccessResponseModel
{
public EmergencyAccessGranteeDetailsResponseModel(EmergencyAccessDetails emergencyAccess)
: base(emergencyAccess, "emergencyAccessGranteeDetails")
{
if (emergencyAccess == null)
{
throw new ArgumentNullException(nameof(emergencyAccess));
}
GranteeId = emergencyAccess.GranteeId.ToString();
Email = emergencyAccess.GranteeEmail;
Name = emergencyAccess.GranteeName;
}
public string GranteeId { get; private set; }
public string Name { get; private set; }
public string Email { get; private set; }
}
public class EmergencyAccessGrantorDetailsResponseModel : EmergencyAccessResponseModel
{
public EmergencyAccessGrantorDetailsResponseModel(EmergencyAccessDetails emergencyAccess)
: base(emergencyAccess, "emergencyAccessGrantorDetails")
{
if (emergencyAccess == null)
{
throw new ArgumentNullException(nameof(emergencyAccess));
}
GrantorId = emergencyAccess.GrantorId.ToString();
Email = emergencyAccess.GrantorEmail;
Name = emergencyAccess.GrantorName;
}
public string GrantorId { get; private set; }
public string Name { get; private set; }
public string Email { get; private set; }
}
public class EmergencyAccessTakeoverResponseModel : ResponseModel
{
public EmergencyAccessTakeoverResponseModel(EmergencyAccess emergencyAccess, User grantor, string obj = "emergencyAccessTakeover") : base(obj)
{
if (emergencyAccess == null)
{
throw new ArgumentNullException(nameof(emergencyAccess));
}
KeyEncrypted = emergencyAccess.KeyEncrypted;
Kdf = grantor.Kdf;
KdfIterations = grantor.KdfIterations;
}
public int KdfIterations { get; private set; }
public KdfType Kdf { get; private set; }
public string KeyEncrypted { get; private set; }
}
public class EmergencyAccessViewResponseModel : ResponseModel
{
public EmergencyAccessViewResponseModel(
IGlobalSettings globalSettings,
EmergencyAccess emergencyAccess,
IEnumerable<CipherDetails> ciphers)
: base("emergencyAccessView")
{
KeyEncrypted = emergencyAccess.KeyEncrypted;
Ciphers = ciphers.Select(c => new CipherResponseModel(c, globalSettings));
}
public string KeyEncrypted { get; set; }
public IEnumerable<CipherResponseModel> Ciphers { get; set; }
}

View File

@ -2,51 +2,50 @@
using Bit.Core.Models.Api;
using Bit.Core.Models.Data;
namespace Bit.Api.Models.Response
{
public class EventResponseModel : ResponseModel
{
public EventResponseModel(IEvent ev)
: base("event")
{
if (ev == null)
{
throw new ArgumentNullException(nameof(ev));
}
namespace Bit.Api.Models.Response;
Type = ev.Type;
UserId = ev.UserId;
OrganizationId = ev.OrganizationId;
ProviderId = ev.ProviderId;
CipherId = ev.CipherId;
CollectionId = ev.CollectionId;
GroupId = ev.GroupId;
PolicyId = ev.PolicyId;
OrganizationUserId = ev.OrganizationUserId;
ProviderUserId = ev.ProviderUserId;
ProviderOrganizationId = ev.ProviderOrganizationId;
ActingUserId = ev.ActingUserId;
Date = ev.Date;
DeviceType = ev.DeviceType;
IpAddress = ev.IpAddress;
InstallationId = ev.InstallationId;
public class EventResponseModel : ResponseModel
{
public EventResponseModel(IEvent ev)
: base("event")
{
if (ev == null)
{
throw new ArgumentNullException(nameof(ev));
}
public EventType Type { get; set; }
public Guid? UserId { get; set; }
public Guid? OrganizationId { get; set; }
public Guid? ProviderId { get; set; }
public Guid? CipherId { get; set; }
public Guid? CollectionId { get; set; }
public Guid? GroupId { get; set; }
public Guid? PolicyId { get; set; }
public Guid? OrganizationUserId { get; set; }
public Guid? ProviderUserId { get; set; }
public Guid? ProviderOrganizationId { get; set; }
public Guid? ActingUserId { get; set; }
public Guid? InstallationId { get; set; }
public DateTime Date { get; set; }
public DeviceType? DeviceType { get; set; }
public string IpAddress { get; set; }
Type = ev.Type;
UserId = ev.UserId;
OrganizationId = ev.OrganizationId;
ProviderId = ev.ProviderId;
CipherId = ev.CipherId;
CollectionId = ev.CollectionId;
GroupId = ev.GroupId;
PolicyId = ev.PolicyId;
OrganizationUserId = ev.OrganizationUserId;
ProviderUserId = ev.ProviderUserId;
ProviderOrganizationId = ev.ProviderOrganizationId;
ActingUserId = ev.ActingUserId;
Date = ev.Date;
DeviceType = ev.DeviceType;
IpAddress = ev.IpAddress;
InstallationId = ev.InstallationId;
}
public EventType Type { get; set; }
public Guid? UserId { get; set; }
public Guid? OrganizationId { get; set; }
public Guid? ProviderId { get; set; }
public Guid? CipherId { get; set; }
public Guid? CollectionId { get; set; }
public Guid? GroupId { get; set; }
public Guid? PolicyId { get; set; }
public Guid? OrganizationUserId { get; set; }
public Guid? ProviderUserId { get; set; }
public Guid? ProviderOrganizationId { get; set; }
public Guid? ActingUserId { get; set; }
public Guid? InstallationId { get; set; }
public DateTime Date { get; set; }
public DeviceType? DeviceType { get; set; }
public string IpAddress { get; set; }
}

View File

@ -1,25 +1,24 @@
using Bit.Core.Entities;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response
{
public class FolderResponseModel : ResponseModel
{
public FolderResponseModel(Folder folder)
: base("folder")
{
if (folder == null)
{
throw new ArgumentNullException(nameof(folder));
}
namespace Bit.Api.Models.Response;
Id = folder.Id.ToString();
Name = folder.Name;
RevisionDate = folder.RevisionDate;
public class FolderResponseModel : ResponseModel
{
public FolderResponseModel(Folder folder)
: base("folder")
{
if (folder == null)
{
throw new ArgumentNullException(nameof(folder));
}
public string Id { get; set; }
public string Name { get; set; }
public DateTime RevisionDate { get; set; }
Id = folder.Id.ToString();
Name = folder.Name;
RevisionDate = folder.RevisionDate;
}
public string Id { get; set; }
public string Name { get; set; }
public DateTime RevisionDate { get; set; }
}

View File

@ -2,40 +2,39 @@
using Bit.Core.Models.Api;
using Bit.Core.Models.Data;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class GroupResponseModel : ResponseModel
{
public class GroupResponseModel : ResponseModel
public GroupResponseModel(Group group, string obj = "group")
: base(obj)
{
public GroupResponseModel(Group group, string obj = "group")
: base(obj)
if (group == null)
{
if (group == null)
{
throw new ArgumentNullException(nameof(group));
}
Id = group.Id.ToString();
OrganizationId = group.OrganizationId.ToString();
Name = group.Name;
AccessAll = group.AccessAll;
ExternalId = group.ExternalId;
throw new ArgumentNullException(nameof(group));
}
public string Id { get; set; }
public string OrganizationId { get; set; }
public string Name { get; set; }
public bool AccessAll { get; set; }
public string ExternalId { get; set; }
Id = group.Id.ToString();
OrganizationId = group.OrganizationId.ToString();
Name = group.Name;
AccessAll = group.AccessAll;
ExternalId = group.ExternalId;
}
public class GroupDetailsResponseModel : GroupResponseModel
{
public GroupDetailsResponseModel(Group group, IEnumerable<SelectionReadOnly> collections)
: base(group, "groupDetails")
{
Collections = collections.Select(c => new SelectionReadOnlyResponseModel(c));
}
public IEnumerable<SelectionReadOnlyResponseModel> Collections { get; set; }
}
public string Id { get; set; }
public string OrganizationId { get; set; }
public string Name { get; set; }
public bool AccessAll { get; set; }
public string ExternalId { get; set; }
}
public class GroupDetailsResponseModel : GroupResponseModel
{
public GroupDetailsResponseModel(Group group, IEnumerable<SelectionReadOnly> collections)
: base(group, "groupDetails")
{
Collections = collections.Select(c => new SelectionReadOnlyResponseModel(c));
}
public IEnumerable<SelectionReadOnlyResponseModel> Collections { get; set; }
}

View File

@ -1,20 +1,19 @@
using Bit.Core.Entities;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response
{
public class InstallationResponseModel : ResponseModel
{
public InstallationResponseModel(Installation installation, bool withKey)
: base("installation")
{
Id = installation.Id.ToString();
Key = withKey ? installation.Key : null;
Enabled = installation.Enabled;
}
namespace Bit.Api.Models.Response;
public string Id { get; set; }
public string Key { get; set; }
public bool Enabled { get; set; }
public class InstallationResponseModel : ResponseModel
{
public InstallationResponseModel(Installation installation, bool withKey)
: base("installation")
{
Id = installation.Id.ToString();
Key = withKey ? installation.Key : null;
Enabled = installation.Enabled;
}
public string Id { get; set; }
public string Key { get; set; }
public bool Enabled { get; set; }
}

View File

@ -1,25 +1,24 @@
using Bit.Core.Entities;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response
{
public class KeysResponseModel : ResponseModel
{
public KeysResponseModel(User user)
: base("keys")
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
namespace Bit.Api.Models.Response;
Key = user.Key;
PublicKey = user.PublicKey;
PrivateKey = user.PrivateKey;
public class KeysResponseModel : ResponseModel
{
public KeysResponseModel(User user)
: base("keys")
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
public string Key { get; set; }
public string PublicKey { get; set; }
public string PrivateKey { get; set; }
Key = user.Key;
PublicKey = user.PublicKey;
PrivateKey = user.PrivateKey;
}
public string Key { get; set; }
public string PublicKey { get; set; }
public string PrivateKey { get; set; }
}

View File

@ -1,17 +1,16 @@
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response
{
public class ListResponseModel<T> : ResponseModel where T : ResponseModel
{
public ListResponseModel(IEnumerable<T> data, string continuationToken = null)
: base("list")
{
Data = data;
ContinuationToken = continuationToken;
}
namespace Bit.Api.Models.Response;
public IEnumerable<T> Data { get; set; }
public string ContinuationToken { get; set; }
public class ListResponseModel<T> : ResponseModel where T : ResponseModel
{
public ListResponseModel(IEnumerable<T> data, string continuationToken = null)
: base("list")
{
Data = data;
ContinuationToken = continuationToken;
}
public IEnumerable<T> Data { get; set; }
public string ContinuationToken { get; set; }
}

View File

@ -1,13 +1,12 @@
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class OrganizationExportResponseModel
{
public class OrganizationExportResponseModel
public OrganizationExportResponseModel()
{
public OrganizationExportResponseModel()
{
}
public ListResponseModel<CollectionResponseModel> Collections { get; set; }
public ListResponseModel<CipherMiniDetailsResponseModel> Ciphers { get; set; }
}
public ListResponseModel<CollectionResponseModel> Collections { get; set; }
public ListResponseModel<CipherMiniDetailsResponseModel> Ciphers { get; set; }
}

View File

@ -2,17 +2,16 @@
using Bit.Core.Enums;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response.Organizations
{
public class OrganizationApiKeyInformation : ResponseModel
{
public OrganizationApiKeyInformation(OrganizationApiKey key) : base("keyInformation")
{
KeyType = key.Type;
RevisionDate = key.RevisionDate;
}
namespace Bit.Api.Models.Response.Organizations;
public OrganizationApiKeyType KeyType { get; set; }
public DateTime RevisionDate { get; set; }
public class OrganizationApiKeyInformation : ResponseModel
{
public OrganizationApiKeyInformation(OrganizationApiKey key) : base("keyInformation")
{
KeyType = key.Type;
RevisionDate = key.RevisionDate;
}
public OrganizationApiKeyType KeyType { get; set; }
public DateTime RevisionDate { get; set; }
}

View File

@ -1,16 +1,15 @@
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response.Organizations
{
public class OrganizationAutoEnrollStatusResponseModel : ResponseModel
{
public OrganizationAutoEnrollStatusResponseModel(Guid orgId, bool resetPasswordEnabled) : base("organizationAutoEnrollStatus")
{
Id = orgId.ToString();
ResetPasswordEnabled = resetPasswordEnabled;
}
namespace Bit.Api.Models.Response.Organizations;
public string Id { get; set; }
public bool ResetPasswordEnabled { get; set; }
public class OrganizationAutoEnrollStatusResponseModel : ResponseModel
{
public OrganizationAutoEnrollStatusResponseModel(Guid orgId, bool resetPasswordEnabled) : base("organizationAutoEnrollStatus")
{
Id = orgId.ToString();
ResetPasswordEnabled = resetPasswordEnabled;
}
public string Id { get; set; }
public bool ResetPasswordEnabled { get; set; }
}

View File

@ -2,28 +2,27 @@
using Bit.Core.Entities;
using Bit.Core.Enums;
namespace Bit.Api.Models.Response.Organizations
namespace Bit.Api.Models.Response.Organizations;
public class OrganizationConnectionResponseModel
{
public class OrganizationConnectionResponseModel
public Guid? Id { get; set; }
public OrganizationConnectionType Type { get; set; }
public Guid OrganizationId { get; set; }
public bool Enabled { get; set; }
public JsonDocument Config { get; set; }
public OrganizationConnectionResponseModel(OrganizationConnection connection, Type configType)
{
public Guid? Id { get; set; }
public OrganizationConnectionType Type { get; set; }
public Guid OrganizationId { get; set; }
public bool Enabled { get; set; }
public JsonDocument Config { get; set; }
public OrganizationConnectionResponseModel(OrganizationConnection connection, Type configType)
if (connection == null)
{
if (connection == null)
{
return;
}
Id = connection.Id;
Type = connection.Type;
OrganizationId = connection.OrganizationId;
Enabled = connection.Enabled;
Config = JsonDocument.Parse(connection.Config);
return;
}
Id = connection.Id;
Type = connection.Type;
OrganizationId = connection.OrganizationId;
Enabled = connection.Enabled;
Config = JsonDocument.Parse(connection.Config);
}
}

View File

@ -1,22 +1,21 @@
using Bit.Core.Entities;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response.Organizations
{
public class OrganizationKeysResponseModel : ResponseModel
{
public OrganizationKeysResponseModel(Organization org) : base("organizationKeys")
{
if (org == null)
{
throw new ArgumentNullException(nameof(org));
}
namespace Bit.Api.Models.Response.Organizations;
PublicKey = org.PublicKey;
PrivateKey = org.PrivateKey;
public class OrganizationKeysResponseModel : ResponseModel
{
public OrganizationKeysResponseModel(Organization org) : base("organizationKeys")
{
if (org == null)
{
throw new ArgumentNullException(nameof(org));
}
public string PublicKey { get; set; }
public string PrivateKey { get; set; }
PublicKey = org.PublicKey;
PrivateKey = org.PrivateKey;
}
public string PublicKey { get; set; }
public string PrivateKey { get; set; }
}

View File

@ -4,110 +4,109 @@ using Bit.Core.Models.Api;
using Bit.Core.Models.Business;
using Bit.Core.Utilities;
namespace Bit.Api.Models.Response.Organizations
namespace Bit.Api.Models.Response.Organizations;
public class OrganizationResponseModel : ResponseModel
{
public class OrganizationResponseModel : ResponseModel
public OrganizationResponseModel(Organization organization, string obj = "organization")
: base(obj)
{
public OrganizationResponseModel(Organization organization, string obj = "organization")
: base(obj)
if (organization == null)
{
if (organization == null)
{
throw new ArgumentNullException(nameof(organization));
}
Id = organization.Id.ToString();
Identifier = organization.Identifier;
Name = organization.Name;
BusinessName = organization.BusinessName;
BusinessAddress1 = organization.BusinessAddress1;
BusinessAddress2 = organization.BusinessAddress2;
BusinessAddress3 = organization.BusinessAddress3;
BusinessCountry = organization.BusinessCountry;
BusinessTaxNumber = organization.BusinessTaxNumber;
BillingEmail = organization.BillingEmail;
Plan = new PlanResponseModel(StaticStore.Plans.FirstOrDefault(plan => plan.Type == organization.PlanType));
PlanType = organization.PlanType;
Seats = organization.Seats;
MaxAutoscaleSeats = organization.MaxAutoscaleSeats;
MaxCollections = organization.MaxCollections;
MaxStorageGb = organization.MaxStorageGb;
UsePolicies = organization.UsePolicies;
UseSso = organization.UseSso;
UseKeyConnector = organization.UseKeyConnector;
UseScim = organization.UseScim;
UseGroups = organization.UseGroups;
UseDirectory = organization.UseDirectory;
UseEvents = organization.UseEvents;
UseTotp = organization.UseTotp;
Use2fa = organization.Use2fa;
UseApi = organization.UseApi;
UseResetPassword = organization.UseResetPassword;
UsersGetPremium = organization.UsersGetPremium;
SelfHost = organization.SelfHost;
HasPublicAndPrivateKeys = organization.PublicKey != null && organization.PrivateKey != null;
throw new ArgumentNullException(nameof(organization));
}
public string Id { get; set; }
public string Identifier { get; set; }
public string Name { get; set; }
public string BusinessName { get; set; }
public string BusinessAddress1 { get; set; }
public string BusinessAddress2 { get; set; }
public string BusinessAddress3 { get; set; }
public string BusinessCountry { get; set; }
public string BusinessTaxNumber { get; set; }
public string BillingEmail { get; set; }
public PlanResponseModel Plan { get; set; }
public PlanType PlanType { get; set; }
public int? Seats { get; set; }
public int? MaxAutoscaleSeats { get; set; } = null;
public short? MaxCollections { get; set; }
public short? MaxStorageGb { get; set; }
public bool UsePolicies { get; set; }
public bool UseSso { get; set; }
public bool UseKeyConnector { get; set; }
public bool UseScim { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public bool UseEvents { get; set; }
public bool UseTotp { get; set; }
public bool Use2fa { get; set; }
public bool UseApi { get; set; }
public bool UseResetPassword { get; set; }
public bool UsersGetPremium { get; set; }
public bool SelfHost { get; set; }
public bool HasPublicAndPrivateKeys { get; set; }
Id = organization.Id.ToString();
Identifier = organization.Identifier;
Name = organization.Name;
BusinessName = organization.BusinessName;
BusinessAddress1 = organization.BusinessAddress1;
BusinessAddress2 = organization.BusinessAddress2;
BusinessAddress3 = organization.BusinessAddress3;
BusinessCountry = organization.BusinessCountry;
BusinessTaxNumber = organization.BusinessTaxNumber;
BillingEmail = organization.BillingEmail;
Plan = new PlanResponseModel(StaticStore.Plans.FirstOrDefault(plan => plan.Type == organization.PlanType));
PlanType = organization.PlanType;
Seats = organization.Seats;
MaxAutoscaleSeats = organization.MaxAutoscaleSeats;
MaxCollections = organization.MaxCollections;
MaxStorageGb = organization.MaxStorageGb;
UsePolicies = organization.UsePolicies;
UseSso = organization.UseSso;
UseKeyConnector = organization.UseKeyConnector;
UseScim = organization.UseScim;
UseGroups = organization.UseGroups;
UseDirectory = organization.UseDirectory;
UseEvents = organization.UseEvents;
UseTotp = organization.UseTotp;
Use2fa = organization.Use2fa;
UseApi = organization.UseApi;
UseResetPassword = organization.UseResetPassword;
UsersGetPremium = organization.UsersGetPremium;
SelfHost = organization.SelfHost;
HasPublicAndPrivateKeys = organization.PublicKey != null && organization.PrivateKey != null;
}
public class OrganizationSubscriptionResponseModel : OrganizationResponseModel
{
public OrganizationSubscriptionResponseModel(Organization organization, SubscriptionInfo subscription = null)
: base(organization, "organizationSubscription")
{
if (subscription != null)
{
Subscription = subscription.Subscription != null ?
new BillingSubscription(subscription.Subscription) : null;
UpcomingInvoice = subscription.UpcomingInvoice != null ?
new BillingSubscriptionUpcomingInvoice(subscription.UpcomingInvoice) : null;
Expiration = DateTime.UtcNow.AddYears(1); // Not used, so just give it a value.
}
else
{
Expiration = organization.ExpirationDate;
}
StorageName = organization.Storage.HasValue ?
CoreHelpers.ReadableBytesSize(organization.Storage.Value) : null;
StorageGb = organization.Storage.HasValue ?
Math.Round(organization.Storage.Value / 1073741824D, 2) : 0; // 1 GB
}
public string StorageName { get; set; }
public double? StorageGb { get; set; }
public BillingSubscription Subscription { get; set; }
public BillingSubscriptionUpcomingInvoice UpcomingInvoice { get; set; }
public DateTime? Expiration { get; set; }
}
public string Id { get; set; }
public string Identifier { get; set; }
public string Name { get; set; }
public string BusinessName { get; set; }
public string BusinessAddress1 { get; set; }
public string BusinessAddress2 { get; set; }
public string BusinessAddress3 { get; set; }
public string BusinessCountry { get; set; }
public string BusinessTaxNumber { get; set; }
public string BillingEmail { get; set; }
public PlanResponseModel Plan { get; set; }
public PlanType PlanType { get; set; }
public int? Seats { get; set; }
public int? MaxAutoscaleSeats { get; set; } = null;
public short? MaxCollections { get; set; }
public short? MaxStorageGb { get; set; }
public bool UsePolicies { get; set; }
public bool UseSso { get; set; }
public bool UseKeyConnector { get; set; }
public bool UseScim { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public bool UseEvents { get; set; }
public bool UseTotp { get; set; }
public bool Use2fa { get; set; }
public bool UseApi { get; set; }
public bool UseResetPassword { get; set; }
public bool UsersGetPremium { get; set; }
public bool SelfHost { get; set; }
public bool HasPublicAndPrivateKeys { get; set; }
}
public class OrganizationSubscriptionResponseModel : OrganizationResponseModel
{
public OrganizationSubscriptionResponseModel(Organization organization, SubscriptionInfo subscription = null)
: base(organization, "organizationSubscription")
{
if (subscription != null)
{
Subscription = subscription.Subscription != null ?
new BillingSubscription(subscription.Subscription) : null;
UpcomingInvoice = subscription.UpcomingInvoice != null ?
new BillingSubscriptionUpcomingInvoice(subscription.UpcomingInvoice) : null;
Expiration = DateTime.UtcNow.AddYears(1); // Not used, so just give it a value.
}
else
{
Expiration = organization.ExpirationDate;
}
StorageName = organization.Storage.HasValue ?
CoreHelpers.ReadableBytesSize(organization.Storage.Value) : null;
StorageGb = organization.Storage.HasValue ?
Math.Round(organization.Storage.Value / 1073741824D, 2) : 0; // 1 GB
}
public string StorageName { get; set; }
public double? StorageGb { get; set; }
public BillingSubscription Subscription { get; set; }
public BillingSubscriptionUpcomingInvoice UpcomingInvoice { get; set; }
public DateTime? Expiration { get; set; }
}

View File

@ -1,15 +1,14 @@
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response.Organizations
{
public class OrganizationSponsorshipSyncStatusResponseModel : ResponseModel
{
public OrganizationSponsorshipSyncStatusResponseModel(DateTime? lastSyncDate)
: base("syncStatus")
{
LastSyncDate = lastSyncDate;
}
namespace Bit.Api.Models.Response.Organizations;
public DateTime? LastSyncDate { get; set; }
public class OrganizationSponsorshipSyncStatusResponseModel : ResponseModel
{
public OrganizationSponsorshipSyncStatusResponseModel(DateTime? lastSyncDate)
: base("syncStatus")
{
LastSyncDate = lastSyncDate;
}
public DateTime? LastSyncDate { get; set; }
}

View File

@ -3,42 +3,41 @@ using Bit.Core.Models.Api;
using Bit.Core.Models.Data;
using Bit.Core.Settings;
namespace Bit.Api.Models.Response.Organizations
namespace Bit.Api.Models.Response.Organizations;
public class OrganizationSsoResponseModel : ResponseModel
{
public class OrganizationSsoResponseModel : ResponseModel
public OrganizationSsoResponseModel(Organization organization, GlobalSettings globalSettings,
SsoConfig config = null) : base("organizationSso")
{
public OrganizationSsoResponseModel(Organization organization, GlobalSettings globalSettings,
SsoConfig config = null) : base("organizationSso")
if (config != null)
{
if (config != null)
{
Enabled = config.Enabled;
Data = config.GetData();
}
Urls = new SsoUrls(organization.Id.ToString(), globalSettings);
Enabled = config.Enabled;
Data = config.GetData();
}
public bool Enabled { get; set; }
public SsoConfigurationData Data { get; set; }
public SsoUrls Urls { get; set; }
Urls = new SsoUrls(organization.Id.ToString(), globalSettings);
}
public class SsoUrls
{
public SsoUrls(string organizationId, GlobalSettings globalSettings)
{
CallbackPath = SsoConfigurationData.BuildCallbackPath(globalSettings.BaseServiceUri.Sso);
SignedOutCallbackPath = SsoConfigurationData.BuildSignedOutCallbackPath(globalSettings.BaseServiceUri.Sso);
SpEntityId = SsoConfigurationData.BuildSaml2ModulePath(globalSettings.BaseServiceUri.Sso);
SpMetadataUrl = SsoConfigurationData.BuildSaml2MetadataUrl(globalSettings.BaseServiceUri.Sso, organizationId);
SpAcsUrl = SsoConfigurationData.BuildSaml2AcsUrl(globalSettings.BaseServiceUri.Sso, organizationId);
}
public string CallbackPath { get; set; }
public string SignedOutCallbackPath { get; set; }
public string SpEntityId { get; set; }
public string SpMetadataUrl { get; set; }
public string SpAcsUrl { get; set; }
}
public bool Enabled { get; set; }
public SsoConfigurationData Data { get; set; }
public SsoUrls Urls { get; set; }
}
public class SsoUrls
{
public SsoUrls(string organizationId, GlobalSettings globalSettings)
{
CallbackPath = SsoConfigurationData.BuildCallbackPath(globalSettings.BaseServiceUri.Sso);
SignedOutCallbackPath = SsoConfigurationData.BuildSignedOutCallbackPath(globalSettings.BaseServiceUri.Sso);
SpEntityId = SsoConfigurationData.BuildSaml2ModulePath(globalSettings.BaseServiceUri.Sso);
SpMetadataUrl = SsoConfigurationData.BuildSaml2MetadataUrl(globalSettings.BaseServiceUri.Sso, organizationId);
SpAcsUrl = SsoConfigurationData.BuildSaml2AcsUrl(globalSettings.BaseServiceUri.Sso, organizationId);
}
public string CallbackPath { get; set; }
public string SignedOutCallbackPath { get; set; }
public string SpEntityId { get; set; }
public string SpMetadataUrl { get; set; }
public string SpAcsUrl { get; set; }
}

View File

@ -5,139 +5,138 @@ using Bit.Core.Models.Data;
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
using Bit.Core.Utilities;
namespace Bit.Api.Models.Response.Organizations
namespace Bit.Api.Models.Response.Organizations;
public class OrganizationUserResponseModel : ResponseModel
{
public class OrganizationUserResponseModel : ResponseModel
public OrganizationUserResponseModel(OrganizationUser organizationUser, string obj = "organizationUser")
: base(obj)
{
public OrganizationUserResponseModel(OrganizationUser organizationUser, string obj = "organizationUser")
: base(obj)
if (organizationUser == null)
{
if (organizationUser == null)
{
throw new ArgumentNullException(nameof(organizationUser));
}
Id = organizationUser.Id.ToString();
UserId = organizationUser.UserId?.ToString();
Type = organizationUser.Type;
Status = organizationUser.Status;
AccessAll = organizationUser.AccessAll;
Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(organizationUser.Permissions);
ResetPasswordEnrolled = !string.IsNullOrEmpty(organizationUser.ResetPasswordKey);
throw new ArgumentNullException(nameof(organizationUser));
}
public OrganizationUserResponseModel(OrganizationUserUserDetails organizationUser, string obj = "organizationUser")
: base(obj)
{
if (organizationUser == null)
{
throw new ArgumentNullException(nameof(organizationUser));
}
Id = organizationUser.Id.ToString();
UserId = organizationUser.UserId?.ToString();
Type = organizationUser.Type;
Status = organizationUser.Status;
AccessAll = organizationUser.AccessAll;
Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(organizationUser.Permissions);
ResetPasswordEnrolled = !string.IsNullOrEmpty(organizationUser.ResetPasswordKey);
UsesKeyConnector = organizationUser.UsesKeyConnector;
}
public string Id { get; set; }
public string UserId { get; set; }
public OrganizationUserType Type { get; set; }
public OrganizationUserStatusType Status { get; set; }
public bool AccessAll { get; set; }
public Permissions Permissions { get; set; }
public bool ResetPasswordEnrolled { get; set; }
public bool UsesKeyConnector { get; set; }
Id = organizationUser.Id.ToString();
UserId = organizationUser.UserId?.ToString();
Type = organizationUser.Type;
Status = organizationUser.Status;
AccessAll = organizationUser.AccessAll;
Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(organizationUser.Permissions);
ResetPasswordEnrolled = !string.IsNullOrEmpty(organizationUser.ResetPasswordKey);
}
public class OrganizationUserDetailsResponseModel : OrganizationUserResponseModel
public OrganizationUserResponseModel(OrganizationUserUserDetails organizationUser, string obj = "organizationUser")
: base(obj)
{
public OrganizationUserDetailsResponseModel(OrganizationUser organizationUser,
IEnumerable<SelectionReadOnly> collections)
: base(organizationUser, "organizationUserDetails")
if (organizationUser == null)
{
Collections = collections.Select(c => new SelectionReadOnlyResponseModel(c));
throw new ArgumentNullException(nameof(organizationUser));
}
public IEnumerable<SelectionReadOnlyResponseModel> Collections { get; set; }
Id = organizationUser.Id.ToString();
UserId = organizationUser.UserId?.ToString();
Type = organizationUser.Type;
Status = organizationUser.Status;
AccessAll = organizationUser.AccessAll;
Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(organizationUser.Permissions);
ResetPasswordEnrolled = !string.IsNullOrEmpty(organizationUser.ResetPasswordKey);
UsesKeyConnector = organizationUser.UsesKeyConnector;
}
public class OrganizationUserUserDetailsResponseModel : OrganizationUserResponseModel
{
public OrganizationUserUserDetailsResponseModel(OrganizationUserUserDetails organizationUser,
bool twoFactorEnabled, string obj = "organizationUserUserDetails")
: base(organizationUser, obj)
{
if (organizationUser == null)
{
throw new ArgumentNullException(nameof(organizationUser));
}
Name = organizationUser.Name;
Email = organizationUser.Email;
TwoFactorEnabled = twoFactorEnabled;
SsoBound = !string.IsNullOrWhiteSpace(organizationUser.SsoExternalId);
// Prevent reset password when using key connector.
ResetPasswordEnrolled = ResetPasswordEnrolled && !organizationUser.UsesKeyConnector;
}
public string Name { get; set; }
public string Email { get; set; }
public bool TwoFactorEnabled { get; set; }
public bool SsoBound { get; set; }
}
public class OrganizationUserResetPasswordDetailsResponseModel : ResponseModel
{
public OrganizationUserResetPasswordDetailsResponseModel(OrganizationUserResetPasswordDetails orgUser,
string obj = "organizationUserResetPasswordDetails") : base(obj)
{
if (orgUser == null)
{
throw new ArgumentNullException(nameof(orgUser));
}
Kdf = orgUser.Kdf;
KdfIterations = orgUser.KdfIterations;
ResetPasswordKey = orgUser.ResetPasswordKey;
EncryptedPrivateKey = orgUser.EncryptedPrivateKey;
}
public KdfType Kdf { get; set; }
public int KdfIterations { get; set; }
public string ResetPasswordKey { get; set; }
public string EncryptedPrivateKey { get; set; }
}
public class OrganizationUserPublicKeyResponseModel : ResponseModel
{
public OrganizationUserPublicKeyResponseModel(Guid id, Guid userId,
string key, string obj = "organizationUserPublicKeyResponseModel") :
base(obj)
{
Id = id;
UserId = userId;
Key = key;
}
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string Key { get; set; }
}
public class OrganizationUserBulkResponseModel : ResponseModel
{
public OrganizationUserBulkResponseModel(Guid id, string error,
string obj = "OrganizationBulkConfirmResponseModel") : base(obj)
{
Id = id;
Error = error;
}
public Guid Id { get; set; }
public string Error { get; set; }
}
public string Id { get; set; }
public string UserId { get; set; }
public OrganizationUserType Type { get; set; }
public OrganizationUserStatusType Status { get; set; }
public bool AccessAll { get; set; }
public Permissions Permissions { get; set; }
public bool ResetPasswordEnrolled { get; set; }
public bool UsesKeyConnector { get; set; }
}
public class OrganizationUserDetailsResponseModel : OrganizationUserResponseModel
{
public OrganizationUserDetailsResponseModel(OrganizationUser organizationUser,
IEnumerable<SelectionReadOnly> collections)
: base(organizationUser, "organizationUserDetails")
{
Collections = collections.Select(c => new SelectionReadOnlyResponseModel(c));
}
public IEnumerable<SelectionReadOnlyResponseModel> Collections { get; set; }
}
public class OrganizationUserUserDetailsResponseModel : OrganizationUserResponseModel
{
public OrganizationUserUserDetailsResponseModel(OrganizationUserUserDetails organizationUser,
bool twoFactorEnabled, string obj = "organizationUserUserDetails")
: base(organizationUser, obj)
{
if (organizationUser == null)
{
throw new ArgumentNullException(nameof(organizationUser));
}
Name = organizationUser.Name;
Email = organizationUser.Email;
TwoFactorEnabled = twoFactorEnabled;
SsoBound = !string.IsNullOrWhiteSpace(organizationUser.SsoExternalId);
// Prevent reset password when using key connector.
ResetPasswordEnrolled = ResetPasswordEnrolled && !organizationUser.UsesKeyConnector;
}
public string Name { get; set; }
public string Email { get; set; }
public bool TwoFactorEnabled { get; set; }
public bool SsoBound { get; set; }
}
public class OrganizationUserResetPasswordDetailsResponseModel : ResponseModel
{
public OrganizationUserResetPasswordDetailsResponseModel(OrganizationUserResetPasswordDetails orgUser,
string obj = "organizationUserResetPasswordDetails") : base(obj)
{
if (orgUser == null)
{
throw new ArgumentNullException(nameof(orgUser));
}
Kdf = orgUser.Kdf;
KdfIterations = orgUser.KdfIterations;
ResetPasswordKey = orgUser.ResetPasswordKey;
EncryptedPrivateKey = orgUser.EncryptedPrivateKey;
}
public KdfType Kdf { get; set; }
public int KdfIterations { get; set; }
public string ResetPasswordKey { get; set; }
public string EncryptedPrivateKey { get; set; }
}
public class OrganizationUserPublicKeyResponseModel : ResponseModel
{
public OrganizationUserPublicKeyResponseModel(Guid id, Guid userId,
string key, string obj = "organizationUserPublicKeyResponseModel") :
base(obj)
{
Id = id;
UserId = userId;
Key = key;
}
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string Key { get; set; }
}
public class OrganizationUserBulkResponseModel : ResponseModel
{
public OrganizationUserBulkResponseModel(Guid id, string error,
string obj = "OrganizationBulkConfirmResponseModel") : base(obj)
{
Id = id;
Error = error;
}
public Guid Id { get; set; }
public string Error { get; set; }
}

View File

@ -1,15 +1,14 @@
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response
{
public class PaymentResponseModel : ResponseModel
{
public PaymentResponseModel()
: base("payment")
{ }
namespace Bit.Api.Models.Response;
public ProfileResponseModel UserProfile { get; set; }
public string PaymentIntentClientSecret { get; set; }
public bool Success { get; set; }
}
public class PaymentResponseModel : ResponseModel
{
public PaymentResponseModel()
: base("payment")
{ }
public ProfileResponseModel UserProfile { get; set; }
public string PaymentIntentClientSecret { get; set; }
public bool Success { get; set; }
}

View File

@ -2,101 +2,100 @@
using Bit.Core.Models.Api;
using Bit.Core.Models.StaticStore;
namespace Bit.Api.Models.Response
{
public class PlanResponseModel : ResponseModel
{
public PlanResponseModel(Plan plan, string obj = "plan")
: base(obj)
{
if (plan == null)
{
throw new ArgumentNullException(nameof(plan));
}
namespace Bit.Api.Models.Response;
Type = plan.Type;
Product = plan.Product;
Name = plan.Name;
IsAnnual = plan.IsAnnual;
NameLocalizationKey = plan.NameLocalizationKey;
DescriptionLocalizationKey = plan.DescriptionLocalizationKey;
CanBeUsedByBusiness = plan.CanBeUsedByBusiness;
BaseSeats = plan.BaseSeats;
BaseStorageGb = plan.BaseStorageGb;
MaxCollections = plan.MaxCollections;
MaxUsers = plan.MaxUsers;
HasAdditionalSeatsOption = plan.HasAdditionalSeatsOption;
HasAdditionalStorageOption = plan.HasAdditionalStorageOption;
MaxAdditionalSeats = plan.MaxAdditionalSeats;
MaxAdditionalStorage = plan.MaxAdditionalStorage;
HasPremiumAccessOption = plan.HasPremiumAccessOption;
TrialPeriodDays = plan.TrialPeriodDays;
HasSelfHost = plan.HasSelfHost;
HasPolicies = plan.HasPolicies;
HasGroups = plan.HasGroups;
HasDirectory = plan.HasDirectory;
HasEvents = plan.HasEvents;
HasTotp = plan.HasTotp;
Has2fa = plan.Has2fa;
HasSso = plan.HasSso;
HasResetPassword = plan.HasResetPassword;
UsersGetPremium = plan.UsersGetPremium;
UpgradeSortOrder = plan.UpgradeSortOrder;
DisplaySortOrder = plan.DisplaySortOrder;
LegacyYear = plan.LegacyYear;
Disabled = plan.Disabled;
StripePlanId = plan.StripePlanId;
StripeSeatPlanId = plan.StripeSeatPlanId;
StripeStoragePlanId = plan.StripeStoragePlanId;
BasePrice = plan.BasePrice;
SeatPrice = plan.SeatPrice;
AdditionalStoragePricePerGb = plan.AdditionalStoragePricePerGb;
PremiumAccessOptionPrice = plan.PremiumAccessOptionPrice;
public class PlanResponseModel : ResponseModel
{
public PlanResponseModel(Plan plan, string obj = "plan")
: base(obj)
{
if (plan == null)
{
throw new ArgumentNullException(nameof(plan));
}
public PlanType Type { get; set; }
public ProductType Product { get; set; }
public string Name { get; set; }
public bool IsAnnual { get; set; }
public string NameLocalizationKey { get; set; }
public string DescriptionLocalizationKey { get; set; }
public bool CanBeUsedByBusiness { get; set; }
public int BaseSeats { get; set; }
public short? BaseStorageGb { get; set; }
public short? MaxCollections { get; set; }
public short? MaxUsers { get; set; }
public bool HasAdditionalSeatsOption { get; set; }
public int? MaxAdditionalSeats { get; set; }
public bool HasAdditionalStorageOption { get; set; }
public short? MaxAdditionalStorage { get; set; }
public bool HasPremiumAccessOption { get; set; }
public int? TrialPeriodDays { get; set; }
public bool HasSelfHost { get; set; }
public bool HasPolicies { get; set; }
public bool HasGroups { get; set; }
public bool HasDirectory { get; set; }
public bool HasEvents { get; set; }
public bool HasTotp { get; set; }
public bool Has2fa { get; set; }
public bool HasApi { get; set; }
public bool HasSso { get; set; }
public bool HasResetPassword { get; set; }
public bool UsersGetPremium { get; set; }
public int UpgradeSortOrder { get; set; }
public int DisplaySortOrder { get; set; }
public int? LegacyYear { get; set; }
public bool Disabled { get; set; }
public string StripePlanId { get; set; }
public string StripeSeatPlanId { get; set; }
public string StripeStoragePlanId { get; set; }
public string StripePremiumAccessPlanId { get; set; }
public decimal BasePrice { get; set; }
public decimal SeatPrice { get; set; }
public decimal AdditionalStoragePricePerGb { get; set; }
public decimal PremiumAccessOptionPrice { get; set; }
Type = plan.Type;
Product = plan.Product;
Name = plan.Name;
IsAnnual = plan.IsAnnual;
NameLocalizationKey = plan.NameLocalizationKey;
DescriptionLocalizationKey = plan.DescriptionLocalizationKey;
CanBeUsedByBusiness = plan.CanBeUsedByBusiness;
BaseSeats = plan.BaseSeats;
BaseStorageGb = plan.BaseStorageGb;
MaxCollections = plan.MaxCollections;
MaxUsers = plan.MaxUsers;
HasAdditionalSeatsOption = plan.HasAdditionalSeatsOption;
HasAdditionalStorageOption = plan.HasAdditionalStorageOption;
MaxAdditionalSeats = plan.MaxAdditionalSeats;
MaxAdditionalStorage = plan.MaxAdditionalStorage;
HasPremiumAccessOption = plan.HasPremiumAccessOption;
TrialPeriodDays = plan.TrialPeriodDays;
HasSelfHost = plan.HasSelfHost;
HasPolicies = plan.HasPolicies;
HasGroups = plan.HasGroups;
HasDirectory = plan.HasDirectory;
HasEvents = plan.HasEvents;
HasTotp = plan.HasTotp;
Has2fa = plan.Has2fa;
HasSso = plan.HasSso;
HasResetPassword = plan.HasResetPassword;
UsersGetPremium = plan.UsersGetPremium;
UpgradeSortOrder = plan.UpgradeSortOrder;
DisplaySortOrder = plan.DisplaySortOrder;
LegacyYear = plan.LegacyYear;
Disabled = plan.Disabled;
StripePlanId = plan.StripePlanId;
StripeSeatPlanId = plan.StripeSeatPlanId;
StripeStoragePlanId = plan.StripeStoragePlanId;
BasePrice = plan.BasePrice;
SeatPrice = plan.SeatPrice;
AdditionalStoragePricePerGb = plan.AdditionalStoragePricePerGb;
PremiumAccessOptionPrice = plan.PremiumAccessOptionPrice;
}
public PlanType Type { get; set; }
public ProductType Product { get; set; }
public string Name { get; set; }
public bool IsAnnual { get; set; }
public string NameLocalizationKey { get; set; }
public string DescriptionLocalizationKey { get; set; }
public bool CanBeUsedByBusiness { get; set; }
public int BaseSeats { get; set; }
public short? BaseStorageGb { get; set; }
public short? MaxCollections { get; set; }
public short? MaxUsers { get; set; }
public bool HasAdditionalSeatsOption { get; set; }
public int? MaxAdditionalSeats { get; set; }
public bool HasAdditionalStorageOption { get; set; }
public short? MaxAdditionalStorage { get; set; }
public bool HasPremiumAccessOption { get; set; }
public int? TrialPeriodDays { get; set; }
public bool HasSelfHost { get; set; }
public bool HasPolicies { get; set; }
public bool HasGroups { get; set; }
public bool HasDirectory { get; set; }
public bool HasEvents { get; set; }
public bool HasTotp { get; set; }
public bool Has2fa { get; set; }
public bool HasApi { get; set; }
public bool HasSso { get; set; }
public bool HasResetPassword { get; set; }
public bool UsersGetPremium { get; set; }
public int UpgradeSortOrder { get; set; }
public int DisplaySortOrder { get; set; }
public int? LegacyYear { get; set; }
public bool Disabled { get; set; }
public string StripePlanId { get; set; }
public string StripeSeatPlanId { get; set; }
public string StripeStoragePlanId { get; set; }
public string StripePremiumAccessPlanId { get; set; }
public decimal BasePrice { get; set; }
public decimal SeatPrice { get; set; }
public decimal AdditionalStoragePricePerGb { get; set; }
public decimal PremiumAccessOptionPrice { get; set; }
}

View File

@ -3,32 +3,31 @@ using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response
{
public class PolicyResponseModel : ResponseModel
{
public PolicyResponseModel(Policy policy, string obj = "policy")
: base(obj)
{
if (policy == null)
{
throw new ArgumentNullException(nameof(policy));
}
namespace Bit.Api.Models.Response;
Id = policy.Id.ToString();
OrganizationId = policy.OrganizationId.ToString();
Type = policy.Type;
Enabled = policy.Enabled;
if (!string.IsNullOrWhiteSpace(policy.Data))
{
Data = JsonSerializer.Deserialize<Dictionary<string, object>>(policy.Data);
}
public class PolicyResponseModel : ResponseModel
{
public PolicyResponseModel(Policy policy, string obj = "policy")
: base(obj)
{
if (policy == null)
{
throw new ArgumentNullException(nameof(policy));
}
public string Id { get; set; }
public string OrganizationId { get; set; }
public PolicyType Type { get; set; }
public Dictionary<string, object> Data { get; set; }
public bool Enabled { get; set; }
Id = policy.Id.ToString();
OrganizationId = policy.OrganizationId.ToString();
Type = policy.Type;
Enabled = policy.Enabled;
if (!string.IsNullOrWhiteSpace(policy.Data))
{
Data = JsonSerializer.Deserialize<Dictionary<string, object>>(policy.Data);
}
}
public string Id { get; set; }
public string OrganizationId { get; set; }
public PolicyType Type { get; set; }
public Dictionary<string, object> Data { get; set; }
public bool Enabled { get; set; }
}

View File

@ -4,98 +4,97 @@ using Bit.Core.Models.Data;
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
using Bit.Core.Utilities;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class ProfileOrganizationResponseModel : ResponseModel
{
public class ProfileOrganizationResponseModel : ResponseModel
public ProfileOrganizationResponseModel(string str) : base(str) { }
public ProfileOrganizationResponseModel(OrganizationUserOrganizationDetails organization) : this("profileOrganization")
{
public ProfileOrganizationResponseModel(string str) : base(str) { }
Id = organization.OrganizationId.ToString();
Name = organization.Name;
UsePolicies = organization.UsePolicies;
UseSso = organization.UseSso;
UseKeyConnector = organization.UseKeyConnector;
UseScim = organization.UseScim;
UseGroups = organization.UseGroups;
UseDirectory = organization.UseDirectory;
UseEvents = organization.UseEvents;
UseTotp = organization.UseTotp;
Use2fa = organization.Use2fa;
UseApi = organization.UseApi;
UseResetPassword = organization.UseResetPassword;
UsersGetPremium = organization.UsersGetPremium;
SelfHost = organization.SelfHost;
Seats = organization.Seats;
MaxCollections = organization.MaxCollections;
MaxStorageGb = organization.MaxStorageGb;
Key = organization.Key;
HasPublicAndPrivateKeys = organization.PublicKey != null && organization.PrivateKey != null;
Status = organization.Status;
Type = organization.Type;
Enabled = organization.Enabled;
SsoBound = !string.IsNullOrWhiteSpace(organization.SsoExternalId);
Identifier = organization.Identifier;
Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(organization.Permissions);
ResetPasswordEnrolled = organization.ResetPasswordKey != null;
UserId = organization.UserId?.ToString();
ProviderId = organization.ProviderId?.ToString();
ProviderName = organization.ProviderName;
FamilySponsorshipFriendlyName = organization.FamilySponsorshipFriendlyName;
FamilySponsorshipAvailable = FamilySponsorshipFriendlyName == null &&
StaticStore.GetSponsoredPlan(PlanSponsorshipType.FamiliesForEnterprise)
.UsersCanSponsor(organization);
PlanProductType = StaticStore.GetPlan(organization.PlanType).Product;
FamilySponsorshipLastSyncDate = organization.FamilySponsorshipLastSyncDate;
FamilySponsorshipToDelete = organization.FamilySponsorshipToDelete;
FamilySponsorshipValidUntil = organization.FamilySponsorshipValidUntil;
public ProfileOrganizationResponseModel(OrganizationUserOrganizationDetails organization) : this("profileOrganization")
if (organization.SsoConfig != null)
{
Id = organization.OrganizationId.ToString();
Name = organization.Name;
UsePolicies = organization.UsePolicies;
UseSso = organization.UseSso;
UseKeyConnector = organization.UseKeyConnector;
UseScim = organization.UseScim;
UseGroups = organization.UseGroups;
UseDirectory = organization.UseDirectory;
UseEvents = organization.UseEvents;
UseTotp = organization.UseTotp;
Use2fa = organization.Use2fa;
UseApi = organization.UseApi;
UseResetPassword = organization.UseResetPassword;
UsersGetPremium = organization.UsersGetPremium;
SelfHost = organization.SelfHost;
Seats = organization.Seats;
MaxCollections = organization.MaxCollections;
MaxStorageGb = organization.MaxStorageGb;
Key = organization.Key;
HasPublicAndPrivateKeys = organization.PublicKey != null && organization.PrivateKey != null;
Status = organization.Status;
Type = organization.Type;
Enabled = organization.Enabled;
SsoBound = !string.IsNullOrWhiteSpace(organization.SsoExternalId);
Identifier = organization.Identifier;
Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(organization.Permissions);
ResetPasswordEnrolled = organization.ResetPasswordKey != null;
UserId = organization.UserId?.ToString();
ProviderId = organization.ProviderId?.ToString();
ProviderName = organization.ProviderName;
FamilySponsorshipFriendlyName = organization.FamilySponsorshipFriendlyName;
FamilySponsorshipAvailable = FamilySponsorshipFriendlyName == null &&
StaticStore.GetSponsoredPlan(PlanSponsorshipType.FamiliesForEnterprise)
.UsersCanSponsor(organization);
PlanProductType = StaticStore.GetPlan(organization.PlanType).Product;
FamilySponsorshipLastSyncDate = organization.FamilySponsorshipLastSyncDate;
FamilySponsorshipToDelete = organization.FamilySponsorshipToDelete;
FamilySponsorshipValidUntil = organization.FamilySponsorshipValidUntil;
if (organization.SsoConfig != null)
{
var ssoConfigData = SsoConfigurationData.Deserialize(organization.SsoConfig);
KeyConnectorEnabled = ssoConfigData.KeyConnectorEnabled && !string.IsNullOrEmpty(ssoConfigData.KeyConnectorUrl);
KeyConnectorUrl = ssoConfigData.KeyConnectorUrl;
}
var ssoConfigData = SsoConfigurationData.Deserialize(organization.SsoConfig);
KeyConnectorEnabled = ssoConfigData.KeyConnectorEnabled && !string.IsNullOrEmpty(ssoConfigData.KeyConnectorUrl);
KeyConnectorUrl = ssoConfigData.KeyConnectorUrl;
}
public string Id { get; set; }
public string Name { get; set; }
public bool UsePolicies { get; set; }
public bool UseSso { get; set; }
public bool UseKeyConnector { get; set; }
public bool UseScim { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public bool UseEvents { get; set; }
public bool UseTotp { get; set; }
public bool Use2fa { get; set; }
public bool UseApi { get; set; }
public bool UseResetPassword { get; set; }
public bool UsersGetPremium { get; set; }
public bool SelfHost { get; set; }
public int? Seats { get; set; }
public short? MaxCollections { get; set; }
public short? MaxStorageGb { get; set; }
public string Key { get; set; }
public OrganizationUserStatusType Status { get; set; }
public OrganizationUserType Type { get; set; }
public bool Enabled { get; set; }
public bool SsoBound { get; set; }
public string Identifier { get; set; }
public Permissions Permissions { get; set; }
public bool ResetPasswordEnrolled { get; set; }
public string UserId { get; set; }
public bool HasPublicAndPrivateKeys { get; set; }
public string ProviderId { get; set; }
public string ProviderName { get; set; }
public string FamilySponsorshipFriendlyName { get; set; }
public bool FamilySponsorshipAvailable { get; set; }
public ProductType PlanProductType { get; set; }
public bool KeyConnectorEnabled { get; set; }
public string KeyConnectorUrl { get; set; }
public DateTime? FamilySponsorshipLastSyncDate { get; set; }
public DateTime? FamilySponsorshipValidUntil { get; set; }
public bool? FamilySponsorshipToDelete { get; set; }
}
public string Id { get; set; }
public string Name { get; set; }
public bool UsePolicies { get; set; }
public bool UseSso { get; set; }
public bool UseKeyConnector { get; set; }
public bool UseScim { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public bool UseEvents { get; set; }
public bool UseTotp { get; set; }
public bool Use2fa { get; set; }
public bool UseApi { get; set; }
public bool UseResetPassword { get; set; }
public bool UsersGetPremium { get; set; }
public bool SelfHost { get; set; }
public int? Seats { get; set; }
public short? MaxCollections { get; set; }
public short? MaxStorageGb { get; set; }
public string Key { get; set; }
public OrganizationUserStatusType Status { get; set; }
public OrganizationUserType Type { get; set; }
public bool Enabled { get; set; }
public bool SsoBound { get; set; }
public string Identifier { get; set; }
public Permissions Permissions { get; set; }
public bool ResetPasswordEnrolled { get; set; }
public string UserId { get; set; }
public bool HasPublicAndPrivateKeys { get; set; }
public string ProviderId { get; set; }
public string ProviderName { get; set; }
public string FamilySponsorshipFriendlyName { get; set; }
public bool FamilySponsorshipAvailable { get; set; }
public ProductType PlanProductType { get; set; }
public bool KeyConnectorEnabled { get; set; }
public string KeyConnectorUrl { get; set; }
public DateTime? FamilySponsorshipLastSyncDate { get; set; }
public DateTime? FamilySponsorshipValidUntil { get; set; }
public bool? FamilySponsorshipToDelete { get; set; }
}

View File

@ -1,43 +1,42 @@
using Bit.Core.Enums;
using Bit.Core.Models.Data;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class ProfileProviderOrganizationResponseModel : ProfileOrganizationResponseModel
{
public class ProfileProviderOrganizationResponseModel : ProfileOrganizationResponseModel
public ProfileProviderOrganizationResponseModel(ProviderUserOrganizationDetails organization)
: base("profileProviderOrganization")
{
public ProfileProviderOrganizationResponseModel(ProviderUserOrganizationDetails organization)
: base("profileProviderOrganization")
{
Id = organization.OrganizationId.ToString();
Name = organization.Name;
UsePolicies = organization.UsePolicies;
UseSso = organization.UseSso;
UseKeyConnector = organization.UseKeyConnector;
UseScim = organization.UseScim;
UseGroups = organization.UseGroups;
UseDirectory = organization.UseDirectory;
UseEvents = organization.UseEvents;
UseTotp = organization.UseTotp;
Use2fa = organization.Use2fa;
UseApi = organization.UseApi;
UseResetPassword = organization.UseResetPassword;
UsersGetPremium = organization.UsersGetPremium;
SelfHost = organization.SelfHost;
Seats = organization.Seats;
MaxCollections = organization.MaxCollections;
MaxStorageGb = organization.MaxStorageGb;
Key = organization.Key;
HasPublicAndPrivateKeys = organization.PublicKey != null && organization.PrivateKey != null;
Status = OrganizationUserStatusType.Confirmed; // Provider users are always confirmed
Type = OrganizationUserType.Owner; // Provider users behave like Owners
Enabled = organization.Enabled;
SsoBound = false;
Identifier = organization.Identifier;
Permissions = new Permissions();
ResetPasswordEnrolled = false;
UserId = organization.UserId?.ToString();
ProviderId = organization.ProviderId?.ToString();
ProviderName = organization.ProviderName;
}
Id = organization.OrganizationId.ToString();
Name = organization.Name;
UsePolicies = organization.UsePolicies;
UseSso = organization.UseSso;
UseKeyConnector = organization.UseKeyConnector;
UseScim = organization.UseScim;
UseGroups = organization.UseGroups;
UseDirectory = organization.UseDirectory;
UseEvents = organization.UseEvents;
UseTotp = organization.UseTotp;
Use2fa = organization.Use2fa;
UseApi = organization.UseApi;
UseResetPassword = organization.UseResetPassword;
UsersGetPremium = organization.UsersGetPremium;
SelfHost = organization.SelfHost;
Seats = organization.Seats;
MaxCollections = organization.MaxCollections;
MaxStorageGb = organization.MaxStorageGb;
Key = organization.Key;
HasPublicAndPrivateKeys = organization.PublicKey != null && organization.PrivateKey != null;
Status = OrganizationUserStatusType.Confirmed; // Provider users are always confirmed
Type = OrganizationUserType.Owner; // Provider users behave like Owners
Enabled = organization.Enabled;
SsoBound = false;
Identifier = organization.Identifier;
Permissions = new Permissions();
ResetPasswordEnrolled = false;
UserId = organization.UserId?.ToString();
ProviderId = organization.ProviderId?.ToString();
ProviderName = organization.ProviderName;
}
}

View File

@ -4,62 +4,61 @@ using Bit.Core.Models.Api;
using Bit.Core.Models.Data;
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class ProfileResponseModel : ResponseModel
{
public class ProfileResponseModel : ResponseModel
public ProfileResponseModel(User user,
IEnumerable<OrganizationUserOrganizationDetails> organizationsUserDetails,
IEnumerable<ProviderUserProviderDetails> providerUserDetails,
IEnumerable<ProviderUserOrganizationDetails> providerUserOrganizationDetails,
bool twoFactorEnabled,
bool premiumFromOrganization) : base("profile")
{
public ProfileResponseModel(User user,
IEnumerable<OrganizationUserOrganizationDetails> organizationsUserDetails,
IEnumerable<ProviderUserProviderDetails> providerUserDetails,
IEnumerable<ProviderUserOrganizationDetails> providerUserOrganizationDetails,
bool twoFactorEnabled,
bool premiumFromOrganization) : base("profile")
if (user == null)
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
Id = user.Id.ToString();
Name = user.Name;
Email = user.Email;
EmailVerified = user.EmailVerified;
Premium = user.Premium;
PremiumFromOrganization = premiumFromOrganization;
MasterPasswordHint = string.IsNullOrWhiteSpace(user.MasterPasswordHint) ? null : user.MasterPasswordHint;
Culture = user.Culture;
TwoFactorEnabled = twoFactorEnabled;
Key = user.Key;
PrivateKey = user.PrivateKey;
SecurityStamp = user.SecurityStamp;
ForcePasswordReset = user.ForcePasswordReset;
UsesKeyConnector = user.UsesKeyConnector;
Organizations = organizationsUserDetails?.Select(o => new ProfileOrganizationResponseModel(o));
Providers = providerUserDetails?.Select(p => new ProfileProviderResponseModel(p));
ProviderOrganizations =
providerUserOrganizationDetails?.Select(po => new ProfileProviderOrganizationResponseModel(po));
throw new ArgumentNullException(nameof(user));
}
public ProfileResponseModel() : base("profile")
{
}
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 bool PremiumFromOrganization { get; set; }
public string MasterPasswordHint { get; set; }
public string Culture { get; set; }
public bool TwoFactorEnabled { get; set; }
public string Key { get; set; }
public string PrivateKey { get; set; }
public string SecurityStamp { get; set; }
public bool ForcePasswordReset { get; set; }
public bool UsesKeyConnector { get; set; }
public IEnumerable<ProfileOrganizationResponseModel> Organizations { get; set; }
public IEnumerable<ProfileProviderResponseModel> Providers { get; set; }
public IEnumerable<ProfileProviderOrganizationResponseModel> ProviderOrganizations { get; set; }
Id = user.Id.ToString();
Name = user.Name;
Email = user.Email;
EmailVerified = user.EmailVerified;
Premium = user.Premium;
PremiumFromOrganization = premiumFromOrganization;
MasterPasswordHint = string.IsNullOrWhiteSpace(user.MasterPasswordHint) ? null : user.MasterPasswordHint;
Culture = user.Culture;
TwoFactorEnabled = twoFactorEnabled;
Key = user.Key;
PrivateKey = user.PrivateKey;
SecurityStamp = user.SecurityStamp;
ForcePasswordReset = user.ForcePasswordReset;
UsesKeyConnector = user.UsesKeyConnector;
Organizations = organizationsUserDetails?.Select(o => new ProfileOrganizationResponseModel(o));
Providers = providerUserDetails?.Select(p => new ProfileProviderResponseModel(p));
ProviderOrganizations =
providerUserOrganizationDetails?.Select(po => new ProfileProviderOrganizationResponseModel(po));
}
public ProfileResponseModel() : base("profile")
{
}
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 bool PremiumFromOrganization { get; set; }
public string MasterPasswordHint { get; set; }
public string Culture { get; set; }
public bool TwoFactorEnabled { get; set; }
public string Key { get; set; }
public string PrivateKey { get; set; }
public string SecurityStamp { get; set; }
public bool ForcePasswordReset { get; set; }
public bool UsesKeyConnector { get; set; }
public IEnumerable<ProfileOrganizationResponseModel> Organizations { get; set; }
public IEnumerable<ProfileProviderResponseModel> Providers { get; set; }
public IEnumerable<ProfileProviderOrganizationResponseModel> ProviderOrganizations { get; set; }
}

View File

@ -3,32 +3,31 @@ using Bit.Core.Models.Api;
using Bit.Core.Models.Data;
using Bit.Core.Utilities;
namespace Bit.Api.Models.Response.Providers
{
public class ProfileProviderResponseModel : ResponseModel
{
public ProfileProviderResponseModel(ProviderUserProviderDetails provider)
: base("profileProvider")
{
Id = provider.ProviderId.ToString();
Name = provider.Name;
Key = provider.Key;
Status = provider.Status;
Type = provider.Type;
Enabled = provider.Enabled;
Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(provider.Permissions);
UserId = provider.UserId?.ToString();
UseEvents = provider.UseEvents;
}
namespace Bit.Api.Models.Response.Providers;
public string Id { get; set; }
public string Name { get; set; }
public string Key { get; set; }
public ProviderUserStatusType Status { get; set; }
public ProviderUserType Type { get; set; }
public bool Enabled { get; set; }
public Permissions Permissions { get; set; }
public string UserId { get; set; }
public bool UseEvents { get; set; }
public class ProfileProviderResponseModel : ResponseModel
{
public ProfileProviderResponseModel(ProviderUserProviderDetails provider)
: base("profileProvider")
{
Id = provider.ProviderId.ToString();
Name = provider.Name;
Key = provider.Key;
Status = provider.Status;
Type = provider.Type;
Enabled = provider.Enabled;
Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(provider.Permissions);
UserId = provider.UserId?.ToString();
UseEvents = provider.UseEvents;
}
public string Id { get; set; }
public string Name { get; set; }
public string Key { get; set; }
public ProviderUserStatusType Status { get; set; }
public ProviderUserType Type { get; set; }
public bool Enabled { get; set; }
public Permissions Permissions { get; set; }
public string UserId { get; set; }
public bool UseEvents { get; set; }
}

View File

@ -2,72 +2,71 @@
using Bit.Core.Models.Api;
using Bit.Core.Models.Data;
namespace Bit.Api.Models.Response.Providers
namespace Bit.Api.Models.Response.Providers;
public class ProviderOrganizationResponseModel : ResponseModel
{
public class ProviderOrganizationResponseModel : ResponseModel
public ProviderOrganizationResponseModel(ProviderOrganization providerOrganization,
string obj = "providerOrganization") : base(obj)
{
public ProviderOrganizationResponseModel(ProviderOrganization providerOrganization,
string obj = "providerOrganization") : base(obj)
if (providerOrganization == null)
{
if (providerOrganization == null)
{
throw new ArgumentNullException(nameof(providerOrganization));
}
Id = providerOrganization.Id;
ProviderId = providerOrganization.ProviderId;
OrganizationId = providerOrganization.OrganizationId;
Key = providerOrganization.Key;
Settings = providerOrganization.Settings;
CreationDate = providerOrganization.CreationDate;
RevisionDate = providerOrganization.RevisionDate;
throw new ArgumentNullException(nameof(providerOrganization));
}
public ProviderOrganizationResponseModel(ProviderOrganizationOrganizationDetails providerOrganization,
string obj = "providerOrganization") : base(obj)
{
if (providerOrganization == null)
{
throw new ArgumentNullException(nameof(providerOrganization));
}
Id = providerOrganization.Id;
ProviderId = providerOrganization.ProviderId;
OrganizationId = providerOrganization.OrganizationId;
Key = providerOrganization.Key;
Settings = providerOrganization.Settings;
CreationDate = providerOrganization.CreationDate;
RevisionDate = providerOrganization.RevisionDate;
UserCount = providerOrganization.UserCount;
Seats = providerOrganization.Seats;
Plan = providerOrganization.Plan;
}
public Guid Id { get; set; }
public Guid ProviderId { get; set; }
public Guid OrganizationId { get; set; }
public string Key { get; set; }
public string Settings { get; set; }
public DateTime CreationDate { get; set; }
public DateTime RevisionDate { get; set; }
public int UserCount { get; set; }
public int? Seats { get; set; }
public string Plan { get; set; }
Id = providerOrganization.Id;
ProviderId = providerOrganization.ProviderId;
OrganizationId = providerOrganization.OrganizationId;
Key = providerOrganization.Key;
Settings = providerOrganization.Settings;
CreationDate = providerOrganization.CreationDate;
RevisionDate = providerOrganization.RevisionDate;
}
public class ProviderOrganizationOrganizationDetailsResponseModel : ProviderOrganizationResponseModel
public ProviderOrganizationResponseModel(ProviderOrganizationOrganizationDetails providerOrganization,
string obj = "providerOrganization") : base(obj)
{
public ProviderOrganizationOrganizationDetailsResponseModel(ProviderOrganizationOrganizationDetails providerOrganization,
string obj = "providerOrganizationOrganizationDetail") : base(providerOrganization, obj)
if (providerOrganization == null)
{
if (providerOrganization == null)
{
throw new ArgumentNullException(nameof(providerOrganization));
}
OrganizationName = providerOrganization.OrganizationName;
throw new ArgumentNullException(nameof(providerOrganization));
}
public string OrganizationName { get; set; }
Id = providerOrganization.Id;
ProviderId = providerOrganization.ProviderId;
OrganizationId = providerOrganization.OrganizationId;
Key = providerOrganization.Key;
Settings = providerOrganization.Settings;
CreationDate = providerOrganization.CreationDate;
RevisionDate = providerOrganization.RevisionDate;
UserCount = providerOrganization.UserCount;
Seats = providerOrganization.Seats;
Plan = providerOrganization.Plan;
}
public Guid Id { get; set; }
public Guid ProviderId { get; set; }
public Guid OrganizationId { get; set; }
public string Key { get; set; }
public string Settings { get; set; }
public DateTime CreationDate { get; set; }
public DateTime RevisionDate { get; set; }
public int UserCount { get; set; }
public int? Seats { get; set; }
public string Plan { get; set; }
}
public class ProviderOrganizationOrganizationDetailsResponseModel : ProviderOrganizationResponseModel
{
public ProviderOrganizationOrganizationDetailsResponseModel(ProviderOrganizationOrganizationDetails providerOrganization,
string obj = "providerOrganizationOrganizationDetail") : base(providerOrganization, obj)
{
if (providerOrganization == null)
{
throw new ArgumentNullException(nameof(providerOrganization));
}
OrganizationName = providerOrganization.OrganizationName;
}
public string OrganizationName { get; set; }
}

View File

@ -1,36 +1,35 @@
using Bit.Core.Entities.Provider;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response.Providers
{
public class ProviderResponseModel : ResponseModel
{
public ProviderResponseModel(Provider provider, string obj = "provider") : base(obj)
{
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
namespace Bit.Api.Models.Response.Providers;
Id = provider.Id;
Name = provider.Name;
BusinessName = provider.BusinessName;
BusinessAddress1 = provider.BusinessAddress1;
BusinessAddress2 = provider.BusinessAddress2;
BusinessAddress3 = provider.BusinessAddress3;
BusinessCountry = provider.BusinessCountry;
BusinessTaxNumber = provider.BusinessTaxNumber;
BillingEmail = provider.BillingEmail;
public class ProviderResponseModel : ResponseModel
{
public ProviderResponseModel(Provider provider, string obj = "provider") : base(obj)
{
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
public Guid Id { get; set; }
public string Name { get; set; }
public string BusinessName { get; set; }
public string BusinessAddress1 { get; set; }
public string BusinessAddress2 { get; set; }
public string BusinessAddress3 { get; set; }
public string BusinessCountry { get; set; }
public string BusinessTaxNumber { get; set; }
public string BillingEmail { get; set; }
Id = provider.Id;
Name = provider.Name;
BusinessName = provider.BusinessName;
BusinessAddress1 = provider.BusinessAddress1;
BusinessAddress2 = provider.BusinessAddress2;
BusinessAddress3 = provider.BusinessAddress3;
BusinessCountry = provider.BusinessCountry;
BusinessTaxNumber = provider.BusinessTaxNumber;
BillingEmail = provider.BillingEmail;
}
public Guid Id { get; set; }
public string Name { get; set; }
public string BusinessName { get; set; }
public string BusinessAddress1 { get; set; }
public string BusinessAddress2 { get; set; }
public string BusinessAddress3 { get; set; }
public string BusinessCountry { get; set; }
public string BusinessTaxNumber { get; set; }
public string BillingEmail { get; set; }
}

View File

@ -4,89 +4,88 @@ using Bit.Core.Models.Api;
using Bit.Core.Models.Data;
using Bit.Core.Utilities;
namespace Bit.Api.Models.Response.Providers
namespace Bit.Api.Models.Response.Providers;
public class ProviderUserResponseModel : ResponseModel
{
public class ProviderUserResponseModel : ResponseModel
public ProviderUserResponseModel(ProviderUser providerUser, string obj = "providerUser")
: base(obj)
{
public ProviderUserResponseModel(ProviderUser providerUser, string obj = "providerUser")
: base(obj)
if (providerUser == null)
{
if (providerUser == null)
{
throw new ArgumentNullException(nameof(providerUser));
}
Id = providerUser.Id.ToString();
UserId = providerUser.UserId?.ToString();
Type = providerUser.Type;
Status = providerUser.Status;
Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(providerUser.Permissions);
throw new ArgumentNullException(nameof(providerUser));
}
public ProviderUserResponseModel(ProviderUserUserDetails providerUser, string obj = "providerUser")
: base(obj)
{
if (providerUser == null)
{
throw new ArgumentNullException(nameof(providerUser));
}
Id = providerUser.Id.ToString();
UserId = providerUser.UserId?.ToString();
Type = providerUser.Type;
Status = providerUser.Status;
Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(providerUser.Permissions);
}
public string Id { get; set; }
public string UserId { get; set; }
public ProviderUserType Type { get; set; }
public ProviderUserStatusType Status { get; set; }
public Permissions Permissions { get; set; }
Id = providerUser.Id.ToString();
UserId = providerUser.UserId?.ToString();
Type = providerUser.Type;
Status = providerUser.Status;
Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(providerUser.Permissions);
}
public class ProviderUserUserDetailsResponseModel : ProviderUserResponseModel
public ProviderUserResponseModel(ProviderUserUserDetails providerUser, string obj = "providerUser")
: base(obj)
{
public ProviderUserUserDetailsResponseModel(ProviderUserUserDetails providerUser,
string obj = "providerUserUserDetails") : base(providerUser, obj)
if (providerUser == null)
{
if (providerUser == null)
{
throw new ArgumentNullException(nameof(providerUser));
}
Name = providerUser.Name;
Email = providerUser.Email;
throw new ArgumentNullException(nameof(providerUser));
}
public string Name { get; set; }
public string Email { get; set; }
Id = providerUser.Id.ToString();
UserId = providerUser.UserId?.ToString();
Type = providerUser.Type;
Status = providerUser.Status;
Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(providerUser.Permissions);
}
public class ProviderUserPublicKeyResponseModel : ResponseModel
{
public ProviderUserPublicKeyResponseModel(Guid id, Guid userId, string key,
string obj = "providerUserPublicKeyResponseModel") : base(obj)
{
Id = id;
UserId = userId;
Key = key;
}
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string Key { get; set; }
}
public class ProviderUserBulkResponseModel : ResponseModel
{
public ProviderUserBulkResponseModel(Guid id, string error,
string obj = "providerBulkConfirmResponseModel") : base(obj)
{
Id = id;
Error = error;
}
public Guid Id { get; set; }
public string Error { get; set; }
}
public string Id { get; set; }
public string UserId { get; set; }
public ProviderUserType Type { get; set; }
public ProviderUserStatusType Status { get; set; }
public Permissions Permissions { get; set; }
}
public class ProviderUserUserDetailsResponseModel : ProviderUserResponseModel
{
public ProviderUserUserDetailsResponseModel(ProviderUserUserDetails providerUser,
string obj = "providerUserUserDetails") : base(providerUser, obj)
{
if (providerUser == null)
{
throw new ArgumentNullException(nameof(providerUser));
}
Name = providerUser.Name;
Email = providerUser.Email;
}
public string Name { get; set; }
public string Email { get; set; }
}
public class ProviderUserPublicKeyResponseModel : ResponseModel
{
public ProviderUserPublicKeyResponseModel(Guid id, Guid userId, string key,
string obj = "providerUserPublicKeyResponseModel") : base(obj)
{
Id = id;
UserId = userId;
Key = key;
}
public Guid Id { get; set; }
public Guid UserId { get; set; }
public string Key { get; set; }
}
public class ProviderUserBulkResponseModel : ResponseModel
{
public ProviderUserBulkResponseModel(Guid id, string error,
string obj = "providerBulkConfirmResponseModel") : base(obj)
{
Id = id;
Error = error;
}
public Guid Id { get; set; }
public string Error { get; set; }
}

View File

@ -1,23 +1,22 @@
using Bit.Core.Models.Data;
namespace Bit.Api.Models.Response
{
public class SelectionReadOnlyResponseModel
{
public SelectionReadOnlyResponseModel(SelectionReadOnly selection)
{
if (selection == null)
{
throw new ArgumentNullException(nameof(selection));
}
namespace Bit.Api.Models.Response;
Id = selection.Id.ToString();
ReadOnly = selection.ReadOnly;
HidePasswords = selection.HidePasswords;
public class SelectionReadOnlyResponseModel
{
public SelectionReadOnlyResponseModel(SelectionReadOnly selection)
{
if (selection == null)
{
throw new ArgumentNullException(nameof(selection));
}
public string Id { get; set; }
public bool ReadOnly { get; set; }
public bool HidePasswords { get; set; }
Id = selection.Id.ToString();
ReadOnly = selection.ReadOnly;
HidePasswords = selection.HidePasswords;
}
public string Id { get; set; }
public bool ReadOnly { get; set; }
public bool HidePasswords { get; set; }
}

View File

@ -6,48 +6,47 @@ using Bit.Core.Models.Data;
using Bit.Core.Settings;
using Bit.Core.Utilities;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class SendAccessResponseModel : ResponseModel
{
public class SendAccessResponseModel : ResponseModel
public SendAccessResponseModel(Send send, GlobalSettings globalSettings)
: base("send-access")
{
public SendAccessResponseModel(Send send, GlobalSettings globalSettings)
: base("send-access")
if (send == null)
{
if (send == null)
{
throw new ArgumentNullException(nameof(send));
}
Id = CoreHelpers.Base64UrlEncode(send.Id.ToByteArray());
Type = send.Type;
SendData sendData;
switch (send.Type)
{
case SendType.File:
var fileData = JsonSerializer.Deserialize<SendFileData>(send.Data);
sendData = fileData;
File = new SendFileModel(fileData);
break;
case SendType.Text:
var textData = JsonSerializer.Deserialize<SendTextData>(send.Data);
sendData = textData;
Text = new SendTextModel(textData);
break;
default:
throw new ArgumentException("Unsupported " + nameof(Type) + ".");
}
Name = sendData.Name;
ExpirationDate = send.ExpirationDate;
throw new ArgumentNullException(nameof(send));
}
public string Id { get; set; }
public SendType Type { get; set; }
public string Name { get; set; }
public SendFileModel File { get; set; }
public SendTextModel Text { get; set; }
public DateTime? ExpirationDate { get; set; }
public string CreatorIdentifier { get; set; }
Id = CoreHelpers.Base64UrlEncode(send.Id.ToByteArray());
Type = send.Type;
SendData sendData;
switch (send.Type)
{
case SendType.File:
var fileData = JsonSerializer.Deserialize<SendFileData>(send.Data);
sendData = fileData;
File = new SendFileModel(fileData);
break;
case SendType.Text:
var textData = JsonSerializer.Deserialize<SendTextData>(send.Data);
sendData = textData;
Text = new SendTextModel(textData);
break;
default:
throw new ArgumentException("Unsupported " + nameof(Type) + ".");
}
Name = sendData.Name;
ExpirationDate = send.ExpirationDate;
}
public string Id { get; set; }
public SendType Type { get; set; }
public string Name { get; set; }
public SendFileModel File { get; set; }
public SendTextModel Text { get; set; }
public DateTime? ExpirationDate { get; set; }
public string CreatorIdentifier { get; set; }
}

View File

@ -1,12 +1,11 @@
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response
{
public class SendFileDownloadDataResponseModel : ResponseModel
{
public string Id { get; set; }
public string Url { get; set; }
namespace Bit.Api.Models.Response;
public SendFileDownloadDataResponseModel() : base("send-fileDownload") { }
}
public class SendFileDownloadDataResponseModel : ResponseModel
{
public string Id { get; set; }
public string Url { get; set; }
public SendFileDownloadDataResponseModel() : base("send-fileDownload") { }
}

View File

@ -1,15 +1,14 @@
using Bit.Core.Enums;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class SendFileUploadDataResponseModel : ResponseModel
{
public class SendFileUploadDataResponseModel : ResponseModel
{
public SendFileUploadDataResponseModel() : base("send-fileUpload") { }
public SendFileUploadDataResponseModel() : base("send-fileUpload") { }
public string Url { get; set; }
public FileUploadType FileUploadType { get; set; }
public SendResponseModel SendResponse { get; set; }
public string Url { get; set; }
public FileUploadType FileUploadType { get; set; }
public SendResponseModel SendResponse { get; set; }
}
}

View File

@ -6,67 +6,66 @@ using Bit.Core.Models.Data;
using Bit.Core.Settings;
using Bit.Core.Utilities;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class SendResponseModel : ResponseModel
{
public class SendResponseModel : ResponseModel
public SendResponseModel(Send send, GlobalSettings globalSettings)
: base("send")
{
public SendResponseModel(Send send, GlobalSettings globalSettings)
: base("send")
if (send == null)
{
if (send == null)
{
throw new ArgumentNullException(nameof(send));
}
Id = send.Id.ToString();
AccessId = CoreHelpers.Base64UrlEncode(send.Id.ToByteArray());
Type = send.Type;
Key = send.Key;
MaxAccessCount = send.MaxAccessCount;
AccessCount = send.AccessCount;
RevisionDate = send.RevisionDate;
ExpirationDate = send.ExpirationDate;
DeletionDate = send.DeletionDate;
Password = send.Password;
Disabled = send.Disabled;
HideEmail = send.HideEmail.GetValueOrDefault();
SendData sendData;
switch (send.Type)
{
case SendType.File:
var fileData = JsonSerializer.Deserialize<SendFileData>(send.Data);
sendData = fileData;
File = new SendFileModel(fileData);
break;
case SendType.Text:
var textData = JsonSerializer.Deserialize<SendTextData>(send.Data);
sendData = textData;
Text = new SendTextModel(textData);
break;
default:
throw new ArgumentException("Unsupported " + nameof(Type) + ".");
}
Name = sendData.Name;
Notes = sendData.Notes;
throw new ArgumentNullException(nameof(send));
}
public string Id { get; set; }
public string AccessId { get; set; }
public SendType Type { get; set; }
public string Name { get; set; }
public string Notes { get; set; }
public SendFileModel File { get; set; }
public SendTextModel Text { get; set; }
public string Key { get; set; }
public int? MaxAccessCount { get; set; }
public int AccessCount { get; set; }
public string Password { get; set; }
public bool Disabled { get; set; }
public DateTime RevisionDate { get; set; }
public DateTime? ExpirationDate { get; set; }
public DateTime DeletionDate { get; set; }
public bool HideEmail { get; set; }
Id = send.Id.ToString();
AccessId = CoreHelpers.Base64UrlEncode(send.Id.ToByteArray());
Type = send.Type;
Key = send.Key;
MaxAccessCount = send.MaxAccessCount;
AccessCount = send.AccessCount;
RevisionDate = send.RevisionDate;
ExpirationDate = send.ExpirationDate;
DeletionDate = send.DeletionDate;
Password = send.Password;
Disabled = send.Disabled;
HideEmail = send.HideEmail.GetValueOrDefault();
SendData sendData;
switch (send.Type)
{
case SendType.File:
var fileData = JsonSerializer.Deserialize<SendFileData>(send.Data);
sendData = fileData;
File = new SendFileModel(fileData);
break;
case SendType.Text:
var textData = JsonSerializer.Deserialize<SendTextData>(send.Data);
sendData = textData;
Text = new SendTextModel(textData);
break;
default:
throw new ArgumentException("Unsupported " + nameof(Type) + ".");
}
Name = sendData.Name;
Notes = sendData.Notes;
}
public string Id { get; set; }
public string AccessId { get; set; }
public SendType Type { get; set; }
public string Name { get; set; }
public string Notes { get; set; }
public SendFileModel File { get; set; }
public SendTextModel Text { get; set; }
public string Key { get; set; }
public int? MaxAccessCount { get; set; }
public int AccessCount { get; set; }
public string Password { get; set; }
public bool Disabled { get; set; }
public DateTime RevisionDate { get; set; }
public DateTime? ExpirationDate { get; set; }
public DateTime DeletionDate { get; set; }
public bool HideEmail { get; set; }
}

View File

@ -3,104 +3,103 @@ using Bit.Core.Models.Api;
using Bit.Core.Models.Business;
using Bit.Core.Utilities;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class SubscriptionResponseModel : ResponseModel
{
public class SubscriptionResponseModel : ResponseModel
public SubscriptionResponseModel(User user, SubscriptionInfo subscription, UserLicense license)
: base("subscription")
{
public SubscriptionResponseModel(User user, SubscriptionInfo subscription, UserLicense license)
: base("subscription")
Subscription = subscription.Subscription != null ? new BillingSubscription(subscription.Subscription) : null;
UpcomingInvoice = subscription.UpcomingInvoice != null ?
new BillingSubscriptionUpcomingInvoice(subscription.UpcomingInvoice) : null;
StorageName = user.Storage.HasValue ? CoreHelpers.ReadableBytesSize(user.Storage.Value) : null;
StorageGb = user.Storage.HasValue ? Math.Round(user.Storage.Value / 1073741824D, 2) : 0; // 1 GB
MaxStorageGb = user.MaxStorageGb;
License = license;
Expiration = License.Expires;
UsingInAppPurchase = subscription.UsingInAppPurchase;
}
public SubscriptionResponseModel(User user, UserLicense license = null)
: base("subscription")
{
StorageName = user.Storage.HasValue ? CoreHelpers.ReadableBytesSize(user.Storage.Value) : null;
StorageGb = user.Storage.HasValue ? Math.Round(user.Storage.Value / 1073741824D, 2) : 0; // 1 GB
MaxStorageGb = user.MaxStorageGb;
Expiration = user.PremiumExpirationDate;
if (license != null)
{
Subscription = subscription.Subscription != null ? new BillingSubscription(subscription.Subscription) : null;
UpcomingInvoice = subscription.UpcomingInvoice != null ?
new BillingSubscriptionUpcomingInvoice(subscription.UpcomingInvoice) : null;
StorageName = user.Storage.HasValue ? CoreHelpers.ReadableBytesSize(user.Storage.Value) : null;
StorageGb = user.Storage.HasValue ? Math.Round(user.Storage.Value / 1073741824D, 2) : 0; // 1 GB
MaxStorageGb = user.MaxStorageGb;
License = license;
Expiration = License.Expires;
UsingInAppPurchase = subscription.UsingInAppPurchase;
}
public SubscriptionResponseModel(User user, UserLicense license = null)
: base("subscription")
{
StorageName = user.Storage.HasValue ? CoreHelpers.ReadableBytesSize(user.Storage.Value) : null;
StorageGb = user.Storage.HasValue ? Math.Round(user.Storage.Value / 1073741824D, 2) : 0; // 1 GB
MaxStorageGb = user.MaxStorageGb;
Expiration = user.PremiumExpirationDate;
if (license != null)
{
License = license;
}
}
public string StorageName { get; set; }
public double? StorageGb { get; set; }
public short? MaxStorageGb { get; set; }
public BillingSubscriptionUpcomingInvoice UpcomingInvoice { get; set; }
public BillingSubscription Subscription { get; set; }
public UserLicense License { get; set; }
public DateTime? Expiration { get; set; }
public bool UsingInAppPurchase { get; set; }
}
public class BillingSubscription
{
public BillingSubscription(SubscriptionInfo.BillingSubscription sub)
{
Status = sub.Status;
TrialStartDate = sub.TrialStartDate;
TrialEndDate = sub.TrialEndDate;
PeriodStartDate = sub.PeriodStartDate;
PeriodEndDate = sub.PeriodEndDate;
CancelledDate = sub.CancelledDate;
CancelAtEndDate = sub.CancelAtEndDate;
Cancelled = sub.Cancelled;
if (sub.Items != null)
{
Items = sub.Items.Select(i => new BillingSubscriptionItem(i));
}
}
public DateTime? TrialStartDate { get; set; }
public DateTime? TrialEndDate { get; set; }
public DateTime? PeriodStartDate { get; set; }
public DateTime? PeriodEndDate { get; set; }
public DateTime? CancelledDate { get; set; }
public bool CancelAtEndDate { get; set; }
public string Status { get; set; }
public bool Cancelled { get; set; }
public IEnumerable<BillingSubscriptionItem> Items { get; set; } = new List<BillingSubscriptionItem>();
public class BillingSubscriptionItem
{
public BillingSubscriptionItem(SubscriptionInfo.BillingSubscription.BillingSubscriptionItem item)
{
Name = item.Name;
Amount = item.Amount;
Interval = item.Interval;
Quantity = item.Quantity;
SponsoredSubscriptionItem = item.SponsoredSubscriptionItem;
}
public string Name { get; set; }
public decimal Amount { get; set; }
public int Quantity { get; set; }
public string Interval { get; set; }
public bool SponsoredSubscriptionItem { get; set; }
}
}
public class BillingSubscriptionUpcomingInvoice
public string StorageName { get; set; }
public double? StorageGb { get; set; }
public short? MaxStorageGb { get; set; }
public BillingSubscriptionUpcomingInvoice UpcomingInvoice { get; set; }
public BillingSubscription Subscription { get; set; }
public UserLicense License { get; set; }
public DateTime? Expiration { get; set; }
public bool UsingInAppPurchase { get; set; }
}
public class BillingSubscription
{
public BillingSubscription(SubscriptionInfo.BillingSubscription sub)
{
public BillingSubscriptionUpcomingInvoice(SubscriptionInfo.BillingUpcomingInvoice inv)
Status = sub.Status;
TrialStartDate = sub.TrialStartDate;
TrialEndDate = sub.TrialEndDate;
PeriodStartDate = sub.PeriodStartDate;
PeriodEndDate = sub.PeriodEndDate;
CancelledDate = sub.CancelledDate;
CancelAtEndDate = sub.CancelAtEndDate;
Cancelled = sub.Cancelled;
if (sub.Items != null)
{
Amount = inv.Amount;
Date = inv.Date;
Items = sub.Items.Select(i => new BillingSubscriptionItem(i));
}
}
public DateTime? TrialStartDate { get; set; }
public DateTime? TrialEndDate { get; set; }
public DateTime? PeriodStartDate { get; set; }
public DateTime? PeriodEndDate { get; set; }
public DateTime? CancelledDate { get; set; }
public bool CancelAtEndDate { get; set; }
public string Status { get; set; }
public bool Cancelled { get; set; }
public IEnumerable<BillingSubscriptionItem> Items { get; set; } = new List<BillingSubscriptionItem>();
public class BillingSubscriptionItem
{
public BillingSubscriptionItem(SubscriptionInfo.BillingSubscription.BillingSubscriptionItem item)
{
Name = item.Name;
Amount = item.Amount;
Interval = item.Interval;
Quantity = item.Quantity;
SponsoredSubscriptionItem = item.SponsoredSubscriptionItem;
}
public string Name { get; set; }
public decimal Amount { get; set; }
public DateTime? Date { get; set; }
public int Quantity { get; set; }
public string Interval { get; set; }
public bool SponsoredSubscriptionItem { get; set; }
}
}
public class BillingSubscriptionUpcomingInvoice
{
public BillingSubscriptionUpcomingInvoice(SubscriptionInfo.BillingUpcomingInvoice inv)
{
Amount = inv.Amount;
Date = inv.Date;
}
public decimal Amount { get; set; }
public DateTime? Date { get; set; }
}

View File

@ -5,44 +5,43 @@ using Bit.Core.Models.Data.Organizations.OrganizationUsers;
using Bit.Core.Settings;
using Core.Models.Data;
namespace Bit.Api.Models.Response
{
public class SyncResponseModel : ResponseModel
{
public SyncResponseModel(
GlobalSettings globalSettings,
User user,
bool userTwoFactorEnabled,
bool userHasPremiumFromOrganization,
IEnumerable<OrganizationUserOrganizationDetails> organizationUserDetails,
IEnumerable<ProviderUserProviderDetails> providerUserDetails,
IEnumerable<ProviderUserOrganizationDetails> providerUserOrganizationDetails,
IEnumerable<Folder> folders,
IEnumerable<CollectionDetails> collections,
IEnumerable<CipherDetails> ciphers,
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersDict,
bool excludeDomains,
IEnumerable<Policy> policies,
IEnumerable<Send> sends)
: base("sync")
{
Profile = new ProfileResponseModel(user, organizationUserDetails, providerUserDetails,
providerUserOrganizationDetails, userTwoFactorEnabled, userHasPremiumFromOrganization);
Folders = folders.Select(f => new FolderResponseModel(f));
Ciphers = ciphers.Select(c => new CipherDetailsResponseModel(c, globalSettings, collectionCiphersDict));
Collections = collections?.Select(
c => new CollectionDetailsResponseModel(c)) ?? new List<CollectionDetailsResponseModel>();
Domains = excludeDomains ? null : new DomainsResponseModel(user, false);
Policies = policies?.Select(p => new PolicyResponseModel(p)) ?? new List<PolicyResponseModel>();
Sends = sends.Select(s => new SendResponseModel(s, globalSettings));
}
namespace Bit.Api.Models.Response;
public ProfileResponseModel Profile { get; set; }
public IEnumerable<FolderResponseModel> Folders { get; set; }
public IEnumerable<CollectionDetailsResponseModel> Collections { get; set; }
public IEnumerable<CipherDetailsResponseModel> Ciphers { get; set; }
public DomainsResponseModel Domains { get; set; }
public IEnumerable<PolicyResponseModel> Policies { get; set; }
public IEnumerable<SendResponseModel> Sends { get; set; }
public class SyncResponseModel : ResponseModel
{
public SyncResponseModel(
GlobalSettings globalSettings,
User user,
bool userTwoFactorEnabled,
bool userHasPremiumFromOrganization,
IEnumerable<OrganizationUserOrganizationDetails> organizationUserDetails,
IEnumerable<ProviderUserProviderDetails> providerUserDetails,
IEnumerable<ProviderUserOrganizationDetails> providerUserOrganizationDetails,
IEnumerable<Folder> folders,
IEnumerable<CollectionDetails> collections,
IEnumerable<CipherDetails> ciphers,
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersDict,
bool excludeDomains,
IEnumerable<Policy> policies,
IEnumerable<Send> sends)
: base("sync")
{
Profile = new ProfileResponseModel(user, organizationUserDetails, providerUserDetails,
providerUserOrganizationDetails, userTwoFactorEnabled, userHasPremiumFromOrganization);
Folders = folders.Select(f => new FolderResponseModel(f));
Ciphers = ciphers.Select(c => new CipherDetailsResponseModel(c, globalSettings, collectionCiphersDict));
Collections = collections?.Select(
c => new CollectionDetailsResponseModel(c)) ?? new List<CollectionDetailsResponseModel>();
Domains = excludeDomains ? null : new DomainsResponseModel(user, false);
Policies = policies?.Select(p => new PolicyResponseModel(p)) ?? new List<PolicyResponseModel>();
Sends = sends.Select(s => new SendResponseModel(s, globalSettings));
}
public ProfileResponseModel Profile { get; set; }
public IEnumerable<FolderResponseModel> Folders { get; set; }
public IEnumerable<CollectionDetailsResponseModel> Collections { get; set; }
public IEnumerable<CipherDetailsResponseModel> Ciphers { get; set; }
public DomainsResponseModel Domains { get; set; }
public IEnumerable<PolicyResponseModel> Policies { get; set; }
public IEnumerable<SendResponseModel> Sends { get; set; }
}

View File

@ -1,35 +1,34 @@
using Bit.Core.Models.Business;
namespace Bit.Api.Models.Response
namespace Bit.Api.Models.Response;
public class TaxInfoResponseModel
{
public class TaxInfoResponseModel
public TaxInfoResponseModel() { }
public TaxInfoResponseModel(TaxInfo taxInfo)
{
public TaxInfoResponseModel() { }
public TaxInfoResponseModel(TaxInfo taxInfo)
if (taxInfo == null)
{
if (taxInfo == null)
{
return;
}
TaxIdNumber = taxInfo.TaxIdNumber;
TaxIdType = taxInfo.TaxIdType;
Line1 = taxInfo.BillingAddressLine1;
Line2 = taxInfo.BillingAddressLine2;
City = taxInfo.BillingAddressCity;
State = taxInfo.BillingAddressState;
PostalCode = taxInfo.BillingAddressPostalCode;
Country = taxInfo.BillingAddressCountry;
return;
}
public string TaxIdNumber { get; set; }
public string TaxIdType { get; set; }
public string Line1 { get; set; }
public string Line2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
TaxIdNumber = taxInfo.TaxIdNumber;
TaxIdType = taxInfo.TaxIdType;
Line1 = taxInfo.BillingAddressLine1;
Line2 = taxInfo.BillingAddressLine2;
City = taxInfo.BillingAddressCity;
State = taxInfo.BillingAddressState;
PostalCode = taxInfo.BillingAddressPostalCode;
Country = taxInfo.BillingAddressCountry;
}
public string TaxIdNumber { get; set; }
public string TaxIdType { get; set; }
public string Line1 { get; set; }
public string Line2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
}

View File

@ -1,29 +1,28 @@
using Bit.Core.Entities;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response
{
public class TaxRateResponseModel : ResponseModel
{
public TaxRateResponseModel(TaxRate taxRate)
: base("profile")
{
if (taxRate == null)
{
throw new ArgumentNullException(nameof(taxRate));
}
namespace Bit.Api.Models.Response;
Id = taxRate.Id;
Country = taxRate.Country;
State = taxRate.State;
PostalCode = taxRate.PostalCode;
Rate = taxRate.Rate;
public class TaxRateResponseModel : ResponseModel
{
public TaxRateResponseModel(TaxRate taxRate)
: base("profile")
{
if (taxRate == null)
{
throw new ArgumentNullException(nameof(taxRate));
}
public string Id { get; set; }
public string Country { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
public decimal Rate { get; set; }
Id = taxRate.Id;
Country = taxRate.Country;
State = taxRate.State;
PostalCode = taxRate.PostalCode;
Rate = taxRate.Rate;
}
public string Id { get; set; }
public string Country { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
public decimal Rate { get; set; }
}

View File

@ -3,33 +3,32 @@ using Bit.Core.Enums;
using Bit.Core.Models.Api;
using OtpNet;
namespace Bit.Api.Models.Response.TwoFactor
{
public class TwoFactorAuthenticatorResponseModel : ResponseModel
{
public TwoFactorAuthenticatorResponseModel(User user)
: base("twoFactorAuthenticator")
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
namespace Bit.Api.Models.Response.TwoFactor;
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Authenticator);
if (provider?.MetaData?.ContainsKey("Key") ?? false)
{
Key = (string)provider.MetaData["Key"];
Enabled = provider.Enabled;
}
else
{
var key = KeyGeneration.GenerateRandomKey(20);
Key = Base32Encoding.ToString(key);
Enabled = false;
}
public class TwoFactorAuthenticatorResponseModel : ResponseModel
{
public TwoFactorAuthenticatorResponseModel(User user)
: base("twoFactorAuthenticator")
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
public bool Enabled { get; set; }
public string Key { get; set; }
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Authenticator);
if (provider?.MetaData?.ContainsKey("Key") ?? false)
{
Key = (string)provider.MetaData["Key"];
Enabled = provider.Enabled;
}
else
{
var key = KeyGeneration.GenerateRandomKey(20);
Key = Base32Encoding.ToString(key);
Enabled = false;
}
}
public bool Enabled { get; set; }
public string Key { get; set; }
}

View File

@ -3,64 +3,63 @@ using Bit.Core.Enums;
using Bit.Core.Models;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response.TwoFactor
namespace Bit.Api.Models.Response.TwoFactor;
public class TwoFactorDuoResponseModel : ResponseModel
{
public class TwoFactorDuoResponseModel : ResponseModel
private const string ResponseObj = "twoFactorDuo";
public TwoFactorDuoResponseModel(User user)
: base(ResponseObj)
{
private const string ResponseObj = "twoFactorDuo";
public TwoFactorDuoResponseModel(User user)
: base(ResponseObj)
if (user == null)
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Duo);
Build(provider);
throw new ArgumentNullException(nameof(user));
}
public TwoFactorDuoResponseModel(Organization org)
: base(ResponseObj)
{
if (org == null)
{
throw new ArgumentNullException(nameof(org));
}
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Duo);
Build(provider);
}
var provider = org.GetTwoFactorProvider(TwoFactorProviderType.OrganizationDuo);
Build(provider);
public TwoFactorDuoResponseModel(Organization org)
: base(ResponseObj)
{
if (org == null)
{
throw new ArgumentNullException(nameof(org));
}
public bool Enabled { get; set; }
public string Host { get; set; }
public string SecretKey { get; set; }
public string IntegrationKey { get; set; }
var provider = org.GetTwoFactorProvider(TwoFactorProviderType.OrganizationDuo);
Build(provider);
}
private void Build(TwoFactorProvider provider)
public bool Enabled { get; set; }
public string Host { get; set; }
public string SecretKey { get; set; }
public string IntegrationKey { get; set; }
private void Build(TwoFactorProvider provider)
{
if (provider?.MetaData != null && provider.MetaData.Count > 0)
{
if (provider?.MetaData != null && provider.MetaData.Count > 0)
{
Enabled = provider.Enabled;
Enabled = provider.Enabled;
if (provider.MetaData.ContainsKey("Host"))
{
Host = (string)provider.MetaData["Host"];
}
if (provider.MetaData.ContainsKey("SKey"))
{
SecretKey = (string)provider.MetaData["SKey"];
}
if (provider.MetaData.ContainsKey("IKey"))
{
IntegrationKey = (string)provider.MetaData["IKey"];
}
}
else
if (provider.MetaData.ContainsKey("Host"))
{
Enabled = false;
Host = (string)provider.MetaData["Host"];
}
if (provider.MetaData.ContainsKey("SKey"))
{
SecretKey = (string)provider.MetaData["SKey"];
}
if (provider.MetaData.ContainsKey("IKey"))
{
IntegrationKey = (string)provider.MetaData["IKey"];
}
}
else
{
Enabled = false;
}
}
}

View File

@ -2,31 +2,30 @@
using Bit.Core.Enums;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response.TwoFactor
{
public class TwoFactorEmailResponseModel : ResponseModel
{
public TwoFactorEmailResponseModel(User user)
: base("twoFactorEmail")
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
namespace Bit.Api.Models.Response.TwoFactor;
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Email);
if (provider?.MetaData?.ContainsKey("Email") ?? false)
{
Email = (string)provider.MetaData["Email"];
Enabled = provider.Enabled;
}
else
{
Enabled = false;
}
public class TwoFactorEmailResponseModel : ResponseModel
{
public TwoFactorEmailResponseModel(User user)
: base("twoFactorEmail")
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
public bool Enabled { get; set; }
public string Email { get; set; }
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Email);
if (provider?.MetaData?.ContainsKey("Email") ?? false)
{
Email = (string)provider.MetaData["Email"];
Enabled = provider.Enabled;
}
else
{
Enabled = false;
}
}
public bool Enabled { get; set; }
public string Email { get; set; }
}

View File

@ -3,51 +3,50 @@ using Bit.Core.Enums;
using Bit.Core.Models;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response.TwoFactor
namespace Bit.Api.Models.Response.TwoFactor;
public class TwoFactorProviderResponseModel : ResponseModel
{
public class TwoFactorProviderResponseModel : ResponseModel
private const string ResponseObj = "twoFactorProvider";
public TwoFactorProviderResponseModel(TwoFactorProviderType type, TwoFactorProvider provider)
: base(ResponseObj)
{
private const string ResponseObj = "twoFactorProvider";
public TwoFactorProviderResponseModel(TwoFactorProviderType type, TwoFactorProvider provider)
: base(ResponseObj)
if (provider == null)
{
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
Enabled = provider.Enabled;
Type = type;
throw new ArgumentNullException(nameof(provider));
}
public TwoFactorProviderResponseModel(TwoFactorProviderType type, User user)
: base(ResponseObj)
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
var provider = user.GetTwoFactorProvider(type);
Enabled = provider?.Enabled ?? false;
Type = type;
}
public TwoFactorProviderResponseModel(TwoFactorProviderType type, Organization organization)
: base(ResponseObj)
{
if (organization == null)
{
throw new ArgumentNullException(nameof(organization));
}
var provider = organization.GetTwoFactorProvider(type);
Enabled = provider?.Enabled ?? false;
Type = type;
}
public bool Enabled { get; set; }
public TwoFactorProviderType Type { get; set; }
Enabled = provider.Enabled;
Type = type;
}
public TwoFactorProviderResponseModel(TwoFactorProviderType type, User user)
: base(ResponseObj)
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
var provider = user.GetTwoFactorProvider(type);
Enabled = provider?.Enabled ?? false;
Type = type;
}
public TwoFactorProviderResponseModel(TwoFactorProviderType type, Organization organization)
: base(ResponseObj)
{
if (organization == null)
{
throw new ArgumentNullException(nameof(organization));
}
var provider = organization.GetTwoFactorProvider(type);
Enabled = provider?.Enabled ?? false;
Type = type;
}
public bool Enabled { get; set; }
public TwoFactorProviderType Type { get; set; }
}

View File

@ -1,21 +1,20 @@
using Bit.Core.Entities;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response.TwoFactor
{
public class TwoFactorRecoverResponseModel : ResponseModel
{
public TwoFactorRecoverResponseModel(User user)
: base("twoFactorRecover")
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
namespace Bit.Api.Models.Response.TwoFactor;
Code = user.TwoFactorRecoveryCode;
public class TwoFactorRecoverResponseModel : ResponseModel
{
public TwoFactorRecoverResponseModel(User user)
: base("twoFactorRecover")
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
public string Code { get; set; }
Code = user.TwoFactorRecoveryCode;
}
public string Code { get; set; }
}

View File

@ -3,40 +3,39 @@ using Bit.Core.Enums;
using Bit.Core.Models;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response.TwoFactor
namespace Bit.Api.Models.Response.TwoFactor;
public class TwoFactorWebAuthnResponseModel : ResponseModel
{
public class TwoFactorWebAuthnResponseModel : ResponseModel
public TwoFactorWebAuthnResponseModel(User user)
: base("twoFactorWebAuthn")
{
public TwoFactorWebAuthnResponseModel(User user)
: base("twoFactorWebAuthn")
if (user == null)
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.WebAuthn);
Enabled = provider?.Enabled ?? false;
Keys = provider?.MetaData?
.Where(k => k.Key.StartsWith("Key"))
.Select(k => new KeyModel(k.Key, new TwoFactorProvider.WebAuthnData((dynamic)k.Value)));
throw new ArgumentNullException(nameof(user));
}
public bool Enabled { get; set; }
public IEnumerable<KeyModel> Keys { get; set; }
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.WebAuthn);
Enabled = provider?.Enabled ?? false;
Keys = provider?.MetaData?
.Where(k => k.Key.StartsWith("Key"))
.Select(k => new KeyModel(k.Key, new TwoFactorProvider.WebAuthnData((dynamic)k.Value)));
}
public class KeyModel
public bool Enabled { get; set; }
public IEnumerable<KeyModel> Keys { get; set; }
public class KeyModel
{
public KeyModel(string id, TwoFactorProvider.WebAuthnData data)
{
public KeyModel(string id, TwoFactorProvider.WebAuthnData data)
{
Name = data.Name;
Id = Convert.ToInt32(id.Replace("Key", string.Empty));
Migrated = data.Migrated;
}
public string Name { get; set; }
public int Id { get; set; }
public bool Migrated { get; set; }
Name = data.Name;
Id = Convert.ToInt32(id.Replace("Key", string.Empty));
Migrated = data.Migrated;
}
public string Name { get; set; }
public int Id { get; set; }
public bool Migrated { get; set; }
}
}

View File

@ -2,60 +2,59 @@
using Bit.Core.Enums;
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response.TwoFactor
namespace Bit.Api.Models.Response.TwoFactor;
public class TwoFactorYubiKeyResponseModel : ResponseModel
{
public class TwoFactorYubiKeyResponseModel : ResponseModel
public TwoFactorYubiKeyResponseModel(User user)
: base("twoFactorYubiKey")
{
public TwoFactorYubiKeyResponseModel(User user)
: base("twoFactorYubiKey")
if (user == null)
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.YubiKey);
if (provider?.MetaData != null && provider.MetaData.Count > 0)
{
Enabled = provider.Enabled;
if (provider.MetaData.ContainsKey("Key1"))
{
Key1 = (string)provider.MetaData["Key1"];
}
if (provider.MetaData.ContainsKey("Key2"))
{
Key2 = (string)provider.MetaData["Key2"];
}
if (provider.MetaData.ContainsKey("Key3"))
{
Key3 = (string)provider.MetaData["Key3"];
}
if (provider.MetaData.ContainsKey("Key4"))
{
Key4 = (string)provider.MetaData["Key4"];
}
if (provider.MetaData.ContainsKey("Key5"))
{
Key5 = (string)provider.MetaData["Key5"];
}
if (provider.MetaData.ContainsKey("Nfc"))
{
Nfc = (bool)provider.MetaData["Nfc"];
}
}
else
{
Enabled = false;
}
throw new ArgumentNullException(nameof(user));
}
public bool Enabled { get; set; }
public string Key1 { get; set; }
public string Key2 { get; set; }
public string Key3 { get; set; }
public string Key4 { get; set; }
public string Key5 { get; set; }
public bool Nfc { get; set; }
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.YubiKey);
if (provider?.MetaData != null && provider.MetaData.Count > 0)
{
Enabled = provider.Enabled;
if (provider.MetaData.ContainsKey("Key1"))
{
Key1 = (string)provider.MetaData["Key1"];
}
if (provider.MetaData.ContainsKey("Key2"))
{
Key2 = (string)provider.MetaData["Key2"];
}
if (provider.MetaData.ContainsKey("Key3"))
{
Key3 = (string)provider.MetaData["Key3"];
}
if (provider.MetaData.ContainsKey("Key4"))
{
Key4 = (string)provider.MetaData["Key4"];
}
if (provider.MetaData.ContainsKey("Key5"))
{
Key5 = (string)provider.MetaData["Key5"];
}
if (provider.MetaData.ContainsKey("Nfc"))
{
Nfc = (bool)provider.MetaData["Nfc"];
}
}
else
{
Enabled = false;
}
}
public bool Enabled { get; set; }
public string Key1 { get; set; }
public string Key2 { get; set; }
public string Key3 { get; set; }
public string Key4 { get; set; }
public string Key5 { get; set; }
public bool Nfc { get; set; }
}

View File

@ -1,17 +1,16 @@
using Bit.Core.Models.Api;
namespace Bit.Api.Models.Response
{
public class UserKeyResponseModel : ResponseModel
{
public UserKeyResponseModel(Guid id, string key)
: base("userKey")
{
UserId = id.ToString();
PublicKey = key;
}
namespace Bit.Api.Models.Response;
public string UserId { get; set; }
public string PublicKey { get; set; }
public class UserKeyResponseModel : ResponseModel
{
public UserKeyResponseModel(Guid id, string key)
: base("userKey")
{
UserId = id.ToString();
PublicKey = key;
}
public string UserId { get; set; }
public string PublicKey { get; set; }
}