Skip to content

Commit dd78b37

Browse files
committed
Merge branch 'update-send-openapi-to-work-for-sdk' of github.com:bitwarden/server into update-send-openapi-to-work-for-sdk
2 parents 3b33550 + f25cdaf commit dd78b37

51 files changed

Lines changed: 409 additions & 153 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bitwarden_license/src/Scim/Controllers/v2/UsersController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public async Task<IActionResult> Put(Guid organizationId, Guid id, [FromBody] Sc
106106
new RevokeOrganizationUsersRequest(
107107
organizationId,
108108
[id],
109-
new SystemUser(EventSystemUser.SCIM)));
109+
new SystemUser(EventSystemUser.SCIM),
110+
RevocationReason.Manual));
110111

111112
var errors = results.Select(x => x.Result.Match(
112113
y => $"{y.Message} for user {x.Id}",

bitwarden_license/src/Scim/Users/PatchUserCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private async Task<bool> HandleActiveOperationAsync(Core.Entities.OrganizationUs
107107
}
108108
else if (!active && orgUser.Status != OrganizationUserStatusType.Revoked)
109109
{
110-
await _revokeOrganizationUserCommand.RevokeUserAsync(orgUser, EventSystemUser.SCIM);
110+
await _revokeOrganizationUserCommand.RevokeUserAsync(orgUser, EventSystemUser.SCIM, RevocationReason.Manual);
111111
return true;
112112
}
113113
return false;

bitwarden_license/test/Scim.Test/Users/PatchUserCommandTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public async Task PatchUser_RevokePath_Success(SutProvider<PatchUserCommand> sut
102102

103103
await sutProvider.Sut.PatchUserAsync(organizationUser.OrganizationId, organizationUser.Id, scimPatchModel);
104104

105-
await sutProvider.GetDependency<IRevokeOrganizationUserCommand>().Received(1).RevokeUserAsync(organizationUser, EventSystemUser.SCIM);
105+
await sutProvider.GetDependency<IRevokeOrganizationUserCommand>().Received(1).RevokeUserAsync(organizationUser, EventSystemUser.SCIM, RevocationReason.Manual);
106106
}
107107

108108
[Theory]
@@ -130,7 +130,7 @@ public async Task PatchUser_RevokeValue_Success(SutProvider<PatchUserCommand> su
130130

131131
await sutProvider.Sut.PatchUserAsync(organizationUser.OrganizationId, organizationUser.Id, scimPatchModel);
132132

133-
await sutProvider.GetDependency<IRevokeOrganizationUserCommand>().Received(1).RevokeUserAsync(organizationUser, EventSystemUser.SCIM);
133+
await sutProvider.GetDependency<IRevokeOrganizationUserCommand>().Received(1).RevokeUserAsync(organizationUser, EventSystemUser.SCIM, RevocationReason.Manual);
134134
}
135135

136136
[Theory]
@@ -150,7 +150,7 @@ public async Task PatchUser_NoAction_Success(SutProvider<PatchUserCommand> sutPr
150150
await sutProvider.Sut.PatchUserAsync(organizationUser.OrganizationId, organizationUser.Id, scimPatchModel);
151151

152152
await sutProvider.GetDependency<IRestoreOrganizationUserCommand>().DidNotReceiveWithAnyArgs().RestoreUserAsync(default, EventSystemUser.SCIM);
153-
await sutProvider.GetDependency<IRevokeOrganizationUserCommand>().DidNotReceiveWithAnyArgs().RevokeUserAsync(default, EventSystemUser.SCIM);
153+
await sutProvider.GetDependency<IRevokeOrganizationUserCommand>().DidNotReceiveWithAnyArgs().RevokeUserAsync(default, EventSystemUser.SCIM, default);
154154
}
155155

156156
[Theory]
@@ -380,7 +380,7 @@ public async Task PatchUser_UnsupportedOperation_LogsWarningAndSucceeds(SutProvi
380380

381381
// Verify no restore or revoke operations were called
382382
await sutProvider.GetDependency<IRestoreOrganizationUserCommand>().DidNotReceiveWithAnyArgs().RestoreUserAsync(default, EventSystemUser.SCIM);
383-
await sutProvider.GetDependency<IRevokeOrganizationUserCommand>().DidNotReceiveWithAnyArgs().RevokeUserAsync(default, EventSystemUser.SCIM);
383+
await sutProvider.GetDependency<IRevokeOrganizationUserCommand>().DidNotReceiveWithAnyArgs().RevokeUserAsync(default, EventSystemUser.SCIM, default);
384384
}
385385

386386
[Theory]
@@ -415,7 +415,7 @@ public async Task PatchUser_ActiveAndExternalIdFromValue_Success(SutProvider<Pat
415415
await sutProvider.Sut.PatchUserAsync(organizationUser.OrganizationId, organizationUser.Id, scimPatchModel);
416416

417417
// Verify both operations were processed
418-
await sutProvider.GetDependency<IRevokeOrganizationUserCommand>().Received(1).RevokeUserAsync(organizationUser, EventSystemUser.SCIM);
418+
await sutProvider.GetDependency<IRevokeOrganizationUserCommand>().Received(1).RevokeUserAsync(organizationUser, EventSystemUser.SCIM, RevocationReason.Manual);
419419
await sutProvider.GetDependency<IOrganizationUserRepository>().Received(1).ReplaceAsync(
420420
Arg.Is<OrganizationUser>(ou => ou.ExternalId == newExternalId));
421421
}

src/Api/AdminConsole/Controllers/OrganizationUsersController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ public async Task<ListResponseModel<OrganizationUserBulkResponseModel>> PostBulk
644644
[Authorize<ManageUsersRequirement>]
645645
public async Task RevokeAsync(Guid orgId, Guid id)
646646
{
647-
await RestoreOrRevokeUserAsync(orgId, id, _revokeOrganizationUserCommand.RevokeUserAsync);
647+
await RestoreOrRevokeUserAsync(orgId, id, (orgUser, userId) => _revokeOrganizationUserCommand.RevokeUserAsync(orgUser, userId, RevocationReason.Manual));
648648
}
649649

650650
[HttpPut("revoke-self")]
@@ -683,7 +683,8 @@ public async Task<ListResponseModel<OrganizationUserBulkResponseModel>> BulkRevo
683683
new V2_RevokeOrganizationUserCommand.RevokeOrganizationUsersRequest(
684684
orgId,
685685
model.Ids.ToArray(),
686-
new StandardUser(currentUserId.Value, await _currentContext.OrganizationOwner(orgId))));
686+
new StandardUser(currentUserId.Value, await _currentContext.OrganizationOwner(orgId)),
687+
RevocationReason.Manual));
687688

