1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

FolderWritableValidator

Fixed: Information in UI when attempting to add a root folder that is not writable
Fixes #1280
This commit is contained in:
Mark McDowall 2016-05-21 01:39:39 -07:00
parent ea0982ecae
commit 67ff871cf6
5 changed files with 30 additions and 5 deletions

View File

@ -17,7 +17,8 @@ public RootFolderModule(IRootFolderService rootFolderService,
PathExistsValidator pathExistsValidator,
DroneFactoryValidator droneFactoryValidator,
MappedNetworkDriveValidator mappedNetworkDriveValidator,
StartupFolderValidator startupFolderValidator)
StartupFolderValidator startupFolderValidator,
FolderWritableValidator folderWritableValidator)
: base(signalRBroadcaster)
{
_rootFolderService = rootFolderService;
@ -34,7 +35,8 @@ public RootFolderModule(IRootFolderService rootFolderService,
.SetValidator(droneFactoryValidator)
.SetValidator(mappedNetworkDriveValidator)
.SetValidator(startupFolderValidator)
.SetValidator(pathExistsValidator);
.SetValidator(pathExistsValidator)
.SetValidator(folderWritableValidator);
}
private RootFolderResource GetRootFolder(int id)

View File

@ -1036,6 +1036,7 @@
<Compile Include="Validation\NzbDroneValidationState.cs" />
<Compile Include="Validation\Paths\MappedNetworkDriveValidator.cs" />
<Compile Include="Validation\Paths\DroneFactoryValidator.cs" />
<Compile Include="Validation\Paths\FolderWritableValidator.cs" />
<Compile Include="Validation\Paths\PathExistsValidator.cs" />
<Compile Include="Validation\Paths\PathValidator.cs" />
<Compile Include="Validation\Paths\StartupFolderValidator.cs" />

View File

@ -0,0 +1,24 @@
using System;
using FluentValidation.Validators;
using NzbDrone.Common.Disk;
namespace NzbDrone.Core.Validation.Paths
{
public class FolderWritableValidator : PropertyValidator
{
private readonly IDiskProvider _diskProvider;
public FolderWritableValidator(IDiskProvider diskProvider)
: base($"Folder is not writable by user {Environment.UserName}")
{
_diskProvider = diskProvider;
}
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null) return false;
return (_diskProvider.FolderWritable(context.PropertyValue.ToString()));
}
}
}

View File

@ -85,7 +85,6 @@
<option name="m_minLength" value="1" />
<option name="m_maxLength" value="32" />
</inspection_tool>
<inspection_tool class="LossyEncoding" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="NegatedIfStatementJS" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="NestedAssignmentJS" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="NestedFunctionCallJS" enabled="false" level="ERROR" enabled_by_default="false" />

View File

@ -5,5 +5,4 @@
<module fileurl="file://$PROJECT_DIR$/.idea/NzbDrone.UI.iml" filepath="$PROJECT_DIR$/.idea/NzbDrone.UI.iml" />
</modules>
</component>
</project>
</project>