mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 02:44:52 +08:00
#17164: Fixing closing comments functionality. Renaming it to enable / disable comments instead of enable / close.
--HG-- branch : 1.x
This commit is contained in:
@@ -173,7 +173,7 @@ namespace Orchard.Comments.Controllers {
|
||||
Options = options,
|
||||
DisplayNameForCommentedItem = _commentService.GetDisplayForCommentedContent(id) == null ? "" : _commentService.GetDisplayForCommentedContent(id).DisplayText,
|
||||
CommentedItemId = id,
|
||||
CommentsClosedOnItem = _commentService.CommentsClosedForCommentedContent(id),
|
||||
CommentsClosedOnItem = _commentService.CommentsDisabledForCommentedContent(id),
|
||||
};
|
||||
return View(model);
|
||||
}
|
||||
@@ -240,14 +240,15 @@ namespace Orchard.Comments.Controllers {
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Close(int commentedItemId, string returnUrl) {
|
||||
public ActionResult Disable(int commentedItemId, string returnUrl) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't close comments")))
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't disable comments")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_commentService.CloseCommentsForCommentedContent(commentedItemId);
|
||||
|
||||
_commentService.DisableCommentsForCommentedContent(commentedItemId);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Closing Comments failed: " + exception.Message));
|
||||
Services.Notifier.Error(T("Disabling Comments failed: " + exception.Message));
|
||||
}
|
||||
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
|
||||
}
|
||||
@@ -257,6 +258,7 @@ namespace Orchard.Comments.Controllers {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't enable comments")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
_commentService.EnableCommentsForCommentedContent(commentedItemId);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
|
@@ -7,11 +7,6 @@ namespace Orchard.Comments {
|
||||
public class Migrations : DataMigrationImpl {
|
||||
|
||||
public int Create() {
|
||||
SchemaBuilder.CreateTable("ClosedCommentsRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey().Identity())
|
||||
.Column<int>("ContentItemId")
|
||||
);
|
||||
|
||||
SchemaBuilder.CreateTable("CommentPartRecord", table => table
|
||||
.ContentPartRecord()
|
||||
.Column<string>("Author")
|
||||
|
@@ -1,6 +0,0 @@
|
||||
namespace Orchard.Comments.Models {
|
||||
public class ClosedCommentsRecord {
|
||||
public virtual int Id { get; set; }
|
||||
public virtual int ContentItemId { get; set; }
|
||||
}
|
||||
}
|
@@ -68,7 +68,6 @@
|
||||
<Compile Include="Annotations\CommentValidationAttributes.cs" />
|
||||
<Compile Include="ResourceManifest.cs" />
|
||||
<Compile Include="Shapes.cs" />
|
||||
<Compile Include="Models\ClosedCommentsRecord.cs" />
|
||||
<Compile Include="Models\CommentPart.cs" />
|
||||
<Compile Include="Handlers\CommentPartHandler.cs" />
|
||||
<Compile Include="Models\CommentStatus.cs" />
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
@@ -10,16 +11,13 @@ using Orchard.Services;
|
||||
namespace Orchard.Comments.Services {
|
||||
[UsedImplicitly]
|
||||
public class CommentService : ICommentService {
|
||||
private readonly IRepository<ClosedCommentsRecord> _closedCommentsRepository;
|
||||
private readonly IClock _clock;
|
||||
private readonly ICommentValidator _commentValidator;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
public CommentService(IRepository<ClosedCommentsRecord> closedCommentsRepository,
|
||||
IClock clock,
|
||||
public CommentService(IClock clock,
|
||||
ICommentValidator commentValidator,
|
||||
IOrchardServices orchardServices) {
|
||||
_closedCommentsRepository = closedCommentsRepository;
|
||||
_clock = clock;
|
||||
_commentValidator = commentValidator;
|
||||
_orchardServices = orchardServices;
|
||||
@@ -120,21 +118,16 @@ namespace Orchard.Comments.Services {
|
||||
_orchardServices.ContentManager.Remove(_orchardServices.ContentManager.Get(commentId));
|
||||
}
|
||||
|
||||
public bool CommentsClosedForCommentedContent(int id) {
|
||||
return _closedCommentsRepository.Fetch(x => x.ContentItemId == id).Count() >= 1;
|
||||
public bool CommentsDisabledForCommentedContent(int id) {
|
||||
return !_orchardServices.ContentManager.Get<CommentsPart>(id).CommentsActive;
|
||||
}
|
||||
|
||||
public void CloseCommentsForCommentedContent(int id) {
|
||||
if (CommentsClosedForCommentedContent(id))
|
||||
return;
|
||||
_closedCommentsRepository.Create(new ClosedCommentsRecord { ContentItemId = id });
|
||||
public void DisableCommentsForCommentedContent(int id) {
|
||||
_orchardServices.ContentManager.Get<CommentsPart>(id).CommentsActive = false;
|
||||
}
|
||||
|
||||
public void EnableCommentsForCommentedContent(int id) {
|
||||
var closedComments = _closedCommentsRepository.Fetch(x => x.ContentItemId == id);
|
||||
foreach (var c in closedComments) {
|
||||
_closedCommentsRepository.Delete(c);
|
||||
}
|
||||
_orchardServices.ContentManager.Get<CommentsPart>(id).CommentsActive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,8 +16,8 @@ namespace Orchard.Comments.Services {
|
||||
void UnapproveComment(int commentId);
|
||||
void MarkCommentAsSpam(int commentId);
|
||||
void DeleteComment(int commentId);
|
||||
bool CommentsClosedForCommentedContent(int id);
|
||||
void CloseCommentsForCommentedContent(int id);
|
||||
bool CommentsDisabledForCommentedContent(int id);
|
||||
void DisableCommentsForCommentedContent(int id);
|
||||
void EnableCommentsForCommentedContent(int id);
|
||||
}
|
||||
}
|
@@ -11,9 +11,9 @@
|
||||
</fieldset>
|
||||
}
|
||||
} else {
|
||||
using (Html.BeginFormAntiForgeryPost(Url.Action("Close", new { commentedItemId = Model.CommentedItemId }), FormMethod.Post, new { @class = "inline" })) {
|
||||
using (Html.BeginFormAntiForgeryPost(Url.Action("Disable", new { commentedItemId = Model.CommentedItemId }), FormMethod.Post, new { @class = "inline" })) {
|
||||
<fieldset>
|
||||
<button type="submit" class="primaryAction" title="@T("Close Comments")">@T("Close Comments")</button>
|
||||
<button type="submit" class="primaryAction" title="@T("Disable Comments")">@T("Disable Comments")</button>
|
||||
</fieldset>
|
||||
}
|
||||
}
|
||||
@@ -106,9 +106,9 @@
|
||||
</fieldset>
|
||||
}
|
||||
} else {
|
||||
using (Html.BeginFormAntiForgeryPost(Url.Action("Close", new { commentedItemId = Model.CommentedItemId }), FormMethod.Post, new { @class = "inline" })) {
|
||||
using (Html.BeginFormAntiForgeryPost(Url.Action("Disable", new { commentedItemId = Model.CommentedItemId }), FormMethod.Post, new { @class = "inline" })) {
|
||||
<fieldset>
|
||||
<button type="submit" class="primaryAction" title="@T("Close Comments")">@T("Close Comments")</button>
|
||||
<button type="submit" class="primaryAction" title="@T("Disable Comments")">@T("Disable Comments")</button>
|
||||
</fieldset>
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user