mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +08:00
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:
@@ -35,14 +35,14 @@ namespace Orchard.Comments.Controllers {
|
|||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult Create(string returnUrl) {
|
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();
|
var viewModel = new CommentsCreateViewModel();
|
||||||
try {
|
try {
|
||||||
UpdateModel(viewModel);
|
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 {
|
var context = new CreateCommentContext {
|
||||||
Author = viewModel.Name,
|
Author = viewModel.Name,
|
||||||
@@ -54,13 +54,12 @@ namespace Orchard.Comments.Controllers {
|
|||||||
|
|
||||||
Comment comment = _commentService.CreateComment(context, CurrentSite.As<CommentSettings>().Record.ModerateComments);
|
Comment comment = _commentService.CreateComment(context, CurrentSite.As<CommentSettings>().Record.ModerateComments);
|
||||||
|
|
||||||
if (!String.IsNullOrEmpty(returnUrl)) {
|
|
||||||
if (comment.Record.Status == CommentStatus.Pending)
|
if (comment.Record.Status == CommentStatus.Pending)
|
||||||
Services.Notifier.Information(T("Your comment will appear after the site administrator approves it."));
|
Services.Notifier.Information(T("Your comment will appear after the site administrator approves it."));
|
||||||
|
|
||||||
return Redirect(returnUrl);
|
return !String.IsNullOrEmpty(returnUrl)
|
||||||
}
|
? Redirect(returnUrl)
|
||||||
return RedirectToAction("Index");
|
: Redirect("~/");
|
||||||
}
|
}
|
||||||
catch (Exception exception) {
|
catch (Exception exception) {
|
||||||
_notifier.Error(T("Creating Comment failed: " + exception.Message));
|
_notifier.Error(T("Creating Comment failed: " + exception.Message));
|
||||||
|
@@ -2,7 +2,6 @@ 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 ModerateComments { 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; }
|
||||||
|
@@ -2,11 +2,6 @@
|
|||||||
<%@ Import Namespace="Orchard.Comments.Models"%>
|
<%@ Import Namespace="Orchard.Comments.Models"%>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><%=_Encoded("Comments")%></legend>
|
<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>
|
<div>
|
||||||
<%=Html.EditorFor(m => m.ModerateComments) %>
|
<%=Html.EditorFor(m => m.ModerateComments) %>
|
||||||
<label class="forcheckbox" for="CommentSettings_ModerateComments"><%=_Encoded("Comments must be approved before they appear")%></label>
|
<label class="forcheckbox" for="CommentSettings_ModerateComments"><%=_Encoded("Comments must be approved before they appear")%></label>
|
||||||
|
Reference in New Issue
Block a user