mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 02:44:52 +08:00
- Comments: Ability to re-enable comments for content items where comments were closed/disabled.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041946
This commit is contained in:
@@ -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);
|
||||
|
@@ -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<Permission> {
|
||||
AddComment,
|
||||
AddCommentWithoutValidation,
|
||||
EnableComment,
|
||||
CloseComment,
|
||||
CloseCommentOnOwnItems,
|
||||
ModerateComment,
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
@@ -81,8 +81,16 @@
|
||||
} %>
|
||||
</table>
|
||||
<li class="clearLayout">
|
||||
<%=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"})%>
|
||||
</li>
|
||||
<% }%>
|
||||
</div>
|
||||
|
||||
<% Html.EndForm(); %>
|
||||
|
@@ -14,8 +14,7 @@
|
||||
</ol>
|
||||
<% if (Model.Closed) { %>
|
||||
<p>Comments have been disabled for this content.</p>
|
||||
<% } %>
|
||||
<% else { %>
|
||||
<% } else { %>
|
||||
<% Html.BeginForm("Create", "Admin", new { area = "Orchard.Comments" }); %>
|
||||
<%= Html.ValidationSummary() %>
|
||||
<div class="yui-g">
|
||||
|
Reference in New Issue
Block a user