diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 4bbdc361..abbcf7f2 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -452,7 +452,7 @@ namespace RMuseum.Controllers [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] - public async Task Get([FromQuery] PagingParameterModel paging) + public async Task GetRecentComments([FromQuery] PagingParameterModel paging) { var comments = await _ganjoorService.GetRecentComments(paging); if (!string.IsNullOrEmpty(comments.ExceptionString)) @@ -466,6 +466,30 @@ namespace RMuseum.Controllers return Ok(comments.Result.Items); } + /// + /// get list of reported comments + /// + /// + /// + [HttpGet] + [Route("comments/reported")] + [Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + RMuseumSecurableItem.ModerateOperationShortName)] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task GetReportedComments([FromQuery] PagingParameterModel paging) + { + var comments = await _ganjoorService.GetReportedComments(paging); + if (!string.IsNullOrEmpty(comments.ExceptionString)) + { + return BadRequest(comments.ExceptionString); + } + + // Paging Header + HttpContext.Response.Headers.Add("paging-headers", JsonConvert.SerializeObject(comments.Result.PagingMeta)); + + return Ok(comments.Result.Items); + } + /// /// post new comment /// diff --git a/RMuseum/Models/Auth/Memory/RMuseumSecurableItem.cs b/RMuseum/Models/Auth/Memory/RMuseumSecurableItem.cs index a1db891a..c30695cc 100644 --- a/RMuseum/Models/Auth/Memory/RMuseumSecurableItem.cs +++ b/RMuseum/Models/Auth/Memory/RMuseumSecurableItem.cs @@ -152,6 +152,7 @@ namespace RMuseum.Models.Auth.Memory new SecurableItemOperation(ReviewSongs, "بازبینی آهنگ‌های پیشنهادی", false), new SecurableItemOperation(AddSongs, "افزودن آهنگ از هر منبع", false), new SecurableItemOperation(ImportOperationShortName, "ورود اطلاعات از منابع خارجی", false), + new SecurableItemOperation(ModerateOperationShortName, "مدیریت حاشیه‌ها", false), } }, diff --git a/RMuseum/Models/Ganjoor/ViewModels/GanjoorCommentAbuseReportViewModel.cs b/RMuseum/Models/Ganjoor/ViewModels/GanjoorCommentAbuseReportViewModel.cs new file mode 100644 index 00000000..e13866be --- /dev/null +++ b/RMuseum/Models/Ganjoor/ViewModels/GanjoorCommentAbuseReportViewModel.cs @@ -0,0 +1,28 @@ +namespace RMuseum.Models.Ganjoor.ViewModels +{ + /// + /// GanjoorCommentAbuseReport View Model + /// + public class GanjoorCommentAbuseReportViewModel + { + /// + /// id + /// + public int Id { get; set; } + + /// + /// reason code for better grouping: offensive, bogus, other + /// + public string ReasonCode { get; set; } + + /// + /// some explanotory text provided by reporter + /// + public string ReasonText { get; set; } + + /// + /// comment + /// + public GanjoorCommentFullViewModel Comment { get; set; } + } +} diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 1d29c02b..c756435b 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -758,13 +758,20 @@ - + get recent comments + + + get list of reported comments + + + + post new comment @@ -4273,6 +4280,31 @@ poems + + + GanjoorCommentAbuseReport View Model + + + + + id + + + + + reason code for better grouping: offensive, bogus, other + + + + + some explanotory text provided by reporter + + + + + comment + + Id @@ -6192,6 +6224,13 @@ + + + Get list of reported comments + + + + get a random poem from hafez @@ -7039,6 +7078,13 @@ + + + Get list of reported comments + + + + get poem images by id (some fields are intentionally field with blank or null), diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 8ab58147..2f8b452e 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -194,6 +194,12 @@ namespace RMuseum.Services /// Task> GetRecentComments(PagingParameterModel paging); + /// + /// Get list of reported comments + /// + /// + /// + Task> GetReportedComments(PagingParameterModel paging); /// /// get a random poem from hafez diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index 6e9b1a55..a68d4269 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -699,7 +699,69 @@ namespace RMuseum.Services.Implementation } } - + /// + /// Get list of reported comments + /// + /// + /// + public async Task> GetReportedComments(PagingParameterModel paging) + { + try + { + var source = + from report in _context.GanjoorReportedComments + join comment in _context.GanjoorComments.Include(c => c.Poem).Include(c => c.User).Include(c => c.InReplyTo).ThenInclude(r => r.User) + on report.GanjoorCommentId equals comment.Id + orderby report.Id descending + select + new GanjoorCommentAbuseReportViewModel() + { + Id = report.Id, + ReasonCode = report.ReasonCode, + ReasonText = report.ReasonText, + Comment = new GanjoorCommentFullViewModel() + { + Id = comment.Id, + AuthorName = comment.User == null ? comment.AuthorName : $"{comment.User.FirstName} {comment.User.SureName}".Trim(), + AuthorUrl = comment.AuthorUrl, + CommentDate = comment.CommentDate, + HtmlComment = comment.HtmlComment, + InReplayTo = comment.InReplyTo == null ? null : + new GanjoorCommentSummaryViewModel() + { + Id = comment.InReplyTo.Id, + AuthorName = comment.InReplyTo.User == null ? comment.InReplyTo.AuthorName : $"{comment.InReplyTo.User.FirstName} {comment.InReplyTo.User.SureName}".Trim(), + AuthorUrl = comment.InReplyTo.AuthorUrl, + CommentDate = comment.InReplyTo.CommentDate, + HtmlComment = comment.InReplyTo.HtmlComment, + PublishStatus = "" + }, + Poem = new GanjoorPoemSummaryViewModel() + { + Id = comment.Poem.Id, + Title = comment.Poem.FullTitle, + UrlSlug = comment.Poem.FullUrl, + Excerpt = "" + } + } + }; + + (PaginationMetadata PagingMeta, GanjoorCommentAbuseReportViewModel[] Items) paginatedResult = + await QueryablePaginator.Paginate(source, paging); + + + foreach (GanjoorCommentAbuseReportViewModel report in paginatedResult.Items) + { + report.Comment.AuthorName = report.Comment.AuthorName.ToPersianNumbers().ApplyCorrectYeKe(); + } + + return new RServiceResult<(PaginationMetadata PagingMeta, GanjoorCommentAbuseReportViewModel[] Items)>(paginatedResult); + } + catch (Exception exp) + { + return new RServiceResult<(PaginationMetadata PagingMeta, GanjoorCommentAbuseReportViewModel[] Items)>((PagingMeta: null, Items: null), exp.ToString()); + } + } ///