Skip to content

Commit 31b1909

Browse files
authored
Merge pull request #515 from poppastring/comment-updates-status
Comment updates status close #514
2 parents fee3ed3 + 0639569 commit 31b1909

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pool:
1010

1111
variables:
1212
buildConfiguration: 'Release'
13-
version: 2.21
13+
version: 2.22
1414

1515
steps:
1616
- task: UseDotNet@2

source/DasBlog.Web.UI/Controllers/BlogPostController.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,14 @@ public IActionResult AddComment(AddCommentViewModel addcomment)
394394
{
395395
List<string> errors = new List<string>();
396396

397-
if (!dasBlogSettings.SiteConfiguration.EnableComments)
397+
if (!ModelState.IsValid)
398398
{
399-
return BadRequest();
399+
errors.Add("[Some of your entries are invalid]");
400400
}
401401

402-
if (!ModelState.IsValid)
402+
if (!dasBlogSettings.SiteConfiguration.EnableComments)
403403
{
404-
return Comment(addcomment.TargetEntryId);
404+
errors.Add("Comments are disabled on the site.");
405405
}
406406

407407
// Optional in case of Captcha. Commenting the settings in the config file
@@ -430,9 +430,10 @@ public IActionResult AddComment(AddCommentViewModel addcomment)
430430
}
431431
}
432432

433-
if(errors.Count > 0)
434-
return CommentError(addcomment, errors);
435-
433+
if (errors.Count > 0)
434+
{
435+
return CommentError(addcomment, errors);
436+
}
436437

437438
addcomment.Content = dasBlogSettings.FilterHtml(addcomment.Content);
438439

@@ -447,32 +448,35 @@ public IActionResult AddComment(AddCommentViewModel addcomment)
447448

448449
if (state == NBR.CommentSaveState.Failed)
449450
{
450-
ModelState.AddModelError("", "Comment failed");
451-
return StatusCode(500);
451+
logger.LogError(new EventDataItem(EventCodes.CommentBlocked, null, "Failed to save comment: {0}", commt.TargetTitle));
452+
errors.Add("Failed to save comment.");
452453
}
453454

454455
if (state == NBR.CommentSaveState.SiteCommentsDisabled)
455456
{
456-
ModelState.AddModelError("", "Comments are closed for this post");
457-
return StatusCode(403);
457+
logger.LogError(new EventDataItem(EventCodes.CommentBlocked, null, "Comments are closed for this post: {0}", commt.TargetTitle));
458+
errors.Add("Comments are closed for this post.");
458459
}
459460

460461
if (state == NBR.CommentSaveState.PostCommentsDisabled)
461462
{
462-
ModelState.AddModelError("", "Comment are currently disabled");
463-
return StatusCode(403);
463+
logger.LogError(new EventDataItem(EventCodes.CommentBlocked, null, "Comment are currently disabled: {0}", commt.TargetTitle));
464+
errors.Add("Comment are currently disabled.");
464465
}
465466

466467
if (state == NBR.CommentSaveState.NotFound)
467468
{
468-
ModelState.AddModelError("", "Invalid Target Post Id");
469-
return NotFound();
469+
logger.LogError(new EventDataItem(EventCodes.CommentBlocked, null, "Invalid Post Id: {0}", commt.TargetTitle));
470+
errors.Add("Invalid Post Id.");
470471
}
471472

472-
logger.LogInformation(new EventDataItem(EventCodes.CommentAdded, null, "Comment created on: {0}", commt.TargetTitle));
473+
if (errors.Count > 0)
474+
{
475+
return CommentError(addcomment, errors);
476+
}
473477

478+
logger.LogInformation(new EventDataItem(EventCodes.CommentAdded, null, "Comment created on: {0}", commt.TargetTitle));
474479
BreakSiteCache();
475-
476480
return Comment(addcomment.TargetEntryId);
477481
}
478482

source/DasBlog.Web.UI/Models/BlogViewModels/AddCommentViewModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace DasBlog.Web.Models.BlogViewModels
55
public class AddCommentViewModel
66
{
77
[Required]
8+
[Display(Name = "Name")]
89
[StringLength(60, MinimumLength = 1)]
910
public string Name { get; set; }
1011

@@ -16,10 +17,11 @@ public class AddCommentViewModel
1617

1718
[Display(Name = "Home page (optional)")]
1819
[StringLength(60, MinimumLength = 1)]
20+
[Url(ErrorMessage ="Invalid home page")]
1921
public string HomePage { get; set; }
2022

2123
[Required]
22-
[Display(Name = "Comment")]
24+
[Display(Name = "Content")]
2325
[StringLength(600, MinimumLength = 1)]
2426
public string Content { get; set; }
2527

source/DasBlog.Web.UI/wwwroot/css/site.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
.dbc-calendar .days li {
4242
border-bottom: 1px solid #eee;
43-
min-height: 8rem;
43+
min-height: 10rem;
4444
}
4545

4646
.dbc-calendar .days li .date {

source/DasBlog.Web.UI/wwwroot/css/site.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)