Skip to content

Commit

Permalink
Adding ability to remove draft and adding grouping to SummaryAdmin co…
Browse files Browse the repository at this point in the history
…ntent menu, see #2661 and #2662

These two issues are tightly connected so better to address them at once.
  • Loading branch information
LombiqTechnologies authored and Piedone committed Dec 4, 2016
1 parent 46c3fe6 commit 5d835ab
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 39 deletions.
28 changes: 28 additions & 0 deletions src/Orchard.Web/Core/Contents/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Web.Mvc;
using System.Web.Routing;
Expand Down Expand Up @@ -424,6 +425,33 @@ public ActionResult Remove(int id, string returnUrl) {
return this.RedirectLocal(returnUrl, () => RedirectToAction("List"));
}

[HttpPost]
public ActionResult DiscardDraft(int id, string returnUrl) {
var contentItem = _contentManager.Get(id, VersionOptions.Latest);

if (contentItem == null) {
return HttpNotFound();
}

if (!contentItem.TypeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable
|| !contentItem.HasPublished()
|| contentItem.IsPublished()) {
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}

if (!Services.Authorizer.Authorize(Permissions.DeleteContent, contentItem, T("Couldn't remove draft"))) {
return new HttpUnauthorizedResult();
}

_contentManager.DiscardDraft(contentItem);

Services.Notifier.Information(string.IsNullOrWhiteSpace(contentItem.TypeDefinition.DisplayName)
? T("That draft has been removed.")
: T("That {0} draft has been removed.", contentItem.TypeDefinition.DisplayName));

return this.RedirectLocal(returnUrl, () => RedirectToAction("List"));
}