688689
return new ListResponseModel<OrganizationUserBulkResponseModel>(results
689690
.Select(result => new OrganizationUserBulkResponseModel(result.Id,

src/Api/AdminConsole/Models/Request/Organizations/OrganizationCreateRequestModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class OrganizationCreateRequestModel : IValidatableObject
3333
[Required]
3434
public string Key { get; set; }
3535

36+
[Required]
3637
public OrganizationKeysRequestModel Keys { get; set; }
3738
public PaymentMethodType? PaymentMethodType { get; set; }
3839
public string PaymentToken { get; set; }
@@ -117,7 +118,7 @@ public virtual OrganizationSignup ToOrganizationSignup(User user)
117118
InitiationPath = InitiationPath,
118119
SkipTrial = SkipTrial,
119120
Coupons = Coupons,
120-
Keys = Keys?.ToPublicKeyEncryptionKeyPairData()
121+
Keys = Keys.ToPublicKeyEncryptionKeyPairData()
121122
};
122123

123124
return orgSignup;

src/Api/AdminConsole/Models/Request/Organizations/OrganizationNoPaymentCreateRequest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class OrganizationNoPaymentCreateRequest
3232
[Required]
3333
public string Key { get; set; }
3434

35+
[Required]
3536
public OrganizationKeysRequestModel Keys { get; set; }
3637
public PaymentMethodType? PaymentMethodType { get; set; }
3738
public string PaymentToken { get; set; }
@@ -110,7 +111,7 @@ public virtual OrganizationSignup ToOrganizationSignup(User user)
110111
BillingAddressCountry = BillingAddressCountry,
111112
},
112113
InitiationPath = InitiationPath,
113-
Keys = Keys?.ToPublicKeyEncryptionKeyPairData()
114+
Keys = Keys.ToPublicKeyEncryptionKeyPairData()
114115
};
115116

