Merge pull request #2541 from tidusjar/revert-2540-feature/purge-issues

Revert "Feature/purge issues"
pull/2580/head
Jamie 6 years ago committed by GitHub
commit a898bf43c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -191,7 +191,6 @@ namespace Ombi.DependencyInjection
services.AddTransient<ILidarrAlbumSync, LidarrAlbumSync>(); services.AddTransient<ILidarrAlbumSync, LidarrAlbumSync>();
services.AddTransient<ILidarrArtistSync, LidarrArtistSync>(); services.AddTransient<ILidarrArtistSync, LidarrArtistSync>();
services.AddTransient<ILidarrAvailabilityChecker, LidarrAvailabilityChecker>(); services.AddTransient<ILidarrAvailabilityChecker, LidarrAvailabilityChecker>();
services.AddTransient<IIssuesPurge, IssuesPurge>();
} }
} }
} }

@ -1,85 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Moq;
using NUnit.Framework;
using Ombi.Core.Settings;
using Ombi.Schedule.Jobs.Ombi;
using Ombi.Settings.Settings.Models;
using Ombi.Store.Entities.Requests;
using Ombi.Store.Repository;
using System.Threading.Tasks;
namespace Ombi.Schedule.Tests
{
[TestFixture]
public class IssuesPurgeTests
{
[SetUp]
public void Setup()
{
Repo = new Mock<IRepository<Issues>>();
Settings = new Mock<ISettingsService<IssueSettings>>();
Settings.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new IssueSettings());
Job = new IssuesPurge(Repo.Object, Settings.Object);
}
public Mock<IRepository<Issues>> Repo { get; set; }
public Mock<ISettingsService<IssueSettings>> Settings { get; set; }
public IssuesPurge Job { get; set; }
[Test]
public async Task DoesNotRun_WhenDisabled()
{
await Job.Start();
Repo.Verify(x => x.GetAll(),Times.Never);
}
[Test]
public async Task Deletes_Correct_Issue()
{
var issues = new List<Issues>()
{
new Issues
{
Status = IssueStatus.Resolved,
ResovledDate = DateTime.Now.AddDays(-5).AddHours(-1)
}
};
Settings.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new IssueSettings { DeleteIssues = true, DaysAfterResolvedToDelete = 5 });
Repo.Setup(x => x.GetAll()).Returns(new EnumerableQuery<Issues>(issues));
await Job.Start();
Assert.That(issues.First().Status, Is.EqualTo(IssueStatus.Deleted));
Repo.Verify(x => x.SaveChangesAsync(), Times.Once);
}
[Test]
public async Task DoesNot_Delete_AnyIssues()
{
var issues = new List<Issues>()
{
new Issues
{
Status = IssueStatus.Resolved,
ResovledDate = DateTime.Now.AddDays(-2)
},
new Issues
{
Status = IssueStatus.Resolved,
ResovledDate = DateTime.Now.AddDays(-6)
}
};
Settings.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new IssueSettings { DeleteIssues = true, DaysAfterResolvedToDelete = 5 });
Repo.Setup(x => x.GetAll()).Returns(new EnumerableQuery<Issues>(issues));
await Job.Start();
Assert.That(issues[0].Status, Is.Not.EqualTo(IssueStatus.Deleted));
Assert.That(issues[1].Status, Is.EqualTo(IssueStatus.Deleted));
Repo.Verify(x => x.SaveChangesAsync(), Times.Once);
}
}
}

