mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 10:54:50 +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,
|
Options = options,
|
||||||
DisplayNameForCommentedItem = _commentService.GetDisplayForCommentedContent(id) == null ? "" : _commentService.GetDisplayForCommentedContent(id).DisplayText,
|
DisplayNameForCommentedItem = _commentService.GetDisplayForCommentedContent(id) == null ? "" : _commentService.GetDisplayForCommentedContent(id).DisplayText,
|
||||||
CommentedItemId = id,
|
CommentedItemId = id,
|
||||||
CommentsClosedOnItem = _commentService.CommentsClosedForCommentedContent(id),
|
CommentsClosedOnItem = _commentService.CommentsDisabledForCommentedContent(id),
|
||||||
};
|
};
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
@@ -240,14 +240,15 @@ namespace Orchard.Comments.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult Close(int commentedItemId, string returnUrl) {
|
public ActionResult Disable(int commentedItemId, string returnUrl) {
|
||||||
try {
|
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();
|
return new HttpUnauthorizedResult();
|
||||||
_commentService.CloseCommentsForCommentedContent(commentedItemId);
|
|
||||||
|
_commentService.DisableCommentsForCommentedContent(commentedItemId);
|
||||||
}
|
}
|
||||||
catch (Exception exception) {
|
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"));
|
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
|
||||||
}
|
}
|
||||||
@@ -257,6 +258,7 @@ namespace Orchard.Comments.Controllers {
|
|||||||
try {
|
try {
|
||||||
if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't enable comments")))
|
if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't enable comments")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
_commentService.EnableCommentsForCommentedContent(commentedItemId);
|
_commentService.EnableCommentsForCommentedContent(commentedItemId);
|
||||||
}
|
}
|
||||||
catch (Exception exception) {
|
catch (Exception exception) {
|
||||||
|
@@ -7,11 +7,6 @@ namespace Orchard.Comments {
|
|||||||
public class Migrations : DataMigrationImpl {
|
public class Migrations : DataMigrationImpl {
|
||||||
|
|
||||||
public int Create() {
|
public int Create() {
|
||||||
SchemaBuilder.CreateTable("ClosedCommentsRecord", table => table
|
|
||||||
.Column<int>("Id", column => column.PrimaryKey().Identity())
|
|
||||||
.Column<int>("ContentItemId")
|
|
||||||
);
|
|
||||||
|
|
||||||
SchemaBuilder.CreateTable("CommentPartRecord", table => table
|
SchemaBuilder.CreateTable("CommentPartRecord", table => table
|
||||||
.ContentPartRecord()
|
.ContentPartRecord()
|
||||||
.Column<string>("Author")
|
.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="Annotations\CommentValidationAttributes.cs" />
|
||||||
<Compile Include="ResourceManifest.cs" />
|
<Compile Include="ResourceManifest.cs" />
|
||||||
<Compile Include="Shapes.cs" />
|
<Compile Include="Shapes.cs" />
|
||||||
<Compile Include="Models\ClosedCommentsRecord.cs" />
|
|
||||||
<Compile Include="Models\CommentPart.cs" />
|
<Compile Include="Models\CommentPart.cs" />
|
||||||
<Compile Include="Handlers\CommentPartHandler.cs" />
|
<Compile Include="Handlers\CommentPartHandler.cs" />
|
||||||
<Compile Include="Models\CommentStatus.cs" />
|
<Compile Include="Models\CommentStatus.cs" />
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Orchard.Comments.Models;
|
using Orchard.Comments.Models;
|
||||||
using Orchard.ContentManagement.Aspects;
|
using Orchard.ContentManagement.Aspects;
|
||||||
@@ -10,16 +11,13 @@ using Orchard.Services;
|
|||||||
namespace Orchard.Comments.Services {
|
namespace Orchard.Comments.Services {
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class CommentService : ICommentService {
|
public class CommentService : ICommentService {
|
||||||
private readonly IRepository<ClosedCommentsRecord> _closedCommentsRepository;
|
|
||||||
private readonly IClock _clock;
|
private readonly IClock _clock;
|
||||||
private readonly ICommentValidator _commentValidator;
|
private readonly ICommentValidator _commentValidator;
|
||||||
private readonly IOrchardServices _orchardServices;
|
private readonly IOrchardServices _orchardServices;
|
||||||
|
|
||||||
public CommentService(IRepository<ClosedCommentsRecord> closedCommentsRepository,
|
public CommentService(IClock clock,
|
||||||
IClock clock,
|
|
||||||
ICommentValidator commentValidator,
|
ICommentValidator commentValidator,
|
||||||
IOrchardServices orchardServices) {
|
IOrchardServices orchardServices) {
|
||||||
_closedCommentsRepository = closedCommentsRepository;
|
|
||||||
_clock = clock;
|
_clock = clock;
|
||||||
_commentValidator = commentValidator;
|
_commentValidator = commentValidator;
|
||||||
_orchardServices = orchardServices;
|
_orchardServices = orchardServices;
|
||||||
@@ -120,21 +118,16 @@ namespace Orchard.Comments.Services {
|
|||||||
_orchardServices.ContentManager.Remove(_orchardServices.ContentManager.Get(commentId));
|
_orchardServices.ContentManager.Remove(_orchardServices.ContentManager.Get(commentId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CommentsClosedForCommentedContent(int id) {
|
public bool CommentsDisabledForCommentedContent(int id) {
|
||||||
return _closedCommentsRepository.Fetch(x => x.ContentItemId == id).Count() >= 1;
|
return !_orchardServices.ContentManager.Get<CommentsPart>(id).CommentsActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CloseCommentsForCommentedContent(int id) {
|
public void DisableCommentsForCommentedContent(int id) {
|
||||||
if (CommentsClosedForCommentedContent(id))
|
_orchardServices.ContentManager.Get<CommentsPart>(id).CommentsActive = false;
|
||||||
return;
|
|
||||||
_closedCommentsRepository.Create(new ClosedCommentsRecord { ContentItemId = id });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnableCommentsForCommentedContent(int id) {
|
public void EnableCommentsForCommentedContent(int id) {
|
||||||
var closedComments = _closedCommentsRepository.Fetch(x => x.ContentItemId == id);
|
_orchardServices.ContentManager.Get<CommentsPart>(id).CommentsActive = true;
|
||||||
foreach (var c in closedComments) {
|
|
||||||
_closedCommentsRepository.Delete(c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,8 +16,8 @@ namespace Orchard.Comments.Services {
|
|||||||
void UnapproveComment(int commentId);
|
void UnapproveComment(int commentId);
|
||||||
void MarkCommentAsSpam(int commentId);
|
void MarkCommentAsSpam(int commentId);
|
||||||
void DeleteComment(int commentId);
|
void DeleteComment(int commentId);
|
||||||
bool CommentsClosedForCommentedContent(int id);
|
bool CommentsDisabledForCommentedContent(int id);
|
||||||
void CloseCommentsForCommentedContent(int id);
|
void DisableCommentsForCommentedContent(int id);
|
||||||
void EnableCommentsForCommentedContent(int id);
|
void EnableCommentsForCommentedContent(int id);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -11,9 +11,9 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
}
|
}
|
||||||
} else {
|
} 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>
|
<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>
|
</fieldset>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,9 +106,9 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
}
|
}
|
||||||
} else {
|
} 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>
|
<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>
|
</fieldset>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user