#16523: Don't allow creating a part with an empty name or a name containing only invalid/filtered-out characters.

--HG--
branch : dev
This commit is contained in:
Dave Reed
2010-12-01 13:24:47 -08:00
parent 6d52280a16
commit 665e641a13
3 changed files with 15 additions and 7 deletions

View File

@@ -242,13 +242,17 @@ namespace Orchard.ContentTypes.Controllers {
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to create a content part.")))
return new HttpUnauthorizedResult();
var partViewModel = _contentDefinitionService.AddPart(viewModel);
if (!ModelState.IsValid)
return View(viewModel);
Services.Notifier.Information(T("The \"{0}\" content part has been created.", partViewModel.Name));
var partViewModel = _contentDefinitionService.AddPart(viewModel);
if (partViewModel == null) {
Services.Notifier.Information(T("The content part could not be created."));
return View(viewModel);
}
Services.Notifier.Information(T("The \"{0}\" content part has been created.", partViewModel.Name));
return RedirectToAction("EditPart", new { id = partViewModel.Name });
}

View File

@@ -184,10 +184,13 @@ namespace Orchard.ContentTypes.Services {
while (_contentDefinitionManager.GetPartDefinition(name) != null)
name = VersionName(name);
var contentPartDefinition = new ContentPartDefinition(name);
_contentDefinitionManager.StorePartDefinition(contentPartDefinition);
if (!String.IsNullOrEmpty(name)) {
var contentPartDefinition = new ContentPartDefinition(name);
_contentDefinitionManager.StorePartDefinition(contentPartDefinition);
return new EditPartViewModel(contentPartDefinition);
}
return new EditPartViewModel(contentPartDefinition);
return null;
}
public void AlterPart(EditPartViewModel partViewModel, IUpdateModel updateModel) {

View File

@@ -2,8 +2,9 @@
<h1>@Html.TitleForPage(T("New Content Part").ToString())</h1>@using (Html.BeginFormAntiForgeryPost()) {
@Html.ValidationSummary()
<fieldset>
<label for="DisplayName">@T("Name")</label>
<label for="Name">@T("Name")</label>
@Html.TextBoxFor(m => m.Name, new {@class = "textMedium", autofocus = "autofocus"})
<span class="hint">@T("Use no spaces or special characters. For example, \"MyCustomPart\"")</span>
</fieldset>
<fieldset>
<button class="primaryAction" type="submit">@T("Create")</button>