From 9ba87ceee38cd42557b0e187fa0c03cec6d34f7b Mon Sep 17 00:00:00 2001 From: ta264 Date: Mon, 26 Apr 2021 21:56:39 +0100 Subject: [PATCH] Fixed: Adding indexers from presets (cherry picked from commit 5cc0331c75993ecd79e17b2da1c2d5dcd08f6b0f) --- .../DownloadClient/DownloadClientResource.cs | 2 +- src/Lidarr.Api.V1/ImportLists/ImportListResource.cs | 2 +- src/Lidarr.Api.V1/Indexers/IndexerResource.cs | 2 +- src/Lidarr.Api.V1/Metadata/MetadataResource.cs | 2 +- .../Notifications/NotificationResource.cs | 2 +- src/Lidarr.Api.V1/ProviderModuleBase.cs | 11 ++++------- src/Lidarr.Api.V1/ProviderResource.cs | 6 +++--- .../PolymorphicWriteOnlyJsonConverter.cs | 2 +- .../ApiTests/IndexerFixture.cs | 8 ++++++++ 9 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Lidarr.Api.V1/DownloadClient/DownloadClientResource.cs b/src/Lidarr.Api.V1/DownloadClient/DownloadClientResource.cs index b1514e956..fa5184a97 100644 --- a/src/Lidarr.Api.V1/DownloadClient/DownloadClientResource.cs +++ b/src/Lidarr.Api.V1/DownloadClient/DownloadClientResource.cs @@ -3,7 +3,7 @@ using NzbDrone.Core.Indexers; namespace Lidarr.Api.V1.DownloadClient { - public class DownloadClientResource : ProviderResource + public class DownloadClientResource : ProviderResource { public bool Enable { get; set; } public DownloadProtocol Protocol { get; set; } diff --git a/src/Lidarr.Api.V1/ImportLists/ImportListResource.cs b/src/Lidarr.Api.V1/ImportLists/ImportListResource.cs index dedc5e706..87950df72 100644 --- a/src/Lidarr.Api.V1/ImportLists/ImportListResource.cs +++ b/src/Lidarr.Api.V1/ImportLists/ImportListResource.cs @@ -2,7 +2,7 @@ using NzbDrone.Core.ImportLists; namespace Lidarr.Api.V1.ImportLists { - public class ImportListResource : ProviderResource + public class ImportListResource : ProviderResource { public bool EnableAutomaticAdd { get; set; } public ImportListMonitorType ShouldMonitor { get; set; } diff --git a/src/Lidarr.Api.V1/Indexers/IndexerResource.cs b/src/Lidarr.Api.V1/Indexers/IndexerResource.cs index 93ec482b7..0b1825861 100644 --- a/src/Lidarr.Api.V1/Indexers/IndexerResource.cs +++ b/src/Lidarr.Api.V1/Indexers/IndexerResource.cs @@ -2,7 +2,7 @@ using NzbDrone.Core.Indexers; namespace Lidarr.Api.V1.Indexers { - public class IndexerResource : ProviderResource + public class IndexerResource : ProviderResource { public bool EnableRss { get; set; } public bool EnableAutomaticSearch { get; set; } diff --git a/src/Lidarr.Api.V1/Metadata/MetadataResource.cs b/src/Lidarr.Api.V1/Metadata/MetadataResource.cs index 864d4cec0..8072bc444 100644 --- a/src/Lidarr.Api.V1/Metadata/MetadataResource.cs +++ b/src/Lidarr.Api.V1/Metadata/MetadataResource.cs @@ -2,7 +2,7 @@ namespace Lidarr.Api.V1.Metadata { - public class MetadataResource : ProviderResource + public class MetadataResource : ProviderResource { public bool Enable { get; set; } } diff --git a/src/Lidarr.Api.V1/Notifications/NotificationResource.cs b/src/Lidarr.Api.V1/Notifications/NotificationResource.cs index bc8e784b1..7badad97b 100644 --- a/src/Lidarr.Api.V1/Notifications/NotificationResource.cs +++ b/src/Lidarr.Api.V1/Notifications/NotificationResource.cs @@ -2,7 +2,7 @@ using NzbDrone.Core.Notifications; namespace Lidarr.Api.V1.Notifications { - public class NotificationResource : ProviderResource + public class NotificationResource : ProviderResource { public string Link { get; set; } public bool OnGrab { get; set; } diff --git a/src/Lidarr.Api.V1/ProviderModuleBase.cs b/src/Lidarr.Api.V1/ProviderModuleBase.cs index bcbe99180..791392287 100644 --- a/src/Lidarr.Api.V1/ProviderModuleBase.cs +++ b/src/Lidarr.Api.V1/ProviderModuleBase.cs @@ -13,7 +13,7 @@ namespace Lidarr.Api.V1 public abstract class ProviderModuleBase : LidarrRestModule where TProviderDefinition : ProviderDefinition, new() where TProvider : IProvider - where TProviderResource : ProviderResource, new() + where TProviderResource : ProviderResource, new() { private readonly IProviderFactory _providerFactory; private readonly ProviderResourceMapper _resourceMapper; @@ -123,12 +123,9 @@ namespace Lidarr.Api.V1 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/Lidarr.Api.V1/ProviderResource.cs b/src/Lidarr.Api.V1/ProviderResource.cs index 537962191..c723a5197 100644 --- a/src/Lidarr.Api.V1/ProviderResource.cs +++ b/src/Lidarr.Api.V1/ProviderResource.cs @@ -6,7 +6,7 @@ using NzbDrone.Core.ThingiProvider; namespace Lidarr.Api.V1 { - public class ProviderResource : RestResource + public class ProviderResource : RestResource { public string Name { get; set; } public List Fields { get; set; } @@ -17,11 +17,11 @@ namespace Lidarr.Api.V1 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) 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 @@ namespace NzbDrone.Common.Serializer { 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 bf55ea58b..0b3fb44c2 100644 --- a/src/NzbDrone.Integration.Test/ApiTests/IndexerFixture.cs +++ b/src/NzbDrone.Integration.Test/ApiTests/IndexerFixture.cs @@ -41,6 +41,14 @@ namespace NzbDrone.Integration.Test.ApiTests return field; } + [Test] + public void all_preset_fields_should_be_set_correctly() + { + var schema = GetNewznabSchemav1(); + + schema.Presets.Any(x => x.SupportsRss).Should().BeTrue(); + } + [Test] public void v2_categories_should_be_array() {