[Fixes #6248] Prevent users from renaming their root folder

This commit is contained in:
Sebastien Ros 2016-01-15 08:55:32 -08:00
parent f17f2c3a93
commit eb7574df0b
2 changed files with 19 additions and 0 deletions

View File

@ -83,6 +83,12 @@ namespace Orchard.MediaLibrary.Controllers {
return new HttpUnauthorizedResult();
}
// Shouldn't be able to rename the root folder
if (IsRootFolder(folderPath)) {
return new HttpUnauthorizedResult();
}
var viewModel = new MediaManagerFolderEditViewModel {
FolderPath = folderPath,
Name = folderPath.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).Last()
@ -104,6 +110,11 @@ namespace Orchard.MediaLibrary.Controllers {
return new HttpUnauthorizedResult();
}
// Shouldn't be able to rename the root folder
if(IsRootFolder(viewModel.FolderPath)) {
return new HttpUnauthorizedResult();
}
try {
_mediaLibraryService.RenameFolder(viewModel.FolderPath, viewModel.Name);
Services.Notifier.Information(T("Media folder renamed"));
@ -165,5 +176,10 @@ namespace Orchard.MediaLibrary.Controllers {
return Json(true);
}
private bool IsRootFolder(string folderPath) {
var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder();
return String.Equals(rootMediaFolder.MediaPath, folderPath, StringComparison.OrdinalIgnoreCase);
}
}
}

View File

@ -609,5 +609,8 @@ $(function () {
});
return false;
});
// Select recent folder when the page is initialized.
viewModel.selectRecent();
})(window.mediaLibrarySettings);
})