1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 21:18:13 -05:00

IsManagedBy to IsClaimedBy

This commit is contained in:
jrmccannon 2025-04-01 16:34:38 -05:00
parent acedd9e66d
commit 9b18ab7373
No known key found for this signature in database
GPG Key ID: CF03F3DB01CE96A6
7 changed files with 18 additions and 18 deletions

View File

@ -184,7 +184,7 @@ public class UsersController : Controller
private async Task<bool?> AccountDeprovisioningEnabled(Guid userId) private async Task<bool?> AccountDeprovisioningEnabled(Guid userId)
{ {
return _featureService.IsEnabled(FeatureFlagKeys.AccountDeprovisioning) return _featureService.IsEnabled(FeatureFlagKeys.AccountDeprovisioning)
? await _userService.IsManagedByAnyOrganizationAsync(userId) ? await _userService.IsClaimedByAnyOrganizationAsync(userId)
: null; : null;
} }
} }

View File

@ -562,7 +562,7 @@ public class AccountsController : Controller
{ {
// If Account Deprovisioning is enabled, we need to check if the user is managed by any organization. // If Account Deprovisioning is enabled, we need to check if the user is managed by any organization.
if (_featureService.IsEnabled(FeatureFlagKeys.AccountDeprovisioning) if (_featureService.IsEnabled(FeatureFlagKeys.AccountDeprovisioning)
&& await _userService.IsManagedByAnyOrganizationAsync(user.Id)) && await _userService.IsClaimedByAnyOrganizationAsync(user.Id))
{ {
throw new BadRequestException("Cannot delete accounts owned by an organization. Contact your organization administrator for additional details."); throw new BadRequestException("Cannot delete accounts owned by an organization. Contact your organization administrator for additional details.");
} }

View File

@ -1021,7 +1021,7 @@ public class CiphersController : Controller
// If Account Deprovisioning is enabled, we need to check if the user is managed by any organization. // If Account Deprovisioning is enabled, we need to check if the user is managed by any organization.
if (_featureService.IsEnabled(FeatureFlagKeys.AccountDeprovisioning) if (_featureService.IsEnabled(FeatureFlagKeys.AccountDeprovisioning)
&& await _userService.IsManagedByAnyOrganizationAsync(user.Id)) && await _userService.IsClaimedByAnyOrganizationAsync(user.Id))
{ {
throw new BadRequestException("Cannot purge accounts owned by an organization. Contact your organization administrator for additional details."); throw new BadRequestException("Cannot purge accounts owned by an organization. Contact your organization administrator for additional details.");
} }

View File

@ -134,7 +134,7 @@ public interface IUserService
/// <returns> /// <returns>
/// False if the Account Deprovisioning feature flag is disabled. /// False if the Account Deprovisioning feature flag is disabled.
/// </returns> /// </returns>
Task<bool> IsManagedByAnyOrganizationAsync(Guid userId); Task<bool> IsClaimedByAnyOrganizationAsync(Guid userId);
/// <summary> /// <summary>
/// Verify whether the new email domain meets the requirements for managed users. /// Verify whether the new email domain meets the requirements for managed users.
@ -152,6 +152,6 @@ public interface IUserService
/// <returns> /// <returns>
/// An empty collection if the Account Deprovisioning feature flag is disabled. /// An empty collection if the Account Deprovisioning feature flag is disabled.
/// </returns> /// </returns>
/// <inheritdoc cref="IsManagedByAnyOrganizationAsync(Guid)"/> /// <inheritdoc cref="IsClaimedByAnyOrganizationAsync"/>
Task<IEnumerable<Organization>> GetOrganizationsClaimingUserAsync(Guid userId); Task<IEnumerable<Organization>> GetOrganizationsClaimingUserAsync(Guid userId);
} }

View File

