Fixed: Add Validation for Import lists, Correct Language/Metadata profiles

pull/288/head
Qstick 7 years ago
parent bdf677479a
commit 3e0d0f17f2

@ -21,9 +21,9 @@ namespace Lidarr.Api.V1.Artist
private Response Import()
{
var resource = Request.Body.FromJson<List<ArtistResource>>();
var newArtist = resource.ToModel();
var newArtists = resource.ToModel();
return _addArtistService.AddArtists(newArtist).ToResource().AsResponse();
return _addArtistService.AddArtists(newArtists).ToResource().AsResponse();
}
}
}

@ -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)

@ -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)

@ -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");
}
}
}

@ -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)

@ -179,6 +179,7 @@
<Compile Include="Datastore\Migration\003_add_medium_support.cs" />
<Compile Include="Datastore\Migration\006_separate_automatic_and_interactive_search.cs" />
<Compile Include="Datastore\Migration\007_change_album_path_to_relative.cs" />
<Compile Include="Datastore\Migration\014_fix_language_metadata_profiles.cs" />
<Compile Include="Datastore\Migration\013_album_download_notification.cs" />
<Compile Include="Datastore\Migration\009_album_releases.cs" />
<Compile Include="Datastore\Migration\010_album_releases_fix.cs" />

Loading…
Cancel
Save