@ -43,7 +43,7 @@ namespace Ombi.Schedule.Jobs.Lidarr
var cachedAlbum = await _cachedAlbums.FirstOrDefaultAsync(x => x.ForeignAlbumId.Equals(request.ForeignAlbumId)); var cachedAlbum = await _cachedAlbums.FirstOrDefaultAsync(x => x.ForeignAlbumId.Equals(request.ForeignAlbumId));
if (cachedAlbum != null) if (cachedAlbum != null)
{ {
if (cachedAlbum.FullyAvailable) if (cachedAlbum.Monitored && cachedAlbum.FullyAvailable)
{ {
request.Available = true; request.Available = true;
request.MarkedAsAvailable = DateTime.Now; request.MarkedAsAvailable = DateTime.Now;

@ -1,9 +0,0 @@
using System.Threading.Tasks;
namespace Ombi.Schedule.Jobs.Ombi
{
public interface IIssuesPurge : IBaseJob
{
Task Start();
}
}

@ -1,63 +0,0 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Ombi.Core.Settings;
using Ombi.Settings.Settings.Models;
using Ombi.Store.Entities.Requests;
using Ombi.Store.Repository;
namespace Ombi.Schedule.Jobs.Ombi
{
public class IssuesPurge : IIssuesPurge
{
public IssuesPurge(IRepository<Issues> issuesRepo, ISettingsService<IssueSettings> issueSettings)
{
_issuesRepository = issuesRepo;
_settings = issueSettings;
_settings.ClearCache();
}
private readonly IRepository<Issues> _issuesRepository;
private readonly ISettingsService<IssueSettings> _settings;
public async Task Start()
{
var settings = await _settings.GetSettingsAsync();
if (!settings.DeleteIssues)
{
return;
}
var now = DateTime.Now.AddDays(-settings.DaysAfterResolvedToDelete).Date;
var resolved = _issuesRepository.GetAll().Where(x => x.Status == IssueStatus.Resolved);
var toDelete = resolved.Where(x => x.ResovledDate.HasValue && x.ResovledDate.Value.Date <= now);
foreach (var d in toDelete)
{
d.Status = IssueStatus.Deleted;
}
await _issuesRepository.SaveChangesAsync();
}
private bool _disposed;
protected virtual void Dispose(bool disposing)
{
if (_disposed)
return;
if (disposing)
{
_issuesRepository?.Dispose();
_settings?.Dispose();
}
_disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}

@ -4,8 +4,5 @@
{ {
public bool Enabled { get; set; } public bool Enabled { get; set; }
public bool EnableInProgress { get; set; } public bool EnableInProgress { get; set; }
public bool DeleteIssues { get; set; }
public int DaysAfterResolvedToDelete { get; set; }
} }
} }

@ -14,6 +14,5 @@
public string RefreshMetadata { get; set; } public string RefreshMetadata { get; set; }
public string Newsletter { get; set; } public string Newsletter { get; set; }
public string LidarrArtistSync { get; set; } public string LidarrArtistSync { get; set; }
public string IssuesPurge { get; set; }
} }
} }

@ -57,11 +57,6 @@ namespace Ombi.Settings.Settings.Models
return Get(s.LidarrArtistSync, Cron.Hourly(40)); return Get(s.LidarrArtistSync, Cron.Hourly(40));
} }
public static string IssuePurge(JobSettings s)
{
return Get(s.IssuesPurge, Cron.Daily());
}
private static string Get(string settings, string defaultCron) private static string Get(string settings, string defaultCron)
{ {
return settings.HasValue() ? settings : defaultCron; return settings.HasValue() ? settings : defaultCron;

@ -29,6 +29,5 @@ namespace Ombi.Store.Entities.Requests
Pending = 0, Pending = 0,
InProgress = 1, InProgress = 1,
Resolved = 2, Resolved = 2,
Deleted = 3,
} }
} }

@ -144,14 +144,11 @@ export interface IJobSettings {
newsletter: string; newsletter: string;
plexRecentlyAddedSync: string; plexRecentlyAddedSync: string;
lidarrArtistSync: string; lidarrArtistSync: string;
issuesPurge: string;
} }
export interface IIssueSettings extends ISettings { export interface IIssueSettings extends ISettings {
enabled: boolean; enabled: boolean;
enableInProgress: boolean; enableInProgress: boolean;
deleteIssues: boolean;
daysAfterResolvedToDelete: number;
} }
export interface IAuthenticationSettings extends ISettings { export interface IAuthenticationSettings extends ISettings {

@ -59,7 +59,7 @@
<div> <div>
<h4> <h4>
<a href="" target="_blank"> <a href="" target="_blank">
{{request.title | truncate: 36}} {{request.title}}
</a> </a>
</h4> </h4>

@ -18,20 +18,6 @@
</div> </div>
</div> </div>
<div class="form-group">
<div class="checkbox">
<input type="checkbox" id="deleteIssues" formControlName="deleteIssues" ng-checked="form.deleteIssues">
<label for="deleteIssues">Delete issues after they have been resolved</label>
</div>
</div>
<div class="form-group" *ngIf="form.controls.deleteIssues.value">
<div class="checkbox">
<input type="checkbox" id="daysAfterResolvedToDelete" formControlName="daysAfterResolvedToDelete" ng-checked="form.daysAfterResolvedToDelete">
<label for="daysAfterResolvedToDelete">Leave the resolved issue for X amount of days before deletion</label>
</div>
</div>
<div class="form-group"> <div class="form-group">
<div> <div>
<button type="submit" [disabled]="form.invalid" class="btn btn-primary-outline ">Submit</button> <button type="submit" [disabled]="form.invalid" class="btn btn-primary-outline ">Submit</button>

@ -23,8 +23,6 @@ export class IssuesComponent implements OnInit {
this.form = this.fb.group({ this.form = this.fb.group({
enabled: [x.enabled], enabled: [x.enabled],
enableInProgress: [x.enableInProgress], enableInProgress: [x.enableInProgress],
deleteIssues: [x.deleteIssues],
daysAfterResolvedToDelete: [x.daysAfterResolvedToDelete],
}); });
}); });
this.getCategories(); this.getCategories();

