From 8e547d07667d27029995cf11b4440e99576c3d65 Mon Sep 17 00:00:00 2001 From: Erik Porter Date: Fri, 26 Feb 2010 15:29:31 -0800 Subject: [PATCH] Added a "ModerateComments" setting for Orchard.Comments --HG-- branch : dev --- .../Orchard.Comments/Controllers/CommentController.cs | 4 ++-- .../Orchard.Comments/Models/CommentSettingsRecord.cs | 1 + .../Modules/Orchard.Comments/Services/CommentService.cs | 6 +++--- .../Views/EditorTemplates/Parts/Comments.SiteSettings.ascx | 5 +++++ .../Views/DisplayTemplates/Parts/Comments.HasComments.ascx | 6 ++---- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Controllers/CommentController.cs b/src/Orchard.Web/Modules/Orchard.Comments/Controllers/CommentController.cs index 187dd5ec9..c310ce3db 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Controllers/CommentController.cs +++ b/src/Orchard.Web/Modules/Orchard.Comments/Controllers/CommentController.cs @@ -47,10 +47,10 @@ namespace Orchard.Comments.Controllers { CommentText = viewModel.CommentText, Email = viewModel.Email, SiteName = viewModel.SiteName, - CommentedOn = viewModel.CommentedOn, + CommentedOn = viewModel.CommentedOn }; - Comment comment = _commentService.CreateComment(context); + Comment comment = _commentService.CreateComment(context, CurrentSite.As().Record.ModerateComments); if (!String.IsNullOrEmpty(returnUrl)) { return Redirect(returnUrl); diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Models/CommentSettingsRecord.cs b/src/Orchard.Web/Modules/Orchard.Comments/Models/CommentSettingsRecord.cs index 998949fda..618a6179e 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Models/CommentSettingsRecord.cs +++ b/src/Orchard.Web/Modules/Orchard.Comments/Models/CommentSettingsRecord.cs @@ -3,6 +3,7 @@ using Orchard.ContentManagement.Records; namespace Orchard.Comments.Models { public class CommentSettingsRecord : ContentPartRecord { public virtual bool RequireLoginToAddComment { get; set; } + public virtual bool ModerateComments { get; set; } public virtual bool EnableSpamProtection { get; set; } public virtual string AkismetKey { get; set; } public virtual string AkismetUrl { get; set; } diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Services/CommentService.cs b/src/Orchard.Web/Modules/Orchard.Comments/Services/CommentService.cs index bb53f5ef0..4b805b032 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Services/CommentService.cs +++ b/src/Orchard.Web/Modules/Orchard.Comments/Services/CommentService.cs @@ -18,7 +18,7 @@ namespace Orchard.Comments.Services { IEnumerable GetCommentsForCommentedContent(int id, CommentStatus status); Comment GetComment(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 ApproveComment(int commentId); void PendComment(int commentId); @@ -100,7 +100,7 @@ namespace Orchard.Comments.Services { return _contentManager.GetItemMetadata(content); } - public Comment CreateComment(CreateCommentContext context) { + public Comment CreateComment(CreateCommentContext context, bool moderateComments) { var comment = _contentManager.Create(CommentDriver.ContentType.Name); comment.Record.Author = context.Author; @@ -111,7 +111,7 @@ namespace Orchard.Comments.Services { comment.Record.UserName = (CurrentUser == null ? context.Author : CurrentUser.UserName); 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 //TODO:(rpaquay) Get rid of this (comment aspect takes care of container) diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Views/EditorTemplates/Parts/Comments.SiteSettings.ascx b/src/Orchard.Web/Modules/Orchard.Comments/Views/EditorTemplates/Parts/Comments.SiteSettings.ascx index fa687e61f..5da78f7f9 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Views/EditorTemplates/Parts/Comments.SiteSettings.ascx +++ b/src/Orchard.Web/Modules/Orchard.Comments/Views/EditorTemplates/Parts/Comments.SiteSettings.ascx @@ -7,6 +7,11 @@ <%=Html.ValidationMessage("RequireLoginToAddComment", "*")%> +
+ <%=Html.EditorFor(m => m.ModerateComments) %> + + <%=Html.ValidationMessage("ModerateComments", "*")%> +
<%=Html.EditorFor(m => m.EnableSpamProtection) %> diff --git a/src/Orchard.Web/Themes/Green/Views/DisplayTemplates/Parts/Comments.HasComments.ascx b/src/Orchard.Web/Themes/Green/Views/DisplayTemplates/Parts/Comments.HasComments.ascx index 1301d25bd..8b7090f6b 100644 --- a/src/Orchard.Web/Themes/Green/Views/DisplayTemplates/Parts/Comments.HasComments.ascx +++ b/src/Orchard.Web/Themes/Green/Views/DisplayTemplates/Parts/Comments.HasComments.ascx @@ -6,7 +6,7 @@ if (Model.CommentsActive == false) { %>

<%=_Encoded("Comments have been disabled for this content.") %>

<% } else { %> <%-- 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() %>

Add a Comment

@@ -37,6 +37,4 @@ if (Model.CommentsActive == false) { %>
<% } -} %> - - \ No newline at end of file +} %> \ No newline at end of file