[HttpPost]
public ActionResult Publish(int id, string returnUrl) {
var contentItem = _contentManager.GetLatest(id);
Expand Down
4 changes: 1 addition & 3 deletions src/Orchard.Web/Core/Contents/Drivers/ContentsDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ protected override DriverResult Display(ContentPart part, string displayType, dy
ContentShape("Parts_Contents_Publish_Summary",
() => shapeHelper.Parts_Contents_Publish_Summary()),
ContentShape("Parts_Contents_Publish_SummaryAdmin",
() => shapeHelper.Parts_Contents_Publish_SummaryAdmin()),
ContentShape("Parts_Contents_Clone_SummaryAdmin",
() => shapeHelper.Parts_Contents_Clone_SummaryAdmin())
() => shapeHelper.Parts_Contents_Publish_SummaryAdmin())
);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Orchard.Web/Core/Contents/Placement.info
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<Place Parts_Contents_Publish="Content:5"/>
</Match>
<Match DisplayType="SummaryAdmin">
<Place Parts_Contents_Publish_SummaryAdmin="Actions:5"
Parts_Contents_Clone_SummaryAdmin="Actions:6"/>
<Place Parts_Contents_Publish_SummaryAdmin="Actions:5"/>
</Match>
</Placement>
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
@using Orchard.ContentManagement;
@using Orchard.Core.Contents
@using Orchard.Core.Contents;
@using Orchard.Utility.Extensions;
@{
ContentItem contentItem = Model.ContentItem;
var returnUrl = ViewContext.RequestContext.HttpContext.Request.ToUrlString();
}
<div class="summary" itemscope="itemscope" itemid="@contentItem.Id" itemtype="http://orchardproject.net/data/ContentItem">
<div class="properties">
Expand All @@ -18,12 +17,6 @@
</div>
<div class="related">
@Display(Model.Actions)
@if (Authorizer.Authorize(Permissions.EditContent, contentItem)) {
@Html.ItemEditLink(T("Edit").Text, contentItem)@T(" | ")
}
@if (Authorizer.Authorize(Permissions.DeleteContent, contentItem)) {
@Html.Link(T("Delete").Text, Url.ItemRemoveUrl(contentItem, new {returnUrl}), new {itemprop = "RemoveUrl UnsafeUrl"})
}
</div>
@if (Model.Content != null) {
<div class="primary">@Display(Model.Content)</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,55 @@

@{
Script.Require("ShapesBase");
ContentPart contentPart = Model.ContentPart;
ContentItem contentItem = Model.ContentItem;
var returnUrl = ViewContext.RequestContext.HttpContext.Request.ToUrlString();
var hasPublished = contentItem.HasPublished();
var hasDraft = contentItem.HasDraft();
var isPublished = contentItem.IsPublished();
var authorizedToEdit = Authorizer.Authorize(Permissions.EditContent, contentItem);
var authorizedToDelete = Authorizer.Authorize(Permissions.DeleteContent, contentItem);
var authorizedToPublish = Authorizer.Authorize(Permissions.PublishContent, contentItem);
}
@if (contentPart.HasPublished()) {
@Html.ItemDisplayLink(T("View").Text, (ContentItem)Model.ContentPart.ContentItem)
@T(" | ")

if (contentPart.HasDraft()) {
if (Authorizer.Authorize(Permissions.PublishContent, contentPart)) {
@Html.Link(T("Publish Draft").Text, Url.Action("Publish", "Admin", new {area = "Contents", id = contentPart.ContentItem.Id, returnUrl = Request.ToUrlString()}), new {itemprop = "UnsafeUrl"})
<div class="item-action-links">
<strong>@T("Item:")</strong>
@if (hasPublished) {
@Html.ItemDisplayLink(T("View").Text, contentItem);
}
@if (authorizedToEdit) {
if (hasPublished) {
@T(" | ")
}
@Html.ItemEditLink(T("Edit").Text, contentItem);
@T(" | ")
@Html.ActionLink(T(" Clone").Text, "Clone", "Admin", new { Id = contentItem.Id, ReturnUrl = Request.ToUrlString(), Area = "Contents" }, new { itemprop = "UnsafeUrl" });
}

if (Authorizer.Authorize(Permissions.PreviewContent, contentPart)) {
@Html.ActionLink(T("Preview").Text, "Display", "Item", new { area = "Contents", id = ((ContentItem)Model.ContentPart.ContentItem).Id, version = ((ContentItem)Model.ContentPart.ContentItem).Version }, new { })
@T(" | ")
}
@if (hasPublished && authorizedToPublish) {
@T(" | ")
@Html.ActionLink(T("Unpublish").Text, "Unpublish", "Admin", new { area = "Contents", id = contentItem.Id, returnUrl = Request.ToUrlString() }, new { itemprop = "UnsafeUrl" });
}

if (Authorizer.Authorize(Permissions.PublishContent, contentPart)) {
@Html.Link(T("Unpublish").Text, Url.Action("Unpublish", "Admin", new {area = "Contents", id = contentPart.ContentItem.Id, returnUrl = Request.ToUrlString()}), new {itemprop = "UnsafeUrl"})
@if (authorizedToDelete) {
@T(" | ")
@Html.Link(T("Remove").Text, Url.ItemRemoveUrl(contentItem, new { returnUrl }), new { itemprop = "RemoveUrl UnsafeUrl" });
}
} else {
if (contentPart.HasDraft()) {
if (Authorizer.Authorize(Permissions.PreviewContent, contentPart)) {
@Html.ActionLink(T("Preview").Text, "Display", "Item", new { area = "Contents", id = ((ContentItem)Model.ContentPart.ContentItem).Id, version = ((ContentItem)Model.ContentPart.ContentItem).Version }, new { })
</div>
@if ((!isPublished || hasDraft) && authorizedToEdit) {
<div class="draft-action-links">
<strong>@T("Draft:")</strong>
@if (!isPublished && Authorizer.Authorize(Permissions.PreviewContent, contentItem)) {
@Html.ActionLink(T("View").Text, "Display", "Item", new { area = "Contents", id = contentItem.Id, version = contentItem.Version }, new { });
}

@if (hasDraft && authorizedToPublish) {
@T(" | ")
@Html.ActionLink(T("Publish").Text, "Publish", "Admin", new { area = "Contents", id = contentItem.Id, returnUrl = Request.ToUrlString() }, new { itemprop = "UnsafeUrl" });
}
}

if (Authorizer.Authorize(Permissions.PublishContent, contentPart)) {
@Html.Link(T("Publish").Text, Url.Action("Publish", "Admin", new {area = "Contents", id = contentPart.ContentItem.Id, returnUrl = Request.ToUrlString()}), new {itemprop = "UnsafeUrl"})
@T(" | ")
}
@if (!isPublished && hasPublished && authorizedToDelete) {
@T(" | ")
@Html.ActionLink(T("Discard").Text, "DiscardDraft", "Admin", new { area = "Contents", id = contentItem.Id, returnUrl = Request.ToUrlString() }, new { itemprop = "RemoveUrl UnsafeUrl" });
}
</div>
}
3 changes: 0 additions & 3 deletions src/Orchard.Web/Core/Orchard.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,6 @@
<ItemGroup>
<Content Include="Navigation\Views\MenuItemLink-ShapeMenuItem.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Contents\Views\Parts.Contents.Clone.SummaryAdmin.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Contents\Views\Item\Display.cshtml" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<a href="@Url.Action("Index", "Admin", new { content = Model.ContentItem.Id, area = "Orchard.AuditTrail" })">@T("Audit Trail")</a>@T(" | ")
<a href="@Url.Action("Index", "Admin", new { content = Model.ContentItem.Id, area = "Orchard.AuditTrail" })">@T("Audit Trail")</a>
15 changes: 15 additions & 0 deletions src/Orchard/ContentManagement/DefaultContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,21 @@ public virtual void Remove(ContentItem contentItem) {
Handlers.Invoke(handler => handler.Removed(context), Logger);
}

public virtual void DiscardDraft(ContentItem contentItem) {
var session = _transactionManager.Value.GetSession();

// Delete the draft content item version record.
session
.CreateQuery("delete from Orchard.ContentManagement.Records.ContentItemVersionRecord civ where civ.ContentItemRecord.Id = (:id) and civ.Published = false and civ.Latest = true")
.SetParameter("id", contentItem.Id)
.ExecuteUpdate();

// After deleting the draft, get the published version. If for any reason there would be more than one,
// get the last one and set the Latest property to true.
var publishedVersionRecord = contentItem.Record.Versions.OrderBy(x => x.Number).ToArray().Last();
publishedVersionRecord.Latest = true;
}

public virtual void Destroy(ContentItem contentItem) {
var session = _transactionManager.Value.GetSession();
var context = new DestroyContentContext(contentItem);
Expand Down
6 changes: 6 additions & 0 deletions src/Orchard/ContentManagement/IContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public interface IContentManager : IDependency {
void Unpublish(ContentItem contentItem);
void Remove(ContentItem contentItem);

/// <summary>
/// Deletes the draft version of the content item permanently.
/// </summary>
/// <param name="contentItem">The content item of which the draft version will be deleted.</param>
void DiscardDraft(ContentItem contentItem);

/// <summary>
/// Permanently deletes the specified content item, including all of its content part records.
/// </summary>
Expand Down

0 comments on commit 5d835ab

Please sign in to comment.