mirror of
https://github.com/bitwarden/server.git
synced 2025-04-05 05:00:19 -05:00
[PM-15621] WIP: Fixed the build and muted the tests
This commit is contained in:
parent
875eb41229
commit
9d2d7ac83a
@ -615,8 +615,10 @@ public class OrganizationUsersController : Controller
|
|||||||
|
|
||||||
var results = await _deleteManagedOrganizationUserAccountCommand.DeleteManyUsersAsync(orgId, model.Ids, currentUser.Id);
|
var results = await _deleteManagedOrganizationUserAccountCommand.DeleteManyUsersAsync(orgId, model.Ids, currentUser.Id);
|
||||||
|
|
||||||
return new ListResponseModel<OrganizationUserBulkResponseModel>(results.Select(r =>
|
// Temporary code.
|
||||||
new OrganizationUserBulkResponseModel(r.OrganizationUserId, r.result)));
|
throw new UnauthorizedAccessException();
|
||||||
|
// return new ListResponseModel<OrganizationUserBulkResponseModel>(results.Select(r =>
|
||||||
|
// new OrganizationUserBulkResponseModel(r.OrganizationUserId, r.result)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPatch("{id}/revoke")]
|
[HttpPatch("{id}/revoke")]
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
namespace Bit.Core.Models.Data.Organizations;
|
||||||
|
|
||||||
|
public class DeleteUserResponse
|
||||||
|
{
|
||||||
|
public Guid OrganizationId { get; init; }
|
||||||
|
}
|
@ -50,28 +50,28 @@ public class DeleteManagedOrganizationUserAccountCommand : IDeleteManagedOrganiz
|
|||||||
_pushService = pushService;
|
_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);
|
var result = await InternalDeleteManyUsersAsync(organizationId, new[] { organizationUserId }, deletingUserId);
|
||||||
|
|
||||||
|
var error = result.InvalidResults.FirstOrDefault()?.Errors.FirstOrDefault();
|
||||||
|
|
||||||
if (result.InvalidResults.Count > 0)
|
if (error != null)
|
||||||
{
|
{
|
||||||
|
return new Failure(error.Message);
|
||||||
var error = result.InvalidResults.FirstOrDefault()?.Errors.FirstOrDefault();
|
|
||||||
|
|
||||||
return new Failure();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Success();
|
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);
|
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 orgUsers = await _organizationUserRepository.GetManyAsync(orgUserIds);
|
||||||
var users = await GetUsersAsync(orgUsers);
|
var users = await GetUsersAsync(orgUsers);
|
||||||
@ -89,7 +89,7 @@ public class DeleteManagedOrganizationUserAccountCommand : IDeleteManagedOrganiz
|
|||||||
|
|
||||||
private List<DeleteUserValidationRequest> CreateRequests(
|
private List<DeleteUserValidationRequest> CreateRequests(
|
||||||
Guid organizationId,
|
Guid organizationId,
|
||||||
Guid? deletingUserId,
|
Guid deletingUserId,
|
||||||
IEnumerable<Guid> orgUserIds,
|
IEnumerable<Guid> orgUserIds,
|
||||||
ICollection<OrganizationUser> orgUsers,
|
ICollection<OrganizationUser> orgUsers,
|
||||||
IEnumerable<User> users,
|
IEnumerable<User> users,
|
||||||
@ -145,22 +145,19 @@ public class DeleteManagedOrganizationUserAccountCommand : IDeleteManagedOrganiz
|
|||||||
var users = requests
|
var users = requests
|
||||||
.Select(request => request.Value.User!);
|
.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);
|
await _userRepository.DeleteManyAsync(users);
|
||||||
|
|
||||||
foreach (var user in users)
|
foreach (var user in users)
|
||||||
{
|
{
|
||||||
await _referenceEventService.RaiseEventAsync(
|
await _referenceEventService.RaiseEventAsync(
|
||||||
new ReferenceEvent(ReferenceEventType.DeleteAccount, user, _currentContext));
|
new ReferenceEvent(ReferenceEventType.DeleteAccount, user, _currentContext));
|
||||||
await _pushService.PushLogOutAsync(user.Id);
|
await _pushService.PushLogOutAsync(user.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CancelPremiumsAsync(List<Valid<DeleteUserValidationRequest>> requests)
|
private async Task CancelPremiumsAsync(List<Valid<DeleteUserValidationRequest>> requests)
|
||||||
|
@ -6,7 +6,7 @@ using Bit.Core.Context;
|
|||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
|
|
||||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.RestoreUser;
|
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers;
|
||||||
|
|
||||||
public class DeleteManagedOrganizationUserAccountValidator(
|
public class DeleteManagedOrganizationUserAccountValidator(
|
||||||
ICurrentContext currentContext,
|
ICurrentContext currentContext,
|
||||||
@ -34,7 +34,8 @@ public class DeleteManagedOrganizationUserAccountValidator(
|
|||||||
{
|
{
|
||||||
EnsureOnlyOwnersCanDeleteOwnersAsync,
|
EnsureOnlyOwnersCanDeleteOwnersAsync,
|
||||||
EnsureUserIsNotSoleOrganizationOwnerAsync,
|
EnsureUserIsNotSoleOrganizationOwnerAsync,
|
||||||
EnsureUserIsNotSoleProviderOwnerAsync
|
EnsureUserIsNotSoleProviderOwnerAsync,
|
||||||
|
EnsureCustomUsersCannotDeleteAdminsAsync
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = await ExecuteValidatorsAsync(validators, asyncValidators, request);
|
var result = await ExecuteValidatorsAsync(validators, asyncValidators, request);
|
||||||
@ -130,7 +131,7 @@ public class DeleteManagedOrganizationUserAccountValidator(
|
|||||||
return new Valid<DeleteUserValidationRequest>(request);
|
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));
|
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);
|
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>();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -8,8 +8,6 @@ public class DeleteUserValidationRequest
|
|||||||
public Guid OrganizationId { get; init; }
|
public Guid OrganizationId { get; init; }
|
||||||
public OrganizationUser? OrganizationUser { get; init; }
|
public OrganizationUser? OrganizationUser { get; init; }
|
||||||
public User? User { get; init; }
|
public User? User { get; init; }
|
||||||
public Guid? DeletingUserId { get; init; }
|
public Guid DeletingUserId { get; init; }
|
||||||
|
|
||||||
public IDictionary<Guid, bool>? ManagementStatus { get; init; }
|
|
||||||
public bool? IsManaged { get; init; }
|
public bool? IsManaged { get; init; }
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,7 @@ public interface IDeleteManagedOrganizationUserAccountCommand
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes a user from an organization and deletes all of their associated user data.
|
/// Removes a user from an organization and deletes all of their associated user data.
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Removes multiple users from an organization and deletes all of their associated user data.
|
/// Removes multiple users from an organization and deletes all of their associated user data.
|
||||||
@ -18,6 +17,5 @@ public interface IDeleteManagedOrganizationUserAccountCommand
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// An error message for each user that could not be removed, otherwise null.
|
/// An error message for each user that could not be removed, otherwise null.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
/// Jimmy temporary comment: consider removing the nullable from deletingUserId.
|
Task<CommandResult> DeleteManyUsersAsync(Guid organizationId, IEnumerable<Guid> orgUserIds, Guid deletingUserId);
|
||||||
Task<IEnumerable<(Guid OrganizationUserId, CommandResult result)>> DeleteManyUsersAsync(Guid organizationId, IEnumerable<Guid> orgUserIds, Guid? deletingUserId);
|
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,7 @@ public static class OrganizationServiceCollectionExtensions
|
|||||||
services.AddScoped<IUpdateOrganizationUserCommand, UpdateOrganizationUserCommand>();
|
services.AddScoped<IUpdateOrganizationUserCommand, UpdateOrganizationUserCommand>();
|
||||||
services.AddScoped<IUpdateOrganizationUserGroupsCommand, UpdateOrganizationUserGroupsCommand>();
|
services.AddScoped<IUpdateOrganizationUserGroupsCommand, UpdateOrganizationUserGroupsCommand>();
|
||||||
services.AddScoped<IDeleteManagedOrganizationUserAccountCommand, DeleteManagedOrganizationUserAccountCommand>();
|
services.AddScoped<IDeleteManagedOrganizationUserAccountCommand, DeleteManagedOrganizationUserAccountCommand>();
|
||||||
|
services.AddScoped<IDeleteManagedOrganizationUserAccountValidator, DeleteManagedOrganizationUserAccountValidator>();
|
||||||
services.AddScoped<IConfirmOrganizationUserCommand, ConfirmOrganizationUserCommand>();
|
services.AddScoped<IConfirmOrganizationUserCommand, ConfirmOrganizationUserCommand>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user