Skip to content

Commit

Permalink
Merge pull request #98 from sbwalker/master
Browse files Browse the repository at this point in the history
notify blog owner of new comments, HtmlEncode summary info injected into HeadContent,  remove requirement for a publish time, improve publish workflow
  • Loading branch information
sbwalker authored Sep 23, 2024
2 parents dcdc22d + dd387bf commit 409cfdd
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 34 deletions.
40 changes: 17 additions & 23 deletions Client/Edit.razor
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,20 @@
</div>
<br />
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="published" ResourceKey="Published" HelpText="Indicate if this blog is visible to all users or only editors">Published? </Label>
<Label Class="col-sm-3" For="published" ResourceKey="Published" HelpText="Indicate if this version of blog content is visible to all users or only editors (ie.draft)">Published? </Label>
<div class="col-sm-9">
<input id="published" type="checkbox" class="form-check-input" @bind="@_isPublished" />
<select id="published" class="form-select" @bind="@_published">
<option value="True">@SharedLocalizer["Yes"]</option>
<option value="False">@SharedLocalizer["No"]</option>
</select>
</div>
</div>
@if (_isPublished)
@if (_published == "True")
{
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="publishDate" ResourceKey="PublishDate" HelpText="Select the publish date of your blog">Publish Date: </Label>
<Label Class="col-sm-3" For="publishDate" ResourceKey="PublishDate" HelpText="Select the publish date of this blog post. This date controls both visibility of the blog post as well as sort order in the summary view.">Publish Date: </Label>
<div class="col-sm-9">
<input id="publishDate" type="datetime-local" class="form-control" @bind="@_publishDate" maxlength="50" />
<input id="publishDate" type="date" class="form-control" @bind="@_publishDate" />
</div>
</div>
}
Expand Down Expand Up @@ -115,7 +118,7 @@
@if (_id != -1)
{
<ActionDialog Header="Delete Blog" Message="Are You Sure You Wish To Delete This Blog?" Action="Delete" Security="SecurityAccessLevel.Edit" Class="btn btn-danger ms-1" ResourceKey="DeleteBlog" OnClick="@(async () => await DeleteBlog())" />
@if (_isPublished && (_publishDate == null || _publishDate <= DateTime.UtcNow) && SettingService.GetSetting(ModuleState.Settings, "Subscriptions", "False") == "True")
@if (_published == "True" && _publishDate <= DateTime.UtcNow && SettingService.GetSetting(ModuleState.Settings, "Subscriptions", "False") == "True")
{
<button type="button" class="btn btn-info ms-1" @onclick="Notify">@Localizer["Notify"]</button>
}
Expand Down Expand Up @@ -216,7 +219,7 @@
private string _summary;
private RichTextEditor RichTextEditorHtml;
private string _content = "";
private bool _isPublished;
private string _published = "False";
private DateTime? _publishDate;
private string _tagsValue;
private string _allowComments = "True";
Expand Down Expand Up @@ -264,7 +267,7 @@
{
_summary = blogContent.Summary;
_content = Utilities.FormatContent(blogContent.Content, PageState.Alias, "render");
_isPublished = blogContent.IsPublished;
_published = blogContent.IsPublished.ToString();
_publishDate = blogContent.PublishDate;
}
}
Expand Down Expand Up @@ -336,32 +339,23 @@
}
}

