mirror of
https://github.com/bitwarden/server.git
synced 2024-11-21 12:05:42 +01:00
PM-13763 Move ResetPasswordEnrolled to response model (#4983)
to adhere to Liskov Substitution Principle. Ensures request models inherit only relevant properties.
This commit is contained in:
parent
a56f3a587c
commit
aa3d71607f
@ -18,7 +18,6 @@ public abstract class MemberBaseModel
|
|||||||
|
|
||||||
Type = user.Type;
|
Type = user.Type;
|
||||||
ExternalId = user.ExternalId;
|
ExternalId = user.ExternalId;
|
||||||
ResetPasswordEnrolled = user.ResetPasswordKey != null;
|
|
||||||
|
|
||||||
if (Type == OrganizationUserType.Custom)
|
if (Type == OrganizationUserType.Custom)
|
||||||
{
|
{
|
||||||
@ -35,7 +34,6 @@ public abstract class MemberBaseModel
|
|||||||
|
|
||||||
Type = user.Type;
|
Type = user.Type;
|
||||||
ExternalId = user.ExternalId;
|
ExternalId = user.ExternalId;
|
||||||
ResetPasswordEnrolled = user.ResetPasswordKey != null;
|
|
||||||
|
|
||||||
if (Type == OrganizationUserType.Custom)
|
if (Type == OrganizationUserType.Custom)
|
||||||
{
|
{
|
||||||
@ -55,11 +53,7 @@ public abstract class MemberBaseModel
|
|||||||
/// <example>external_id_123456</example>
|
/// <example>external_id_123456</example>
|
||||||
[StringLength(300)]
|
[StringLength(300)]
|
||||||
public string ExternalId { get; set; }
|
public string ExternalId { get; set; }
|
||||||
/// <summary>
|
|
||||||
/// Returns <c>true</c> if the member has enrolled in Password Reset assistance within the organization
|
|
||||||
/// </summary>
|
|
||||||
[Required]
|
|
||||||
public bool ResetPasswordEnrolled { get; set; }
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The member's custom permissions if the member has a Custom role. If not supplied, all custom permissions will
|
/// The member's custom permissions if the member has a Custom role. If not supplied, all custom permissions will
|
||||||
/// default to false.
|
/// default to false.
|
||||||
|
@ -28,6 +28,7 @@ public class MemberResponseModel : MemberBaseModel, IResponseModel
|
|||||||
Email = user.Email;
|
Email = user.Email;
|
||||||
Status = user.Status;
|
Status = user.Status;
|
||||||
Collections = collections?.Select(c => new AssociationWithPermissionsResponseModel(c));
|
Collections = collections?.Select(c => new AssociationWithPermissionsResponseModel(c));
|
||||||
|
ResetPasswordEnrolled = user.ResetPasswordKey != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MemberResponseModel(OrganizationUserUserDetails user, bool twoFactorEnabled,
|
public MemberResponseModel(OrganizationUserUserDetails user, bool twoFactorEnabled,
|
||||||
@ -45,6 +46,7 @@ public class MemberResponseModel : MemberBaseModel, IResponseModel
|
|||||||
TwoFactorEnabled = twoFactorEnabled;
|
TwoFactorEnabled = twoFactorEnabled;
|
||||||
Status = user.Status;
|
Status = user.Status;
|
||||||
Collections = collections?.Select(c => new AssociationWithPermissionsResponseModel(c));
|
Collections = collections?.Select(c => new AssociationWithPermissionsResponseModel(c));
|
||||||
|
ResetPasswordEnrolled = user.ResetPasswordKey != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -93,4 +95,10 @@ public class MemberResponseModel : MemberBaseModel, IResponseModel
|
|||||||
/// The associated collections that this member can access.
|
/// The associated collections that this member can access.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<AssociationWithPermissionsResponseModel> Collections { get; set; }
|
public IEnumerable<AssociationWithPermissionsResponseModel> Collections { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns <c>true</c> if the member has enrolled in Password Reset assistance within the organization
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
public bool ResetPasswordEnrolled { get; }
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
using Bit.Api.AdminConsole.Public.Models.Response;
|
||||||
|
using Bit.Core.Entities;
|
||||||
|
using Bit.Core.Models.Data;
|
||||||
|
using NSubstitute;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Bit.Api.Test.AdminConsole.Public.Models.Response;
|
||||||
|
|
||||||
|
|
||||||
|
public class MemberResponseModelTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void ResetPasswordEnrolled_ShouldBeTrue_WhenUserHasResetPasswordKey()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var user = Substitute.For<OrganizationUser>();
|
||||||
|
var collections = Substitute.For<IEnumerable<CollectionAccessSelection>>();
|
||||||
|
user.ResetPasswordKey = "none-empty";
|
||||||
|
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var sut = new MemberResponseModel(user, collections);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.True(sut.ResetPasswordEnrolled);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ResetPasswordEnrolled_ShouldBeFalse_WhenUserDoesNotHaveResetPasswordKey()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var user = Substitute.For<OrganizationUser>();
|
||||||
|
var collections = Substitute.For<IEnumerable<CollectionAccessSelection>>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var sut = new MemberResponseModel(user, collections);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.False(sut.ResetPasswordEnrolled);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user