Skip to content
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
48 changes: 16 additions & 32 deletions bitwarden_license/src/Scim/Controllers/v2/UsersController.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
ο»Ώ// FIXME: Update this file to be null safe and then delete the line below
#nullable disable

using Bit.Core;
using Bit.Core.AdminConsole.Models.Data;
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Interfaces;
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.RestoreUser.v1;
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.RevokeUser.v2;
using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Scim.Models;
using Bit.Scim.Users.Interfaces;
using Bit.Scim.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using IRevokeOrganizationUserCommand = Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.RevokeUser.v1.IRevokeOrganizationUserCommand;
using IRevokeOrganizationUserCommandV2 = Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.RevokeUser.v2.IRevokeOrganizationUserCommand;

namespace Bit.Scim.Controllers.v2;
Expand All @@ -32,8 +29,6 @@ public class UsersController : Controller
private readonly IPatchUserCommand _patchUserCommand;
private readonly IPostUserCommand _postUserCommand;
private readonly IRestoreOrganizationUserCommand _restoreOrganizationUserCommand;
private readonly IRevokeOrganizationUserCommand _revokeOrganizationUserCommand;
private readonly IFeatureService _featureService;
private readonly IRevokeOrganizationUserCommandV2 _revokeOrganizationUserCommandV2;

public UsersController(IOrganizationUserRepository organizationUserRepository,
Expand All @@ -42,8 +37,6 @@ public UsersController(IOrganizationUserRepository organizationUserRepository,
IPatchUserCommand patchUserCommand,
IPostUserCommand postUserCommand,
IRestoreOrganizationUserCommand restoreOrganizationUserCommand,
IRevokeOrganizationUserCommand revokeOrganizationUserCommand,
IFeatureService featureService,
IRevokeOrganizationUserCommandV2 revokeOrganizationUserCommandV2)
{
_organizationUserRepository = organizationUserRepository;
Expand All @@ -52,8 +45,6 @@ public UsersController(IOrganizationUserRepository organizationUserRepository,
_patchUserCommand = patchUserCommand;
_postUserCommand = postUserCommand;
_restoreOrganizationUserCommand = restoreOrganizationUserCommand;
_revokeOrganizationUserCommand = revokeOrganizationUserCommand;
_featureService = featureService;
_revokeOrganizationUserCommandV2 = revokeOrganizationUserCommandV2;
}

Expand Down Expand Up @@ -111,32 +102,25 @@ public async Task<IActionResult> Put(Guid organizationId, Guid id, [FromBody] Sc
}
else if (!model.Active && orgUser.Status != OrganizationUserStatusType.Revoked)
{
if (_featureService.IsEnabled(FeatureFlagKeys.ScimRevokeV2))
{
var results = await _revokeOrganizationUserCommandV2.RevokeUsersAsync(
new RevokeOrganizationUsersRequest(
organizationId,
[id],
new SystemUser(EventSystemUser.SCIM)));
var results = await _revokeOrganizationUserCommandV2.RevokeUsersAsync(
new RevokeOrganizationUsersRequest(
organizationId,
[id],
new SystemUser(EventSystemUser.SCIM)));

var errors = results.Select(x => x.Result.Match(
y => $"{y.Message} for user {x.Id}",
_ => null))
.Where(x => !string.IsNullOrWhiteSpace(x))
.ToList();
var errors = results.Select(x => x.Result.Match(
y => $"{y.Message} for user {x.Id}",
_ => null))
.Where(x => !string.IsNullOrWhiteSpace(x))
.ToList();

if (errors.Count != 0)
{
return new BadRequestObjectResult(new ScimErrorResponseModel
{
Status = 400,
Detail = string.Join(", ", errors)
});
}
}
else
if (errors.Count != 0)
{
await _revokeOrganizationUserCommand.RevokeUserAsync(orgUser, EventSystemUser.SCIM);
return new BadRequestObjectResult(new ScimErrorResponseModel
{
Status = 400,
Detail = string.Join(", ", errors)
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,16 +394,10 @@ public async Task Post_ExistingData_Conflict(string email, string externalId)
Assert.Equal(_initialUserCount, databaseContext.OrganizationUsers.Count());
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task Put_RevokeUser_Success(bool scimRevokeV2Enabled)
[Fact]
public async Task Put_RevokeUser_Success()
{
var localFactory = new ScimApplicationFactory();
localFactory.SubstituteService((IFeatureService featureService)
=> featureService.IsEnabled(FeatureFlagKeys.ScimRevokeV2)
.Returns(scimRevokeV2Enabled));

localFactory.ReinitializeDbForTests(localFactory.GetDatabaseContext());

var organizationUserId = ScimApplicationFactory.TestOrganizationUserId2;
Expand Down
1 change: 0 additions & 1 deletion src/Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ public static class FeatureFlagKeys
public const string PolicyRequirements = "pm-14439-policy-requirements";
public const string ScimInviteUserOptimization = "pm-16811-optimize-invite-user-flow-to-fail-fast";
public const string AutomaticConfirmUsers = "pm-19934-auto-confirm-organization-users";
public const string ScimRevokeV2 = "pm-32394-scim-revoke-put-v2";
public const string BulkReinviteUI = "pm-28416-bulk-reinvite-ux-improvements";
public const string RefactorOrgAcceptInit = "pm-33082-refactor-org-accept-init";
public const string AdminResetTwoFactor = "pm-15489-reset-two-factor-account-recovery";
Expand Down
Loading