1
0
mirror of https://github.com/bitwarden/server synced 2025-12-18 01:03:17 +00:00

job to delete trashed ciphers nightly (#1243)

* job to delete trashed items nightly

* remove script from migration project file

* admin setting for controlling trash deleting dates
This commit is contained in:
Kyle Spearrin
2021-04-02 11:14:21 -04:00
committed by GitHub
parent 1b8b9b7539
commit 597fa01344
8 changed files with 122 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
using System;
using System.Threading.Tasks;
using Bit.Core;
using Bit.Core.Jobs;
using Bit.Core.Repositories;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Quartz;
namespace Bit.Admin.Jobs
{
public class DeleteCiphersJob : BaseJob
{
private readonly ICipherRepository _cipherRepository;
private readonly AdminSettings _adminSettings;
public DeleteCiphersJob(
ICipherRepository cipherRepository,
IOptions<AdminSettings> adminSettings,
ILogger<DeleteCiphersJob> logger)
: base(logger)
{
_cipherRepository = cipherRepository;
_adminSettings = adminSettings?.Value;
}
protected async override Task ExecuteJobAsync(IJobExecutionContext context)
{
_logger.LogInformation(Constants.BypassFiltersEventId, "Execute job task: DeleteDeletedAsync");
var deleteDate = DateTime.UtcNow.AddDays(-30);
var daysAgoSetting = (_adminSettings?.DeleteTrashDaysAgo).GetValueOrDefault();
if (daysAgoSetting > 0)
{
deleteDate = DateTime.UtcNow.AddDays(-1 * daysAgoSetting);
}
await _cipherRepository.DeleteDeletedAsync(deleteDate);
_logger.LogInformation(Constants.BypassFiltersEventId, "Finished job task: DeleteDeletedAsync");
}
}
}