#85 api for moderate (delete other user's) comments
This commit is contained in:
parent
0a5740e30d
commit
604ecacb2f
@ -598,6 +598,7 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// get list of reported comments
|
||||
/// </summary>
|
||||
@ -622,6 +623,30 @@ namespace RMuseum.Controllers
|
||||
return Ok(comments.Result.Items);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// delete other users comment comment
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="reason"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
[Route("comment/moderate")]
|
||||
[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, string reason)
|
||||
{
|
||||
|
||||
var res =
|
||||
await _ganjoorService.DeleteModerateComment(id, reason);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
if (!res.Result)
|
||||
return NotFound();
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// imports data from ganjoor SQLite database
|
||||
/// </summary>
|
||||
|
||||
@ -801,6 +801,14 @@
|
||||
<param name="paging"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.DeleteModerateComment(System.Int32,System.String)">
|
||||
<summary>
|
||||
delete other users comment comment
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<param name="reason"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.ImportLocalSQLiteDb">
|
||||
<summary>
|
||||
imports data from ganjoor SQLite database
|
||||
@ -6237,6 +6245,14 @@
|
||||
<param name="htmlComment"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.DeleteModerateComment(System.Int32,System.String)">
|
||||
<summary>
|
||||
delete a reported or abusive comment
|
||||
</summary>
|
||||
<param name="commentId"></param>
|
||||
<param name="reason"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.DeleteMyComment(System.Guid,System.Int32)">
|
||||
<summary>
|
||||
delete user own comment
|
||||
@ -7100,6 +7116,14 @@
|
||||
<param name="htmlComment"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.DeleteModerateComment(System.Int32,System.String)">
|
||||
<summary>
|
||||
delete a reported or abusive comment
|
||||
</summary>
|
||||
<param name="commentId"></param>
|
||||
<param name="reason"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.DeleteMyComment(System.Guid,System.Int32)">
|
||||
<summary>
|
||||
delete user own comment
|
||||
|
||||
@ -179,6 +179,14 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> EditMyComment(Guid userId, int commentId, string htmlComment);
|
||||
|
||||
/// <summary>
|
||||
/// delete a reported or abusive comment
|
||||
/// </summary>
|
||||
/// <param name="commentId"></param>
|
||||
/// <param name="reason"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> DeleteModerateComment(int commentId, string reason);
|
||||
|
||||
/// <summary>
|
||||
/// delete user own comment
|
||||
/// </summary>
|
||||
|
||||
@ -588,6 +588,62 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// delete a reported or abusive comment
|
||||
/// </summary>
|
||||
/// <param name="commentId"></param>
|
||||
/// <param name="reason"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<bool>> DeleteModerateComment(int commentId, string reason)
|
||||
{
|
||||
try
|
||||
{
|
||||
GanjoorComment comment = await _context.GanjoorComments.Where(c => c.Id == commentId).SingleOrDefaultAsync();
|
||||
if (comment == null)
|
||||
{
|
||||
return new RServiceResult<bool>(false); //not found
|
||||
}
|
||||
|
||||
if (comment.UserId != null)
|
||||
{
|
||||
await _notificationService.PushNotification((Guid)comment.UserId,
|
||||
"حذف حاشیهٔ شما",
|
||||
$"حاشیهٔ شما به دلیل ناسازگاری با قوانین حاشیهگذاری گنجور و طبق گزارشات دیگر کاربران حذف شده است..{Environment.NewLine}" +
|
||||
$"علت ارائه شده برای حذف: {Environment.NewLine}" +
|
||||
$"{reason} {Environment.NewLine}" +
|
||||
$"این متن حاشیهٔ حذف شدهٔ شماست: {Environment.NewLine}" +
|
||||
$"{comment.HtmlComment}"
|
||||
);
|
||||
}
|
||||
|
||||
//if user has got replies, delete them and notify their owners of what happened
|
||||
var replies = await _FindReplies(comment);
|
||||
for (int i = replies.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (replies[i].UserId != null)
|
||||
{
|
||||
await _notificationService.PushNotification((Guid)replies[i].UserId,
|
||||
"حذف پاسخ شما به حاشیه",
|
||||
$"پاسخ شما به یکی از حاشیههای گنجور به دلیل حذف زنجیرهٔ حاشیه توسط یکی از حاشیهگذاران حذف شده است.{Environment.NewLine}" +
|
||||
$"این متن حاشیهٔ حذف شدهٔ شماست: {Environment.NewLine}" +
|
||||
$"{replies[i].HtmlComment}"
|
||||
);
|
||||
}
|
||||
_context.GanjoorComments.Remove(replies[i]);
|
||||
}
|
||||
|
||||
_context.GanjoorComments.Remove(comment);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<bool>(false, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// delete user own comment
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user