From 4256197ef4fcd6ee37f61fabba025e030d801e10 Mon Sep 17 00:00:00 2001 From: Mark Downie Date: Tue, 15 Dec 2020 23:52:59 -0500 Subject: [PATCH 1/2] Ensure we have better feedback for comments. Improve data model. Bumped the minor version. --- azure-pipelines.yml | 2 +- .../Controllers/BlogPostController.cs | 38 ++++++++++--------- .../BlogViewModels/AddCommentViewModel.cs | 4 +- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d1a0486b..ca46dc41 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -10,7 +10,7 @@ pool: variables: buildConfiguration: 'Release' - version: 2.21 + version: 2.22 steps: - task: UseDotNet@2 diff --git a/source/DasBlog.Web.UI/Controllers/BlogPostController.cs b/source/DasBlog.Web.UI/Controllers/BlogPostController.cs index 2dc349b4..a7e1f930 100644 --- a/source/DasBlog.Web.UI/Controllers/BlogPostController.cs +++ b/source/DasBlog.Web.UI/Controllers/BlogPostController.cs @@ -394,14 +394,14 @@ public IActionResult AddComment(AddCommentViewModel addcomment) { List errors = new List(); - if (!dasBlogSettings.SiteConfiguration.EnableComments) + if (!ModelState.IsValid) { - return BadRequest(); + errors.Add("[Some of your entries are invalid]"); } - if (!ModelState.IsValid) + if (!dasBlogSettings.SiteConfiguration.EnableComments) { - return Comment(addcomment.TargetEntryId); + errors.Add("Comments are disabled on the site."); } // Optional in case of Captcha. Commenting the settings in the config file @@ -430,9 +430,10 @@ public IActionResult AddComment(AddCommentViewModel addcomment) } } - if(errors.Count > 0) - return CommentError(addcomment, errors); - + if (errors.Count > 0) + { + return CommentError(addcomment, errors); + } addcomment.Content = dasBlogSettings.FilterHtml(addcomment.Content); @@ -447,32 +448,35 @@ public IActionResult AddComment(AddCommentViewModel addcomment) if (state == NBR.CommentSaveState.Failed) { - ModelState.AddModelError("", "Comment failed"); - return StatusCode(500); + logger.LogError(new EventDataItem(EventCodes.CommentBlocked, null, "Failed to save comment: {0}", commt.TargetTitle)); + errors.Add("Failed to save comment."); } if (state == NBR.CommentSaveState.SiteCommentsDisabled) { - ModelState.AddModelError("", "Comments are closed for this post"); - return StatusCode(403); + logger.LogError(new EventDataItem(EventCodes.CommentBlocked, null, "Comments are closed for this post: {0}", commt.TargetTitle)); + errors.Add("Comments are closed for this post."); } if (state == NBR.CommentSaveState.PostCommentsDisabled) { - ModelState.AddModelError("", "Comment are currently disabled"); - return StatusCode(403); + logger.LogError(new EventDataItem(EventCodes.CommentBlocked, null, "Comment are currently disabled: {0}", commt.TargetTitle)); + errors.Add("Comment are currently disabled."); } if (state == NBR.CommentSaveState.NotFound) { - ModelState.AddModelError("", "Invalid Target Post Id"); - return NotFound(); + logger.LogError(new EventDataItem(EventCodes.CommentBlocked, null, "Invalid Post Id: {0}", commt.TargetTitle)); + errors.Add("Invalid Post Id."); } - logger.LogInformation(new EventDataItem(EventCodes.CommentAdded, null, "Comment created on: {0}", commt.TargetTitle)); + if (errors.Count > 0) + { + return CommentError(addcomment, errors); + } + logger.LogInformation(new EventDataItem(EventCodes.CommentAdded, null, "Comment created on: {0}", commt.TargetTitle)); BreakSiteCache(); - return Comment(addcomment.TargetEntryId); } diff --git a/source/DasBlog.Web.UI/Models/BlogViewModels/AddCommentViewModel.cs b/source/DasBlog.Web.UI/Models/BlogViewModels/AddCommentViewModel.cs index 59695c52..25ba19d5 100644 --- a/source/DasBlog.Web.UI/Models/BlogViewModels/AddCommentViewModel.cs +++ b/source/DasBlog.Web.UI/Models/BlogViewModels/AddCommentViewModel.cs @@ -5,6 +5,7 @@ namespace DasBlog.Web.Models.BlogViewModels public class AddCommentViewModel { [Required] + [Display(Name = "Name")] [StringLength(60, MinimumLength = 1)] public string Name { get; set; } @@ -16,10 +17,11 @@ public class AddCommentViewModel [Display(Name = "Home page (optional)")] [StringLength(60, MinimumLength = 1)] + [Url(ErrorMessage ="Invalid home page")] public string HomePage { get; set; } [Required] - [Display(Name = "Comment")] + [Display(Name = "Content")] [StringLength(600, MinimumLength = 1)] public string Content { get; set; } From 0639569e24183ed6fa9ce36911d35bad1286af64 Mon Sep 17 00:00:00 2001 From: Mark Downie Date: Wed, 16 Dec 2020 00:02:49 -0500 Subject: [PATCH 2/2] Allow post titles to be longer in the calendar view. --- source/DasBlog.Web.UI/wwwroot/css/site.css | 2 +- source/DasBlog.Web.UI/wwwroot/css/site.min.css | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/DasBlog.Web.UI/wwwroot/css/site.css b/source/DasBlog.Web.UI/wwwroot/css/site.css index e5eb1ece..3bab0a9d 100644 --- a/source/DasBlog.Web.UI/wwwroot/css/site.css +++ b/source/DasBlog.Web.UI/wwwroot/css/site.css @@ -40,7 +40,7 @@ .dbc-calendar .days li { border-bottom: 1px solid #eee; - min-height: 8rem; + min-height: 10rem; } .dbc-calendar .days li .date { diff --git a/source/DasBlog.Web.UI/wwwroot/css/site.min.css b/source/DasBlog.Web.UI/wwwroot/css/site.min.css index 58e210d2..cd46e1ee 100644 --- a/source/DasBlog.Web.UI/wwwroot/css/site.min.css +++ b/source/DasBlog.Web.UI/wwwroot/css/site.min.css @@ -1 +1 @@ -.clearfix::after,.dbc-calendar ol::after{content:".";display:block;height:0;clear:both;visibility:hidden}.dbc-calendar{border-radius:10px}.month{font-size:2rem}@media(min-width:992px){.month{font-size:3.5rem}}.dbc-calendar ol li{float:left;width:14.28571%}.dbc-calendar .day-names{border-bottom:1px solid #eee}.dbc-calendar .day-names li{text-transform:uppercase;margin-bottom:.5rem}.dbc-calendar .days li{border-bottom:1px solid #eee;min-height:8rem}.dbc-calendar .days li .date{margin:.5rem 0}.dbc-calendar .days li .event{font-size:.75rem;padding:.2rem .1rem .2rem .1rem;overflow:hidden;text-overflow:ellipsis;margin-bottom:1px}.dbc-calendar .days li .event.span-2{width:200%}.dbc-calendar .days li .event.begin{border-radius:1rem 0 0 1rem}.dbc-calendar .days li .event.end{border-radius:0 1rem 1rem 0}.dbc-calendar .days li .event.clear{background:none}.dbc-calendar .days li:nth-child(n+29){border-bottom:none}.dbc-calendar .days li.outside .date{color:#ddd}.dbc-activity-table-column{border:solid 1px;padding:3px;margin-top:3px;margin-bottom:3px}.dbc-activity-table-header-column{border-left:solid 1px;border-right:solid 1px;border-bottom:solid 2px;border-top:solid 1px;padding:3px;font-size:105%;font-weight:bold}.dbc-activity-table{margin-top:10px;margin-bottom:10px;border:solid 1px;width:100%;border-collapse:collapse}.dbc-activity-rable-row-error{BACKGROUND-COLOR:lightpink}.dbc-activity-table-row-blocked{BACKGROUND-COLOR:lightgoldenrodyellow}.dbc-activity-table-row-security-failure{BACKGROUND-COLOR:lightsalmon}.dbc-blogpost-fields-allignment-compatibility{padding-left:15px;padding-right:15px}@media screen and (max-width:767px){.carousel-caption{display:none}}.dbc-form-check{position:relative;display:block}.dbc-form-group{margin-bottom:1rem}.dbc-col-form-label{padding-top:calc(.375rem + 1px);padding-bottom:calc(.375rem + 1px);margin-bottom:0;font-size:inherit;line-height:1.5}.dbc-post-content img{width:100%;height:100%} \ No newline at end of file +.clearfix::after,.dbc-calendar ol::after{content:".";display:block;height:0;clear:both;visibility:hidden}.dbc-calendar{border-radius:10px}.month{font-size:2rem}@media(min-width:992px){.month{font-size:3.5rem}}.dbc-calendar ol li{float:left;width:14.28571%}.dbc-calendar .day-names{border-bottom:1px solid #eee}.dbc-calendar .day-names li{text-transform:uppercase;margin-bottom:.5rem}.dbc-calendar .days li{border-bottom:1px solid #eee;min-height:10rem}.dbc-calendar .days li .date{margin:.5rem 0}.dbc-calendar .days li .event{font-size:.75rem;padding:.2rem .1rem .2rem .1rem;overflow:hidden;text-overflow:ellipsis;margin-bottom:1px}.dbc-calendar .days li .event.span-2{width:200%}.dbc-calendar .days li .event.begin{border-radius:1rem 0 0 1rem}.dbc-calendar .days li .event.end{border-radius:0 1rem 1rem 0}.dbc-calendar .days li .event.clear{background:none}.dbc-calendar .days li:nth-child(n+29){border-bottom:none}.dbc-calendar .days li.outside .date{color:#ddd}.dbc-activity-table-column{border:solid 1px;padding:3px;margin-top:3px;margin-bottom:3px}.dbc-activity-table-header-column{border-left:solid 1px;border-right:solid 1px;border-bottom:solid 2px;border-top:solid 1px;padding:3px;font-size:105%;font-weight:bold}.dbc-activity-table{margin-top:10px;margin-bottom:10px;border:solid 1px;width:100%;border-collapse:collapse}.dbc-activity-rable-row-error{BACKGROUND-COLOR:lightpink}.dbc-activity-table-row-blocked{BACKGROUND-COLOR:lightgoldenrodyellow}.dbc-activity-table-row-security-failure{BACKGROUND-COLOR:lightsalmon}.dbc-blogpost-fields-allignment-compatibility{padding-left:15px;padding-right:15px}@media screen and (max-width:767px){.carousel-caption{display:none}}.dbc-form-check{position:relative;display:block}.dbc-form-group{margin-bottom:1rem}.dbc-col-form-label{padding-top:calc(.375rem + 1px);padding-bottom:calc(.375rem + 1px);margin-bottom:0;font-size:inherit;line-height:1.5}.dbc-post-content img{width:100%;height:100%} \ No newline at end of file