#135 improving comment moderation
This commit is contained in:
parent
5ae483281f
commit
7c85f1e660
@ -35,7 +35,7 @@ else
|
||||
else
|
||||
color = "gray";
|
||||
|
||||
<div style="background-color:@color" id="comment-@report.Comment.Id">
|
||||
<div style="background-color:@color" id="report-@report.Id">
|
||||
<p style="color:red">
|
||||
@report.ReasonCode
|
||||
</p>
|
||||
@ -50,7 +50,7 @@ else
|
||||
@report.Comment.AuthorName <small>در @report.Comment.CommentDate.ToFriendlyPersianDateTextify()</small> دربارهٔ <a href="@report.Comment.Poem.UrlSlug#comment-@report.Comment.Id">@report.Comment.Poem.Title</a>
|
||||
</p>
|
||||
</blockquote>
|
||||
<a role="button" onclick="deleteComment(@report.Comment.Id, '@report.ReasonCode', '@report.ReasonText')" class="actionlink" style="color:green" title="تأیید و حذف حاشیه">✓ درست میگوید</a>
|
||||
<a role="button" onclick="moderateReportedComment(@report.Id)" class="actionlink" style="color:green" title="تأیید و حذف حاشیه">✓ درست میگوید</a>
|
||||
|
||||
<a role="button" onclick="deleteReport(@report.Id, @report.Comment.Id)" class="actionlink" style="color:red" title="حذف گزارش">گزارش نابجا ❌</a>
|
||||
</div>
|
||||
|
||||
@ -144,27 +144,14 @@ namespace GanjooRazor.Areas.User.Pages
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostModerateComment(int id, string reasonCode, string reasonText)
|
||||
public async Task<IActionResult> OnPostModerateComment(int id)
|
||||
{
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
string reason;
|
||||
switch(reasonCode)
|
||||
{
|
||||
case "offensive":
|
||||
reason = "توهین آمیز است. " + reasonText;
|
||||
break;
|
||||
case "bogus":
|
||||
reason = "نامفهوم است. " + reasonText;
|
||||
break;
|
||||
default:
|
||||
reason = reasonText;
|
||||
break;
|
||||
}
|
||||
|
||||
var response = await secureClient.PostAsync($"{APIRoot.Url}/api/ganjoor/comment/moderate/{id}", new StringContent(JsonConvert.SerializeObject(reason), Encoding.UTF8, "application/json"));
|
||||
var response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/ganjoor/comment/reported/moderate/{id}");
|
||||
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
@ -173,7 +160,7 @@ namespace GanjooRazor.Areas.User.Pages
|
||||
|
||||
}
|
||||
}
|
||||
return await OnGetAsync();
|
||||
return new OkResult();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnDeleteReport(int id)
|
||||
@ -191,7 +178,7 @@ namespace GanjooRazor.Areas.User.Pages
|
||||
|
||||
}
|
||||
}
|
||||
return await OnGetAsync();
|
||||
return new OkResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,6 +78,7 @@
|
||||
<input type="radio" asp-for="Report.ReasonCode" value="brokenlink ">لینک شکسته است.<br>
|
||||
<input type="radio" asp-for="Report.ReasonCode" value="ad ">تبلیغاتی است.<br>
|
||||
<input type="radio" asp-for="Report.ReasonCode" value="bogus">نامفهوم است.<br>
|
||||
<input type="radio" asp-for="Report.ReasonCode" value="latin">فارسی ننوشته است.<br>
|
||||
<input type="radio" asp-for="Report.ReasonCode" value="other"> دلیل دیگری دارم (کوتاه):<br>
|
||||
<input asp-for="Report.ReasonText" maxlength="30" />
|
||||
<input type="hidden" asp-for="Report.CommentId" />
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
<script src="/lib/tinymce/tinymce.min.js"></script>
|
||||
<script>tinymce.init({ selector: 'textarea.editor', language: 'fa_IR' });</script>
|
||||
<script>
|
||||
function deleteComment(commentId, reasonCode, reasonText) {
|
||||
function moderateReportedComment(reportId) {
|
||||
if (!confirm('آیا از حذف این حاشیه اطمینان دارید؟'))
|
||||
return;
|
||||
|
||||
@ -25,19 +25,17 @@
|
||||
type: "POST",
|
||||
url: '?handler=ModerateComment',
|
||||
data: {
|
||||
id: commentId,
|
||||
reasonCode: reasonCode,
|
||||
reasonText: reasonText
|
||||
id: reportId,
|
||||
},
|
||||
success: function () {
|
||||
var commentBlockId = '#comment-' + commentId;
|
||||
var commentBlockId = '#report-' + reportId;
|
||||
$(commentBlockId).remove();
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function deleteReport(reportId, commentId) {
|
||||
function deleteReport(reportId) {
|
||||
$.ajax({
|
||||
type: "DELETE",
|
||||
url: '?handler=Report',
|
||||
@ -45,7 +43,7 @@
|
||||
id: reportId
|
||||
},
|
||||
success: function () {
|
||||
var commentBlockId = '#comment-' + commentId;
|
||||
var commentBlockId = '#report-' + reportId;
|
||||
$(commentBlockId).remove();
|
||||
},
|
||||
});
|
||||
|
||||
@ -972,22 +972,21 @@ namespace RMuseum.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// delete other users comment comment
|
||||
/// delete reported other users comment comment
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="reason"></param>
|
||||
/// <param name="reportid"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("comment/moderate/{id}")]
|
||||
[HttpDelete]
|
||||
[Route("comment/reported/moderate/{reportid}")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + RMuseumSecurableItem.ModerateOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
|
||||
public async Task<IActionResult> DeleteModerateComment(int id, [FromBody]string reason)
|
||||
public async Task<IActionResult> DeleteModerateComment(int reportid)
|
||||
{
|
||||
|
||||
var res =
|
||||
await _ganjoorService.DeleteModerateComment(id, reason);
|
||||
await _ganjoorService.DeleteModerateComment(reportid);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
if (!res.Result)
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:3439",
|
||||
"applicationUrl": "http://localhost:3439/",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
|
||||
@ -933,12 +933,11 @@
|
||||
<param name="paging"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.DeleteModerateComment(System.Int32,System.String)">
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.DeleteModerateComment(System.Int32)">
|
||||
<summary>
|
||||
delete other users comment comment
|
||||
delete reported other users comment comment
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<param name="reason"></param>
|
||||
<param name="reportid"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.ImportLocalSQLiteDb">
|
||||
@ -7185,12 +7184,11 @@
|
||||
<param name="htmlComment"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.DeleteModerateComment(System.Int32,System.String)">
|
||||
<member name="M:RMuseum.Services.IGanjoorService.DeleteModerateComment(System.Int32)">
|
||||
<summary>
|
||||
delete a reported or abusive comment
|
||||
delete a reported comment
|
||||
</summary>
|
||||
<param name="commentId"></param>
|
||||
<param name="reason"></param>
|
||||
<param name="reportId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.DeleteMyComment(System.Guid,System.Int32)">
|
||||
@ -8438,12 +8436,11 @@
|
||||
<param name="htmlComment"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.DeleteModerateComment(System.Int32,System.String)">
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.DeleteModerateComment(System.Int32)">
|
||||
<summary>
|
||||
delete a reported or abusive comment
|
||||
delete a reported comment
|
||||
</summary>
|
||||
<param name="commentId"></param>
|
||||
<param name="reason"></param>
|
||||
<param name="repordId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.DeleteMyComment(System.Guid,System.Int32)">
|
||||
|
||||
@ -186,12 +186,11 @@ namespace RMuseum.Services
|
||||
Task<RServiceResult<bool>> EditMyComment(Guid userId, int commentId, string htmlComment);
|
||||
|
||||
/// <summary>
|
||||
/// delete a reported or abusive comment
|
||||
/// delete a reported comment
|
||||
/// </summary>
|
||||
/// <param name="commentId"></param>
|
||||
/// <param name="reason"></param>
|
||||
/// <param name="reportId"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> DeleteModerateComment(int commentId, string reason);
|
||||
Task<RServiceResult<bool>> DeleteModerateComment(int reportId);
|
||||
|
||||
/// <summary>
|
||||
/// delete user own comment
|
||||
|
||||
@ -764,25 +764,66 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// delete a reported or abusive comment
|
||||
/// delete a reported comment
|
||||
/// </summary>
|
||||
/// <param name="commentId"></param>
|
||||
/// <param name="reason"></param>
|
||||
/// <param name="repordId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<bool>> DeleteModerateComment(int commentId, string reason)
|
||||
public async Task<RServiceResult<bool>> DeleteModerateComment(int repordId)
|
||||
{
|
||||
try
|
||||
{
|
||||
GanjoorComment comment = await _context.GanjoorComments.Where(c => c.Id == commentId).SingleOrDefaultAsync();
|
||||
GanjoorCommentAbuseReport report = await _context.GanjoorReportedComments.Where(r => r.Id == repordId).SingleOrDefaultAsync();
|
||||
if (report == null)
|
||||
{
|
||||
return new RServiceResult<bool>(false);
|
||||
}
|
||||
|
||||
|
||||
GanjoorComment comment = await _context.GanjoorComments.Where(c => c.Id == report.GanjoorCommentId).SingleOrDefaultAsync();
|
||||
if (comment == null)
|
||||
{
|
||||
return new RServiceResult<bool>(false); //not found
|
||||
}
|
||||
|
||||
await CacheCleanForComment(commentId);
|
||||
var commentId = report.GanjoorCommentId;
|
||||
|
||||
|
||||
if (comment.UserId != null)
|
||||
{
|
||||
string reason = "";
|
||||
switch (report.ReasonCode)
|
||||
{
|
||||
case "offensive":
|
||||
reason = "توهینآمیز است.";
|
||||
break;
|
||||
case "religious":
|
||||
reason = "بحث مذهبی کرده.";
|
||||
break;
|
||||
case "repeated":
|
||||
reason = "تکراری است.";
|
||||
break;
|
||||
case "unrelated":
|
||||
reason = "به این شعر ربطی ندارد.";
|
||||
break;
|
||||
case "brokenlink":
|
||||
reason = "لینک شکسته است.";
|
||||
break;
|
||||
case "ad":
|
||||
reason = "تبلیغاتی است.";
|
||||
break;
|
||||
case "bogus":
|
||||
reason = "نامفهوم است.";
|
||||
break;
|
||||
case "latin":
|
||||
reason = "فارسی ننوشته.";
|
||||
break;
|
||||
case "other":
|
||||
reason = "دلیل دیگر";
|
||||
break;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(report.ReasonText))
|
||||
reason += $" {report.ReasonText}";
|
||||
reason = reason.Trim();
|
||||
reason = string.IsNullOrEmpty(reason) ? "" : $"علت ارائه شده برای حذف یا متن گزارش کاربر شاکی: {Environment.NewLine}" +
|
||||
$"{reason} {Environment.NewLine}";
|
||||
await _notificationService.PushNotification((Guid)comment.UserId,
|
||||
@ -813,6 +854,8 @@ namespace RMuseum.Services.Implementation
|
||||
_context.GanjoorComments.Remove(comment);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
await CacheCleanForComment(report.GanjoorCommentId);
|
||||
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user