From 3e0d0f17f2ebba45588ea031f7f359c708456f9d Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 8 Apr 2018 22:57:09 -0400 Subject: [PATCH] Fixed: Add Validation for Import lists, Correct Language/Metadata profiles --- .../Artist/ArtistImportModule.cs | 4 ++-- src/Lidarr.Api.V1/Artist/ArtistModule.cs | 2 ++ .../ImportLists/ImportListModule.cs | 16 ++++++++++++- .../014_fix_language_metadata_profiles.cs | 24 +++++++++++++++++++ .../HealthCheck/Checks/RootFolderCheck.cs | 13 +++++++++- src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 6 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/014_fix_language_metadata_profiles.cs diff --git a/src/Lidarr.Api.V1/Artist/ArtistImportModule.cs b/src/Lidarr.Api.V1/Artist/ArtistImportModule.cs index f24c04f86..d20038b38 100644 --- a/src/Lidarr.Api.V1/Artist/ArtistImportModule.cs +++ b/src/Lidarr.Api.V1/Artist/ArtistImportModule.cs @@ -21,9 +21,9 @@ namespace Lidarr.Api.V1.Artist private Response Import() { var resource = Request.Body.FromJson>(); - var newArtist = resource.ToModel(); + var newArtists = resource.ToModel(); - return _addArtistService.AddArtists(newArtist).ToResource().AsResponse(); + return _addArtistService.AddArtists(newArtists).ToResource().AsResponse(); } } } diff --git a/src/Lidarr.Api.V1/Artist/ArtistModule.cs b/src/Lidarr.Api.V1/Artist/ArtistModule.cs index a7380e441..532ca93cc 100644 --- a/src/Lidarr.Api.V1/Artist/ArtistModule.cs +++ b/src/Lidarr.Api.V1/Artist/ArtistModule.cs @@ -73,6 +73,8 @@ namespace Lidarr.Api.V1.Artist DeleteResource = DeleteArtist; Http.Validation.RuleBuilderExtensions.ValidId(SharedValidator.RuleFor(s => s.QualityProfileId)); + Http.Validation.RuleBuilderExtensions.ValidId(SharedValidator.RuleFor(s => s.LanguageProfileId)); + Http.Validation.RuleBuilderExtensions.ValidId(SharedValidator.RuleFor(s => s.MetadataProfileId)); SharedValidator.RuleFor(s => s.Path) .Cascade(CascadeMode.StopOnFirstFailure) diff --git a/src/Lidarr.Api.V1/ImportLists/ImportListModule.cs b/src/Lidarr.Api.V1/ImportLists/ImportListModule.cs index 122dbef7c..b187f1840 100644 --- a/src/Lidarr.Api.V1/ImportLists/ImportListModule.cs +++ b/src/Lidarr.Api.V1/ImportLists/ImportListModule.cs @@ -1,4 +1,6 @@ using NzbDrone.Core.ImportLists; +using NzbDrone.Core.Validation; +using NzbDrone.Core.Validation.Paths; namespace Lidarr.Api.V1.ImportLists { @@ -6,9 +8,21 @@ namespace Lidarr.Api.V1.ImportLists { public static readonly ImportListResourceMapper ResourceMapper = new ImportListResourceMapper(); - public ImportListModule(ImportListFactory importListFactory) + public ImportListModule(ImportListFactory importListFactory, + ProfileExistsValidator profileExistsValidator, + LanguageProfileExistsValidator languageProfileExistsValidator, + MetadataProfileExistsValidator metadataProfileExistsValidator + ) : base(importListFactory, "importlist", ResourceMapper) { + Http.Validation.RuleBuilderExtensions.ValidId(SharedValidator.RuleFor(s => s.QualityProfileId)); + Http.Validation.RuleBuilderExtensions.ValidId(SharedValidator.RuleFor(s => s.LanguageProfileId)); + Http.Validation.RuleBuilderExtensions.ValidId(SharedValidator.RuleFor(s => s.MetadataProfileId)); + + SharedValidator.RuleFor(c => c.RootFolderPath).IsValidPath(); + SharedValidator.RuleFor(c => c.QualityProfileId).SetValidator(profileExistsValidator); + SharedValidator.RuleFor(c => c.LanguageProfileId).SetValidator(languageProfileExistsValidator); + SharedValidator.RuleFor(c => c.MetadataProfileId).SetValidator(metadataProfileExistsValidator); } protected override void Validate(ImportListDefinition definition, bool includeWarnings) diff --git a/src/NzbDrone.Core/Datastore/Migration/014_fix_language_metadata_profiles.cs b/src/NzbDrone.Core/Datastore/Migration/014_fix_language_metadata_profiles.cs new file mode 100644 index 000000000..20f62fa65 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/014_fix_language_metadata_profiles.cs @@ -0,0 +1,24 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(14)] + public class fix_language_metadata_profiles : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Execute.Sql("UPDATE artists SET metadataProfileId = " + + "CASE WHEN ((SELECT COUNT(*) FROM metadataprofiles) > 0) " + + "THEN (SELECT id FROM metadataprofiles ORDER BY id ASC LIMIT 1) " + + "ELSE 0 END " + + "WHERE artists.metadataProfileId == 0"); + + Execute.Sql("UPDATE artists SET languageProfileId = " + + "CASE WHEN ((SELECT COUNT(*) FROM languageprofiles) > 0) " + + "THEN (SELECT id FROM languageprofiles ORDER BY id ASC LIMIT 1) " + + "ELSE 0 END " + + "WHERE artists.languageProfileId == 0"); + } + } +} diff --git a/src/NzbDrone.Core/HealthCheck/Checks/RootFolderCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/RootFolderCheck.cs index edc7a7b44..ecdaf5e24 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/RootFolderCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/RootFolderCheck.cs @@ -1,5 +1,6 @@ using System.Linq; using NzbDrone.Common.Disk; +using NzbDrone.Core.ImportLists; using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Music; using NzbDrone.Core.Music.Events; @@ -13,11 +14,13 @@ namespace NzbDrone.Core.HealthCheck.Checks public class RootFolderCheck : HealthCheckBase { private readonly IArtistService _artistService; + private readonly IImportListFactory _importListFactory; private readonly IDiskProvider _diskProvider; - public RootFolderCheck(IArtistService artistService, IDiskProvider diskProvider) + public RootFolderCheck(IArtistService artistService, IImportListFactory importListFactory, IDiskProvider diskProvider) { _artistService = artistService; + _importListFactory = importListFactory; _diskProvider = diskProvider; } @@ -29,6 +32,14 @@ namespace NzbDrone.Core.HealthCheck.Checks .Where(s => !_diskProvider.FolderExists(s)) .ToList(); + missingRootFolders.AddRange(_importListFactory.All() + .Select(s => s.RootFolderPath) + .Distinct() + .Where(s => !_diskProvider.FolderExists(s)) + .ToList()); + + missingRootFolders = missingRootFolders.Distinct().ToList(); + if (missingRootFolders.Any()) { if (missingRootFolders.Count == 1) diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 46a3612d1..b9196c308 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -179,6 +179,7 @@ +