Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send notification based on a future datetime #625

Merged
merged 5 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Oqtane.Client/Modules/Admin/UserProfile/Add.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion Oqtane.Client/Modules/Admin/UserProfile/View.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion Oqtane.Server/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private async Task<User> 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);
Expand All @@ -157,6 +157,7 @@ private async Task<User> CreateUser(User user)
notification.CreatedOn = DateTime.UtcNow;
notification.IsDelivered = false;
notification.DeliveredOn = null;
notification.SendOn = DateTime.UtcNow;
_notifications.AddNotification(notification);
}

Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions Oqtane.Server/Oqtane.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
<Content Remove="wwwroot\Modules\Templates\**" />
<EmbeddedResource Remove="wwwroot\Modules\Templates\**" />
</ItemGroup>
<ItemGroup>
<None Remove="Scripts\Tenant.01.00.01.01.sql" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Scripts\Master.00.00.00.00.sql" />
<EmbeddedResource Include="Scripts\Master.00.09.00.00.sql" />
<EmbeddedResource Include="Scripts\Master.01.00.01.00.sql" />
<EmbeddedResource Include="Scripts\Tenant.01.00.01.01.sql" />
<EmbeddedResource Include="Scripts\Tenant.00.00.00.00.sql" />
<EmbeddedResource Include="Scripts\Tenant.00.09.00.00.sql" />
<EmbeddedResource Include="Scripts\Tenant.00.09.01.00.sql" />
Expand Down
1 change: 1 addition & 0 deletions Oqtane.Server/Repository/NotificationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public IEnumerable<Notification> 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();
}

Expand Down
12 changes: 12 additions & 0 deletions Oqtane.Server/Scripts/Tenant.01.00.01.01.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*

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
1 change: 1 addition & 0 deletions Oqtane.Shared/Models/Notification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}

}