mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 00:52:49 -05:00
SM-561: Update Secret Revision Dates (#2770)
* SM-561: Update secret revision date on restore * SM-561: Update secret revision dates when a project is deleted * SM-561: Fix bug when updating revision dates for secrets when their parent project is deleted * SM-561: Handle case when there are no secrets in the projects that are being deleted * SM-561: Rename func to GetManyWithSecretsByIds and move UpdateRevisionDates call from ProjectsController to projects delete command * SM-561: update secret ids before project deletion * SM-561: Refactor out command in command call to follow CQRS pattern * SM-561: Remove null check
This commit is contained in:
@ -11,11 +11,13 @@ public class DeleteProjectCommand : IDeleteProjectCommand
|
||||
{
|
||||
private readonly IProjectRepository _projectRepository;
|
||||
private readonly ICurrentContext _currentContext;
|
||||
private readonly ISecretRepository _secretRepository;
|
||||
|
||||
public DeleteProjectCommand(IProjectRepository projectRepository, ICurrentContext currentContext)
|
||||
public DeleteProjectCommand(IProjectRepository projectRepository, ICurrentContext currentContext, ISecretRepository secretRepository)
|
||||
{
|
||||
_projectRepository = projectRepository;
|
||||
_currentContext = currentContext;
|
||||
_secretRepository = secretRepository;
|
||||
}
|
||||
|
||||
public async Task<List<Tuple<Project, string>>> DeleteProjects(List<Guid> ids, Guid userId)
|
||||
@ -25,7 +27,7 @@ public class DeleteProjectCommand : IDeleteProjectCommand
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
var projects = (await _projectRepository.GetManyByIds(ids))?.ToList();
|
||||
var projects = (await _projectRepository.GetManyWithSecretsByIds(ids))?.ToList();
|
||||
|
||||
if (projects?.Any() != true || projects.Count != ids.Count)
|
||||
{
|
||||
@ -72,9 +74,16 @@ public class DeleteProjectCommand : IDeleteProjectCommand
|
||||
|
||||
if (deleteIds.Count > 0)
|
||||
{
|
||||
var secretIds = results.SelectMany(projTuple => projTuple.Item1?.Secrets?.Select(s => s.Id) ?? Array.Empty<Guid>()).ToList();
|
||||
|
||||
if (secretIds.Count > 0)
|
||||
{
|
||||
await _secretRepository.UpdateRevisionDates(secretIds);
|
||||
}
|
||||
|
||||
await _projectRepository.DeleteManyByIdAsync(deleteIds);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user