mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#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:
@@ -242,13 +242,17 @@ namespace Orchard.ContentTypes.Controllers {
|
|||||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to create a content part.")))
|
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to create a content part.")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var partViewModel = _contentDefinitionService.AddPart(viewModel);
|
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return View(viewModel);
|
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 });
|
return RedirectToAction("EditPart", new { id = partViewModel.Name });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -184,10 +184,13 @@ namespace Orchard.ContentTypes.Services {
|
|||||||
while (_contentDefinitionManager.GetPartDefinition(name) != null)
|
while (_contentDefinitionManager.GetPartDefinition(name) != null)
|
||||||
name = VersionName(name);
|
name = VersionName(name);
|
||||||
|
|
||||||
var contentPartDefinition = new ContentPartDefinition(name);
|
if (!String.IsNullOrEmpty(name)) {
|
||||||
_contentDefinitionManager.StorePartDefinition(contentPartDefinition);
|
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) {
|
public void AlterPart(EditPartViewModel partViewModel, IUpdateModel updateModel) {
|
||||||
|
@@ -2,8 +2,9 @@
|
|||||||
<h1>@Html.TitleForPage(T("New Content Part").ToString())</h1>@using (Html.BeginFormAntiForgeryPost()) {
|
<h1>@Html.TitleForPage(T("New Content Part").ToString())</h1>@using (Html.BeginFormAntiForgeryPost()) {
|
||||||
@Html.ValidationSummary()
|
@Html.ValidationSummary()
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label for="DisplayName">@T("Name")</label>
|
<label for="Name">@T("Name")</label>
|
||||||
@Html.TextBoxFor(m => m.Name, new {@class = "textMedium", autofocus = "autofocus"})
|
@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>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<button class="primaryAction" type="submit">@T("Create")</button>
|
<button class="primaryAction" type="submit">@T("Create")</button>
|
||||||
|
Reference in New Issue
Block a user