From f2e60b539fa2d2a6fc5cf1eb5b04b49ec7f6cb17 Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Wed, 5 Jan 2011 12:46:51 -0800 Subject: [PATCH] #17164: Fixing closing comments functionality. Renaming it to enable / disable comments instead of enable / close. --HG-- branch : 1.x --- .../Controllers/AdminController.cs | 12 ++++++---- .../Modules/Orchard.Comments/Migrations.cs | 5 ---- .../Models/ClosedCommentsRecord.cs | 6 ----- .../Orchard.Comments/Orchard.Comments.csproj | 1 - .../Services/CommentService.cs | 23 +++++++------------ .../Services/ICommentService.cs | 4 ++-- .../Views/Admin/Details.cshtml | 8 +++---- 7 files changed, 21 insertions(+), 38 deletions(-) delete mode 100644 src/Orchard.Web/Modules/Orchard.Comments/Models/ClosedCommentsRecord.cs diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Comments/Controllers/AdminController.cs index d04e14b6a..293093ce0 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Comments/Controllers/AdminController.cs @@ -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) { diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Comments/Migrations.cs index 8297c3fa3..977a8e231 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Comments/Migrations.cs @@ -7,11 +7,6 @@ namespace Orchard.Comments { public class Migrations : DataMigrationImpl { public int Create() { - SchemaBuilder.CreateTable("ClosedCommentsRecord", table => table - .Column("Id", column => column.PrimaryKey().Identity()) - .Column("ContentItemId") - ); - SchemaBuilder.CreateTable("CommentPartRecord", table => table .ContentPartRecord() .Column("Author") diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Models/ClosedCommentsRecord.cs b/src/Orchard.Web/Modules/Orchard.Comments/Models/ClosedCommentsRecord.cs deleted file mode 100644 index f879dea56..000000000 --- a/src/Orchard.Web/Modules/Orchard.Comments/Models/ClosedCommentsRecord.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Orchard.Comments.Models { - public class ClosedCommentsRecord { - public virtual int Id { get; set; } - public virtual int ContentItemId { get; set; } - } -} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj b/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj index 1e8557652..2e157667c 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj +++ b/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj @@ -68,7 +68,6 @@ - diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Services/CommentService.cs b/src/Orchard.Web/Modules/Orchard.Comments/Services/CommentService.cs index 9f44c5b7f..fdd20a65e 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Services/CommentService.cs +++ b/src/Orchard.Web/Modules/Orchard.Comments/Services/CommentService.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 _closedCommentsRepository; private readonly IClock _clock; private readonly ICommentValidator _commentValidator; private readonly IOrchardServices _orchardServices; - public CommentService(IRepository 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(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(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(id).CommentsActive = true; } } } diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Services/ICommentService.cs b/src/Orchard.Web/Modules/Orchard.Comments/Services/ICommentService.cs index ef87afa0c..5963b7fd9 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Services/ICommentService.cs +++ b/src/Orchard.Web/Modules/Orchard.Comments/Services/ICommentService.cs @@ -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); } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Views/Admin/Details.cshtml b/src/Orchard.Web/Modules/Orchard.Comments/Views/Admin/Details.cshtml index 99156e28b..ca9e83c8d 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Views/Admin/Details.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Comments/Views/Admin/Details.cshtml @@ -11,9 +11,9 @@ } } 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" })) {
- +
} } @@ -106,9 +106,9 @@ } } 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" })) {
- +
} }