1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-19 17:32:38 +01:00

Fixed: Validate root folder existence when adding movie

This commit is contained in:
Bogdan 2024-08-21 04:31:39 +03:00
parent 14b125ccd9
commit d346d969de
2 changed files with 6 additions and 1 deletions

View File

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

View File

@ -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<int, MovieTranslation
[RestPostById]
[Consumes("application/json")]
[Produces("application/json")]
public ActionResult<MovieResource> AddMovie([FromBody] MovieResource moviesResource)
{
var movie = _addMovieService.AddMovie(moviesResource.ToModel());
@ -249,6 +252,7 @@ public ActionResult<MovieResource> AddMovie([FromBody] MovieResource moviesResou
[RestPutById]
[Consumes("application/json")]
[Produces("application/json")]
public ActionResult<MovieResource> UpdateMovie([FromBody] MovieResource moviesResource, [FromQuery] bool moveFiles = false)
{
var movie = _moviesService.GetMovie(moviesResource.Id);