From ab8a1e7324e26a9ec42339d160c5312acfed4b55 Mon Sep 17 00:00:00 2001 From: Mike Casas Date: Thu, 18 Jun 2020 06:13:15 -0400 Subject: [PATCH 1/5] Step 1. --- Oqtane.Server/Controllers/UserController.cs | 2 ++ Oqtane.Server/Oqtane.Server.csproj | 4 ++++ Oqtane.Server/Scripts/Notification.01.00.01.00.sql | 9 +++++++++ Oqtane.Shared/Models/Notification.cs | 1 + 4 files changed, 16 insertions(+) create mode 100644 Oqtane.Server/Scripts/Notification.01.00.01.00.sql diff --git a/Oqtane.Server/Controllers/UserController.cs b/Oqtane.Server/Controllers/UserController.cs index 6fb3c93bd..d850f9ae9 100644 --- a/Oqtane.Server/Controllers/UserController.cs +++ b/Oqtane.Server/Controllers/UserController.cs @@ -157,6 +157,7 @@ private async Task CreateUser(User user) notification.CreatedOn = DateTime.UtcNow; notification.IsDelivered = false; notification.DeliveredOn = null; + notification.SendOn = DateTime.UtcNow; _notifications.AddNotification(notification); } @@ -385,6 +386,7 @@ public async Task Forgot([FromBody] User user) notification.CreatedOn = DateTime.UtcNow; notification.IsDelivered = false; notification.DeliveredOn = null; + notification.SendOn = DateTime.UtcNow; _notifications.AddNotification(notification); _logger.Log(LogLevel.Information, this, LogFunction.Security, "Password Reset Notification Sent For {Username}", user.Username); } diff --git a/Oqtane.Server/Oqtane.Server.csproj b/Oqtane.Server/Oqtane.Server.csproj index 0db9ece52..6c2af7534 100644 --- a/Oqtane.Server/Oqtane.Server.csproj +++ b/Oqtane.Server/Oqtane.Server.csproj @@ -22,10 +22,14 @@ + + + + diff --git a/Oqtane.Server/Scripts/Notification.01.00.01.00.sql b/Oqtane.Server/Scripts/Notification.01.00.01.00.sql new file mode 100644 index 000000000..3acdbf29a --- /dev/null +++ b/Oqtane.Server/Scripts/Notification.01.00.01.00.sql @@ -0,0 +1,9 @@ +/* + +Version 1.0.1 Notification migration script + +*/ + +ALTER TABLE [dbo].[Notification] ADD + [SendOn] [datetime] NULL +GO \ No newline at end of file diff --git a/Oqtane.Shared/Models/Notification.cs b/Oqtane.Shared/Models/Notification.cs index aeb7235da..7ccdbd9d4 100644 --- a/Oqtane.Shared/Models/Notification.cs +++ b/Oqtane.Shared/Models/Notification.cs @@ -22,6 +22,7 @@ public class Notification : IDeletable public string DeletedBy { get; set; } public DateTime? DeletedOn { get; set; } public bool IsDeleted { get; set; } + public DateTime? SendOn { get; set; } } } From ee5553ad8a3d908bccafb81c8a7316639e351a4d Mon Sep 17 00:00:00 2001 From: Mike Casas Date: Thu, 18 Jun 2020 07:35:40 -0400 Subject: [PATCH 2/5] Step 2. --- Oqtane.Client/Modules/Admin/UserProfile/Add.razor | 3 ++- Oqtane.Client/Modules/Admin/UserProfile/View.razor | 3 ++- Oqtane.Server/Repository/NotificationRepository.cs | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Oqtane.Client/Modules/Admin/UserProfile/Add.razor b/Oqtane.Client/Modules/Admin/UserProfile/Add.razor index c413ec919..b19bae1dc 100644 --- a/Oqtane.Client/Modules/Admin/UserProfile/Add.razor +++ b/Oqtane.Client/Modules/Admin/UserProfile/Add.razor @@ -65,7 +65,8 @@ notification.ParentId = null; notification.CreatedOn = DateTime.UtcNow; notification.IsDelivered = false; - notification.DeliveredOn = null; + notification.DeliveredOn = null; + notification.SendOn = DateTime.UtcNow; notification = await NotificationService.AddNotificationAsync(notification); await logger.LogInformation("Notification Created {Notification}", notification); NavigationManager.NavigateTo(NavigateUrl()); diff --git a/Oqtane.Client/Modules/Admin/UserProfile/View.razor b/Oqtane.Client/Modules/Admin/UserProfile/View.razor index 2e48fcb1f..32dde145e 100644 --- a/Oqtane.Client/Modules/Admin/UserProfile/View.razor +++ b/Oqtane.Client/Modules/Admin/UserProfile/View.razor @@ -191,7 +191,8 @@ notification.ParentId = notificationid; notification.CreatedOn = DateTime.UtcNow; notification.IsDelivered = false; - notification.DeliveredOn = null; + notification.DeliveredOn = null; + notification.SendOn = DateTime.UtcNow; notification = await NotificationService.AddNotificationAsync(notification); await logger.LogInformation("Notification Created {Notification}", notification); NavigationManager.NavigateTo(NavigateUrl()); diff --git a/Oqtane.Server/Repository/NotificationRepository.cs b/Oqtane.Server/Repository/NotificationRepository.cs index 4e6550d29..45730d841 100644 --- a/Oqtane.Server/Repository/NotificationRepository.cs +++ b/Oqtane.Server/Repository/NotificationRepository.cs @@ -21,6 +21,7 @@ public IEnumerable GetNotifications(int siteId, int fromUserId, in return _db.Notification .Where(item => item.SiteId == siteId) .Where(item => item.IsDelivered == false) + .Where(item => item.SendOn < System.DateTime.UtcNow) .ToList(); } From 40571bfb6eb937d8188f0171bf7b4b341b0b8477 Mon Sep 17 00:00:00 2001 From: Mike Casas Date: Thu, 18 Jun 2020 08:40:43 -0400 Subject: [PATCH 3/5] Bug Fix. Not sure why the email address was not being added to the notification. --- Oqtane.Server/Controllers/UserController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Oqtane.Server/Controllers/UserController.cs b/Oqtane.Server/Controllers/UserController.cs index d850f9ae9..d27694b41 100644 --- a/Oqtane.Server/Controllers/UserController.cs +++ b/Oqtane.Server/Controllers/UserController.cs @@ -148,7 +148,7 @@ private async Task CreateUser(User user) notification.SiteId = user.SiteId; notification.FromUserId = null; notification.ToUserId = newUser.UserId; - notification.ToEmail = ""; + notification.ToEmail = newUser.Email; notification.Subject = "User Account Verification"; string token = await _identityUserManager.GenerateEmailConfirmationTokenAsync(identityuser); string url = HttpContext.Request.Scheme + "://" + _tenants.GetAlias().Name + "/login?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token); From 7d896709305249a688831cbdef75ef65b5a1e00c Mon Sep 17 00:00:00 2001 From: Mike Casas Date: Thu, 18 Jun 2020 12:58:30 -0400 Subject: [PATCH 4/5] Fixed the sql script file name and added update for null values. --- .../{Notification.01.00.01.00.sql => Tenant.01.00.01.01.sql} | 3 +++ 1 file changed, 3 insertions(+) rename Oqtane.Server/Scripts/{Notification.01.00.01.00.sql => Tenant.01.00.01.01.sql} (61%) diff --git a/Oqtane.Server/Scripts/Notification.01.00.01.00.sql b/Oqtane.Server/Scripts/Tenant.01.00.01.01.sql similarity index 61% rename from Oqtane.Server/Scripts/Notification.01.00.01.00.sql rename to Oqtane.Server/Scripts/Tenant.01.00.01.01.sql index 3acdbf29a..76af104c2 100644 --- a/Oqtane.Server/Scripts/Notification.01.00.01.00.sql +++ b/Oqtane.Server/Scripts/Tenant.01.00.01.01.sql @@ -6,4 +6,7 @@ Version 1.0.1 Notification migration script ALTER TABLE [dbo].[Notification] ADD [SendOn] [datetime] NULL +GO + +UPDATE [dbo].[Notification] SET SendOn = CreatedOn WHERE SendOn IS NULL GO \ No newline at end of file From 20b83c88090e55e472a26f750b332293db359f04 Mon Sep 17 00:00:00 2001 From: Mike Casas Date: Thu, 18 Jun 2020 13:09:57 -0400 Subject: [PATCH 5/5] Updated csproj. --- Oqtane.Server/Oqtane.Server.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Oqtane.Server/Oqtane.Server.csproj b/Oqtane.Server/Oqtane.Server.csproj index 6c2af7534..7ae38416c 100644 --- a/Oqtane.Server/Oqtane.Server.csproj +++ b/Oqtane.Server/Oqtane.Server.csproj @@ -23,13 +23,13 @@ - + - +