116117
return orgSignup;

src/Api/AdminConsole/Public/Controllers/MembersController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ public async Task<IActionResult> Revoke(Guid id)
339339
var request = new RevokeOrganizationUsersRequest(
340340
_currentContext.OrganizationId!.Value,
341341
[id],
342-
new SystemUser(EventSystemUser.PublicApi)
342+
new SystemUser(EventSystemUser.PublicApi),
343+
RevocationReason.Manual
343344
);
344345

345346
var results = await _revokeOrganizationUserCommandV2.RevokeUsersAsync(request);

src/Api/Dirt/Controllers/OrganizationIntegrationController.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Bit.Api.Dirt.Models.Response;
33
using Bit.Core.Context;
44
using Bit.Core.Dirt.EventIntegrations.OrganizationIntegrations.Interfaces;
5-
using Bit.Core.Exceptions;
65
using Microsoft.AspNetCore.Authorization;
76
using Microsoft.AspNetCore.Mvc;
87

@@ -18,17 +17,17 @@ public class OrganizationIntegrationController(
1817
IGetOrganizationIntegrationsQuery getQuery) : Controller
1918
{
2019
[HttpGet("")]
21-
public async Task<List<OrganizationIntegrationResponseModel>> GetAsync(Guid organizationId)
20+
public async Task<ActionResult<List<OrganizationIntegrationResponseModel>>> GetAsync(Guid organizationId)
2221
{
2322
if (!await HasPermission(organizationId))
2423
{
25-
throw new NotFoundException();
24+
return NotFound();
2625
}
2726

2827
var integrations = await getQuery.GetManyByOrganizationAsync(organizationId);
29-
return integrations
28+
return Ok(integrations
3029
.Select(integration => new OrganizationIntegrationResponseModel(integration))
31-
.ToList();
30+
.ToList());
3231
}
3332

3433
/// <summary>
@@ -38,7 +37,7 @@ public async Task<List<OrganizationIntegrationResponseModel>> GetAsync(Guid orga
3837
/// <param name="organizationId"></param>
3938
/// <param name="model"></param>
4039
/// <returns></returns>
41-
/// <exception cref="NotFoundException">Not enough permissions to access the organization.</exception>
40+
/// <exception cref="NotFoundResult">Not enough permissions to access the organization.</exception>
4241
/// <exception cref="ConflictResult">When an integration of the same type already exists for the organization.</exception>
4342
[HttpPost("")]
4443
public async Task<ActionResult<OrganizationIntegrationResponseModel>> CreateAsync(Guid organizationId, [FromBody] OrganizationIntegrationRequestModel model)
@@ -50,7 +49,7 @@ public async Task<ActionResult<OrganizationIntegrationResponseModel>> CreateAsyn
5049

5150
if (!await HasPermission(organizationId))
5251
{
53-
throw new NotFoundException();
52+
return NotFound();
5453
}
5554

5655
var integration = model.ToOrganizationIntegration(organizationId);
@@ -62,40 +61,40 @@ public async Task<ActionResult<OrganizationIntegrationResponseModel>> CreateAsyn
6261
}
6362

6463
var created = await createCommand.CreateAsync(integration);
65-
6664
return Ok(new OrganizationIntegrationResponseModel(created));
65+
6766
}
6867

