mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 17:12:49 -05:00
Revert filescoped (#2227)
* Revert "Add git blame entry (#2226)" This reverts commit239286737d
. * Revert "Turn on file scoped namespaces (#2225)" This reverts commit34fb4cca2a
.
This commit is contained in:
@ -1,26 +1,27 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Core.Models.Api.Request.Accounts;
|
||||
|
||||
public class KeysRequestModel
|
||||
namespace Bit.Core.Models.Api.Request.Accounts
|
||||
{
|
||||
public string PublicKey { get; set; }
|
||||
[Required]
|
||||
public string EncryptedPrivateKey { get; set; }
|
||||
|
||||
public User ToUser(User existingUser)
|
||||
public class KeysRequestModel
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(existingUser.PublicKey) && !string.IsNullOrWhiteSpace(PublicKey))
|
||||
{
|
||||
existingUser.PublicKey = PublicKey;
|
||||
}
|
||||
public string PublicKey { get; set; }
|
||||
[Required]
|
||||
public string EncryptedPrivateKey { get; set; }
|
||||
|
||||
if (string.IsNullOrWhiteSpace(existingUser.PrivateKey))
|
||||
public User ToUser(User existingUser)
|
||||
{
|
||||
existingUser.PrivateKey = EncryptedPrivateKey;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(existingUser.PublicKey) && !string.IsNullOrWhiteSpace(PublicKey))
|
||||
{
|
||||
existingUser.PublicKey = PublicKey;
|
||||
}
|
||||
|
||||
return existingUser;
|
||||
if (string.IsNullOrWhiteSpace(existingUser.PrivateKey))
|
||||
{
|
||||
existingUser.PrivateKey = EncryptedPrivateKey;
|
||||
}
|
||||
|
||||
return existingUser;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Core.Models.Api.Request.Accounts;
|
||||
|
||||
public class PreloginRequestModel
|
||||
namespace Bit.Core.Models.Api.Request.Accounts
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
[StringLength(256)]
|
||||
public string Email { get; set; }
|
||||
public class PreloginRequestModel
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
[StringLength(256)]
|
||||
public string Email { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -4,73 +4,74 @@ using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Core.Models.Api.Request.Accounts;
|
||||
|
||||
public class RegisterRequestModel : IValidatableObject, ICaptchaProtectedModel
|
||||
namespace Bit.Core.Models.Api.Request.Accounts
|
||||
{
|
||||
[StringLength(50)]
|
||||
public string Name { get; set; }
|
||||
[Required]
|
||||
[StrictEmailAddress]
|
||||
[StringLength(256)]
|
||||
public string Email { get; set; }
|
||||
[Required]
|
||||
[StringLength(1000)]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
[StringLength(50)]
|
||||
public string MasterPasswordHint { get; set; }
|
||||
public string CaptchaResponse { get; set; }
|
||||
public string Key { get; set; }
|
||||
public KeysRequestModel Keys { get; set; }
|
||||
public string Token { get; set; }
|
||||
public Guid? OrganizationUserId { get; set; }
|
||||
public KdfType? Kdf { get; set; }
|
||||
public int? KdfIterations { get; set; }
|
||||
public Dictionary<string, object> ReferenceData { get; set; }
|
||||
|
||||
public User ToUser()
|
||||
public class RegisterRequestModel : IValidatableObject, ICaptchaProtectedModel
|
||||
{
|
||||
var user = new User
|
||||
{
|
||||
Name = Name,
|
||||
Email = Email,
|
||||
MasterPasswordHint = MasterPasswordHint,
|
||||
Kdf = Kdf.GetValueOrDefault(KdfType.PBKDF2_SHA256),
|
||||
KdfIterations = KdfIterations.GetValueOrDefault(5000),
|
||||
};
|
||||
[StringLength(50)]
|
||||
public string Name { get; set; }
|
||||
[Required]
|
||||
[StrictEmailAddress]
|
||||
[StringLength(256)]
|
||||
public string Email { get; set; }
|
||||
[Required]
|
||||
[StringLength(1000)]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
[StringLength(50)]
|
||||
public string MasterPasswordHint { get; set; }
|
||||
public string CaptchaResponse { get; set; }
|
||||
public string Key { get; set; }
|
||||
public KeysRequestModel Keys { get; set; }
|
||||
public string Token { get; set; }
|
||||
public Guid? OrganizationUserId { get; set; }
|
||||
public KdfType? Kdf { get; set; }
|
||||
public int? KdfIterations { get; set; }
|
||||
public Dictionary<string, object> ReferenceData { get; set; }
|
||||
|
||||
if (ReferenceData != null)
|
||||
public User ToUser()
|
||||
{
|
||||
user.ReferenceData = JsonSerializer.Serialize(ReferenceData);
|
||||
}
|
||||
|
||||
if (Key != null)
|
||||
{
|
||||
user.Key = Key;
|
||||
}
|
||||
|
||||
if (Keys != null)
|
||||
{
|
||||
Keys.ToUser(user);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (Kdf.HasValue && KdfIterations.HasValue)
|
||||
{
|
||||
switch (Kdf.Value)
|
||||
var user = new User
|
||||
{
|
||||
case KdfType.PBKDF2_SHA256:
|
||||
if (KdfIterations.Value < 5000 || KdfIterations.Value > 1_000_000)
|
||||
{
|
||||
yield return new ValidationResult("KDF iterations must be between 5000 and 1000000.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
Name = Name,
|
||||
Email = Email,
|
||||
MasterPasswordHint = MasterPasswordHint,
|
||||
Kdf = Kdf.GetValueOrDefault(KdfType.PBKDF2_SHA256),
|
||||
KdfIterations = KdfIterations.GetValueOrDefault(5000),
|
||||
};
|
||||
|
||||
if (ReferenceData != null)
|
||||
{
|
||||
user.ReferenceData = JsonSerializer.Serialize(ReferenceData);
|
||||
}
|
||||
|
||||
if (Key != null)
|
||||
{
|
||||
user.Key = Key;
|
||||
}
|
||||
|
||||
if (Keys != null)
|
||||
{
|
||||
Keys.ToUser(user);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (Kdf.HasValue && KdfIterations.HasValue)
|
||||
{
|
||||
switch (Kdf.Value)
|
||||
{
|
||||
case KdfType.PBKDF2_SHA256:
|
||||
if (KdfIterations.Value < 5000 || KdfIterations.Value > 1_000_000)
|
||||
{
|
||||
yield return new ValidationResult("KDF iterations must be between 5000 and 1000000.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
namespace Bit.Core.Models.Api;
|
||||
|
||||
public interface ICaptchaProtectedModel
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
string CaptchaResponse { get; set; }
|
||||
public interface ICaptchaProtectedModel
|
||||
{
|
||||
string CaptchaResponse { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -2,54 +2,55 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Data.Organizations.OrganizationSponsorships;
|
||||
|
||||
namespace Bit.Core.Models.Api.Request.OrganizationSponsorships;
|
||||
|
||||
public class OrganizationSponsorshipRequestModel
|
||||
namespace Bit.Core.Models.Api.Request.OrganizationSponsorships
|
||||
{
|
||||
public Guid SponsoringOrganizationUserId { get; set; }
|
||||
public string FriendlyName { get; set; }
|
||||
public string OfferedToEmail { get; set; }
|
||||
public PlanSponsorshipType PlanSponsorshipType { get; set; }
|
||||
public DateTime? LastSyncDate { get; set; }
|
||||
public DateTime? ValidUntil { get; set; }
|
||||
public bool ToDelete { get; set; }
|
||||
|
||||
public OrganizationSponsorshipRequestModel() { }
|
||||
|
||||
public OrganizationSponsorshipRequestModel(OrganizationSponsorshipData sponsorshipData)
|
||||
public class OrganizationSponsorshipRequestModel
|
||||
{
|
||||
SponsoringOrganizationUserId = sponsorshipData.SponsoringOrganizationUserId;
|
||||
FriendlyName = sponsorshipData.FriendlyName;
|
||||
OfferedToEmail = sponsorshipData.OfferedToEmail;
|
||||
PlanSponsorshipType = sponsorshipData.PlanSponsorshipType;
|
||||
LastSyncDate = sponsorshipData.LastSyncDate;
|
||||
ValidUntil = sponsorshipData.ValidUntil;
|
||||
ToDelete = sponsorshipData.ToDelete;
|
||||
}
|
||||
public Guid SponsoringOrganizationUserId { get; set; }
|
||||
public string FriendlyName { get; set; }
|
||||
public string OfferedToEmail { get; set; }
|
||||
public PlanSponsorshipType PlanSponsorshipType { get; set; }
|
||||
public DateTime? LastSyncDate { get; set; }
|
||||
public DateTime? ValidUntil { get; set; }
|
||||
public bool ToDelete { get; set; }
|
||||
|
||||
public OrganizationSponsorshipRequestModel(OrganizationSponsorship sponsorship)
|
||||
{
|
||||
SponsoringOrganizationUserId = sponsorship.SponsoringOrganizationUserId;
|
||||
FriendlyName = sponsorship.FriendlyName;
|
||||
OfferedToEmail = sponsorship.OfferedToEmail;
|
||||
PlanSponsorshipType = sponsorship.PlanSponsorshipType.GetValueOrDefault();
|
||||
LastSyncDate = sponsorship.LastSyncDate;
|
||||
ValidUntil = sponsorship.ValidUntil;
|
||||
ToDelete = sponsorship.ToDelete;
|
||||
}
|
||||
public OrganizationSponsorshipRequestModel() { }
|
||||
|
||||
public OrganizationSponsorshipData ToOrganizationSponsorship()
|
||||
{
|
||||
return new OrganizationSponsorshipData
|
||||
public OrganizationSponsorshipRequestModel(OrganizationSponsorshipData sponsorshipData)
|
||||
{
|
||||
SponsoringOrganizationUserId = SponsoringOrganizationUserId,
|
||||
FriendlyName = FriendlyName,
|
||||
OfferedToEmail = OfferedToEmail,
|
||||
PlanSponsorshipType = PlanSponsorshipType,
|
||||
LastSyncDate = LastSyncDate,
|
||||
ValidUntil = ValidUntil,
|
||||
ToDelete = ToDelete,
|
||||
};
|
||||
SponsoringOrganizationUserId = sponsorshipData.SponsoringOrganizationUserId;
|
||||
FriendlyName = sponsorshipData.FriendlyName;
|
||||
OfferedToEmail = sponsorshipData.OfferedToEmail;
|
||||
PlanSponsorshipType = sponsorshipData.PlanSponsorshipType;
|
||||
LastSyncDate = sponsorshipData.LastSyncDate;
|
||||
ValidUntil = sponsorshipData.ValidUntil;
|
||||
ToDelete = sponsorshipData.ToDelete;
|
||||
}
|
||||
|
||||
public OrganizationSponsorshipRequestModel(OrganizationSponsorship sponsorship)
|
||||
{
|
||||
SponsoringOrganizationUserId = sponsorship.SponsoringOrganizationUserId;
|
||||
FriendlyName = sponsorship.FriendlyName;
|
||||
OfferedToEmail = sponsorship.OfferedToEmail;
|
||||
PlanSponsorshipType = sponsorship.PlanSponsorshipType.GetValueOrDefault();
|
||||
LastSyncDate = sponsorship.LastSyncDate;
|
||||
ValidUntil = sponsorship.ValidUntil;
|
||||
ToDelete = sponsorship.ToDelete;
|
||||
}
|
||||
|
||||
public OrganizationSponsorshipData ToOrganizationSponsorship()
|
||||
{
|
||||
return new OrganizationSponsorshipData
|
||||
{
|
||||
SponsoringOrganizationUserId = SponsoringOrganizationUserId,
|
||||
FriendlyName = FriendlyName,
|
||||
OfferedToEmail = OfferedToEmail,
|
||||
PlanSponsorshipType = PlanSponsorshipType,
|
||||
LastSyncDate = LastSyncDate,
|
||||
ValidUntil = ValidUntil,
|
||||
ToDelete = ToDelete,
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,40 @@
|
||||
using Bit.Core.Models.Data.Organizations.OrganizationSponsorships;
|
||||
|
||||
namespace Bit.Core.Models.Api.Request.OrganizationSponsorships;
|
||||
|
||||
public class OrganizationSponsorshipSyncRequestModel
|
||||
namespace Bit.Core.Models.Api.Request.OrganizationSponsorships
|
||||
{
|
||||
public string BillingSyncKey { get; set; }
|
||||
public Guid SponsoringOrganizationCloudId { get; set; }
|
||||
public IEnumerable<OrganizationSponsorshipRequestModel> SponsorshipsBatch { get; set; }
|
||||
|
||||
public OrganizationSponsorshipSyncRequestModel() { }
|
||||
|
||||
public OrganizationSponsorshipSyncRequestModel(IEnumerable<OrganizationSponsorshipRequestModel> sponsorshipsBatch)
|
||||
public class OrganizationSponsorshipSyncRequestModel
|
||||
{
|
||||
SponsorshipsBatch = sponsorshipsBatch;
|
||||
}
|
||||
public string BillingSyncKey { get; set; }
|
||||
public Guid SponsoringOrganizationCloudId { get; set; }
|
||||
public IEnumerable<OrganizationSponsorshipRequestModel> SponsorshipsBatch { get; set; }
|
||||
|
||||
public OrganizationSponsorshipSyncRequestModel(OrganizationSponsorshipSyncData syncData)
|
||||
{
|
||||
if (syncData == null)
|
||||
public OrganizationSponsorshipSyncRequestModel() { }
|
||||
|
||||
public OrganizationSponsorshipSyncRequestModel(IEnumerable<OrganizationSponsorshipRequestModel> sponsorshipsBatch)
|
||||
{
|
||||
return;
|
||||
SponsorshipsBatch = sponsorshipsBatch;
|
||||
}
|
||||
BillingSyncKey = syncData.BillingSyncKey;
|
||||
SponsoringOrganizationCloudId = syncData.SponsoringOrganizationCloudId;
|
||||
SponsorshipsBatch = syncData.SponsorshipsBatch.Select(o => new OrganizationSponsorshipRequestModel(o));
|
||||
}
|
||||
|
||||
public OrganizationSponsorshipSyncData ToOrganizationSponsorshipSync()
|
||||
{
|
||||
return new OrganizationSponsorshipSyncData()
|
||||
public OrganizationSponsorshipSyncRequestModel(OrganizationSponsorshipSyncData syncData)
|
||||
{
|
||||
BillingSyncKey = BillingSyncKey,
|
||||
SponsoringOrganizationCloudId = SponsoringOrganizationCloudId,
|
||||
SponsorshipsBatch = SponsorshipsBatch.Select(o => o.ToOrganizationSponsorship())
|
||||
};
|
||||
}
|
||||
if (syncData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
BillingSyncKey = syncData.BillingSyncKey;
|
||||
SponsoringOrganizationCloudId = syncData.SponsoringOrganizationCloudId;
|
||||
SponsorshipsBatch = syncData.SponsorshipsBatch.Select(o => new OrganizationSponsorshipRequestModel(o));
|
||||
}
|
||||
|
||||
public OrganizationSponsorshipSyncData ToOrganizationSponsorshipSync()
|
||||
{
|
||||
return new OrganizationSponsorshipSyncData()
|
||||
{
|
||||
BillingSyncKey = BillingSyncKey,
|
||||
SponsoringOrganizationCloudId = SponsoringOrganizationCloudId,
|
||||
SponsorshipsBatch = SponsorshipsBatch.Select(o => o.ToOrganizationSponsorship())
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,19 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Core.Models.Api;
|
||||
|
||||
public class PushRegistrationRequestModel
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
[Required]
|
||||
public string DeviceId { get; set; }
|
||||
[Required]
|
||||
public string PushToken { get; set; }
|
||||
[Required]
|
||||
public string UserId { get; set; }
|
||||
[Required]
|
||||
public DeviceType Type { get; set; }
|
||||
[Required]
|
||||
public string Identifier { get; set; }
|
||||
public class PushRegistrationRequestModel
|
||||
{
|
||||
[Required]
|
||||
public string DeviceId { get; set; }
|
||||
[Required]
|
||||
public string PushToken { get; set; }
|
||||
[Required]
|
||||
public string UserId { get; set; }
|
||||
[Required]
|
||||
public DeviceType Type { get; set; }
|
||||
[Required]
|
||||
public string Identifier { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,25 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Core.Models.Api;
|
||||
|
||||
public class PushSendRequestModel : IValidatableObject
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public string UserId { get; set; }
|
||||
public string OrganizationId { get; set; }
|
||||
public string DeviceId { get; set; }
|
||||
public string Identifier { get; set; }
|
||||
[Required]
|
||||
public PushType? Type { get; set; }
|
||||
[Required]
|
||||
public object Payload { get; set; }
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
public class PushSendRequestModel : IValidatableObject
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(UserId) && string.IsNullOrWhiteSpace(OrganizationId))
|
||||
public string UserId { get; set; }
|
||||
public string OrganizationId { get; set; }
|
||||
public string DeviceId { get; set; }
|
||||
public string Identifier { get; set; }
|
||||
[Required]
|
||||
public PushType? Type { get; set; }
|
||||
[Required]
|
||||
public object Payload { get; set; }
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
yield return new ValidationResult($"{nameof(UserId)} or {nameof(OrganizationId)} is required.");
|
||||
if (string.IsNullOrWhiteSpace(UserId) && string.IsNullOrWhiteSpace(OrganizationId))
|
||||
{
|
||||
yield return new ValidationResult($"{nameof(UserId)} or {nameof(OrganizationId)} is required.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,21 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Core.Models.Api;
|
||||
|
||||
public class PushUpdateRequestModel
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public PushUpdateRequestModel()
|
||||
{ }
|
||||
|
||||
public PushUpdateRequestModel(IEnumerable<string> deviceIds, string organizationId)
|
||||
public class PushUpdateRequestModel
|
||||
{
|
||||
DeviceIds = deviceIds;
|
||||
OrganizationId = organizationId;
|
||||
}
|
||||
public PushUpdateRequestModel()
|
||||
{ }
|
||||
|
||||
[Required]
|
||||
public IEnumerable<string> DeviceIds { get; set; }
|
||||
[Required]
|
||||
public string OrganizationId { get; set; }
|
||||
public PushUpdateRequestModel(IEnumerable<string> deviceIds, string organizationId)
|
||||
{
|
||||
DeviceIds = deviceIds;
|
||||
OrganizationId = organizationId;
|
||||
}
|
||||
|
||||
[Required]
|
||||
public IEnumerable<string> DeviceIds { get; set; }
|
||||
[Required]
|
||||
public string OrganizationId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,17 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Models.Api.Response.Accounts;
|
||||
|
||||
public class PreloginResponseModel
|
||||
namespace Bit.Core.Models.Api.Response.Accounts
|
||||
{
|
||||
public PreloginResponseModel(UserKdfInformation kdfInformation)
|
||||
public class PreloginResponseModel
|
||||
{
|
||||
Kdf = kdfInformation.Kdf;
|
||||
KdfIterations = kdfInformation.KdfIterations;
|
||||
}
|
||||
public PreloginResponseModel(UserKdfInformation kdfInformation)
|
||||
{
|
||||
Kdf = kdfInformation.Kdf;
|
||||
KdfIterations = kdfInformation.KdfIterations;
|
||||
}
|
||||
|
||||
public KdfType Kdf { get; set; }
|
||||
public int KdfIterations { get; set; }
|
||||
public KdfType Kdf { get; set; }
|
||||
public int KdfIterations { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,73 +1,74 @@
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
|
||||
namespace Bit.Core.Models.Api;
|
||||
|
||||
public class ErrorResponseModel : ResponseModel
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public ErrorResponseModel()
|
||||
: base("error")
|
||||
{ }
|
||||
|
||||
public ErrorResponseModel(string message)
|
||||
: this()
|
||||
public class ErrorResponseModel : ResponseModel
|
||||
{
|
||||
Message = message;
|
||||
}
|
||||
public ErrorResponseModel()
|
||||
: base("error")
|
||||
{ }
|
||||
|
||||
public ErrorResponseModel(ModelStateDictionary modelState)
|
||||
: this()
|
||||
{
|
||||
Message = "The model state is invalid.";
|
||||
ValidationErrors = new Dictionary<string, IEnumerable<string>>();
|
||||
|
||||
var keys = modelState.Keys.ToList();
|
||||
var values = modelState.Values.ToList();
|
||||
|
||||
for (var i = 0; i < values.Count; i++)
|
||||
public ErrorResponseModel(string message)
|
||||
: this()
|
||||
{
|
||||
var value = values[i];
|
||||
|
||||
if (keys.Count <= i)
|
||||
{
|
||||
// Keys not available for some reason.
|
||||
break;
|
||||
}
|
||||
|
||||
var key = keys[i];
|
||||
|
||||
if (value.ValidationState != ModelValidationState.Invalid || value.Errors.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var errors = value.Errors.Select(e => e.ErrorMessage);
|
||||
ValidationErrors.Add(key, errors);
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public ErrorResponseModel(ModelStateDictionary modelState)
|
||||
: this()
|
||||
{
|
||||
Message = "The model state is invalid.";
|
||||
ValidationErrors = new Dictionary<string, IEnumerable<string>>();
|
||||
|
||||
var keys = modelState.Keys.ToList();
|
||||
var values = modelState.Values.ToList();
|
||||
|
||||
for (var i = 0; i < values.Count; i++)
|
||||
{
|
||||
var value = values[i];
|
||||
|
||||
if (keys.Count <= i)
|
||||
{
|
||||
// Keys not available for some reason.
|
||||
break;
|
||||
}
|
||||
|
||||
var key = keys[i];
|
||||
|
||||
if (value.ValidationState != ModelValidationState.Invalid || value.Errors.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var errors = value.Errors.Select(e => e.ErrorMessage);
|
||||
ValidationErrors.Add(key, errors);
|
||||
}
|
||||
}
|
||||
|
||||
public ErrorResponseModel(Dictionary<string, IEnumerable<string>> errors)
|
||||
: this("Errors have occurred.", errors)
|
||||
{ }
|
||||
|
||||
public ErrorResponseModel(string errorKey, string errorValue)
|
||||
: this(errorKey, new string[] { errorValue })
|
||||
{ }
|
||||
|
||||
public ErrorResponseModel(string errorKey, IEnumerable<string> errorValues)
|
||||
: this(new Dictionary<string, IEnumerable<string>> { { errorKey, errorValues } })
|
||||
{ }
|
||||
|
||||
public ErrorResponseModel(string message, Dictionary<string, IEnumerable<string>> errors)
|
||||
: this()
|
||||
{
|
||||
Message = message;
|
||||
ValidationErrors = errors;
|
||||
}
|
||||
|
||||
public string Message { get; set; }
|
||||
public Dictionary<string, IEnumerable<string>> ValidationErrors { get; set; }
|
||||
// For use in development environments.
|
||||
public string ExceptionMessage { get; set; }
|
||||
public string ExceptionStackTrace { get; set; }
|
||||
public string InnerExceptionMessage { get; set; }
|
||||
}
|
||||
|
||||
public ErrorResponseModel(Dictionary<string, IEnumerable<string>> errors)
|
||||
: this("Errors have occurred.", errors)
|
||||
{ }
|
||||
|
||||
public ErrorResponseModel(string errorKey, string errorValue)
|
||||
: this(errorKey, new string[] { errorValue })
|
||||
{ }
|
||||
|
||||
public ErrorResponseModel(string errorKey, IEnumerable<string> errorValues)
|
||||
: this(new Dictionary<string, IEnumerable<string>> { { errorKey, errorValues } })
|
||||
{ }
|
||||
|
||||
public ErrorResponseModel(string message, Dictionary<string, IEnumerable<string>> errors)
|
||||
: this()
|
||||
{
|
||||
Message = message;
|
||||
ValidationErrors = errors;
|
||||
}
|
||||
|
||||
public string Message { get; set; }
|
||||
public Dictionary<string, IEnumerable<string>> ValidationErrors { get; set; }
|
||||
// For use in development environments.
|
||||
public string ExceptionMessage { get; set; }
|
||||
public string ExceptionStackTrace { get; set; }
|
||||
public string InnerExceptionMessage { get; set; }
|
||||
}
|
||||
|
@ -1,47 +1,48 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Data.Organizations.OrganizationSponsorships;
|
||||
|
||||
namespace Bit.Core.Models.Api.Response.OrganizationSponsorships;
|
||||
|
||||
public class OrganizationSponsorshipResponseModel
|
||||
namespace Bit.Core.Models.Api.Response.OrganizationSponsorships
|
||||
{
|
||||
public Guid SponsoringOrganizationUserId { get; set; }
|
||||
public string FriendlyName { get; set; }
|
||||
public string OfferedToEmail { get; set; }
|
||||
public PlanSponsorshipType PlanSponsorshipType { get; set; }
|
||||
public DateTime? LastSyncDate { get; set; }
|
||||
public DateTime? ValidUntil { get; set; }
|
||||
public bool ToDelete { get; set; }
|
||||
|
||||
public bool CloudSponsorshipRemoved { get; set; }
|
||||
|
||||
public OrganizationSponsorshipResponseModel() { }
|
||||
|
||||
public OrganizationSponsorshipResponseModel(OrganizationSponsorshipData sponsorshipData)
|
||||
public class OrganizationSponsorshipResponseModel
|
||||
{
|
||||
SponsoringOrganizationUserId = sponsorshipData.SponsoringOrganizationUserId;
|
||||
FriendlyName = sponsorshipData.FriendlyName;
|
||||
OfferedToEmail = sponsorshipData.OfferedToEmail;
|
||||
PlanSponsorshipType = sponsorshipData.PlanSponsorshipType;
|
||||
LastSyncDate = sponsorshipData.LastSyncDate;
|
||||
ValidUntil = sponsorshipData.ValidUntil;
|
||||
ToDelete = sponsorshipData.ToDelete;
|
||||
CloudSponsorshipRemoved = sponsorshipData.CloudSponsorshipRemoved;
|
||||
}
|
||||
public Guid SponsoringOrganizationUserId { get; set; }
|
||||
public string FriendlyName { get; set; }
|
||||
public string OfferedToEmail { get; set; }
|
||||
public PlanSponsorshipType PlanSponsorshipType { get; set; }
|
||||
public DateTime? LastSyncDate { get; set; }
|
||||
public DateTime? ValidUntil { get; set; }
|
||||
public bool ToDelete { get; set; }
|
||||
|
||||
public OrganizationSponsorshipData ToOrganizationSponsorship()
|
||||
{
|
||||
return new OrganizationSponsorshipData
|
||||
public bool CloudSponsorshipRemoved { get; set; }
|
||||
|
||||
public OrganizationSponsorshipResponseModel() { }
|
||||
|
||||
public OrganizationSponsorshipResponseModel(OrganizationSponsorshipData sponsorshipData)
|
||||
{
|
||||
SponsoringOrganizationUserId = SponsoringOrganizationUserId,
|
||||
FriendlyName = FriendlyName,
|
||||
OfferedToEmail = OfferedToEmail,
|
||||
PlanSponsorshipType = PlanSponsorshipType,
|
||||
LastSyncDate = LastSyncDate,
|
||||
ValidUntil = ValidUntil,
|
||||
ToDelete = ToDelete,
|
||||
CloudSponsorshipRemoved = CloudSponsorshipRemoved
|
||||
};
|
||||
SponsoringOrganizationUserId = sponsorshipData.SponsoringOrganizationUserId;
|
||||
FriendlyName = sponsorshipData.FriendlyName;
|
||||
OfferedToEmail = sponsorshipData.OfferedToEmail;
|
||||
PlanSponsorshipType = sponsorshipData.PlanSponsorshipType;
|
||||
LastSyncDate = sponsorshipData.LastSyncDate;
|
||||
ValidUntil = sponsorshipData.ValidUntil;
|
||||
ToDelete = sponsorshipData.ToDelete;
|
||||
CloudSponsorshipRemoved = sponsorshipData.CloudSponsorshipRemoved;
|
||||
}
|
||||
|
||||
public OrganizationSponsorshipData ToOrganizationSponsorship()
|
||||
{
|
||||
return new OrganizationSponsorshipData
|
||||
{
|
||||
SponsoringOrganizationUserId = SponsoringOrganizationUserId,
|
||||
FriendlyName = FriendlyName,
|
||||
OfferedToEmail = OfferedToEmail,
|
||||
PlanSponsorshipType = PlanSponsorshipType,
|
||||
LastSyncDate = LastSyncDate,
|
||||
ValidUntil = ValidUntil,
|
||||
ToDelete = ToDelete,
|
||||
CloudSponsorshipRemoved = CloudSponsorshipRemoved
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,30 @@
|
||||
using Bit.Core.Models.Data.Organizations.OrganizationSponsorships;
|
||||
|
||||
namespace Bit.Core.Models.Api.Response.OrganizationSponsorships;
|
||||
|
||||
public class OrganizationSponsorshipSyncResponseModel
|
||||
namespace Bit.Core.Models.Api.Response.OrganizationSponsorships
|
||||
{
|
||||
public IEnumerable<OrganizationSponsorshipResponseModel> SponsorshipsBatch { get; set; }
|
||||
|
||||
public OrganizationSponsorshipSyncResponseModel() { }
|
||||
|
||||
public OrganizationSponsorshipSyncResponseModel(OrganizationSponsorshipSyncData syncData)
|
||||
public class OrganizationSponsorshipSyncResponseModel
|
||||
{
|
||||
if (syncData == null)
|
||||
public IEnumerable<OrganizationSponsorshipResponseModel> SponsorshipsBatch { get; set; }
|
||||
|
||||
public OrganizationSponsorshipSyncResponseModel() { }
|
||||
|
||||
public OrganizationSponsorshipSyncResponseModel(OrganizationSponsorshipSyncData syncData)
|
||||
{
|
||||
return;
|
||||
if (syncData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SponsorshipsBatch = syncData.SponsorshipsBatch.Select(o => new OrganizationSponsorshipResponseModel(o));
|
||||
|
||||
}
|
||||
SponsorshipsBatch = syncData.SponsorshipsBatch.Select(o => new OrganizationSponsorshipResponseModel(o));
|
||||
|
||||
}
|
||||
|
||||
public OrganizationSponsorshipSyncData ToOrganizationSponsorshipSync()
|
||||
{
|
||||
return new OrganizationSponsorshipSyncData()
|
||||
public OrganizationSponsorshipSyncData ToOrganizationSponsorshipSync()
|
||||
{
|
||||
SponsorshipsBatch = SponsorshipsBatch.Select(o => o.ToOrganizationSponsorship())
|
||||
};
|
||||
}
|
||||
return new OrganizationSponsorshipSyncData()
|
||||
{
|
||||
SponsorshipsBatch = SponsorshipsBatch.Select(o => o.ToOrganizationSponsorship())
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,20 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Core.Models.Api;
|
||||
|
||||
public abstract class ResponseModel
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public ResponseModel(string obj)
|
||||
public abstract class ResponseModel
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(obj))
|
||||
public ResponseModel(string obj)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
if (string.IsNullOrWhiteSpace(obj))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
Object = obj;
|
||||
}
|
||||
|
||||
Object = obj;
|
||||
[JsonProperty(Order = -200)] // Always the first property
|
||||
public string Object { get; private set; }
|
||||
}
|
||||
|
||||
[JsonProperty(Order = -200)] // Always the first property
|
||||
public string Object { get; private set; }
|
||||
}
|
||||
|
Reference in New Issue
Block a user