mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
Fixed: Prevent series from being added with an invalid Profile ID
Closes #977
This commit is contained in:
parent
dc176a83b3
commit
d514699ab7
@ -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();
|
||||
|
@ -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>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
23
src/NzbDrone.Core/Validation/ProfileExistsValidator.cs
Normal file
23
src/NzbDrone.Core/Validation/ProfileExistsValidator.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user