@ -91,13 +91,6 @@
<small *ngIf="form.get('newsletter').hasError('required')" class="error-text">The Newsletter is required</small> <small *ngIf="form.get('newsletter').hasError('required')" class="error-text">The Newsletter is required</small>
<button type="button" class="btn btn-sm btn-primary-outline" (click)="testCron(form.get('newsletter')?.value)">Test</button> <button type="button" class="btn btn-sm btn-primary-outline" (click)="testCron(form.get('newsletter')?.value)">Test</button>
</div> </div>
<div class="form-group">
<label for="userImporter" class="control-label">Issue Purge/Delete</label>
<input type="text" class="form-control form-control-custom" [ngClass]="{'form-error': form.get('issuesPurge').hasError('required')}" id="issuesPurge" name="issuesPurge" formControlName="issuesPurge">
<small *ngIf="form.get('issuesPurge').hasError('required')" class="error-text">The Issues Purge is required</small>
<button type="button" class="btn btn-sm btn-primary-outline" (click)="testCron(form.get('issuesPurge')?.value)">Test</button>
</div>
</div> </div>
<div class="form-group"> <div class="form-group">
<div> <div>

@ -35,7 +35,6 @@ export class JobsComponent implements OnInit {
newsletter: [x.newsletter, Validators.required], newsletter: [x.newsletter, Validators.required],
plexRecentlyAddedSync: [x.plexRecentlyAddedSync, Validators.required], plexRecentlyAddedSync: [x.plexRecentlyAddedSync, Validators.required],
lidarrArtistSync: [x.lidarrArtistSync, Validators.required], lidarrArtistSync: [x.lidarrArtistSync, Validators.required],
issuesPurge: [x.issuesPurge, Validators.required],
}); });
}); });
} }

