diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 056fabae..67ed785a 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -598,6 +598,7 @@ namespace RMuseum.Controllers return Ok(res.Result); } + /// /// get list of reported comments /// @@ -622,6 +623,30 @@ namespace RMuseum.Controllers return Ok(comments.Result.Items); } + /// + /// delete other users comment comment + /// + /// + /// + /// + [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 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(); + } + /// /// imports data from ganjoor SQLite database /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index a8b85bc0..acef2d21 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -801,6 +801,14 @@ + + + delete other users comment comment + + + + + imports data from ganjoor SQLite database @@ -6237,6 +6245,14 @@ + + + delete a reported or abusive comment + + + + + delete user own comment @@ -7100,6 +7116,14 @@ + + + delete a reported or abusive comment + + + + + delete user own comment diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 9f4898aa..6d9fda22 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -179,6 +179,14 @@ namespace RMuseum.Services /// Task> EditMyComment(Guid userId, int commentId, string htmlComment); + /// + /// delete a reported or abusive comment + /// + /// + /// + /// + Task> DeleteModerateComment(int commentId, string reason); + /// /// delete user own comment /// diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index 23e5ba40..620e4bc4 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -588,6 +588,62 @@ namespace RMuseum.Services.Implementation } } + /// + /// delete a reported or abusive comment + /// + /// + /// + /// + public async Task> DeleteModerateComment(int commentId, string reason) + { + try + { + GanjoorComment comment = await _context.GanjoorComments.Where(c => c.Id == commentId).SingleOrDefaultAsync(); + if (comment == null) + { + return new RServiceResult(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(true); + } + catch (Exception exp) + { + return new RServiceResult(false, exp.ToString()); + } + } + + /// /// delete user own comment ///