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

[PM-15621] WIP: Fixed the build and muted the tests

This commit is contained in:
Jimmy Vo 2025-04-04 12:53:07 -04:00
parent 875eb41229
commit 9d2d7ac83a
No known key found for this signature in database
GPG Key ID: 7CB834D6F4FFCA11
7 changed files with 41 additions and 27 deletions

View File

@ -615,8 +615,10 @@ public class OrganizationUsersController : Controller
var results = await _deleteManagedOrganizationUserAccountCommand.DeleteManyUsersAsync(orgId, model.Ids, currentUser.Id);
return new ListResponseModel<OrganizationUserBulkResponseModel>(results.Select(r =>
new OrganizationUserBulkResponseModel(r.OrganizationUserId, r.result)));
// Temporary code.
throw new UnauthorizedAccessException();
// return new ListResponseModel<OrganizationUserBulkResponseModel>(results.Select(r =>
// new OrganizationUserBulkResponseModel(r.OrganizationUserId, r.result)));
}
[HttpPatch("{id}/revoke")]

View File

@ -0,0 +1,6 @@
namespace Bit.Core.Models.Data.Organizations;
public class DeleteUserResponse
{
public Guid OrganizationId { get; init; }
}

View File

@ -50,28 +50,28 @@ public class DeleteManagedOrganizationUserAccountCommand : IDeleteManagedOrganiz
_pushService = pushService;
}
public async Task<CommandResult> DeleteUserAsync(Guid organizationId, Guid organizationUserId, Guid? deletingUserId)
public async Task<CommandResult> DeleteUserAsync(Guid organizationId, Guid organizationUserId, Guid deletingUserId)
{
var result = await InternalDeleteManyUsersAsync(organizationId, new[] { organizationUserId }, deletingUserId);
if (result.InvalidResults.Count > 0)
{
var error = result.InvalidResults.FirstOrDefault()?.Errors.FirstOrDefault();
return new Failure();
if (error != null)
{
return new Failure(error.Message);
}
return new Success();
}
public async Task<IEnumerable<(Guid OrganizationUserId, CommandResult result)>> DeleteManyUsersAsync(Guid organizationId, IEnumerable<Guid> orgUserIds, Guid? deletingUserId)
public async Task<CommandResult> DeleteManyUsersAsync(Guid organizationId, IEnumerable<Guid> orgUserIds, Guid deletingUserId)
{
var results = await InternalDeleteManyUsersAsync(organizationId, orgUserIds, deletingUserId);
return new Success();
}
private async Task<PartialValidationResult<DeleteUserValidationRequest>> InternalDeleteManyUsersAsync(Guid organizationId, IEnumerable<Guid> orgUserIds, Guid? deletingUserId)
private async Task<PartialValidationResult<DeleteUserValidationRequest>> InternalDeleteManyUsersAsync(Guid organizationId, IEnumerable<Guid> orgUserIds, Guid deletingUserId)
{
var orgUsers = await _organizationUserRepository.GetManyAsync(orgUserIds);
var users = await GetUsersAsync(orgUsers);
@ -89,7 +89,7 @@ public class DeleteManagedOrganizationUserAccountCommand : IDeleteManagedOrganiz
private List<DeleteUserValidationRequest> CreateRequests(
Guid organizationId,
Guid? deletingUserId,
Guid deletingUserId,
IEnumerable<Guid> orgUserIds,
ICollection<OrganizationUser> orgUsers,
IEnumerable<User> users,
@ -145,22 +145,19 @@ public class DeleteManagedOrganizationUserAccountCommand : IDeleteManagedOrganiz
var users = requests
.Select(request => request.Value.User!);
if (users.Any())
if (!users.Any())
{
await DeleteManyAsync(users);
}
return;
}
private async Task DeleteManyAsync(IEnumerable<User> users)
{
await _userRepository.DeleteManyAsync(users);
foreach (var user in users)
{
await _referenceEventService.RaiseEventAsync(
new ReferenceEvent(ReferenceEventType.DeleteAccount, user, _currentContext));
await _pushService.PushLogOutAsync(user.Id);
}
}
private async Task CancelPremiumsAsync(List<Valid<DeleteUserValidationRequest>> requests)

View File

@ -6,7 +6,7 @@ using Bit.Core.Context;
using Bit.Core.Enums;
using Bit.Core.Repositories;
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.RestoreUser;
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers;
public class DeleteManagedOrganizationUserAccountValidator(
ICurrentContext currentContext,
@ -34,7 +34,8 @@ public class DeleteManagedOrganizationUserAccountValidator(
{
EnsureOnlyOwnersCanDeleteOwnersAsync,
EnsureUserIsNotSoleOrganizationOwnerAsync,
EnsureUserIsNotSoleProviderOwnerAsync
EnsureUserIsNotSoleProviderOwnerAsync,
EnsureCustomUsersCannotDeleteAdminsAsync
};
var result = await ExecuteValidatorsAsync(validators, asyncValidators, request);
@ -130,7 +131,7 @@ public class DeleteManagedOrganizationUserAccountValidator(
return new Valid<DeleteUserValidationRequest>(request);
}
if (request.DeletingUserId.HasValue && !await currentContext.OrganizationOwner(request.OrganizationId))
if (!await currentContext.OrganizationOwner(request.OrganizationId))
{
return new Invalid<DeleteUserValidationRequest>(new BadRequestError<DeleteUserValidationRequest>("Only owners can delete other owners.", request));
}
@ -158,4 +159,15 @@ public class DeleteManagedOrganizationUserAccountValidator(
return new Valid<DeleteUserValidationRequest>(request);
}
private async Task<ValidationResult<DeleteUserValidationRequest>> EnsureCustomUsersCannotDeleteAdminsAsync(DeleteUserValidationRequest request)
{
if (request.OrganizationUser.Type == OrganizationUserType.Admin && await currentContext.OrganizationCustom(request.OrganizationId))
{
return new Invalid<DeleteUserValidationRequest>(new BadRequestError<DeleteUserValidationRequest>("Custom users can not delete admins.", request));
}
return new Valid<DeleteUserValidationRequest>();
}
}

View File

@ -8,8 +8,6 @@ public class DeleteUserValidationRequest
public Guid OrganizationId { get; init; }
public OrganizationUser? OrganizationUser { get; init; }
public User? User { get; init; }
public Guid? DeletingUserId { get; init; }
public IDictionary<Guid, bool>? ManagementStatus { get; init; }
public Guid DeletingUserId { get; init; }
public bool? IsManaged { get; init; }
}

View File

@ -9,8 +9,7 @@ public interface IDeleteManagedOrganizationUserAccountCommand
/// <summary>
/// Removes a user from an organization and deletes all of their associated user data.
/// </summary>
/// Jimmy temporary comment: consider removing the nullable from deletingUserId.
Task<CommandResult> DeleteUserAsync(Guid organizationId, Guid organizationUserId, Guid? deletingUserId);
Task<CommandResult> DeleteUserAsync(Guid organizationId, Guid organizationUserId, Guid deletingUserId);
/// <summary>
/// Removes multiple users from an organization and deletes all of their associated user data.
@ -18,6 +17,5 @@ public interface IDeleteManagedOrganizationUserAccountCommand
/// <returns>
/// An error message for each user that could not be removed, otherwise null.
/// </returns>
/// Jimmy temporary comment: consider removing the nullable from deletingUserId.
Task<IEnumerable<(Guid OrganizationUserId, CommandResult result)>> DeleteManyUsersAsync(Guid organizationId, IEnumerable<Guid> orgUserIds, Guid? deletingUserId);
Task<CommandResult> DeleteManyUsersAsync(Guid organizationId, IEnumerable<Guid> orgUserIds, Guid deletingUserId);
}

View File

@ -117,6 +117,7 @@ public static class OrganizationServiceCollectionExtensions
services.AddScoped<IUpdateOrganizationUserCommand, UpdateOrganizationUserCommand>();
services.AddScoped<IUpdateOrganizationUserGroupsCommand, UpdateOrganizationUserGroupsCommand>();
services.AddScoped<IDeleteManagedOrganizationUserAccountCommand, DeleteManagedOrganizationUserAccountCommand>();
services.AddScoped<IDeleteManagedOrganizationUserAccountValidator, DeleteManagedOrganizationUserAccountValidator>();
services.AddScoped<IConfirmOrganizationUserCommand, ConfirmOrganizationUserCommand>();
}