mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 09:02:48 -05:00
PM-2944] Make Entities Nullable In Admin Console (#4386)
* Enable `nullable` in `ISubscriber` * Enable `nullable` in `Group` * Enable `nullable` in `GroupUser` * Enable `nullable` in `Organization` * Enable `nullable` in `OrganizationUser` * Enable `nullable` in `Policy` * Enable `nullable` in `Provider` * Enable `nullable` in `ProviderOrganization` * Enable `nullable` in `ProviderUser` * Update Tests * Formatting * Update TwoFactor Tests * Fix Scim Tests * Format * Add Migrations * Format
This commit is contained in:
@ -3,6 +3,8 @@ using Bit.Core.Entities;
|
||||
using Bit.Core.Models;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Core.AdminConsole.Entities;
|
||||
|
||||
public class Group : ITableObject<Guid>, IExternal
|
||||
@ -10,10 +12,10 @@ public class Group : ITableObject<Guid>, IExternal
|
||||
public Guid Id { get; set; }
|
||||
public Guid OrganizationId { get; set; }
|
||||
[MaxLength(100)]
|
||||
public string Name { get; set; }
|
||||
public string Name { get; set; } = null!;
|
||||
public bool AccessAll { get; set; }
|
||||
[MaxLength(300)]
|
||||
public string ExternalId { get; set; }
|
||||
public string? ExternalId { get; set; }
|
||||
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
||||
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
namespace Bit.Core.AdminConsole.Entities;
|
||||
|
||||
#nullable enable
|
||||
|
||||
public class GroupUser
|
||||
{
|
||||
public Guid GroupId { get; set; }
|
||||
|
@ -10,39 +10,41 @@ using Bit.Core.Models.Business;
|
||||
using Bit.Core.Tools.Entities;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Core.AdminConsole.Entities;
|
||||
|
||||
public class Organization : ITableObject<Guid>, IStorableSubscriber, IRevisable, IReferenceable
|
||||
{
|
||||
private Dictionary<TwoFactorProviderType, TwoFactorProvider> _twoFactorProviders;
|
||||
private Dictionary<TwoFactorProviderType, TwoFactorProvider>? _twoFactorProviders;
|
||||
|
||||
public Guid Id { get; set; }
|
||||
[MaxLength(50)]
|
||||
public string Identifier { get; set; }
|
||||
public string? Identifier { get; set; }
|
||||
/// <summary>
|
||||
/// This value is HTML encoded. For display purposes use the method DisplayName() instead.
|
||||
/// </summary>
|
||||
[MaxLength(50)]
|
||||
public string Name { get; set; }
|
||||
public string Name { get; set; } = null!;
|
||||
/// <summary>
|
||||
/// This value is HTML encoded. For display purposes use the method DisplayBusinessName() instead.
|
||||
/// </summary>
|
||||
[MaxLength(50)]
|
||||
public string BusinessName { get; set; }
|
||||
public string? BusinessName { get; set; }
|
||||
[MaxLength(50)]
|
||||
public string BusinessAddress1 { get; set; }
|
||||
public string? BusinessAddress1 { get; set; }
|
||||
[MaxLength(50)]
|
||||
public string BusinessAddress2 { get; set; }
|
||||
public string? BusinessAddress2 { get; set; }
|
||||
[MaxLength(50)]
|
||||
public string BusinessAddress3 { get; set; }
|
||||
public string? BusinessAddress3 { get; set; }
|
||||
[MaxLength(2)]
|
||||
public string BusinessCountry { get; set; }
|
||||
public string? BusinessCountry { get; set; }
|
||||
[MaxLength(30)]
|
||||
public string BusinessTaxNumber { get; set; }
|
||||
public string? BusinessTaxNumber { get; set; }
|
||||
[MaxLength(256)]
|
||||
public string BillingEmail { get; set; }
|
||||
public string BillingEmail { get; set; } = null!;
|
||||
[MaxLength(50)]
|
||||
public string Plan { get; set; }
|
||||
public string Plan { get; set; } = null!;
|
||||
public PlanType PlanType { get; set; }
|
||||
public int? Seats { get; set; }
|
||||
public short? MaxCollections { get; set; }
|
||||
@ -65,16 +67,16 @@ public class Organization : ITableObject<Guid>, IStorableSubscriber, IRevisable,
|
||||
public short? MaxStorageGb { get; set; }
|
||||
public GatewayType? Gateway { get; set; }
|
||||
[MaxLength(50)]
|
||||
public string GatewayCustomerId { get; set; }
|
||||
public string? GatewayCustomerId { get; set; }
|
||||
[MaxLength(50)]
|
||||
public string GatewaySubscriptionId { get; set; }
|
||||
public string ReferenceData { get; set; }
|
||||
public string? GatewaySubscriptionId { get; set; }
|
||||
public string? ReferenceData { get; set; }
|
||||
public bool Enabled { get; set; } = true;
|
||||
[MaxLength(100)]
|
||||
public string LicenseKey { get; set; }
|
||||
public string PublicKey { get; set; }
|
||||
public string PrivateKey { get; set; }
|
||||
public string TwoFactorProviders { get; set; }
|
||||
public string? LicenseKey { get; set; }
|
||||
public string? PublicKey { get; set; }
|
||||
public string? PrivateKey { get; set; }
|
||||
public string? TwoFactorProviders { get; set; }
|
||||
public DateTime? ExpirationDate { get; set; }
|
||||
public DateTime CreationDate { get; set; } = DateTime.UtcNow;
|
||||
public DateTime RevisionDate { get; set; } = DateTime.UtcNow;
|
||||
@ -123,22 +125,22 @@ public class Organization : ITableObject<Guid>, IStorableSubscriber, IRevisable,
|
||||
/// <summary>
|
||||
/// Returns the business name of the organization, HTML decoded ready for display.
|
||||
/// </summary>
|
||||
public string DisplayBusinessName()
|
||||
public string? DisplayBusinessName()
|
||||
{
|
||||
return WebUtility.HtmlDecode(BusinessName);
|
||||
}
|
||||
|
||||
public string BillingEmailAddress()
|
||||
public string? BillingEmailAddress()
|
||||
{
|
||||
return BillingEmail?.ToLowerInvariant()?.Trim();
|
||||
}
|
||||
|
||||
public string BillingName()
|
||||
public string? BillingName()
|
||||
{
|
||||
return DisplayBusinessName();
|
||||
}
|
||||
|
||||
public string SubscriberName()
|
||||
public string? SubscriberName()
|
||||
{
|
||||
return DisplayName();
|
||||
}
|
||||
@ -198,7 +200,7 @@ public class Organization : ITableObject<Guid>, IStorableSubscriber, IRevisable,
|
||||
return maxStorageBytes - Storage.Value;
|
||||
}
|
||||
|
||||
public Dictionary<TwoFactorProviderType, TwoFactorProvider> GetTwoFactorProviders()
|
||||
public Dictionary<TwoFactorProviderType, TwoFactorProvider>? GetTwoFactorProviders()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(TwoFactorProviders))
|
||||
{
|
||||
@ -257,7 +259,7 @@ public class Organization : ITableObject<Guid>, IStorableSubscriber, IRevisable,
|
||||
return providers.Any(p => (p.Value?.Enabled ?? false) && Use2fa);
|
||||
}
|
||||
|
||||
public TwoFactorProvider GetTwoFactorProvider(TwoFactorProviderType provider)
|
||||
public TwoFactorProvider? GetTwoFactorProvider(TwoFactorProviderType provider)
|
||||
{
|
||||
var providers = GetTwoFactorProviders();
|
||||
if (providers == null || !providers.ContainsKey(provider))
|
||||
|
@ -4,6 +4,8 @@ using Bit.Core.Models;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Core.Entities;
|
||||
|
||||
public class OrganizationUser : ITableObject<Guid>, IExternal
|
||||
@ -12,17 +14,17 @@ public class OrganizationUser : ITableObject<Guid>, IExternal
|
||||
public Guid OrganizationId { get; set; }
|
||||
public Guid? UserId { get; set; }
|
||||
[MaxLength(256)]
|
||||
public string Email { get; set; }
|
||||
public string Key { get; set; }
|
||||
public string ResetPasswordKey { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Key { get; set; }
|
||||
public string? ResetPasswordKey { get; set; }
|
||||
public OrganizationUserStatusType Status { get; set; }
|
||||
public OrganizationUserType Type { get; set; }
|
||||
public bool AccessAll { get; set; }
|
||||
[MaxLength(300)]
|
||||
public string ExternalId { get; set; }
|
||||
public string? ExternalId { get; set; }
|
||||
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
||||
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
|
||||
public string Permissions { get; set; }
|
||||
public string? Permissions { get; set; }
|
||||
public bool AccessSecretsManager { get; set; }
|
||||
|
||||
public void SetNewId()
|
||||
@ -30,7 +32,7 @@ public class OrganizationUser : ITableObject<Guid>, IExternal
|
||||
Id = CoreHelpers.GenerateComb();
|
||||
}
|
||||
|
||||
public Permissions GetPermissions()
|
||||
public Permissions? GetPermissions()
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(Permissions) ? null
|
||||
: CoreHelpers.LoadClassFromJsonData<Permissions>(Permissions);
|
||||
|
@ -3,6 +3,8 @@ using Bit.Core.AdminConsole.Models.Data.Organizations.Policies;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Core.AdminConsole.Entities;
|
||||
|
||||
public class Policy : ITableObject<Guid>
|
||||
@ -10,7 +12,7 @@ public class Policy : ITableObject<Guid>
|
||||
public Guid Id { get; set; }
|
||||
public Guid OrganizationId { get; set; }
|
||||
public PolicyType Type { get; set; }
|
||||
public string Data { get; set; }
|
||||
public string? Data { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
||||
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
|
||||
|
@ -4,6 +4,8 @@ using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Core.AdminConsole.Entities.Provider;
|
||||
|
||||
public class Provider : ITableObject<Guid>, ISubscriber
|
||||
@ -12,18 +14,18 @@ public class Provider : ITableObject<Guid>, ISubscriber
|
||||
/// <summary>
|
||||
/// This value is HTML encoded. For display purposes use the method DisplayName() instead.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
public string? Name { get; set; }
|
||||
/// <summary>
|
||||
/// This value is HTML encoded. For display purposes use the method DisplayBusinessName() instead.
|
||||
/// </summary>
|
||||
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 string BillingPhone { 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 string? BillingPhone { get; set; }
|
||||
public ProviderStatusType Status { get; set; }
|
||||
public bool UseEvents { get; set; }
|
||||
public ProviderType Type { get; set; }
|
||||
@ -31,14 +33,14 @@ public class Provider : ITableObject<Guid>, ISubscriber
|
||||
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
||||
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
|
||||
public GatewayType? Gateway { get; set; }
|
||||
public string GatewayCustomerId { get; set; }
|
||||
public string GatewaySubscriptionId { get; set; }
|
||||
public string? GatewayCustomerId { get; set; }
|
||||
public string? GatewaySubscriptionId { get; set; }
|
||||
|
||||
public string BillingEmailAddress() => BillingEmail?.ToLowerInvariant().Trim();
|
||||
public string? BillingEmailAddress() => BillingEmail?.ToLowerInvariant().Trim();
|
||||
|
||||
public string BillingName() => DisplayBusinessName();
|
||||
public string? BillingName() => DisplayBusinessName();
|
||||
|
||||
public string SubscriberName() => DisplayName();
|
||||
public string? SubscriberName() => DisplayName();
|
||||
|
||||
public string BraintreeCustomerIdPrefix() => "p";
|
||||
|
||||
@ -65,7 +67,7 @@ public class Provider : ITableObject<Guid>, ISubscriber
|
||||
/// <summary>
|
||||
/// Returns the name of the provider, HTML decoded ready for display.
|
||||
/// </summary>
|
||||
public string DisplayName()
|
||||
public string? DisplayName()
|
||||
{
|
||||
return WebUtility.HtmlDecode(Name);
|
||||
}
|
||||
@ -73,7 +75,7 @@ public class Provider : ITableObject<Guid>, ISubscriber
|
||||
/// <summary>
|
||||
/// Returns the business name of the provider, HTML decoded ready for display.
|
||||
/// </summary>
|
||||
public string DisplayBusinessName()
|
||||
public string? DisplayBusinessName()
|
||||
{
|
||||
return WebUtility.HtmlDecode(BusinessName);
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Core.AdminConsole.Entities.Provider;
|
||||
|
||||
public class ProviderOrganization : ITableObject<Guid>
|
||||
@ -8,8 +10,8 @@ public class ProviderOrganization : ITableObject<Guid>
|
||||
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 string? Key { get; set; }
|
||||
public string? Settings { get; set; }
|
||||
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
||||
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Core.AdminConsole.Entities.Provider;
|
||||
|
||||
public class ProviderUser : ITableObject<Guid>
|
||||
@ -9,11 +11,11 @@ public class ProviderUser : ITableObject<Guid>
|
||||
public Guid Id { get; set; }
|
||||
public Guid ProviderId { get; set; }
|
||||
public Guid? UserId { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Key { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Key { get; set; }
|
||||
public ProviderUserStatusType Status { get; set; }
|
||||
public ProviderUserType Type { get; set; }
|
||||
public string Permissions { get; set; }
|
||||
public string? Permissions { get; set; }
|
||||
public DateTime CreationDate { get; set; } = DateTime.UtcNow;
|
||||
public DateTime RevisionDate { get; set; } = DateTime.UtcNow;
|
||||
|
||||
|
Reference in New Issue
Block a user