diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index 55b3edc9fc..372b0671ae 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -6,10 +6,9 @@ using System.Net.Http; using System.Web.Http; using System.Web.Http.ModelBinding; using Umbraco.Core; -using Umbraco.Core.Logging; using Umbraco.Core.Models; -using Umbraco.Core.Models.Editors; using Umbraco.Core.Models.Membership; +using Umbraco.Core.Publishing; using Umbraco.Core.Services; using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Models.Mapping; @@ -22,89 +21,6 @@ using umbraco; namespace Umbraco.Web.Editors { - public abstract class ContentControllerBase : UmbracoAuthorizedJsonController - { - /// - /// Constructor - /// - protected ContentControllerBase() - : this(UmbracoContext.Current) - { - } - - /// - /// Constructor - /// - /// - protected ContentControllerBase(UmbracoContext umbracoContext) - : base(umbracoContext) - { - } - - protected void HandleContentNotFound(int id) - { - ModelState.AddModelError("id", string.Format("content with id: {0} was not found", id)); - var errorResponse = Request.CreateErrorResponse( - HttpStatusCode.NotFound, - ModelState); - throw new HttpResponseException(errorResponse); - } - - protected void UpdateName(ContentItemSave contentItem) - where TPersisted : IContentBase - { - //Don't update the name if it is empty - if (!contentItem.Name.IsNullOrWhiteSpace()) - { - contentItem.PersistedContent.Name = contentItem.Name; - } - } - - protected void MapPropertyValues(ContentItemSave contentItem) - where TPersisted : IContentBase - { - //Map the property values - foreach (var p in contentItem.ContentDto.Properties) - { - //get the dbo property - var dboProperty = contentItem.PersistedContent.Properties[p.Alias]; - - //create the property data to send to the property editor - var d = new Dictionary(); - //add the files if any - var files = contentItem.UploadedFiles.Where(x => x.PropertyId == p.Id).ToArray(); - if (files.Any()) - { - d.Add("files", files); - } - var data = new ContentPropertyData(p.Value, d); - - //get the deserialized value from the property editor - if (p.PropertyEditor == null) - { - LogHelper.Warn("No property editor found for property " + p.Alias); - } - else - { - dboProperty.Value = p.PropertyEditor.ValueEditor.DeserializeValue(data, dboProperty.Value); - } - } - } - - protected void HandleInvalidModelState(ContentItemDisplayBase display) - where TPersisted : IContentBase - where T : ContentPropertyBasic - { - //lasty, if it is not valid, add the modelstate to the outgoing object and throw a 403 - if (!ModelState.IsValid) - { - display.Errors = ModelState.ToErrorDictionary(); - throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Forbidden, display)); - } - } - - } - /// /// The API controller used for editing content /// @@ -226,7 +142,9 @@ namespace Umbraco.Web.Editors } } - bool isPublishSuccess = false; + //initialize this to successful + var publishStatus = new Attempt(true, null); + if (contentItem.Action == ContentSaveAction.Save || contentItem.Action == ContentSaveAction.SaveNew) { //save the item @@ -235,7 +153,7 @@ namespace Umbraco.Web.Editors else { //publish the item and check if it worked, if not we will show a diff msg below - isPublishSuccess = Services.ContentService.SaveAndPublish(contentItem.PersistedContent); + publishStatus = ((ContentService)Services.ContentService).SaveAndPublishInternal(contentItem.PersistedContent); } @@ -254,30 +172,53 @@ namespace Umbraco.Web.Editors break; case ContentSaveAction.Publish: case ContentSaveAction.PublishNew: - - //If the document is at a level deeper than the root but it's ancestor's path is not published, - //it means that we cannot actually publish this document because one of it's parent's is not published. - //So, we still need to save the document but we'll show a different notification. - if (contentItem.PersistedContent.Level > 1 && !Services.ContentService.IsPublishable(contentItem.PersistedContent)) - { - display.AddWarningNotification(ui.Text("publish"), ui.Text("speechBubbles", "editContentPublishedFailedByParent")); - } - else - { - if (isPublishSuccess) - { - display.AddSuccessNotification(ui.Text("speechBubbles", "editContentPublishedHeader"), ui.Text("speechBubbles", "editContentPublishedText")); - } - else - { - display.AddWarningNotification(ui.Text("publish"), ui.Text("speechBubbles", "contentPublishedFailedByEvent")); - } - } + ShowMessageForStatus(publishStatus.Result, display); break; } return display; } + private void ShowMessageForStatus(PublishStatus status, ContentItemDisplay display) + { + switch (status.StatusType) + { + case PublishStatusType.Success: + case PublishStatusType.SuccessAlreadyPublished: + display.AddSuccessNotification( + ui.Text("speechBubbles", "editContentPublishedHeader", UmbracoUser), + ui.Text("speechBubbles", "editContentPublishedText", UmbracoUser)); + break; + case PublishStatusType.FailedPathNotPublished: + display.AddWarningNotification( + ui.Text("publish"), + ui.Text("publish", "contentPublishedFailedByParent", + string.Format("{0} ({1})", status.ContentItem.Name, status.ContentItem.Id), + UmbracoUser).Trim()); + break; + case PublishStatusType.FailedCancelledByEvent: + display.AddWarningNotification( + ui.Text("publish"), + ui.Text("speechBubbles", "contentPublishedFailedByEvent")); + break; + case PublishStatusType.FailedHasExpired: + case PublishStatusType.FailedAwaitingRelease: + case PublishStatusType.FailedIsTrashed: + case PublishStatusType.FailedContentInvalid: + display.AddWarningNotification( + ui.Text("publish"), + ui.Text("publish", "contentPublishedFailedInvalid", + new[] + { + string.Format("{0} ({1})", status.ContentItem.Name, status.ContentItem.Id), + string.Join(",", status.InvalidProperties.Select(x => x.Alias)) + }, + UmbracoUser).Trim()); + break; + default: + throw new IndexOutOfRangeException(); + } + } + } } \ No newline at end of file diff --git a/src/Umbraco.Web/Editors/ContentControllerBase.cs b/src/Umbraco.Web/Editors/ContentControllerBase.cs new file mode 100644 index 0000000000..12da55b2ee --- /dev/null +++ b/src/Umbraco.Web/Editors/ContentControllerBase.cs @@ -0,0 +1,99 @@ +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Web.Http; +using Umbraco.Core; +using Umbraco.Core.Logging; +using Umbraco.Core.Models; +using Umbraco.Core.Models.Editors; +using Umbraco.Web.Models.ContentEditing; + +namespace Umbraco.Web.Editors +{ + /// + /// An abstract base controller used for media/content (and probably members) to try to reduce code replication. + /// + public abstract class ContentControllerBase : UmbracoAuthorizedJsonController + { + /// + /// Constructor + /// + protected ContentControllerBase() + : this(UmbracoContext.Current) + { + } + + /// + /// Constructor + /// + /// + protected ContentControllerBase(UmbracoContext umbracoContext) + : base(umbracoContext) + { + } + + protected void HandleContentNotFound(int id) + { + ModelState.AddModelError("id", string.Format("content with id: {0} was not found", id)); + var errorResponse = Request.CreateErrorResponse( + HttpStatusCode.NotFound, + ModelState); + throw new HttpResponseException(errorResponse); + } + + protected void UpdateName(ContentItemSave contentItem) + where TPersisted : IContentBase + { + //Don't update the name if it is empty + if (!contentItem.Name.IsNullOrWhiteSpace()) + { + contentItem.PersistedContent.Name = contentItem.Name; + } + } + + protected void MapPropertyValues(ContentItemSave contentItem) + where TPersisted : IContentBase + { + //Map the property values + foreach (var p in contentItem.ContentDto.Properties) + { + //get the dbo property + var dboProperty = contentItem.PersistedContent.Properties[p.Alias]; + + //create the property data to send to the property editor + var d = new Dictionary(); + //add the files if any + var files = contentItem.UploadedFiles.Where(x => x.PropertyId == p.Id).ToArray(); + if (files.Any()) + { + d.Add("files", files); + } + var data = new ContentPropertyData(p.Value, d); + + //get the deserialized value from the property editor + if (p.PropertyEditor == null) + { + LogHelper.Warn("No property editor found for property " + p.Alias); + } + else + { + dboProperty.Value = p.PropertyEditor.ValueEditor.DeserializeValue(data, dboProperty.Value); + } + } + } + + protected void HandleInvalidModelState(ContentItemDisplayBase display) + where TPersisted : IContentBase + where T : ContentPropertyBasic + { + //lasty, if it is not valid, add the modelstate to the outgoing object and throw a 403 + if (!ModelState.IsValid) + { + display.Errors = ModelState.ToErrorDictionary(); + throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Forbidden, display)); + } + } + + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 1abb5c1ac7..fd44567e6f 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -298,6 +298,7 @@ +