#17664: Edit media - New file name is not allowed.

- Fixed view bugs when editing fails.
- Improved error message when no extension was given.
- Refactored actions

--HG--
branch : 1.x
This commit is contained in:
Dave Reed
2011-04-05 12:55:43 -07:00
parent 6abd7f2efe
commit 02e4dbdb66
2 changed files with 8 additions and 14 deletions

View File

@@ -234,16 +234,8 @@ namespace Orchard.Media.Controllers {
}
}
public ActionResult EditMedia(string name, DateTime lastUpdated, long size, string folderName, string mediaPath) {
var model = new MediaItemEditViewModel();
model.Name = name;
// todo: reimplement
//model.Caption = caption ?? String.Empty;
model.LastUpdated = lastUpdated;
model.Size = size;
model.FolderName = folderName;
model.MediaPath = mediaPath;
model.PublicUrl = _mediaService.GetPublicUrl(Path.Combine(mediaPath, name));
public ActionResult EditMedia(MediaItemEditViewModel model) {
model.PublicUrl = _mediaService.GetPublicUrl(Path.Combine(model.MediaPath, model.Name));
return View(model);
}
@@ -294,9 +286,8 @@ namespace Orchard.Media.Controllers {
mediaPath = viewModel.MediaPath });
}
catch (Exception exception) {
this.Error(exception, T("Editing media file failed: {0}", exception.Message), Logger, Services.Notifier);
return View(viewModel);
this.Error(exception, T("Editing media file failed."), Logger, Services.Notifier);
return EditMedia(viewModel);
}
}
}

View File

@@ -140,7 +140,10 @@ namespace Orchard.Media.Services {
Argument.ThrowIfNullOrEmpty(newFileName, "newFileName");
if (!FileAllowed(newFileName, false)) {
throw new ArgumentException(T("New file name {0} is not allowed", newFileName).ToString());
if (string.IsNullOrEmpty(Path.GetExtension(newFileName))) {
throw new ArgumentException(T("New file name \"{0}\" is not allowed. Please provide a file extension.", newFileName).ToString());
}
throw new ArgumentException(T("New file name \"{0}\" is not allowed.", newFileName).ToString());
}
_storageProvider.RenameFile(_storageProvider.Combine(folderPath, currentFileName), _storageProvider.Combine(folderPath, newFileName));