From 3a146ea667ebd678f04822d3331962490e75ad00 Mon Sep 17 00:00:00 2001 From: ta264 Date: Thu, 4 Feb 2021 21:14:52 +0000 Subject: [PATCH] Fixed: Adding indexers from presets --- .../DownloadClient/DownloadClientResource.cs | 2 +- src/NzbDrone.Api/Indexers/IndexerResource.cs | 2 +- src/NzbDrone.Api/Metadata/MetadataResource.cs | 2 +- .../NetImport/ImportExclusionsResource.cs | 2 +- src/NzbDrone.Api/NetImport/NetImportResource.cs | 2 +- .../Notifications/NotificationResource.cs | 2 +- src/NzbDrone.Api/ProviderModuleBase.cs | 5 ++--- src/NzbDrone.Api/ProviderResource.cs | 4 ++-- .../PolymorphicWriteOnlyJsonConverter.cs | 2 +- .../ApiTests/IndexerFixture.cs | 8 ++++++++ .../DownloadClient/DownloadClientResource.cs | 2 +- .../ImportLists/ImportExclusionsResource.cs | 2 +- src/Radarr.Api.V3/ImportLists/ImportListResource.cs | 2 +- src/Radarr.Api.V3/Indexers/IndexerResource.cs | 2 +- src/Radarr.Api.V3/Metadata/MetadataResource.cs | 2 +- .../Notifications/NotificationResource.cs | 2 +- src/Radarr.Api.V3/ProviderModuleBase.cs | 11 ++++------- src/Radarr.Api.V3/ProviderResource.cs | 6 +++--- 18 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/NzbDrone.Api/DownloadClient/DownloadClientResource.cs b/src/NzbDrone.Api/DownloadClient/DownloadClientResource.cs index 4344c491f..903587efc 100644 --- a/src/NzbDrone.Api/DownloadClient/DownloadClientResource.cs +++ b/src/NzbDrone.Api/DownloadClient/DownloadClientResource.cs @@ -2,7 +2,7 @@ namespace NzbDrone.Api.DownloadClient { - public class DownloadClientResource : ProviderResource + public class DownloadClientResource : ProviderResource { public bool Enable { get; set; } public DownloadProtocol Protocol { get; set; } diff --git a/src/NzbDrone.Api/Indexers/IndexerResource.cs b/src/NzbDrone.Api/Indexers/IndexerResource.cs index 6d79362e6..59c8c4488 100644 --- a/src/NzbDrone.Api/Indexers/IndexerResource.cs +++ b/src/NzbDrone.Api/Indexers/IndexerResource.cs @@ -2,7 +2,7 @@ namespace NzbDrone.Api.Indexers { - public class IndexerResource : ProviderResource + public class IndexerResource : ProviderResource { public bool EnableRss { get; set; } public bool EnableSearch { get; set; } diff --git a/src/NzbDrone.Api/Metadata/MetadataResource.cs b/src/NzbDrone.Api/Metadata/MetadataResource.cs index 7404d89db..756070248 100644 --- a/src/NzbDrone.Api/Metadata/MetadataResource.cs +++ b/src/NzbDrone.Api/Metadata/MetadataResource.cs @@ -1,6 +1,6 @@ namespace NzbDrone.Api.Metadata { - public class MetadataResource : ProviderResource + public class MetadataResource : ProviderResource { public bool Enable { get; set; } } diff --git a/src/NzbDrone.Api/NetImport/ImportExclusionsResource.cs b/src/NzbDrone.Api/NetImport/ImportExclusionsResource.cs index fb984eebb..644f6ccf2 100644 --- a/src/NzbDrone.Api/NetImport/ImportExclusionsResource.cs +++ b/src/NzbDrone.Api/NetImport/ImportExclusionsResource.cs @@ -3,7 +3,7 @@ namespace NzbDrone.Api.ImportList { - public class ImportExclusionsResource : ProviderResource + public class ImportExclusionsResource : ProviderResource { //public int Id { get; set; } public int TmdbId { get; set; } diff --git a/src/NzbDrone.Api/NetImport/NetImportResource.cs b/src/NzbDrone.Api/NetImport/NetImportResource.cs index 8f211b432..0a1b4d00d 100644 --- a/src/NzbDrone.Api/NetImport/NetImportResource.cs +++ b/src/NzbDrone.Api/NetImport/NetImportResource.cs @@ -3,7 +3,7 @@ namespace NzbDrone.Api.ImportList { - public class ImportListResource : ProviderResource + public class ImportListResource : ProviderResource { public bool Enabled { get; set; } public bool EnableAuto { get; set; } diff --git a/src/NzbDrone.Api/Notifications/NotificationResource.cs b/src/NzbDrone.Api/Notifications/NotificationResource.cs index 0a7a99410..a5909270c 100644 --- a/src/NzbDrone.Api/Notifications/NotificationResource.cs +++ b/src/NzbDrone.Api/Notifications/NotificationResource.cs @@ -2,7 +2,7 @@ namespace NzbDrone.Api.Notifications { - public class NotificationResource : ProviderResource + public class NotificationResource : ProviderResource { public bool OnGrab { get; set; } public bool OnDownload { get; set; } diff --git a/src/NzbDrone.Api/ProviderModuleBase.cs b/src/NzbDrone.Api/ProviderModuleBase.cs index 81b31c007..24a48d728 100644 --- a/src/NzbDrone.Api/ProviderModuleBase.cs +++ b/src/NzbDrone.Api/ProviderModuleBase.cs @@ -15,7 +15,7 @@ namespace NzbDrone.Api public abstract class ProviderModuleBase : RadarrRestModule where TProviderDefinition : ProviderDefinition, new() where TProvider : IProvider - where TProviderResource : ProviderResource, new() + where TProviderResource : ProviderResource, new() { private readonly IProviderFactory _providerFactory; @@ -160,8 +160,7 @@ private object GetTemplates() { var presetResource = new TProviderResource(); MapToResource(presetResource, v); - - return presetResource as ProviderResource; + return presetResource; }).ToList(); result.Add(providerResource); diff --git a/src/NzbDrone.Api/ProviderResource.cs b/src/NzbDrone.Api/ProviderResource.cs index 910709706..c617cbb25 100644 --- a/src/NzbDrone.Api/ProviderResource.cs +++ b/src/NzbDrone.Api/ProviderResource.cs @@ -5,7 +5,7 @@ namespace NzbDrone.Api { - public class ProviderResource : RestResource + public class ProviderResource : RestResource { public string Name { get; set; } public List Fields { get; set; } @@ -15,6 +15,6 @@ public class ProviderResource : RestResource public string InfoLink { get; set; } public ProviderMessage Message { get; set; } - public List Presets { get; set; } + public List Presets { get; set; } } } diff --git a/src/NzbDrone.Common/Serializer/System.Text.Json/PolymorphicWriteOnlyJsonConverter.cs b/src/NzbDrone.Common/Serializer/System.Text.Json/PolymorphicWriteOnlyJsonConverter.cs index 7f4e76c50..2e99401ab 100644 --- a/src/NzbDrone.Common/Serializer/System.Text.Json/PolymorphicWriteOnlyJsonConverter.cs +++ b/src/NzbDrone.Common/Serializer/System.Text.Json/PolymorphicWriteOnlyJsonConverter.cs @@ -8,7 +8,7 @@ public class PolymorphicWriteOnlyJsonConverter : JsonConverter { public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - throw new NotImplementedException(); + return JsonSerializer.Deserialize(ref reader, options); } public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) diff --git a/src/NzbDrone.Integration.Test/ApiTests/IndexerFixture.cs b/src/NzbDrone.Integration.Test/ApiTests/IndexerFixture.cs index fa53ce54c..9acb6a5a3 100644 --- a/src/NzbDrone.Integration.Test/ApiTests/IndexerFixture.cs +++ b/src/NzbDrone.Integration.Test/ApiTests/IndexerFixture.cs @@ -53,6 +53,14 @@ private Field GetCategoriesField(IndexerResource resource) return field; } + [Test] + public void all_preset_fields_should_be_set_correctly() + { + var schema = GetNewznabSchemav3(); + + schema.Presets.Any(x => x.SupportsRss).Should().BeTrue(); + } + [Test] public void v2_categories_should_be_array() { diff --git a/src/Radarr.Api.V3/DownloadClient/DownloadClientResource.cs b/src/Radarr.Api.V3/DownloadClient/DownloadClientResource.cs index f3d846ab1..d2ebcc5cf 100644 --- a/src/Radarr.Api.V3/DownloadClient/DownloadClientResource.cs +++ b/src/Radarr.Api.V3/DownloadClient/DownloadClientResource.cs @@ -3,7 +3,7 @@ namespace Radarr.Api.V3.DownloadClient { - public class DownloadClientResource : ProviderResource + public class DownloadClientResource : ProviderResource { public bool Enable { get; set; } public DownloadProtocol Protocol { get; set; } diff --git a/src/Radarr.Api.V3/ImportLists/ImportExclusionsResource.cs b/src/Radarr.Api.V3/ImportLists/ImportExclusionsResource.cs index 78ec75099..6a40c26b8 100644 --- a/src/Radarr.Api.V3/ImportLists/ImportExclusionsResource.cs +++ b/src/Radarr.Api.V3/ImportLists/ImportExclusionsResource.cs @@ -4,7 +4,7 @@ namespace Radarr.Api.V3.ImportLists { - public class ImportExclusionsResource : ProviderResource + public class ImportExclusionsResource : ProviderResource { //public int Id { get; set; } public int TmdbId { get; set; } diff --git a/src/Radarr.Api.V3/ImportLists/ImportListResource.cs b/src/Radarr.Api.V3/ImportLists/ImportListResource.cs index 05e3c2aed..08019e064 100644 --- a/src/Radarr.Api.V3/ImportLists/ImportListResource.cs +++ b/src/Radarr.Api.V3/ImportLists/ImportListResource.cs @@ -3,7 +3,7 @@ namespace Radarr.Api.V3.ImportLists { - public class ImportListResource : ProviderResource + public class ImportListResource : ProviderResource { public bool Enabled { get; set; } public bool EnableAuto { get; set; } diff --git a/src/Radarr.Api.V3/Indexers/IndexerResource.cs b/src/Radarr.Api.V3/Indexers/IndexerResource.cs index f490a31ab..f70852c2c 100644 --- a/src/Radarr.Api.V3/Indexers/IndexerResource.cs +++ b/src/Radarr.Api.V3/Indexers/IndexerResource.cs @@ -2,7 +2,7 @@ namespace Radarr.Api.V3.Indexers { - public class IndexerResource : ProviderResource + public class IndexerResource : ProviderResource { public bool EnableRss { get; set; } public bool EnableAutomaticSearch { get; set; } diff --git a/src/Radarr.Api.V3/Metadata/MetadataResource.cs b/src/Radarr.Api.V3/Metadata/MetadataResource.cs index 72e31307d..9cdf5be30 100644 --- a/src/Radarr.Api.V3/Metadata/MetadataResource.cs +++ b/src/Radarr.Api.V3/Metadata/MetadataResource.cs @@ -2,7 +2,7 @@ namespace Radarr.Api.V3.Metadata { - public class MetadataResource : ProviderResource + public class MetadataResource : ProviderResource { public bool Enable { get; set; } } diff --git a/src/Radarr.Api.V3/Notifications/NotificationResource.cs b/src/Radarr.Api.V3/Notifications/NotificationResource.cs index ee0b90bfe..ce2851297 100644 --- a/src/Radarr.Api.V3/Notifications/NotificationResource.cs +++ b/src/Radarr.Api.V3/Notifications/NotificationResource.cs @@ -2,7 +2,7 @@ namespace Radarr.Api.V3.Notifications { - public class NotificationResource : ProviderResource + public class NotificationResource : ProviderResource { public string Link { get; set; } public bool OnGrab { get; set; } diff --git a/src/Radarr.Api.V3/ProviderModuleBase.cs b/src/Radarr.Api.V3/ProviderModuleBase.cs index 281fc6a18..216015ce2 100644 --- a/src/Radarr.Api.V3/ProviderModuleBase.cs +++ b/src/Radarr.Api.V3/ProviderModuleBase.cs @@ -14,7 +14,7 @@ namespace Radarr.Api.V3 public abstract class ProviderModuleBase : RadarrRestModule where TProviderDefinition : ProviderDefinition, new() where TProvider : IProvider - where TProviderResource : ProviderResource, new() + where TProviderResource : ProviderResource, new() { private readonly IProviderFactory _providerFactory; private readonly ProviderResourceMapper _resourceMapper; @@ -124,12 +124,9 @@ private object GetTemplates() var providerResource = _resourceMapper.ToResource(providerDefinition); var presetDefinitions = _providerFactory.GetPresetDefinitions(providerDefinition); - providerResource.Presets = presetDefinitions.Select(v => - { - var presetResource = _resourceMapper.ToResource(v); - - return presetResource as ProviderResource; - }).ToList(); + providerResource.Presets = presetDefinitions + .Select(v => _resourceMapper.ToResource(v)) + .ToList(); result.Add(providerResource); } diff --git a/src/Radarr.Api.V3/ProviderResource.cs b/src/Radarr.Api.V3/ProviderResource.cs index 8aff55c1d..5e37d3952 100644 --- a/src/Radarr.Api.V3/ProviderResource.cs +++ b/src/Radarr.Api.V3/ProviderResource.cs @@ -6,7 +6,7 @@ namespace Radarr.Api.V3 { - public class ProviderResource : RestResource + public class ProviderResource : RestResource { public string Name { get; set; } public List Fields { get; set; } @@ -17,11 +17,11 @@ public class ProviderResource : RestResource public ProviderMessage Message { get; set; } public HashSet Tags { get; set; } - public List Presets { get; set; } + public List Presets { get; set; } } public class ProviderResourceMapper - where TProviderResource : ProviderResource, new() + where TProviderResource : ProviderResource, new() where TProviderDefinition : ProviderDefinition, new() { public virtual TProviderResource ToResource(TProviderDefinition definition)