//update blog content
// update blog content
var blogContents = await BlogContentService.GetBlogContentAsync(ModuleState.ModuleId, _id);
var blogContent = blogContents.OrderByDescending(i => i.BlogContentId).FirstOrDefault();
if (_summary != blogContent?.Summary || _content != blogContent?.Content || _isPublished != blogContent?.IsPublished || _publishDate != blogContent?.PublishDate)
if (_summary != blogContent?.Summary || _content != blogContent?.Content || _published != blogContent?.IsPublished.ToString() || _publishDate != blogContent?.PublishDate)
{
var contentChanged = _summary != blogContent?.Summary || _content != blogContent?.Content;
if (contentChanged && (blogContent == null || blogContent.IsPublished && (blogContent.PublishDate == null || blogContent.PublishDate <= DateTime.UtcNow)))
{
//set publish status to draft for new edited version.
if (blogContent != null)
{
_isPublished = false;
_publishDate = null;
}
else
{
_publishDate = (!_isPublished) ? null : (_publishDate == null) ? DateTime.UtcNow : _publishDate;
}
_publishDate = (_published != "True") ? null : (_publishDate == null) ? DateTime.UtcNow : _publishDate;

blogContent = new BlogContent
{
BlogId = _id,
Version = blogContent != null ? blogContent.Version + 1 : BlogConstants.DefaultVersion,
Summary = _summary,
Content = _content,
IsPublished = _isPublished,
IsPublished = bool.Parse(_published),
PublishDate = _publishDate
};

Expand All @@ -371,8 +365,8 @@
{
blogContent.Summary = _summary;
blogContent.Content = _content;
blogContent.IsPublished = _isPublished;
blogContent.PublishDate = (!_isPublished) ? null : (_publishDate == null) ? DateTime.UtcNow : _publishDate;
blogContent.IsPublished = bool.Parse(_published);
blogContent.PublishDate = (_published != "True") ? null : (_publishDate == null) ? DateTime.UtcNow : _publishDate;

await BlogContentService.UpdateBlogContentAsync(ModuleState.ModuleId, blogContent);
}
Expand Down
2 changes: 1 addition & 1 deletion Client/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ else

if (!string.IsNullOrEmpty(blogContent.Summary))
{
AddHeadContent($"<meta name=\"description\" content=\"{blogContent.Summary}\" />");
AddHeadContent($"<meta name=\"description\" content=\"{WebUtility.HtmlEncode(blogContent.Summary)}\" />");
}
if (!string.IsNullOrEmpty(_blog.Tags))
{
Expand Down
4 changes: 2 additions & 2 deletions Client/Resources/Oqtane.Blogs.Edit.resx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<value>Save</value>
</data>
<data name="Published.HelpText" xml:space="preserve">
<value>Indicate if this blog is visible to all users or only editors</value>
<value>Indicate if this version of blog content is visible to all users or only editors (ie.draft)</value>
</data>
<data name="Published.Text" xml:space="preserve">
<value>Published?</value>
Expand Down Expand Up @@ -190,7 +190,7 @@
<value>Tags:</value>
</data>
<data name="PublishDate.HelpText" xml:space="preserve">
<value>Select the publish date of your blog</value>
<value>Select the publish date of this blog post. This date controls both visibility of the blog post as well as sort order in the summary view.</value>
</data>
<data name="PublishDate.Text" xml:space="preserve">
<value>Publish Date:</value>
Expand Down
12 changes: 6 additions & 6 deletions Client/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
</select>
</div>
</div>
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="sender" ResourceKey="Sender" ResourceType="@resourceType" HelpText="Email address which notifications will be sent from">Sender: </Label>
<div class="col-sm-9">
<input id="sender" type="text" class="form-control" @bind="@_sender" />
</div>
</div>
<Section Name="Subscriptions" Heading="Subscriptions" ResourceKey="Subscriptions">
<div class="container">
<div class="row mb-1 align-items-center">
Expand All @@ -83,12 +89,6 @@
</select>
</div>
</div>
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="sender" ResourceKey="Sender" ResourceType="@resourceType" HelpText="Email address which subscriptions will be sent from">Sender: </Label>
<div class="col-sm-9">
<input id="sender" type="text" class="form-control" @bind="@_sender" />
</div>
</div>
</div>
</Section>
<Section Name="SEO" Heading="SEO" ResourceKey="SEO">
Expand Down
17 changes: 15 additions & 2 deletions Server/Controllers/BlogCommentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using Oqtane.Repository;
using Oqtane.Security;
using System.Net;
using Oqtane.Extensions;
using System.Linq;

namespace Oqtane.Blogs.Controllers
{
Expand All @@ -21,14 +23,16 @@ public class BlogCommentController : ModuleControllerBase
private readonly IBlogRepository _blogRepository;
private readonly IBlogCommentRepository _blogCommentRepository;
private readonly INotificationRepository _notificationRepository;
private readonly ISettingRepository _settingRepository;
private readonly IUserPermissions _userPermissions;
private readonly Alias _alias;

public BlogCommentController(IBlogRepository blogRepository, IBlogCommentRepository blogCommentRepository, INotificationRepository notificationRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor) : base(logger,accessor)
public BlogCommentController(IBlogRepository blogRepository, IBlogCommentRepository blogCommentRepository, INotificationRepository notificationRepository, ISettingRepository settingRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor) : base(logger,accessor)
{
_blogRepository = blogRepository;
_blogCommentRepository = blogCommentRepository;
_notificationRepository = notificationRepository;
_settingRepository = settingRepository;
_userPermissions = userPermissions;
_alias = tenantManager.GetAlias();
}
Expand Down Expand Up @@ -80,9 +84,18 @@ public BlogComment Post([FromBody] BlogComment blogComment)
if (!blogComment.IsPublished)
{
string url = _alias.Protocol + _alias.Name + ((blogComment.PagePath == "") ? "" : "/" + blogComment.PagePath) + "/!/" + blogComment.BlogId.ToString() + "/?comment=" + blogComment.BlogCommentId.ToString() + "&created=" + blogComment.CreatedOn.ToString("yyyyMMddHHmmssfff");
var body = "You Recently Submitted A Comment To The Blog: " + blog.Title + ". Please Use The Following Link To Publish Or Edit Your Comment: " + url;
var body = "You Recently Submitted A Comment To The Blog " + blog.Title + ". Please Use The Following Link To Publish Or Edit Your Comment: " + url;
var notification = new Notification(_alias.SiteId, blogComment.Name, blogComment.Email, "Blog Comment Authorization", body);
_notificationRepository.AddNotification(notification);

var settings = _settingRepository.GetSettings(EntityNames.Module, blog.ModuleId);
var sender = settings.FirstOrDefault(item => item.SettingName == "Sender");
if (sender != null)
{
body = "A Comment Was Recently Submitted To The Blog " + blog.Title + " By " + blogComment.Name + ". Please Use The Following Link To Review The Comment: " + url;
notification = new Notification(_alias.SiteId, "Blog Administrator", sender.SettingValue, "Blog Comment Notification", body);
_notificationRepository.AddNotification(notification);
}
}
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Blog Comment Added {blogComment}", blogComment);
}
Expand Down

0 comments on commit 409cfdd

Please sign in to comment.