Merge pull request #2025 from sbwalker/dev

Added more constructors for convenience in creating  Notification objects. Refactored to use the new constructors where applicable. Fixed localization key issue in Site Settings and added scroll to top when testing SMTP.
This commit is contained in:
Shaun Walker 2022-02-24 08:51:10 -05:00 committed by GitHub
commit 893b09e7e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 25 deletions

View File

@ -605,8 +605,10 @@
await SettingService.UpdateSiteSettingsAsync(settings, PageState.Site.SiteId);
await logger.LogInformation("Site SMTP Settings Saved");
await NotificationService.AddNotificationAsync(new Notification(PageState.Site.SiteId, PageState.User.DisplayName, PageState.User.Email, PageState.User.DisplayName, PageState.User.Email, PageState.Site.Name + " SMTP Configuration Test", "SMTP Server Is Configured Correctly."));
await NotificationService.AddNotificationAsync(new Notification(PageState.Site.SiteId, PageState.User, PageState.Site.Name + " SMTP Configuration Test", "SMTP Server Is Configured Correctly."));
AddModuleMessage(Localizer["Info.Smtp.SaveSettings"], MessageType.Info);
var interop = new Interop(JSRuntime);
await interop.ScrollTo(0, 0, "smooth");
}
catch (Exception ex)
{
@ -616,7 +618,7 @@
}
else
{
AddModuleMessage(Localizer["Message.required.Smtp"], MessageType.Warning);
AddModuleMessage(Localizer["Message.Required.Smtp"], MessageType.Warning);
}
}

View File

@ -49,7 +49,7 @@
var user = await UserService.GetUserAsync(username, PageState.Site.SiteId);
if (user != null)
{
var notification = new Notification(PageState.Site.SiteId, PageState.User, user, subject, body, null);
var notification = new Notification(PageState.Site.SiteId, PageState.User, user, subject, body);
notification = await NotificationService.AddNotificationAsync(notification);
await logger.LogInformation("Notification Created {NotificationId}", notification.NotificationId);
NavigationManager.NavigateTo(NavigateUrl());

View File

@ -173,7 +173,7 @@ namespace Oqtane.Controllers
string token = await _identityUserManager.GenerateEmailConfirmationTokenAsync(identityuser);
string url = HttpContext.Request.Scheme + "://" + _alias.Name + "/login?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
string body = "Dear " + user.DisplayName + ",\n\nIn Order To Complete The Registration Of Your User Account Please Click The Link Displayed Below:\n\n" + url + "\n\nThank You!";
var notification = new Notification(user.SiteId, null, newUser, "User Account Verification", body, null);
var notification = new Notification(user.SiteId, newUser, "User Account Verification", body);
_notifications.AddNotification(notification);
}
@ -428,7 +428,7 @@ namespace Oqtane.Controllers
"\n\nIf you did not request to reset your password you can safely ignore this message." +
"\n\nThank You!";
var notification = new Notification(user.SiteId, null, user, "User Password Reset", body, null);
var notification = new Notification(user.SiteId, user, "User Password Reset", body);
_notifications.AddNotification(notification);
_logger.Log(LogLevel.Information, this, LogFunction.Security, "Password Reset Notification Sent For {Username}", user.Username);
}

View File

@ -208,7 +208,7 @@ namespace Oqtane.Infrastructure
if (userrole.Role.Name == RoleNames.Host)
{
var url = _accessor.HttpContext.Request.Scheme + "://" + _tenantManager.GetAlias().Name + "/admin/log";
var notification = new Notification(log.SiteId.Value, null, userrole.User, "Site " + log.Level + " Notification", "Please visit " + url + " for more information", null);
var notification = new Notification(log.SiteId.Value, userrole.User, "Site " + log.Level + " Notification", "Please visit " + url + " for more information");
_notifications.AddNotification(notification);
}
}

View File

@ -94,9 +94,46 @@ namespace Oqtane.Models
/// </summary>
public DateTime? SendOn { get; set; }
// constructors
public Notification() {}
public Notification(int siteId, User to, string subject, string body)
{
ConstructNotification(siteId, null, "", "", to, "", "", subject, body, null, null);
}
public Notification(int siteId, User to, string subject, string body, DateTime sendOn)
{
ConstructNotification(siteId, null, "", "", to, "", "", subject, body, null, sendOn);
}
public Notification(int siteId, User from, User to, string subject, string body)
{
ConstructNotification(siteId, from, "", "", to, "", "", subject, body, null, null);
}
public Notification(int siteId, User from, User to, string subject, string body, int? parentId)
{
ConstructNotification(siteId, from, "", "", to, "", "", subject, body, parentId, null);
}
public Notification(int siteId, string toDisplayName, string toEmail, string subject, string body)
{
ConstructNotification(siteId, null, "", "", null, toDisplayName, toEmail, subject, body, null, null);
}
public Notification(int siteId, string toDisplayName, string toEmail, string subject, string body, DateTime sendOn)
{
ConstructNotification(siteId, null, "", "", null, toDisplayName, toEmail, subject, body, null, sendOn);
}
public Notification(int siteId, string fromDisplayName, string fromEmail, string toDisplayName, string toEmail, string subject, string body)
{
ConstructNotification(siteId, null, fromDisplayName, fromEmail, null, toDisplayName, toEmail, subject, body, null, null);
}
private void ConstructNotification(int siteId, User from, string fromDisplayName, string fromEmail, User to, string toDisplayName, string toEmail, string subject, string body, int? parentId, DateTime? sendOn)
{
SiteId = siteId;
if (from != null)
@ -105,37 +142,38 @@ namespace Oqtane.Models
FromDisplayName = from.DisplayName;
FromEmail = from.Email;
}
else
{
FromUserId = null;
FromDisplayName = fromDisplayName;
FromEmail = fromEmail;
}
if (to != null)
{
ToUserId = to.UserId;
ToDisplayName = to.DisplayName;
ToEmail = to.Email;
}
else
{
ToUserId = null;
ToDisplayName = toDisplayName;
ToEmail = toEmail;
}
Subject = subject;
Body = body;
ParentId = parentId;
CreatedOn = DateTime.UtcNow;
if (sendOn != null)
{
SendOn = sendOn;
}
else
{
SendOn = CreatedOn;
}
IsDelivered = false;
DeliveredOn = null;
SendOn = DateTime.UtcNow;
}
public Notification(int siteId, string fromDisplayName, string fromEmail, string toDisplayName, string toEmail, string subject, string body)
{
SiteId = siteId;
FromUserId = null;
FromDisplayName = fromDisplayName;
FromEmail = fromEmail;
ToUserId = null;
ToDisplayName = toDisplayName;
ToEmail = toEmail;
Subject = subject;
Body = body;
ParentId = null;
CreatedOn = DateTime.UtcNow;
IsDelivered = false;
DeliveredOn = null;
SendOn = DateTime.UtcNow;
}
}