Skip to content

Commit

Permalink
Merge pull request #515 from poppastring/comment-updates-status
Browse files Browse the repository at this point in the history
Comment updates status

close #514
  • Loading branch information
poppastring authored Dec 16, 2020
2 parents fee3ed3 + 0639569 commit 31b1909
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pool:

variables:
buildConfiguration: 'Release'
version: 2.21
version: 2.22

steps:
- task: UseDotNet@2
Expand Down
38 changes: 21 additions & 17 deletions source/DasBlog.Web.UI/Controllers/BlogPostController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,14 @@ public IActionResult AddComment(AddCommentViewModel addcomment)
{
List<string> errors = new List<string>();

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
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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; }

Expand Down
2 changes: 1 addition & 1 deletion source/DasBlog.Web.UI/wwwroot/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

.dbc-calendar .days li {
border-bottom: 1px solid #eee;
min-height: 8rem;
min-height: 10rem;
}

.dbc-calendar .days li .date {
Expand Down
2 changes: 1 addition & 1 deletion source/DasBlog.Web.UI/wwwroot/css/site.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 31b1909

Please sign in to comment.