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.")))
|
||||
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 });
|
||||
}
|
||||
|
||||
|
@@ -184,12 +184,15 @@ namespace Orchard.ContentTypes.Services {
|
||||
while (_contentDefinitionManager.GetPartDefinition(name) != null)
|
||||
name = VersionName(name);
|
||||
|
||||
if (!String.IsNullOrEmpty(name)) {
|
||||
var contentPartDefinition = new ContentPartDefinition(name);
|
||||
_contentDefinitionManager.StorePartDefinition(contentPartDefinition);
|
||||
|
||||
return new EditPartViewModel(contentPartDefinition);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void AlterPart(EditPartViewModel partViewModel, IUpdateModel updateModel) {
|
||||
var updater = new Updater(updateModel);
|
||||
_contentDefinitionManager.AlterPartDefinition(partViewModel.Name, partBuilder => {
|
||||
|
@@ -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>
|
||||
|
Reference in New Issue
Block a user