11// FIXME: Update this file to be null safe and then delete the line below
22#nullable disable
33
4+ using Bit . Core ;
5+ using Bit . Core . AdminConsole . Models . Data ;
46using Bit . Core . AdminConsole . OrganizationFeatures . OrganizationUsers . Interfaces ;
57using Bit . Core . AdminConsole . OrganizationFeatures . OrganizationUsers . RestoreUser . v1 ;
6- using Bit . Core . AdminConsole . OrganizationFeatures . OrganizationUsers . RevokeUser . v1 ;
8+ using Bit . Core . AdminConsole . OrganizationFeatures . OrganizationUsers . RevokeUser . v2 ;
79using Bit . Core . Enums ;
810using Bit . Core . Exceptions ;
911using Bit . Core . Repositories ;
12+ using Bit . Core . Services ;
1013using Bit . Scim . Models ;
1114using Bit . Scim . Users . Interfaces ;
1215using Bit . Scim . Utilities ;
1316using Microsoft . AspNetCore . Authorization ;
1417using Microsoft . AspNetCore . Mvc ;
18+ using IRevokeOrganizationUserCommand = Bit . Core . AdminConsole . OrganizationFeatures . OrganizationUsers . RevokeUser . v1 . IRevokeOrganizationUserCommand ;
19+ using IRevokeOrganizationUserCommandV2 = Bit . Core . AdminConsole . OrganizationFeatures . OrganizationUsers . RevokeUser . v2 . IRevokeOrganizationUserCommand ;
1520
1621namespace Bit . Scim . Controllers . v2 ;
1722
@@ -28,14 +33,18 @@ public class UsersController : Controller
2833 private readonly IPostUserCommand _postUserCommand ;
2934 private readonly IRestoreOrganizationUserCommand _restoreOrganizationUserCommand ;
3035 private readonly IRevokeOrganizationUserCommand _revokeOrganizationUserCommand ;
36+ private readonly IFeatureService _featureService ;
37+ private readonly IRevokeOrganizationUserCommandV2 _revokeOrganizationUserCommandV2 ;
3138
3239 public UsersController ( IOrganizationUserRepository organizationUserRepository ,
3340 IGetUsersListQuery getUsersListQuery ,
3441 IRemoveOrganizationUserCommand removeOrganizationUserCommand ,
3542 IPatchUserCommand patchUserCommand ,
3643 IPostUserCommand postUserCommand ,
3744 IRestoreOrganizationUserCommand restoreOrganizationUserCommand ,
38- IRevokeOrganizationUserCommand revokeOrganizationUserCommand )
45+ IRevokeOrganizationUserCommand revokeOrganizationUserCommand ,
46+ IFeatureService featureService ,
47+ IRevokeOrganizationUserCommandV2 revokeOrganizationUserCommandV2 )
3948 {
4049 _organizationUserRepository = organizationUserRepository ;
4150 _getUsersListQuery = getUsersListQuery ;
@@ -44,6 +53,8 @@ public UsersController(IOrganizationUserRepository organizationUserRepository,
4453 _postUserCommand = postUserCommand ;
4554 _restoreOrganizationUserCommand = restoreOrganizationUserCommand ;
4655 _revokeOrganizationUserCommand = revokeOrganizationUserCommand ;
56+ _featureService = featureService ;
57+ _revokeOrganizationUserCommandV2 = revokeOrganizationUserCommandV2 ;
4758 }
4859
4960 [ HttpGet ( "{id}" ) ]
@@ -100,7 +111,33 @@ public async Task<IActionResult> Put(Guid organizationId, Guid id, [FromBody] Sc
100111 }
101112 else if ( ! model . Active && orgUser . Status != OrganizationUserStatusType . Revoked )
102113 {
103- await _revokeOrganizationUserCommand . RevokeUserAsync ( orgUser , EventSystemUser . SCIM ) ;
114+ if ( _featureService . IsEnabled ( FeatureFlagKeys . ScimRevokeV2 ) )
115+ {
116+ var results = await _revokeOrganizationUserCommandV2 . RevokeUsersAsync (
117+ new RevokeOrganizationUsersRequest (
118+ organizationId ,
119+ [ id ] ,
120+ new SystemUser ( EventSystemUser . SCIM ) ) ) ;
121+
122+ var errors = results . Select ( x => x . Result . Match (
123+ y => $ "{ y . Message } for user { x . Id } ",
124+ _ => null ) )
125+ . Where ( x => ! string . IsNullOrWhiteSpace ( x ) )
126+ . ToList ( ) ;
127+
128+ if ( errors . Count != 0 )
129+ {
130+ return new BadRequestObjectResult ( new ScimErrorResponseModel
131+ {
132+ Status = 400 ,
133+ Detail = string . Join ( ", " , errors )
134+ } ) ;
135+ }
136+ }
137+ else
138+ {
139+ await _revokeOrganizationUserCommand . RevokeUserAsync ( orgUser , EventSystemUser . SCIM ) ;
140+ }
104141 }
105142
106143 // Have to get full details object for response model
0 commit comments