From 67ff871cf655c9a4bc10452b8195f95b2c840438 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 21 May 2016 01:39:39 -0700 Subject: [PATCH] FolderWritableValidator Fixed: Information in UI when attempting to add a root folder that is not writable Fixes #1280 --- .../RootFolders/RootFolderModule.cs | 6 +++-- src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + .../Paths/FolderWritableValidator.cs | 24 +++++++++++++++++++ .../inspectionProfiles/Project_Default.xml | 1 - src/UI/.idea/modules.xml | 3 +-- 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 src/NzbDrone.Core/Validation/Paths/FolderWritableValidator.cs diff --git a/src/NzbDrone.Api/RootFolders/RootFolderModule.cs b/src/NzbDrone.Api/RootFolders/RootFolderModule.cs index a4c0f892b..a2c4daed8 100644 --- a/src/NzbDrone.Api/RootFolders/RootFolderModule.cs +++ b/src/NzbDrone.Api/RootFolders/RootFolderModule.cs @@ -17,7 +17,8 @@ namespace NzbDrone.Api.RootFolders PathExistsValidator pathExistsValidator, DroneFactoryValidator droneFactoryValidator, MappedNetworkDriveValidator mappedNetworkDriveValidator, - StartupFolderValidator startupFolderValidator) + StartupFolderValidator startupFolderValidator, + FolderWritableValidator folderWritableValidator) : base(signalRBroadcaster) { _rootFolderService = rootFolderService; @@ -34,7 +35,8 @@ namespace NzbDrone.Api.RootFolders .SetValidator(droneFactoryValidator) .SetValidator(mappedNetworkDriveValidator) .SetValidator(startupFolderValidator) - .SetValidator(pathExistsValidator); + .SetValidator(pathExistsValidator) + .SetValidator(folderWritableValidator); } private RootFolderResource GetRootFolder(int id) diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index a5a945d9a..75fd71535 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -1036,6 +1036,7 @@ + diff --git a/src/NzbDrone.Core/Validation/Paths/FolderWritableValidator.cs b/src/NzbDrone.Core/Validation/Paths/FolderWritableValidator.cs new file mode 100644 index 000000000..bf88cf3be --- /dev/null +++ b/src/NzbDrone.Core/Validation/Paths/FolderWritableValidator.cs @@ -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())); + } + } +} \ No newline at end of file diff --git a/src/UI/.idea/inspectionProfiles/Project_Default.xml b/src/UI/.idea/inspectionProfiles/Project_Default.xml index 7f20f79f3..7aba4e3c2 100644 --- a/src/UI/.idea/inspectionProfiles/Project_Default.xml +++ b/src/UI/.idea/inspectionProfiles/Project_Default.xml @@ -85,7 +85,6 @@