mirror of
https://github.com/bitwarden/server
synced 2026-01-27 06:43:19 +00:00
updating tests and command to include feature flag
This commit is contained in:
@@ -104,12 +104,12 @@ public class RestoreOrganizationUserCommand(
|
||||
var status = OrganizationService.GetPriorActiveOrganizationUserStatusType(organizationUser);
|
||||
|
||||
await organizationUserRepository.RestoreAsync(organizationUser.Id, status);
|
||||
organizationUser.Status = status;
|
||||
|
||||
if (organizationUser.UserId.HasValue
|
||||
&& (await policyRequirementQuery.GetAsync<OrganizationDataOwnershipPolicyRequirement>(organizationUser.UserId
|
||||
.Value)).State == OrganizationDataOwnershipState.Enabled
|
||||
&& status == OrganizationUserStatusType.Confirmed
|
||||
&& featureService.IsEnabled(FeatureFlagKeys.DefaultUserCollectionRestore)
|
||||
&& !string.IsNullOrWhiteSpace(defaultCollectionName))
|
||||
{
|
||||
await collectionRepository.CreateDefaultCollectionsAsync(organizationUser.OrganizationId,
|
||||
@@ -238,20 +238,21 @@ public class RestoreOrganizationUserCommand(
|
||||
var status = OrganizationService.GetPriorActiveOrganizationUserStatusType(organizationUser);
|
||||
|
||||
await organizationUserRepository.RestoreAsync(organizationUser.Id, status);
|
||||
organizationUser.Status = status;
|
||||
|
||||
await eventService.LogOrganizationUserEventAsync(organizationUser, EventType.OrganizationUser_Restored);
|
||||
if (organizationUser.UserId.HasValue)
|
||||
{
|
||||
if (organizationUsersDataOwnershipEnabled.Contains(organizationUser.Id)
|
||||
&& organizationUser.Status == OrganizationUserStatusType.Confirmed
|
||||
&& !string.IsNullOrWhiteSpace(defaultCollectionName))
|
||||
&& status == OrganizationUserStatusType.Confirmed
|
||||
&& !string.IsNullOrWhiteSpace(defaultCollectionName)
|
||||
&& featureService.IsEnabled(FeatureFlagKeys.DefaultUserCollectionRestore))
|
||||
{
|
||||
await collectionRepository.CreateDefaultCollectionsAsync(organizationUser.OrganizationId,
|
||||
[organizationUser.Id],
|
||||
defaultCollectionName);
|
||||
}
|
||||
|
||||
await eventService.LogOrganizationUserEventAsync(organizationUser, EventType.OrganizationUser_Restored);
|
||||
|
||||
await pushNotificationService.PushSyncOrgKeysAsync(organizationUser.UserId.Value);
|
||||
}
|
||||
|
||||
|
||||
@@ -1188,6 +1188,10 @@ public class RestoreOrganizationUserCommandTests
|
||||
organizationUser.Email = null; // This causes user to restore to Confirmed status
|
||||
RestoreUser_Setup(organization, owner, organizationUser, sutProvider);
|
||||
|
||||
sutProvider.GetDependency<IFeatureService>()
|
||||
.IsEnabled(FeatureFlagKeys.DefaultUserCollectionRestore)
|
||||
.Returns(true);
|
||||
|
||||
SetupOrganizationDataOwnershipPolicy(
|
||||
sutProvider,
|
||||
organizationUser.UserId!.Value,
|
||||
@@ -1219,6 +1223,10 @@ public class RestoreOrganizationUserCommandTests
|
||||
organizationUser.Email = null; // This causes user to restore to Confirmed status
|
||||
RestoreUser_Setup(organization, owner, organizationUser, sutProvider);
|
||||
|
||||
sutProvider.GetDependency<IFeatureService>()
|
||||
.IsEnabled(FeatureFlagKeys.DefaultUserCollectionRestore)
|
||||
.Returns(true);
|
||||
|
||||
SetupOrganizationDataOwnershipPolicy(
|
||||
sutProvider,
|
||||
organizationUser.UserId!.Value,
|
||||
@@ -1246,6 +1254,10 @@ public class RestoreOrganizationUserCommandTests
|
||||
organizationUser.Email = null; // This causes user to restore to Confirmed status
|
||||
RestoreUser_Setup(organization, owner, organizationUser, sutProvider);
|
||||
|
||||
sutProvider.GetDependency<IFeatureService>()
|
||||
.IsEnabled(FeatureFlagKeys.DefaultUserCollectionRestore)
|
||||
.Returns(true);
|
||||
|
||||
SetupOrganizationDataOwnershipPolicy(
|
||||
sutProvider,
|
||||
organizationUser.UserId!.Value,
|
||||
@@ -1276,6 +1288,10 @@ public class RestoreOrganizationUserCommandTests
|
||||
organizationUser.Email = null; // This causes user to restore to Confirmed status
|
||||
RestoreUser_Setup(organization, owner, organizationUser, sutProvider);
|
||||
|
||||
sutProvider.GetDependency<IFeatureService>()
|
||||
.IsEnabled(FeatureFlagKeys.DefaultUserCollectionRestore)
|
||||
.Returns(true);
|
||||
|
||||
SetupOrganizationDataOwnershipPolicy(
|
||||
sutProvider,
|
||||
organizationUser.UserId!.Value,
|
||||
@@ -1307,6 +1323,10 @@ public class RestoreOrganizationUserCommandTests
|
||||
organizationUser.Key = null;
|
||||
RestoreUser_Setup(organization, owner, organizationUser, sutProvider);
|
||||
|
||||
sutProvider.GetDependency<IFeatureService>()
|
||||
.IsEnabled(FeatureFlagKeys.DefaultUserCollectionRestore)
|
||||
.Returns(true);
|
||||
|
||||
// Act
|
||||
await sutProvider.Sut.RestoreUserAsync(organizationUser, owner.Id, defaultCollectionName);
|
||||
|
||||
@@ -1331,6 +1351,10 @@ public class RestoreOrganizationUserCommandTests
|
||||
organizationUser.Key = null;
|
||||
RestoreUser_Setup(organization, owner, organizationUser, sutProvider);
|
||||
|
||||
sutProvider.GetDependency<IFeatureService>()
|
||||
.IsEnabled(FeatureFlagKeys.DefaultUserCollectionRestore)
|
||||
.Returns(true);
|
||||
|
||||
// Act
|
||||
await sutProvider.Sut.RestoreUserAsync(organizationUser, owner.Id, defaultCollectionName);
|
||||
|
||||
@@ -1358,6 +1382,10 @@ public class RestoreOrganizationUserCommandTests
|
||||
var organizationUserRepository = sutProvider.GetDependency<IOrganizationUserRepository>();
|
||||
var userService = Substitute.For<IUserService>();
|
||||
|
||||
sutProvider.GetDependency<IFeatureService>()
|
||||
.IsEnabled(FeatureFlagKeys.DefaultUserCollectionRestore)
|
||||
.Returns(true);
|
||||
|
||||
// orgUser1: Will restore to Confirmed (Email = null)
|
||||
orgUser1.Email = null;
|
||||
orgUser1.OrganizationId = organization.Id;
|
||||
@@ -1415,6 +1443,10 @@ public class RestoreOrganizationUserCommandTests
|
||||
var organizationUserRepository = sutProvider.GetDependency<IOrganizationUserRepository>();
|
||||
var userService = Substitute.For<IUserService>();
|
||||
|
||||
sutProvider.GetDependency<IFeatureService>()
|
||||
.IsEnabled(FeatureFlagKeys.DefaultUserCollectionRestore)
|
||||
.Returns(true);
|
||||
|
||||
// Both users will restore to Confirmed
|
||||
orgUser1.Email = null;
|
||||
orgUser1.OrganizationId = organization.Id;
|
||||
@@ -1468,6 +1500,10 @@ public class RestoreOrganizationUserCommandTests
|
||||
var organizationUserRepository = sutProvider.GetDependency<IOrganizationUserRepository>();
|
||||
var userService = Substitute.For<IUserService>();
|
||||
|
||||
sutProvider.GetDependency<IFeatureService>()
|
||||
.IsEnabled(FeatureFlagKeys.DefaultUserCollectionRestore)
|
||||
.Returns(true);
|
||||
|
||||
// Both users will restore to Confirmed
|
||||
orgUser1.Email = null;
|
||||
orgUser1.OrganizationId = organization.Id;
|
||||
|
||||
Reference in New Issue
Block a user