6968
[HttpPut("{integrationId:guid}")]
70-
public async Task<OrganizationIntegrationResponseModel> UpdateAsync(Guid organizationId, Guid integrationId, [FromBody] OrganizationIntegrationRequestModel model)
69+
public async Task<ActionResult<OrganizationIntegrationResponseModel>> UpdateAsync(Guid organizationId, Guid integrationId, [FromBody] OrganizationIntegrationRequestModel model)
7170
{
7271
if (!await HasPermission(organizationId))
7372
{
74-
throw new NotFoundException();
73+
return NotFound();
7574
}
7675

7776
var integration = model.ToOrganizationIntegration(organizationId);
7877
var updated = await updateCommand.UpdateAsync(organizationId, integrationId, integration);
79-
80-
return new OrganizationIntegrationResponseModel(updated);
78+
return Ok(new OrganizationIntegrationResponseModel(updated));
8179
}
8280

8381
[HttpDelete("{integrationId:guid}")]
84-
public async Task DeleteAsync(Guid organizationId, Guid integrationId)
82+
public async Task<IActionResult> DeleteAsync(Guid organizationId, Guid integrationId)
8583
{
8684
if (!await HasPermission(organizationId))
8785
{
88-
throw new NotFoundException();
86+
return NotFound();
8987
}
9088

9189
await deleteCommand.DeleteAsync(organizationId, integrationId);
90+
return NoContent();
9291
}
9392

9493
[HttpPost("{integrationId:guid}/delete")]
9594
[Obsolete("This endpoint is deprecated. Use DELETE method instead")]
96-
public async Task PostDeleteAsync(Guid organizationId, Guid integrationId)
95+
public async Task<IActionResult> PostDeleteAsync(Guid organizationId, Guid integrationId)
9796
{
98-
await DeleteAsync(organizationId, integrationId);
97+
return await DeleteAsync(organizationId, integrationId);
9998
}
10099

101100
private async Task<bool> HasPermission(Guid organizationId)

src/Core/AdminConsole/OrganizationFeatures/AccountRecovery/v2/AdminRecoverAccountCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ await revokeNonCompliantOrganizationUserCommand.RevokeNonCompliantOrganizationUs
125125
new RevokeOrganizationUsersRequest(
126126
o.OrganizationId,
127127
[new OrganizationUserUserDetails { Id = o.OrganizationUserId, OrganizationId = o.OrganizationId }],
128-
new SystemUser(EventSystemUser.TwoFactorDisabled)));
128+
new SystemUser(EventSystemUser.TwoFactorDisabled),
129+
RevocationReason.TwoFactorPolicyNonCompliance));
129130
await mailService.SendOrganizationUserRevokedForTwoFactorPolicyEmailAsync(organization.DisplayName(), user.Email);
130131
}).ToArray();
131132

src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/RemoveOrganizationUserCommand.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,11 @@ await _pushRegistrationService.DeleteUserRegistrationOrganizationAsync(devices,
212212
}
213213

214214
var deletingUserIsOwner = false;
215+
var deletingUserIsCustom = false;
215216
if (deletingUserId.HasValue)
216217
{
217218
deletingUserIsOwner = await _currentContext.OrganizationOwner(organizationId);
219+
deletingUserIsCustom = await _currentContext.OrganizationCustom(organizationId);
218220
}
219221

220222
var claimedStatus = deletingUserId.HasValue && eventSystemUser == null
@@ -235,6 +237,11 @@ await _pushRegistrationService.DeleteUserRegistrationOrganizationAsync(devices,
235237
throw new BadRequestException(RemoveOwnerByNonOwnerErrorMessage);
236238
}
237239

240+
if (orgUser.Type == OrganizationUserType.Admin && deletingUserIsCustom)
241+
{
242+
throw new BadRequestException(RemoveAdminByCustomUserErrorMessage);
243+
}
244+
238245
if (claimedStatus.TryGetValue(orgUser.Id, out var isClaimed) && isClaimed)
239246
{
240247
throw new BadRequestException(RemoveClaimedAccountErrorMessage);

0 commit comments

Comments
 (0)