Changing comment creation to be solely permission-based, for now

- It would be nice to bring back some form of "RequireLoginToAddComment" to comment site setting where that checkbox flipped the Anonymous role's "Add comment" permission

--HG--
branch : dev
This commit is contained in:
Nathan Heskew 2010-03-02 07:01:33 -08:00
parent 3ebdb0019c
commit bcce1c3a6c
3 changed files with 10 additions and 17 deletions

View File

@ -35,14 +35,14 @@ namespace Orchard.Comments.Controllers {
[HttpPost]
public ActionResult Create(string returnUrl) {
if (!Services.Authorizer.Authorize(Permissions.AddComment, T("Couldn't add comment")))
return !String.IsNullOrEmpty(returnUrl)
? Redirect(returnUrl)
: Redirect("~/");
var viewModel = new CommentsCreateViewModel();
try {
UpdateModel(viewModel);
if (CurrentSite.As<CommentSettings>().Record.RequireLoginToAddComment) {
if (!_authorizer.Authorize(Permissions.AddComment, T("Couldn't add comment"))) {
return new HttpUnauthorizedResult();
}
}
var context = new CreateCommentContext {
Author = viewModel.Name,
@ -54,13 +54,12 @@ namespace Orchard.Comments.Controllers {
Comment comment = _commentService.CreateComment(context, CurrentSite.As<CommentSettings>().Record.ModerateComments);
if (!String.IsNullOrEmpty(returnUrl)) {
if (comment.Record.Status == CommentStatus.Pending)
Services.Notifier.Information(T("Your comment will appear after the site administrator approves it."));
if (comment.Record.Status == CommentStatus.Pending)
Services.Notifier.Information(T("Your comment will appear after the site administrator approves it."));
return Redirect(returnUrl);
}
return RedirectToAction("Index");
return !String.IsNullOrEmpty(returnUrl)
? Redirect(returnUrl)
: Redirect("~/");
}
catch (Exception exception) {
_notifier.Error(T("Creating Comment failed: " + exception.Message));

View File

@ -2,7 +2,6 @@ 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; }

View File

@ -2,11 +2,6 @@
<%@ Import Namespace="Orchard.Comments.Models"%>
<fieldset>
<legend><%=_Encoded("Comments")%></legend>
<div>
<%=Html.EditorFor(m => m.RequireLoginToAddComment) %>
<label class="forcheckbox" for="CommentSettings_RequireLoginToAddComment"><%=_Encoded("Require login to comment")%></label>
<%=Html.ValidationMessage("RequireLoginToAddComment", "*")%>
</div>
<div>
<%=Html.EditorFor(m => m.ModerateComments) %>
<label class="forcheckbox" for="CommentSettings_ModerateComments"><%=_Encoded("Comments must be approved before they appear")%></label>