mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01: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:
parent
3ebdb0019c
commit
bcce1c3a6c
@ -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));
|
||||
|
@ -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; }
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user