@ -144,7 +144,7 @@
<div class="panel panel-default a"> <div class="panel panel-default a">
<div class="panel-body"> <div class="panel-body">
<div class="form-group" *ngIf="sonarrQualities"> <div class="form-group" *ngIf="user.userQualityProfiles.sonarrQualityProfile">
<label for="sonarrQualities" class="control-label">Sonarr Quality Profile</label> <label for="sonarrQualities" class="control-label">Sonarr Quality Profile</label>
<div id="sonarrQualities"> <div id="sonarrQualities">
<select class="form-control form-control-custom" [(ngModel)]="user.userQualityProfiles.sonarrQualityProfile"> <select class="form-control form-control-custom" [(ngModel)]="user.userQualityProfiles.sonarrQualityProfile">
@ -153,7 +153,7 @@
</div> </div>
</div> </div>
<div class="form-group" *ngIf="sonarrQualities"> <div class="form-group" *ngIf="user.userQualityProfiles.sonarrQualityProfileAnime">
<label for="sonarrQualityProfileAnime" class="control-label">Sonarr Quality Profile (Anime)</label> <label for="sonarrQualityProfileAnime" class="control-label">Sonarr Quality Profile (Anime)</label>
<div id="sonarrQualityProfileAnime"> <div id="sonarrQualityProfileAnime">
<select class="form-control form-control-custom" [(ngModel)]="user.userQualityProfiles.sonarrQualityProfileAnime"> <select class="form-control form-control-custom" [(ngModel)]="user.userQualityProfiles.sonarrQualityProfileAnime">
@ -162,7 +162,7 @@
</div> </div>
</div> </div>
<div class="form-group" *ngIf="sonarrRootFolders"> <div class="form-group" *ngIf="user.userQualityProfiles.sonarrRootPath">
<label for="sonarrRootPath" class="control-label">Sonarr Root Folder</label> <label for="sonarrRootPath" class="control-label">Sonarr Root Folder</label>
<div id="sonarrRootPath"> <div id="sonarrRootPath">
<select class="form-control form-control-custom" [(ngModel)]="user.userQualityProfiles.sonarrRootPath"> <select class="form-control form-control-custom" [(ngModel)]="user.userQualityProfiles.sonarrRootPath">
@ -171,7 +171,7 @@
</div> </div>
</div> </div>
<div class="form-group" *ngIf="sonarrRootFolders"> <div class="form-group" *ngIf="user.userQualityProfiles.sonarrRootPathAnime">
<label for="sonarrRootPathAnime" class="control-label">Sonarr Root Folder (Anime)</label> <label for="sonarrRootPathAnime" class="control-label">Sonarr Root Folder (Anime)</label>
<div id="sonarrRootPathAnime"> <div id="sonarrRootPathAnime">
<select class="form-control form-control-custom" [(ngModel)]="user.userQualityProfiles.sonarrRootPathAnime"> <select class="form-control form-control-custom" [(ngModel)]="user.userQualityProfiles.sonarrRootPathAnime">
@ -179,7 +179,7 @@
</select> </select>
</div> </div>
</div> </div>
<div class="form-group" *ngIf="radarrQualities"> <div class="form-group" *ngIf="user.userQualityProfiles.radarrQualityProfile">
<label for="radarrQualityProfile" class="control-label">Radarr Quality Profiles</label> <label for="radarrQualityProfile" class="control-label">Radarr Quality Profiles</label>
<div id="radarrQualityProfile"> <div id="radarrQualityProfile">
<select class="form-control form-control-custom" [(ngModel)]="user.userQualityProfiles.radarrQualityProfile"> <select class="form-control form-control-custom" [(ngModel)]="user.userQualityProfiles.radarrQualityProfile">
@ -187,7 +187,7 @@
</select> </select>
</div> </div>
</div> </div>
<div class="form-group" *ngIf="radarrRootFolders"> <div class="form-group" *ngIf="user.userQualityProfiles.radarrRootPath">
<label for="radarrRootPath" class="control-label">Radarr Root Folder</label> <label for="radarrRootPath" class="control-label">Radarr Root Folder</label>
<div id="radarrRootPath"> <div id="radarrRootPath">
<select class="form-control form-control-custom" [(ngModel)]="user.userQualityProfiles.radarrRootPath"> <select class="form-control form-control-custom" [(ngModel)]="user.userQualityProfiles.radarrRootPath">

@ -519,7 +519,6 @@ namespace Ombi.Controllers
j.PlexRecentlyAddedSync = j.PlexRecentlyAddedSync.HasValue() ? j.PlexRecentlyAddedSync : JobSettingsHelper.PlexRecentlyAdded(j); j.PlexRecentlyAddedSync = j.PlexRecentlyAddedSync.HasValue() ? j.PlexRecentlyAddedSync : JobSettingsHelper.PlexRecentlyAdded(j);
j.Newsletter = j.Newsletter.HasValue() ? j.Newsletter : JobSettingsHelper.Newsletter(j); j.Newsletter = j.Newsletter.HasValue() ? j.Newsletter : JobSettingsHelper.Newsletter(j);
j.LidarrArtistSync = j.LidarrArtistSync.HasValue() ? j.LidarrArtistSync : JobSettingsHelper.LidarrArtistSync(j); j.LidarrArtistSync = j.LidarrArtistSync.HasValue() ? j.LidarrArtistSync : JobSettingsHelper.LidarrArtistSync(j);
j.IssuesPurge = j.IssuesPurge.HasValue() ? j.IssuesPurge : JobSettingsHelper.IssuePurge(j);
return j; return j;
} }

Loading…
Cancel
Save