1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00

Fixed: Prevent series from being added with an invalid Profile ID

Closes #977
This commit is contained in:
Mark McDowall 2015-12-05 02:22:22 -08:00
parent dc176a83b3
commit d514699ab7
5 changed files with 42 additions and 4 deletions

View File

@ -10,11 +10,11 @@
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.SeriesStats;
using NzbDrone.Core.Tv;
using NzbDrone.Api.Validation;
using NzbDrone.Api.Mapping;
using NzbDrone.Core.Tv.Events;
using NzbDrone.Core.Validation.Paths;
using NzbDrone.Core.DataAugmentation.Scene;
using NzbDrone.Core.Validation;
using NzbDrone.SignalR;
namespace NzbDrone.Api.Series
@ -43,7 +43,8 @@ public SeriesModule(IBroadcastSignalRMessage signalRBroadcaster,
SeriesPathValidator seriesPathValidator,
SeriesExistsValidator seriesExistsValidator,
DroneFactoryValidator droneFactoryValidator,
SeriesAncestorValidator seriesAncestorValidator
SeriesAncestorValidator seriesAncestorValidator,
ProfileExistsValidator profileExistsValidator
)
: base(signalRBroadcaster)
{
@ -59,7 +60,7 @@ SeriesAncestorValidator seriesAncestorValidator
UpdateResource = UpdateSeries;
DeleteResource = DeleteSeries;
SharedValidator.RuleFor(s => s.ProfileId).ValidId();
Validation.RuleBuilderExtensions.ValidId(SharedValidator.RuleFor(s => s.ProfileId));
SharedValidator.RuleFor(s => s.Path)
.Cascade(CascadeMode.StopOnFirstFailure)
@ -70,6 +71,8 @@ SeriesAncestorValidator seriesAncestorValidator
.SetValidator(seriesAncestorValidator)
.When(s => !s.Path.IsNullOrWhiteSpace());
SharedValidator.RuleFor(s => s.ProfileId).SetValidator(profileExistsValidator);
PostValidator.RuleFor(s => s.Path).IsValidPath().When(s => s.RootFolderPath.IsNullOrWhiteSpace());
PostValidator.RuleFor(s => s.RootFolderPath).IsValidPath().When(s => s.Path.IsNullOrWhiteSpace());
PostValidator.RuleFor(s => s.Title).NotEmpty();

View File

@ -1004,6 +1004,7 @@
<Compile Include="Validation\Paths\SeriesAncestorValidator.cs" />
<Compile Include="Validation\Paths\SeriesExistsValidator.cs" />
<Compile Include="Validation\Paths\SeriesPathValidator.cs" />
<Compile Include="Validation\ProfileExistsValidator.cs" />
<Compile Include="Validation\RuleBuilderExtensions.cs" />
<Compile Include="Validation\UrlValidator.cs" />
</ItemGroup>

View File

@ -5,7 +5,7 @@ namespace NzbDrone.Core.Profiles
{
public interface IProfileRepository : IBasicRepository<Profile>
{
bool Exists(int id);
}
public class ProfileRepository : BasicRepository<Profile>, IProfileRepository
@ -14,5 +14,10 @@ public ProfileRepository(IMainDatabase database, IEventAggregator eventAggregato
: base(database, eventAggregator)
{
}
public bool Exists(int id)
{
return DataMapper.Query<Profile>().Where(p => p.Id == id).GetRowCount() == 1;
}
}
}

View File

@ -16,6 +16,7 @@ public interface IProfileService
void Delete(int id);
List<Profile> All();
Profile Get(int id);
bool Exists(int id);
}
public class ProfileService : IProfileService, IHandle<ApplicationStartedEvent>
@ -61,6 +62,11 @@ public Profile Get(int id)
return _profileRepository.Get(id);
}
public bool Exists(int id)
{
return _profileRepository.Exists(id);
}
private Profile AddDefaultProfile(string name, Quality cutoff, params Quality[] allowed)
{
var items = Quality.DefaultQualityDefinitions

View File

@ -0,0 +1,23 @@
using FluentValidation.Validators;
using NzbDrone.Core.Profiles;
namespace NzbDrone.Core.Validation
{
public class ProfileExistsValidator : PropertyValidator
{
private readonly IProfileService _profileService;
public ProfileExistsValidator(IProfileService profileService)
: base("Profile does not exist")
{
_profileService = profileService;
}
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null) return true;
return _profileService.Exists((int)context.PropertyValue);
}
}
}