Added a "ModerateComments" setting for Orchard.Comments

--HG--
branch : dev
This commit is contained in:
Erik Porter
2010-02-26 15:29:31 -08:00
parent 2145f4e544
commit 8e547d0766
5 changed files with 13 additions and 9 deletions

View File

@@ -47,10 +47,10 @@ namespace Orchard.Comments.Controllers {
CommentText = viewModel.CommentText, CommentText = viewModel.CommentText,
Email = viewModel.Email, Email = viewModel.Email,
SiteName = viewModel.SiteName, SiteName = viewModel.SiteName,
CommentedOn = viewModel.CommentedOn, CommentedOn = viewModel.CommentedOn
}; };
Comment comment = _commentService.CreateComment(context); Comment comment = _commentService.CreateComment(context, CurrentSite.As<CommentSettings>().Record.ModerateComments);
if (!String.IsNullOrEmpty(returnUrl)) { if (!String.IsNullOrEmpty(returnUrl)) {
return Redirect(returnUrl); return Redirect(returnUrl);

View File

@@ -3,6 +3,7 @@ using Orchard.ContentManagement.Records;
namespace Orchard.Comments.Models { namespace Orchard.Comments.Models {
public class CommentSettingsRecord : ContentPartRecord { public class CommentSettingsRecord : ContentPartRecord {
public virtual bool RequireLoginToAddComment { get; set; } public virtual bool RequireLoginToAddComment { get; set; }
public virtual bool ModerateComments { get; set; }
public virtual bool EnableSpamProtection { get; set; } public virtual bool EnableSpamProtection { get; set; }
public virtual string AkismetKey { get; set; } public virtual string AkismetKey { get; set; }
public virtual string AkismetUrl { get; set; } public virtual string AkismetUrl { get; set; }

View File

@@ -18,7 +18,7 @@ namespace Orchard.Comments.Services {
IEnumerable<Comment> GetCommentsForCommentedContent(int id, CommentStatus status); IEnumerable<Comment> GetCommentsForCommentedContent(int id, CommentStatus status);
Comment GetComment(int id); Comment GetComment(int id);
ContentItemMetadata GetDisplayForCommentedContent(int id); ContentItemMetadata GetDisplayForCommentedContent(int id);
Comment CreateComment(CreateCommentContext commentRecord); Comment CreateComment(CreateCommentContext commentRecord, bool moderateComments);
void UpdateComment(int id, string name, string email, string siteName, string commentText, CommentStatus status); void UpdateComment(int id, string name, string email, string siteName, string commentText, CommentStatus status);
void ApproveComment(int commentId); void ApproveComment(int commentId);
void PendComment(int commentId); void PendComment(int commentId);
@@ -100,7 +100,7 @@ namespace Orchard.Comments.Services {
return _contentManager.GetItemMetadata(content); return _contentManager.GetItemMetadata(content);
} }
public Comment CreateComment(CreateCommentContext context) { public Comment CreateComment(CreateCommentContext context, bool moderateComments) {
var comment = _contentManager.Create<Comment>(CommentDriver.ContentType.Name); var comment = _contentManager.Create<Comment>(CommentDriver.ContentType.Name);
comment.Record.Author = context.Author; comment.Record.Author = context.Author;
@@ -111,7 +111,7 @@ namespace Orchard.Comments.Services {
comment.Record.UserName = (CurrentUser == null ? context.Author : CurrentUser.UserName); comment.Record.UserName = (CurrentUser == null ? context.Author : CurrentUser.UserName);
comment.Record.CommentedOn = context.CommentedOn; comment.Record.CommentedOn = context.CommentedOn;
comment.Record.Status = _commentValidator.ValidateComment(comment) ? CommentStatus.Pending : CommentStatus.Spam; comment.Record.Status = _commentValidator.ValidateComment(comment) ? moderateComments ? CommentStatus.Pending : CommentStatus.Approved : CommentStatus.Spam;
// store id of the next layer for large-grained operations, e.g. rss on blog // store id of the next layer for large-grained operations, e.g. rss on blog
//TODO:(rpaquay) Get rid of this (comment aspect takes care of container) //TODO:(rpaquay) Get rid of this (comment aspect takes care of container)

View File

@@ -7,6 +7,11 @@
<label class="forcheckbox" for="CommentSettings_RequireLoginToAddComment"><%=_Encoded("Require login to comment")%></label> <label class="forcheckbox" for="CommentSettings_RequireLoginToAddComment"><%=_Encoded("Require login to comment")%></label>
<%=Html.ValidationMessage("RequireLoginToAddComment", "*")%> <%=Html.ValidationMessage("RequireLoginToAddComment", "*")%>
</div> </div>
<div>
<%=Html.EditorFor(m => m.ModerateComments) %>
<label class="forcheckbox" for="CommentSettings_ModerateComments"><%=_Encoded("Enable comment moderation")%></label>
<%=Html.ValidationMessage("ModerateComments", "*")%>
</div>
<div> <div>
<%=Html.EditorFor(m => m.EnableSpamProtection) %> <%=Html.EditorFor(m => m.EnableSpamProtection) %>
<label class="forcheckbox" for="CommentSettings_EnableSpamProtection"><%=_Encoded("Enable spam protection") %></label> <label class="forcheckbox" for="CommentSettings_EnableSpamProtection"><%=_Encoded("Enable spam protection") %></label>

View File

@@ -6,7 +6,7 @@ if (Model.CommentsActive == false) { %>
<p><%=_Encoded("Comments have been disabled for this content.") %></p><% <p><%=_Encoded("Comments have been disabled for this content.") %></p><%
} else { %> } else { %>
<%-- todo: (heskew) need a comment form for the authenticated user... --%> <%-- todo: (heskew) need a comment form for the authenticated user... --%>
<% using(Html.BeginForm("Create", "Admin", new { area = "Orchard.Comments" }, FormMethod.Post, new { @class = "comment" })) { %> <% using(Html.BeginForm("Create", "Comment", new { area = "Orchard.Comments" }, FormMethod.Post, new { @class = "comment" })) { %>
<%=Html.ValidationSummary() %> <%=Html.ValidationSummary() %>
<h2>Add a Comment</h2> <h2>Add a Comment</h2>
<fieldset class="who"> <fieldset class="who">
@@ -37,6 +37,4 @@ if (Model.CommentsActive == false) { %>
</div> </div>
</fieldset><% </fieldset><%
} }
} %> } %>