#17164: Fixing closing comments functionality. Renaming it to enable / disable comments instead of enable / close.

--HG--
branch : 1.x
This commit is contained in:
Andre Rodrigues
2011-01-05 12:46:51 -08:00
parent c30e6ef2f7
commit f2e60b539f
7 changed files with 21 additions and 38 deletions

View File

@@ -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) {

View File

@@ -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")

View File

@@ -1,6 +0,0 @@
namespace Orchard.Comments.Models {
public class ClosedCommentsRecord {
public virtual int Id { get; set; }
public virtual int ContentItemId { get; set; }
}
}

View File

@@ -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" />

View File

@@ -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;
}
}
}

View File

@@ -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);
}
}

View File

@@ -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>
}
}