Improved Trakt list validation

New: Able to add empty Trakt lists (shows warning during test)
Fixed: Show error in UI if Trakt list hasn't been authenticated

Closes #4022
This commit is contained in:
Mark McDowall 2020-10-25 11:48:57 -07:00
parent fa2e70d571
commit 3fc3aef268
3 changed files with 20 additions and 5 deletions

View File

@ -12,6 +12,7 @@ using NzbDrone.Core.ImportLists.Exceptions;
using NzbDrone.Core.Indexers.Exceptions;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.ImportLists
{
@ -212,7 +213,9 @@ namespace NzbDrone.Core.ImportLists
if (releases.Empty())
{
return new ValidationFailure(string.Empty, "No results were returned from your import list, please check your settings.");
return new NzbDroneValidationFailure(string.Empty,
"No results were returned from your import list, please check your settings.")
{IsWarning = true};
}
}
catch (RequestLimitReachedException)

View File

@ -8,6 +8,8 @@ namespace NzbDrone.Core.ImportLists.Trakt.List
public TraktListSettingsValidator()
: base()
{
RuleFor(c => c.Username).NotEmpty();
RuleFor(c => c.Listname).NotEmpty();
}
}

View File

@ -3,7 +3,6 @@ using System.Text.RegularExpressions;
using FluentValidation;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.ImportLists.Trakt
@ -14,9 +13,20 @@ namespace NzbDrone.Core.ImportLists.Trakt
public TraktSettingsBaseValidator()
{
RuleFor(c => c.BaseUrl).ValidRootUrl();
RuleFor(c => c.AccessToken).NotEmpty();
RuleFor(c => c.RefreshToken).NotEmpty();
RuleFor(c => c.Expires).NotEmpty();
RuleFor(c => c.AccessToken).NotEmpty()
.OverridePropertyName("SignIn")
.WithMessage("Must authenticate with Trakt");
RuleFor(c => c.RefreshToken).NotEmpty()
.OverridePropertyName("SignIn")
.WithMessage("Must authenticate with Trakt")
.When(c => c.AccessToken.IsNotNullOrWhiteSpace());
RuleFor(c => c.Expires).NotEmpty()
.OverridePropertyName("SignIn")
.WithMessage("Must authenticate with Trakt")
.When(c => c.AccessToken.IsNotNullOrWhiteSpace() && c.RefreshToken.IsNotNullOrWhiteSpace());
// Loose validation @TODO
RuleFor(c => c.Rating)