Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PM-13763 Move ResetPasswordEnrolled to response model #4983

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/Api/AdminConsole/Public/Models/MemberBaseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

Type = user.Type;
ExternalId = user.ExternalId;
ResetPasswordEnrolled = user.ResetPasswordKey != null;

if (Type == OrganizationUserType.Custom)
{
Expand All @@ -35,7 +34,6 @@

Type = user.Type;
ExternalId = user.ExternalId;
ResetPasswordEnrolled = user.ResetPasswordKey != null;

if (Type == OrganizationUserType.Custom)
{
Expand All @@ -55,14 +53,10 @@
/// <example>external_id_123456</example>
[StringLength(300)]
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>
/// The member's custom permissions if the member has a Custom role. If not supplied, all custom permissions will
/// default to false.
/// </summary>
public PermissionsModel? Permissions { get; set; }

Check warning on line 61 in src/Api/AdminConsole/Public/Models/MemberBaseModel.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Api, ./src)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 61 in src/Api/AdminConsole/Public/Models/MemberBaseModel.cs

View workflow job for this annotation

GitHub Actions / Upload

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public MemberResponseModel(OrganizationUser user, IEnumerable<CollectionAccessSe
Email = user.Email;
Status = user.Status;
Collections = collections?.Select(c => new AssociationWithPermissionsResponseModel(c));
ResetPasswordEnrolled = user.ResetPasswordKey != null;
}

public MemberResponseModel(OrganizationUserUserDetails user, bool twoFactorEnabled,
Expand All @@ -45,6 +46,7 @@ public MemberResponseModel(OrganizationUserUserDetails user, bool twoFactorEnabl
TwoFactorEnabled = twoFactorEnabled;
Status = user.Status;
Collections = collections?.Select(c => new AssociationWithPermissionsResponseModel(c));
ResetPasswordEnrolled = user.ResetPasswordKey != null;
}

/// <summary>
Expand Down Expand Up @@ -93,4 +95,10 @@ public MemberResponseModel(OrganizationUserUserDetails user, bool twoFactorEnabl
/// The associated collections that this member can access.
/// </summary>
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; }
}
Original file line number Diff line number Diff line change
@@ -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()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following patterns that I’ve seen in the codebase. If anything doesn’t meet standards, please feel free to leave comments, documentation, or suggestions. I’m happy to receive feedback and learn! 😄

{
// 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