From 45011198e229d47d73c6b65e8bde81d3a2064792 Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 29 Oct 2020 20:50:35 -0400 Subject: [PATCH] Improved Trakt list validation Fixes #5262 Co-Authored-By: Mark McDowall --- .../ImportLists/HttpImportListBase.cs | 5 ++++- .../ImportLists/Trakt/List/TraktListSettings.cs | 2 ++ .../ImportLists/Trakt/TraktSettingsBase.cs | 17 ++++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/HttpImportListBase.cs b/src/NzbDrone.Core/ImportLists/HttpImportListBase.cs index e5421356a..a97974f8c 100644 --- a/src/NzbDrone.Core/ImportLists/HttpImportListBase.cs +++ b/src/NzbDrone.Core/ImportLists/HttpImportListBase.cs @@ -13,6 +13,7 @@ using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.Parser; using NzbDrone.Core.ThingiProvider; +using NzbDrone.Core.Validation; namespace NzbDrone.Core.ImportLists { @@ -187,7 +188,9 @@ protected virtual ValidationFailure TestConnection() if (releases.Empty()) { - return new ValidationFailure(string.Empty, "No results were returned from your 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) diff --git a/src/NzbDrone.Core/ImportLists/Trakt/List/TraktListSettings.cs b/src/NzbDrone.Core/ImportLists/Trakt/List/TraktListSettings.cs index 932307392..0e2438730 100644 --- a/src/NzbDrone.Core/ImportLists/Trakt/List/TraktListSettings.cs +++ b/src/NzbDrone.Core/ImportLists/Trakt/List/TraktListSettings.cs @@ -8,6 +8,8 @@ public class TraktListSettingsValidator : TraktSettingsBaseValidator c.Username).NotEmpty(); + RuleFor(c => c.Listname).NotEmpty(); } } diff --git a/src/NzbDrone.Core/ImportLists/Trakt/TraktSettingsBase.cs b/src/NzbDrone.Core/ImportLists/Trakt/TraktSettingsBase.cs index b5dbf6407..426c3a090 100644 --- a/src/NzbDrone.Core/ImportLists/Trakt/TraktSettingsBase.cs +++ b/src/NzbDrone.Core/ImportLists/Trakt/TraktSettingsBase.cs @@ -14,9 +14,20 @@ public class TraktSettingsBaseValidator : AbstractValidator c.Link).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)