diff --git a/src/Orchard.Web/Packages/Orchard.Comments/Controllers/AdminController.cs b/src/Orchard.Web/Packages/Orchard.Comments/Controllers/AdminController.cs index 0d4e09947..9d5898016 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/Controllers/AdminController.cs +++ b/src/Orchard.Web/Packages/Orchard.Comments/Controllers/AdminController.cs @@ -166,6 +166,7 @@ namespace Orchard.Comments.Controllers { Options = options, DisplayNameForCommentedItem = _commentService.GetDisplayForCommentedContent(id).DisplayText, CommentedItemId = id, + CommentsClosedOnItem = _commentService.CommentsClosedForCommentedContent(id), }; return View(model); } @@ -228,6 +229,19 @@ namespace Orchard.Comments.Controllers { } } + public ActionResult Enable(int commentedItemId) { + try { + if (!_authorizer.Authorize(Permissions.EnableComment, T("Couldn't enable comments"))) + return new HttpUnauthorizedResult(); + _commentService.EnableCommentsForCommentedContent(commentedItemId); + return RedirectToAction("Index"); + } + catch (Exception exception) { + _notifier.Error(T("Enabling Comments failed: " + exception.Message)); + return RedirectToAction("Index"); + } + } + public ActionResult Edit(int id) { try { Comment comment = _commentService.GetComment(id); diff --git a/src/Orchard.Web/Packages/Orchard.Comments/Permissions.cs b/src/Orchard.Web/Packages/Orchard.Comments/Permissions.cs index aa77f859c..a901ec4c9 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/Permissions.cs +++ b/src/Orchard.Web/Packages/Orchard.Comments/Permissions.cs @@ -5,6 +5,7 @@ namespace Orchard.Comments { public class Permissions : IPermissionProvider { public static readonly Permission AddComment = new Permission { Description = "Adding a Comment", Name = "AddComment" }; public static readonly Permission AddCommentWithoutValidation = new Permission { Description = "Adding a Comment without validation", Name = "AddCommentWithoutValidation" }; + public static readonly Permission EnableComment = new Permission { Description = "Enabling Comments on content items", Name = "EnableComment" }; public static readonly Permission CloseComment = new Permission { Description = "Closing Comments", Name = "CloseComment" }; public static readonly Permission CloseCommentOnOwnItems = new Permission { Description = "Closing Comments on own items", Name = "CloseCommentOnOwnItems" }; public static readonly Permission ModerateComment = new Permission { Description = "Moderating Comments", Name = "ModerateComment" }; @@ -20,6 +21,7 @@ namespace Orchard.Comments { return new List { AddComment, AddCommentWithoutValidation, + EnableComment, CloseComment, CloseCommentOnOwnItems, ModerateComment, diff --git a/src/Orchard.Web/Packages/Orchard.Comments/Services/CommentService.cs b/src/Orchard.Web/Packages/Orchard.Comments/Services/CommentService.cs index d8c7fbc24..8a8aee8dd 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/Services/CommentService.cs +++ b/src/Orchard.Web/Packages/Orchard.Comments/Services/CommentService.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Orchard.Comments.Models; using Orchard.Data; @@ -20,7 +21,9 @@ namespace Orchard.Comments.Services { void UpdateComment(int id, string name, string email, string siteName, string commentText); void MarkCommentAsSpam(int commentId); void DeleteComment(int commentId); + bool CommentsClosedForCommentedContent(int id); void CloseCommentsForCommentedContent(int id); + void EnableCommentsForCommentedContent(int id); } public class CommentService : ICommentService { @@ -97,10 +100,21 @@ namespace Orchard.Comments.Services { _commentRepository.Delete(GetComment(commentId)); } + public bool CommentsClosedForCommentedContent(int id) { + return _closedCommentsRepository.Get(x => x.ContentItemId == id) == null ? false : true; + } + public void CloseCommentsForCommentedContent(int id) { _closedCommentsRepository.Create(new ClosedComments { ContentItemId = id }); } + public void EnableCommentsForCommentedContent(int id) { + ClosedComments closedComments = _closedCommentsRepository.Get(x => x.ContentItemId == id); + if (closedComments != null) { + _closedCommentsRepository.Delete(closedComments); + } + } + #endregion } } diff --git a/src/Orchard.Web/Packages/Orchard.Comments/ViewModels/CommentsDetailsViewModel.cs b/src/Orchard.Web/Packages/Orchard.Comments/ViewModels/CommentsDetailsViewModel.cs index 43545bea0..527f1557d 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/ViewModels/CommentsDetailsViewModel.cs +++ b/src/Orchard.Web/Packages/Orchard.Comments/ViewModels/CommentsDetailsViewModel.cs @@ -7,6 +7,7 @@ namespace Orchard.Comments.ViewModels { public CommentDetailsOptions Options { get; set; } public string DisplayNameForCommentedItem { get; set; } public int CommentedItemId { get; set; } + public bool CommentsClosedOnItem { get; set; } } public class CommentDetailsOptions { diff --git a/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Details.aspx b/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Details.aspx index 69cc1194b..479605789 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Details.aspx +++ b/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Details.aspx @@ -81,8 +81,16 @@ } %>
  • - <%=Html.ActionLink("Close Comments", "Close", new {commentedItemId = Model.CommentedItemId}, new {@class="floatRight topSpacer"}) %> + <% if (Model.CommentsClosedOnItem) {%> + <%=Html.ActionLink("Enable Comments", "Enable", + new {commentedItemId = Model.CommentedItemId}, + new {@class="floatRight topSpacer"}) %> + <%} else {%> + <%=Html.ActionLink("Close Comments", "Close", + new {commentedItemId = Model.CommentedItemId}, + new {@class = "floatRight topSpacer"})%>
  • + <% }%> <% Html.EndForm(); %> diff --git a/src/Orchard.Web/Packages/Orchard.Comments/Views/Models/DisplayTemplates/HasComments.ascx b/src/Orchard.Web/Packages/Orchard.Comments/Views/Models/DisplayTemplates/HasComments.ascx index 8de5307ab..0dad7f76e 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/Views/Models/DisplayTemplates/HasComments.ascx +++ b/src/Orchard.Web/Packages/Orchard.Comments/Views/Models/DisplayTemplates/HasComments.ascx @@ -14,8 +14,7 @@ <% if (Model.Closed) { %>

    Comments have been disabled for this content.

    -<% } %> -<% else { %> +<% } else { %> <% Html.BeginForm("Create", "Admin", new { area = "Orchard.Comments" }); %> <%= Html.ValidationSummary() %>