@ -314,7 +314,7 @@ public class UserService : UserManager<User>, IUserService, IDisposable
return; return;
} }
if (await IsManagedByAnyOrganizationAsync(user.Id)) if (await IsClaimedByAnyOrganizationAsync(user.Id))
{ {
await _mailService.SendCannotDeleteManagedAccountEmailAsync(user.Email); await _mailService.SendCannotDeleteManagedAccountEmailAsync(user.Email);
return; return;
@ -1366,7 +1366,7 @@ public class UserService : UserManager<User>, IUserService, IDisposable
return IsLegacyUser(user); return IsLegacyUser(user);
} }
public async Task<bool> IsManagedByAnyOrganizationAsync(Guid userId) public async Task<bool> IsClaimedByAnyOrganizationAsync(Guid userId)
{ {
var organizationsClaimingUser = await GetOrganizationsClaimingUserAsync(userId); var organizationsClaimingUser = await GetOrganizationsClaimingUserAsync(userId);
return organizationsClaimingUser.Any(); return organizationsClaimingUser.Any();

View File

@ -197,7 +197,7 @@ public class AccountsControllerTests : IDisposable
_userService.ChangeEmailAsync(user, default, default, default, default, default) _userService.ChangeEmailAsync(user, default, default, default, default, default)
.Returns(Task.FromResult(IdentityResult.Success)); .Returns(Task.FromResult(IdentityResult.Success));
_featureService.IsEnabled(FeatureFlagKeys.AccountDeprovisioning).Returns(true); _featureService.IsEnabled(FeatureFlagKeys.AccountDeprovisioning).Returns(true);
_userService.IsManagedByAnyOrganizationAsync(user.Id).Returns(false); _userService.IsClaimedByAnyOrganizationAsync(user.Id).Returns(false);
await _sut.PostEmail(new EmailRequestModel()); await _sut.PostEmail(new EmailRequestModel());
@ -539,7 +539,7 @@ public class AccountsControllerTests : IDisposable
ConfigureUserServiceToReturnValidPrincipalFor(user); ConfigureUserServiceToReturnValidPrincipalFor(user);
ConfigureUserServiceToAcceptPasswordFor(user); ConfigureUserServiceToAcceptPasswordFor(user);
_featureService.IsEnabled(FeatureFlagKeys.AccountDeprovisioning).Returns(true); _featureService.IsEnabled(FeatureFlagKeys.AccountDeprovisioning).Returns(true);
_userService.IsManagedByAnyOrganizationAsync(user.Id).Returns(true); _userService.IsClaimedByAnyOrganizationAsync(user.Id).Returns(true);
var result = await Assert.ThrowsAsync<BadRequestException>(() => _sut.Delete(new SecretVerificationRequestModel())); var result = await Assert.ThrowsAsync<BadRequestException>(() => _sut.Delete(new SecretVerificationRequestModel()));
@ -553,7 +553,7 @@ public class AccountsControllerTests : IDisposable
ConfigureUserServiceToReturnValidPrincipalFor(user); ConfigureUserServiceToReturnValidPrincipalFor(user);
ConfigureUserServiceToAcceptPasswordFor(user); ConfigureUserServiceToAcceptPasswordFor(user);
_featureService.IsEnabled(FeatureFlagKeys.AccountDeprovisioning).Returns(true); _featureService.IsEnabled(FeatureFlagKeys.AccountDeprovisioning).Returns(true);
_userService.IsManagedByAnyOrganizationAsync(user.Id).Returns(false); _userService.IsClaimedByAnyOrganizationAsync(user.Id).Returns(false);
_userService.DeleteAsync(user).Returns(IdentityResult.Success); _userService.DeleteAsync(user).Returns(IdentityResult.Success);
await _sut.Delete(new SecretVerificationRequestModel()); await _sut.Delete(new SecretVerificationRequestModel());

View File

@ -341,19 +341,19 @@ public class UserServiceTests
} }
[Theory, BitAutoData] [Theory, BitAutoData]
public async Task IsManagedByAnyOrganizationAsync_WithAccountDeprovisioningDisabled_ReturnsFalse( public async Task IsClaimedByAnyOrganizationAsync_WithAccountDeprovisioningDisabled_ReturnsFalse(
SutProvider<UserService> sutProvider, Guid userId) SutProvider<UserService> sutProvider, Guid userId)
{ {
sutProvider.GetDependency<IFeatureService>() sutProvider.GetDependency<IFeatureService>()
.IsEnabled(FeatureFlagKeys.AccountDeprovisioning) .IsEnabled(FeatureFlagKeys.AccountDeprovisioning)
.Returns(false); .Returns(false);
var result = await sutProvider.Sut.IsManagedByAnyOrganizationAsync(userId); var result = await sutProvider.Sut.IsClaimedByAnyOrganizationAsync(userId);
Assert.False(result); Assert.False(result);
} }
[Theory, BitAutoData] [Theory, BitAutoData]
public async Task IsManagedByAnyOrganizationAsync_WithAccountDeprovisioningEnabled_WithManagingEnabledOrganization_ReturnsTrue( public async Task IsClaimedByAnyOrganizationAsync_WithAccountDeprovisioningEnabled_WithManagingEnabledOrganization_ReturnsTrue(
SutProvider<UserService> sutProvider, Guid userId, Organization organization) SutProvider<UserService> sutProvider, Guid userId, Organization organization)
{ {
organization.Enabled = true; organization.Enabled = true;
@ -367,12 +367,12 @@ public class UserServiceTests
.GetByVerifiedUserEmailDomainAsync(userId) .GetByVerifiedUserEmailDomainAsync(userId)
.Returns(new[] { organization }); .Returns(new[] { organization });
var result = await sutProvider.Sut.IsManagedByAnyOrganizationAsync(userId); var result = await sutProvider.Sut.IsClaimedByAnyOrganizationAsync(userId);
Assert.True(result); Assert.True(result);
} }
[Theory, BitAutoData] [Theory, BitAutoData]
public async Task IsManagedByAnyOrganizationAsync_WithAccountDeprovisioningEnabled_WithManagingDisabledOrganization_ReturnsFalse( public async Task IsClaimedByAnyOrganizationAsync_WithAccountDeprovisioningEnabled_WithManagingDisabledOrganization_ReturnsFalse(
SutProvider<UserService> sutProvider, Guid userId, Organization organization) SutProvider<UserService> sutProvider, Guid userId, Organization organization)
{ {
organization.Enabled = false; organization.Enabled = false;
@ -386,12 +386,12 @@ public class UserServiceTests
.GetByVerifiedUserEmailDomainAsync(userId) .GetByVerifiedUserEmailDomainAsync(userId)
.Returns(new[] { organization }); .Returns(new[] { organization });
var result = await sutProvider.Sut.IsManagedByAnyOrganizationAsync(userId); var result = await sutProvider.Sut.IsClaimedByAnyOrganizationAsync(userId);
Assert.False(result); Assert.False(result);
} }
[Theory, BitAutoData] [Theory, BitAutoData]
public async Task IsManagedByAnyOrganizationAsync_WithAccountDeprovisioningEnabled_WithOrganizationUseSsoFalse_ReturnsFalse( public async Task IsClaimedByAnyOrganizationAsync_WithAccountDeprovisioningEnabled_WithOrganizationUseSsoFalse_ReturnsFalse(
SutProvider<UserService> sutProvider, Guid userId, Organization organization) SutProvider<UserService> sutProvider, Guid userId, Organization organization)
{ {
organization.Enabled = true; organization.Enabled = true;
@ -405,7 +405,7 @@ public class UserServiceTests
.GetByVerifiedUserEmailDomainAsync(userId) .GetByVerifiedUserEmailDomainAsync(userId)
.Returns(new[] { organization }); .Returns(new[] { organization });
var result = await sutProvider.Sut.IsManagedByAnyOrganizationAsync(userId); var result = await sutProvider.Sut.IsClaimedByAnyOrganizationAsync(userId);
Assert.False(result); Assert.False(result);
} }