Prevents saving blueprint with same name as other existing
This commit is contained in:
@@ -335,18 +335,13 @@ namespace Umbraco.Web.Editors
|
||||
[HttpPost]
|
||||
public SimpleNotificationModel CreateBlueprintFromContent([FromUri]int contentId, [FromUri]string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
|
||||
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
|
||||
|
||||
var content = Services.ContentService.GetById(contentId);
|
||||
if (content == null)
|
||||
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
|
||||
|
||||
var existing = Services.ContentService.GetBlueprintsForContentTypes(content.ContentTypeId);
|
||||
if (existing.Any(x => x.Name == name))
|
||||
{
|
||||
ModelState.AddModelError("name", Services.TextService.Localize("content/duplicateBlueprintMessage"));
|
||||
throw new HttpResponseException(Request.CreateValidationErrorResponse(ModelState));
|
||||
}
|
||||
EnsureUniqueName(name, content, "name");
|
||||
|
||||
var blueprint = Services.ContentService.CreateContentFromBlueprint(content, name, Security.GetUserId());
|
||||
|
||||
@@ -356,11 +351,21 @@ namespace Umbraco.Web.Editors
|
||||
notificationModel.AddSuccessNotification(
|
||||
Services.TextService.Localize("content/createdBlueprintHeading"),
|
||||
Services.TextService.Localize("content/createdBlueprintMessage", new[]{ content.Name})
|
||||
);
|
||||
|
||||
);
|
||||
|
||||
return notificationModel;
|
||||
}
|
||||
|
||||
private void EnsureUniqueName(string name, IContent content, string modelName)
|
||||
{
|
||||
var existing = Services.ContentService.GetBlueprintsForContentTypes(content.ContentTypeId);
|
||||
if (existing.Any(x => x.Name == name && x.Id != content.Id))
|
||||
{
|
||||
ModelState.AddModelError(modelName, Services.TextService.Localize("content/duplicateBlueprintMessage"));
|
||||
throw new HttpResponseException(Request.CreateValidationErrorResponse(ModelState));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves content
|
||||
/// </summary>
|
||||
@@ -373,6 +378,8 @@ namespace Umbraco.Web.Editors
|
||||
var contentItemDisplay = PostSaveInternal(contentItem,
|
||||
content =>
|
||||
{
|
||||
EnsureUniqueName(content.Name, content, "Name");
|
||||
|
||||
Services.ContentService.SaveBlueprint(contentItem.PersistedContent, Security.CurrentUser.Id);
|
||||
//we need to reuse the underlying logic so return the result that it wants
|
||||
return Attempt<OperationStatus>.Succeed(new OperationStatus(OperationStatusType.Success, new EventMessages()));
|
||||
|
||||
Reference in New Issue
Block a user