Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/1349 improve comment moderation possibilities #1526

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/Piranha.AspNetCore/Models/SinglePageWithComments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ public override async Task<IActionResult> OnGet(Guid id, bool draft = false)
/// <param name="draft">If the draft should be fetched</param>
public virtual async Task<IActionResult> OnPostSaveComment(Guid id, bool draft = false)
{
var ipAddress = Request.HttpContext.Connection.RemoteIpAddress;

// Create the comment
var comment = new Comment
{
IpAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString(),
IpAddress = ipAddress == null ? string.Empty : ipAddress.ToString(),
UserAgent = Request.Headers.ContainsKey("User-Agent") ? Request.Headers["User-Agent"].ToString() : "",
Author = CommentAuthor,
Email = CommentEmail,
Expand Down
4 changes: 3 additions & 1 deletion core/Piranha.AspNetCore/Models/SinglePostWithComments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ public override async Task<IActionResult> OnGet(Guid id, bool draft = false)
/// <param name="draft">If the draft should be fetched</param>
public virtual async Task<IActionResult> OnPostSaveComment(Guid id, bool draft = false)
{
var ipAddress = Request.HttpContext.Connection.RemoteIpAddress;

// Create the comment
var comment = new Comment
{
IpAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString(),
IpAddress = ipAddress == null ? string.Empty : ipAddress.ToString(),
UserAgent = Request.Headers.ContainsKey("User-Agent") ? Request.Headers["User-Agent"].ToString() : "",
Author = CommentAuthor,
Email = CommentEmail,
Expand Down
9 changes: 8 additions & 1 deletion core/Piranha.Manager/Areas/Manager/Pages/CommentList.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<button v-on:click.prevent="setStatus('all')" class="btn btn-sm" :class="{ 'btn-primary': state === 'all', 'btn-light': state !== 'all' }">@Localizer.General["All"]</button>
<button v-on:click.prevent="setStatus('pending')" class="btn btn-sm" :class="{ 'btn-primary': state === 'pending', 'btn-light': state !== 'pending' }">@Localizer.Comment["Pending"]</button>
<button v-on:click.prevent="setStatus('approved')" class="btn btn-sm" :class="{ 'btn-primary': state === 'approved', 'btn-light': state !== 'approved' }">@Localizer.Comment["Approved"]</button>
<button v-on:click.prevent="setStatus('rejected')" class="btn btn-sm" :class="{ 'btn-primary': state === 'rejected', 'btn-light': state !== 'rejected' }">@Localizer.Comment["Rejected"]</button>
</div>
<table class="table table-borderless table-comments">
<thead>
Expand All @@ -51,6 +52,8 @@
<th class="w-50">@Localizer.Comment["Comment"]</th>
<th class="text-nowrap">@Localizer.Comment["Response to"]</th>
<th class="text-center">@Localizer.Comment["Approved"]</th>
<th class="text-center">@Localizer.Comment["Rejected"]</th>
<th class="text-nowrap">@Localizer.Comment["Reason"]</th>
<th>@Localizer.General["Created"]</th>
<th class="actions one"></th>
</tr>
Expand All @@ -68,7 +71,11 @@
<td class="text-center text-success align-middle">
<button v-on:click.prevent="toggleApproved(comment)" class="switch" :aria-pressed="comment.isApproved"><span></span></button>
</td>
<td class="align-middle">{{ comment.created }}</td>
<td class="actions one align-middle">
<a v-if="comment.isRejected" href="#" title="@Localizer.General["Rejected"]" class="danger"><i class="fas fa-exclamation-circle"></i></a>
</td>
<td class="text-center align-middle">{{ comment.statusReason }}</td>
<td class="align-middle text-nowrap">{{ comment.created }}</td>
<td class="actions one align-middle">
<a v-if="piranha.permissions.comments.delete" v-on:click.prevent="remove(comment.id)" href="#" title="@Localizer.General["Delete"]" class="danger"><i class="fas fa-trash"></i></a>
</td>
Expand Down
2 changes: 2 additions & 0 deletions core/Piranha.Manager/Models/CommentListModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class ListItem
public string ArticleTitle { get; set; }
public string ArticleUrl { get; set; }
public bool IsApproved { get; set; }
public bool IsRejected { get; set; }
public string StatusReason { get; set; }
public string Created { get; set; }
internal DateTime CreatedDate { get; set; }
}
Expand Down
20 changes: 14 additions & 6 deletions core/Piranha.Manager/Services/CommentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public async Task<CommentListModel> Get(Guid? id = null)
AuthorImage = Utils.GenerateGravatarUrl(postComment.Email, 25),
Email = postComment.Email,
Body = postComment.Body,
IsApproved = postComment.IsApproved,
IsApproved = postComment.Status == CommentStatus.Approved,
IsRejected = postComment.Status == CommentStatus.Rejected,
StatusReason = postComment.StatusReason,
Created = postComment.Created.ToString("yyyy-MM-dd"),
CreatedDate = postComment.Created
});
Expand All @@ -76,7 +78,9 @@ public async Task<CommentListModel> Get(Guid? id = null)
AuthorImage = Utils.GenerateGravatarUrl(pageComment.Email, 25),
Email = pageComment.Email,
Body = pageComment.Body,
IsApproved = pageComment.IsApproved,
IsApproved = pageComment.Status == CommentStatus.Approved,
IsRejected = pageComment.Status == CommentStatus.Rejected,
StatusReason = pageComment.StatusReason,
Created = pageComment.Created.ToString("yyyy-MM-dd"),
CreatedDate = pageComment.Created
});
Expand All @@ -95,7 +99,8 @@ public async Task ApproveAsync(Guid id)

if (comment != null)
{
comment.IsApproved = true;
comment.Status = CommentStatus.Approved;
comment.StatusReason = "Manager Approved";
await _api.Posts.SaveCommentAsync(comment.ContentId, comment);
}
else
Expand All @@ -104,7 +109,8 @@ public async Task ApproveAsync(Guid id)

if (comment != null)
{
comment.IsApproved = true;
comment.Status = CommentStatus.Approved;
comment.StatusReason = "Manager Approved";
await _api.Pages.SaveCommentAsync(comment.ContentId, comment);
}
}
Expand All @@ -116,7 +122,8 @@ public async Task UnApproveAsync(Guid id)

if (comment != null)
{
comment.IsApproved = false;
comment.Status = CommentStatus.Rejected;
comment.StatusReason = "Manually rejected";
await _api.Posts.SaveCommentAsync(comment.ContentId, comment);
}
else
Expand All @@ -125,7 +132,8 @@ public async Task UnApproveAsync(Guid id)

if (comment != null)
{
comment.IsApproved = false;
comment.Status = CommentStatus.Rejected;
comment.StatusReason = "Manually rejected";
await _api.Pages.SaveCommentAsync(comment.ContentId, comment);
}
}
Expand Down
Loading