From d346d969deedff47af97059bc36dea8782a9aa3f Mon Sep 17 00:00:00 2001 From: Bogdan Date: Wed, 21 Aug 2024 04:31:39 +0300 Subject: [PATCH] Fixed: Validate root folder existence when adding movie --- .../Validation/Paths/RootFolderExistsValidator.cs | 3 ++- src/Radarr.Api.V3/Movies/MovieController.cs | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core/Validation/Paths/RootFolderExistsValidator.cs b/src/NzbDrone.Core/Validation/Paths/RootFolderExistsValidator.cs index 8b4c4e7a0..d879af0d9 100644 --- a/src/NzbDrone.Core/Validation/Paths/RootFolderExistsValidator.cs +++ b/src/NzbDrone.Core/Validation/Paths/RootFolderExistsValidator.cs @@ -1,4 +1,5 @@ using FluentValidation.Validators; +using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; using NzbDrone.Core.RootFolders; @@ -19,7 +20,7 @@ protected override bool IsValid(PropertyValidatorContext context) { context.MessageFormatter.AppendArgument("path", context.PropertyValue?.ToString()); - return context.PropertyValue == null || _rootFolderService.All().Exists(r => r.Path.PathEquals(context.PropertyValue.ToString())); + return context.PropertyValue == null || _rootFolderService.All().Exists(r => r.Path.IsPathValid(PathValidationType.CurrentOs) && r.Path.PathEquals(context.PropertyValue.ToString())); } } } diff --git a/src/Radarr.Api.V3/Movies/MovieController.cs b/src/Radarr.Api.V3/Movies/MovieController.cs index 0bd19f6e1..884943a7c 100644 --- a/src/Radarr.Api.V3/Movies/MovieController.cs +++ b/src/Radarr.Api.V3/Movies/MovieController.cs @@ -70,6 +70,7 @@ public MovieController(IBroadcastSignalRMessage signalRBroadcaster, RecycleBinValidator recycleBinValidator, SystemFolderValidator systemFolderValidator, QualityProfileExistsValidator qualityProfileExistsValidator, + RootFolderExistsValidator rootFolderExistsValidator, MovieFolderAsRootFolderValidator movieFolderAsRootFolderValidator, Logger logger) : base(signalRBroadcaster) @@ -103,6 +104,7 @@ public MovieController(IBroadcastSignalRMessage signalRBroadcaster, PostValidator.RuleFor(s => s.Path).IsValidPath().When(s => s.RootFolderPath.IsNullOrWhiteSpace()); PostValidator.RuleFor(s => s.RootFolderPath) .IsValidPath() + .SetValidator(rootFolderExistsValidator) .SetValidator(movieFolderAsRootFolderValidator) .When(s => s.Path.IsNullOrWhiteSpace()); PostValidator.RuleFor(s => s.Title).NotEmpty().When(s => s.TmdbId <= 0); @@ -240,6 +242,7 @@ private MovieTranslation GetTranslationFromDict(Dictionary AddMovie([FromBody] MovieResource moviesResource) { var movie = _addMovieService.AddMovie(moviesResource.ToModel()); @@ -249,6 +252,7 @@ public ActionResult AddMovie([FromBody] MovieResource moviesResou [RestPutById] [Consumes("application/json")] + [Produces("application/json")] public ActionResult UpdateMovie([FromBody] MovieResource moviesResource, [FromQuery] bool moveFiles = false) { var movie = _moviesService.GetMovie(moviesResource.Id);