From a69ff8dcd1c8ddd3aa1c75b3bf1bc4eaf3335a9a Mon Sep 17 00:00:00 2001 From: Jonas Gauffin Date: Tue, 10 Dec 2019 19:47:52 +0100 Subject: [PATCH 1/6] push --- .../Commands/UpdateBrowserSubscription.cs | 17 +++ .../Users/Commands/UpdateNotifications.cs | 6 +- .../Core/Users/NotificationSettings.cs | 5 - .../Core/Users/NotificationState.cs | 13 +- .../Users/WebApi/GetUserSettingsHandler.cs | 1 - .../WebApi/UpdateNotificationsHandler.cs | 1 - .../UserNotifications/NotificationState.cs | 8 +- .../UserNotificationSettings.cs | 12 +- .../Inbound/SaveReportHandler.cs | 3 +- .../Handlers/CheckForNotificationsToSend.cs | 5 - .../UserNotificationSettingsMap.cs | 3 - .../Boot/Cqs/CqsObjectMapper.cs | 16 +- .../Coderr.Server.Web/ClientApp/boot.ts | 12 +- .../components/home/navmenu/navmenu.vue.html | 7 +- .../components/manage/account/home/home.css | 69 +++++++++ .../components/manage/account/home/home.ts | 139 ++++++++++++++++++ .../manage/account/home/home.vue.html | 94 ++++++++++++ .../components/manage/account/manage.ts | 12 ++ .../components/manage/account/manage.vue.html | 12 ++ .../components/manage/system/whitelist/add.ts | 6 +- .../ClientApp/dto/Core/Users.ts | 10 +- .../Coderr.Server.Web.csproj | 1 + .../Controllers/CqsController.cs | 3 +- .../Controllers/PushController.cs | 31 ++++ src/Server/Coderr.Server.Web/Program.cs | 2 +- .../Coderr.Server.Web/Services/PushService.cs | 42 ++++++ src/Server/Coderr.Server.Web/appsettings.json | 13 +- src/Server/Coderr.Server.Web/compilenpm.cmd | 3 + .../Coderr.Server.Web/npm-shrinkwrap.json | 83 +++++++++++ src/Server/Coderr.Server.Web/package.json | 1 + src/Server/Coderr.Server.Web/tsconfig.json | 13 +- .../Coderr.Server.Web/webpack.config.js | 46 +++--- .../webpack.config.vendor.js | 12 +- .../wwwroot/css/bootstrap-grid.min.css | 7 - .../wwwroot/css/bootstrap-grid.min.css.map | 1 - .../wwwroot/css/bootstrap-reboot.min.css | 8 - .../wwwroot/css/bootstrap-reboot.min.css.map | 1 - .../wwwroot/css/bootstrap.min.css | 7 - .../wwwroot/css/bootstrap.min.css.map | 1 - .../wwwroot/js/pushworker.js | 64 ++++++++ .../wwwroot/scss/bootstrap-coderr.scss | 1 + .../Coderr.Server.Web/wwwroot/scss/site.scss | 66 +++++++++ 42 files changed, 754 insertions(+), 103 deletions(-) create mode 100644 src/Server/Coderr.Server.Api/Core/Users/Commands/UpdateBrowserSubscription.cs create mode 100644 src/Server/Coderr.Server.Web/ClientApp/components/manage/account/home/home.css create mode 100644 src/Server/Coderr.Server.Web/ClientApp/components/manage/account/home/home.ts create mode 100644 src/Server/Coderr.Server.Web/ClientApp/components/manage/account/home/home.vue.html create mode 100644 src/Server/Coderr.Server.Web/ClientApp/components/manage/account/manage.ts create mode 100644 src/Server/Coderr.Server.Web/ClientApp/components/manage/account/manage.vue.html create mode 100644 src/Server/Coderr.Server.Web/Controllers/PushController.cs create mode 100644 src/Server/Coderr.Server.Web/Services/PushService.cs create mode 100644 src/Server/Coderr.Server.Web/compilenpm.cmd delete mode 100644 src/Server/Coderr.Server.Web/wwwroot/css/bootstrap-grid.min.css delete mode 100644 src/Server/Coderr.Server.Web/wwwroot/css/bootstrap-grid.min.css.map delete mode 100644 src/Server/Coderr.Server.Web/wwwroot/css/bootstrap-reboot.min.css delete mode 100644 src/Server/Coderr.Server.Web/wwwroot/css/bootstrap-reboot.min.css.map delete mode 100644 src/Server/Coderr.Server.Web/wwwroot/css/bootstrap.min.css delete mode 100644 src/Server/Coderr.Server.Web/wwwroot/css/bootstrap.min.css.map create mode 100644 src/Server/Coderr.Server.Web/wwwroot/js/pushworker.js diff --git a/src/Server/Coderr.Server.Api/Core/Users/Commands/UpdateBrowserSubscription.cs b/src/Server/Coderr.Server.Api/Core/Users/Commands/UpdateBrowserSubscription.cs new file mode 100644 index 00000000..84dd9ef7 --- /dev/null +++ b/src/Server/Coderr.Server.Api/Core/Users/Commands/UpdateBrowserSubscription.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Coderr.Server.Api.Core.Users.Commands +{ + [Message] + public class UpdateBrowserSubscription + { + public int UserId { get; set; } + public string Endpoint { get; set; } + + + public DateTime ExpiresAtUtc { get; set; } + } + +} diff --git a/src/Server/Coderr.Server.Api/Core/Users/Commands/UpdateNotifications.cs b/src/Server/Coderr.Server.Api/Core/Users/Commands/UpdateNotifications.cs index 628dfbc9..b79dadf9 100644 --- a/src/Server/Coderr.Server.Api/Core/Users/Commands/UpdateNotifications.cs +++ b/src/Server/Coderr.Server.Api/Core/Users/Commands/UpdateNotifications.cs @@ -16,11 +16,6 @@ public class UpdateNotifications /// public NotificationState NotifyOnNewIncidents { get; set; } - /// - /// How to notify when a new report is created (receive an exception) - /// - public NotificationState NotifyOnNewReport { get; set; } - /// /// How to notify user when a peak is detected /// @@ -36,6 +31,7 @@ public class UpdateNotifications /// public NotificationState NotifyOnUserFeedback { get; set; } + /// /// User that configured its settings. /// diff --git a/src/Server/Coderr.Server.Api/Core/Users/NotificationSettings.cs b/src/Server/Coderr.Server.Api/Core/Users/NotificationSettings.cs index b32a5ce7..25e74f2b 100644 --- a/src/Server/Coderr.Server.Api/Core/Users/NotificationSettings.cs +++ b/src/Server/Coderr.Server.Api/Core/Users/NotificationSettings.cs @@ -12,11 +12,6 @@ public class NotificationSettings /// public NotificationState NotifyOnNewIncidents { get; set; } - /// - /// How to notify when a new report is created (receive an exception) - /// - public NotificationState NotifyOnNewReport { get; set; } - /// /// How to notify user when a peak is detected /// diff --git a/src/Server/Coderr.Server.Api/Core/Users/NotificationState.cs b/src/Server/Coderr.Server.Api/Core/Users/NotificationState.cs index acdb558d..8ab94b9b 100644 --- a/src/Server/Coderr.Server.Api/Core/Users/NotificationState.cs +++ b/src/Server/Coderr.Server.Api/Core/Users/NotificationState.cs @@ -8,21 +8,26 @@ public enum NotificationState /// /// Use global setting /// - UseGlobalSetting, + UseGlobalSetting = 0, /// /// Do not notify /// - Disabled, + Disabled = 1, /// /// By cellphone (text message) /// - Cellphone, + Cellphone = 2, /// /// By email /// - Email + Email = 3, + + /// + /// Use browser/desktop notifications. + /// + BrowserNotification = 4 } } \ No newline at end of file diff --git a/src/Server/Coderr.Server.App/Core/Users/WebApi/GetUserSettingsHandler.cs b/src/Server/Coderr.Server.App/Core/Users/WebApi/GetUserSettingsHandler.cs index 1c08e9b8..38beed89 100644 --- a/src/Server/Coderr.Server.App/Core/Users/WebApi/GetUserSettingsHandler.cs +++ b/src/Server/Coderr.Server.App/Core/Users/WebApi/GetUserSettingsHandler.cs @@ -38,7 +38,6 @@ public async Task HandleAsync(IMessageContext context, Ge NotifyOnReOpenedIncident = settings.ReopenedIncident.ConvertEnum(), NotifyOnUserFeedback = settings.UserFeedback.ConvertEnum(), NotifyOnPeaks = settings.ApplicationSpike.ConvertEnum(), - NotifyOnNewReport = settings.NewReport.ConvertEnum(), NotifyOnNewIncidents = settings.NewIncident.ConvertEnum() } }; diff --git a/src/Server/Coderr.Server.App/Core/Users/WebApi/UpdateNotificationsHandler.cs b/src/Server/Coderr.Server.App/Core/Users/WebApi/UpdateNotificationsHandler.cs index 15118ed8..e7ad28fd 100644 --- a/src/Server/Coderr.Server.App/Core/Users/WebApi/UpdateNotificationsHandler.cs +++ b/src/Server/Coderr.Server.App/Core/Users/WebApi/UpdateNotificationsHandler.cs @@ -45,7 +45,6 @@ public async Task HandleAsync(IMessageContext context, UpdateNotifications comma settings.ApplicationSpike = command.NotifyOnPeaks.ConvertEnum(); settings.NewIncident = command.NotifyOnNewIncidents.ConvertEnum(); - settings.NewReport = command.NotifyOnNewReport.ConvertEnum(); settings.ReopenedIncident = command.NotifyOnReOpenedIncident.ConvertEnum(); settings.UserFeedback = command.NotifyOnUserFeedback.ConvertEnum(); await _notificationsRepository.UpdateAsync(settings); diff --git a/src/Server/Coderr.Server.Domain/Modules/UserNotifications/NotificationState.cs b/src/Server/Coderr.Server.Domain/Modules/UserNotifications/NotificationState.cs index bdc3eff7..3ac6ba32 100644 --- a/src/Server/Coderr.Server.Domain/Modules/UserNotifications/NotificationState.cs +++ b/src/Server/Coderr.Server.Domain/Modules/UserNotifications/NotificationState.cs @@ -8,21 +8,21 @@ public enum NotificationState /// /// Use global setting /// - UseGlobalSetting, + UseGlobalSetting = 1, /// /// Do not notify /// - Disabled, + Disabled = 2, /// /// By cellphone (text message) /// - Cellphone, + Cellphone = 3, /// /// By email /// - Email + Email = 4 } } \ No newline at end of file diff --git a/src/Server/Coderr.Server.Domain/Modules/UserNotifications/UserNotificationSettings.cs b/src/Server/Coderr.Server.Domain/Modules/UserNotifications/UserNotificationSettings.cs index a1a1e903..b511683a 100644 --- a/src/Server/Coderr.Server.Domain/Modules/UserNotifications/UserNotificationSettings.cs +++ b/src/Server/Coderr.Server.Domain/Modules/UserNotifications/UserNotificationSettings.cs @@ -18,6 +18,13 @@ public UserNotificationSettings(int accountId, int applicationId) if (accountId <= 0) throw new ArgumentOutOfRangeException("accountId"); AccountId = accountId; ApplicationId = applicationId; + if (applicationId != 0) + return; + + ApplicationSpike = NotificationState.Disabled; + NewIncident = NotificationState.Disabled; + ReopenedIncident = NotificationState.Disabled; + UserFeedback = NotificationState.Disabled; } /// @@ -47,11 +54,6 @@ protected UserNotificationSettings() /// public NotificationState NewIncident { get; set; } - /// - /// Notify each time a new exception is received (no matter if it's unique or not) - /// - public NotificationState NewReport { get; set; } - /// /// Notify when we received a report for an incident that has been closed /// diff --git a/src/Server/Coderr.Server.ReportAnalyzer/Inbound/SaveReportHandler.cs b/src/Server/Coderr.Server.ReportAnalyzer/Inbound/SaveReportHandler.cs index e0509ae9..bb837c94 100644 --- a/src/Server/Coderr.Server.ReportAnalyzer/Inbound/SaveReportHandler.cs +++ b/src/Server/Coderr.Server.ReportAnalyzer/Inbound/SaveReportHandler.cs @@ -182,8 +182,9 @@ private async Task GetAppAsync(string appKey) { using (var cmd = _unitOfWork.CreateDbCommand()) { - cmd.CommandText = "SELECT Id, SharedSecret FROM Applications WHERE AppKey = @key"; + cmd.CommandText = "SELECT Id, SharedSecret FROM Applications WHERE AppKey = @key OR AppKey = @key2"; cmd.AddParameter("key", appKey); + cmd.AddParameter("key2", appKey.Replace("-", "")); using (var reader = await cmd.ExecuteReaderAsync()) { if (!await reader.ReadAsync()) diff --git a/src/Server/Coderr.Server.ReportAnalyzer/UserNotifications/Handlers/CheckForNotificationsToSend.cs b/src/Server/Coderr.Server.ReportAnalyzer/UserNotifications/Handlers/CheckForNotificationsToSend.cs index 50d03c10..eace6712 100644 --- a/src/Server/Coderr.Server.ReportAnalyzer/UserNotifications/Handlers/CheckForNotificationsToSend.cs +++ b/src/Server/Coderr.Server.ReportAnalyzer/UserNotifications/Handlers/CheckForNotificationsToSend.cs @@ -6,7 +6,6 @@ using Coderr.Server.ReportAnalyzer.Abstractions.Incidents; using Coderr.Server.ReportAnalyzer.UserNotifications.Handlers.Tasks; using DotNetCqs; -using Coderr.Server.Abstractions.Boot; using Coderr.Server.Abstractions.Config; using log4net; @@ -55,10 +54,6 @@ public async Task HandleAsync(IMessageContext context, ReportAddedToIncident e) { await CreateNotification(context, e, setting.AccountId, setting.NewIncident); } - else if (setting.NewReport != NotificationState.Disabled) - { - await CreateNotification(context, e, setting.AccountId, setting.NewReport); - } else if (setting.ReopenedIncident != NotificationState.Disabled && e.IsReOpened) { await CreateNotification(context, e, setting.AccountId, setting.ReopenedIncident); diff --git a/src/Server/Coderr.Server.SqlServer/Core/Notifications/UserNotificationSettingsMap.cs b/src/Server/Coderr.Server.SqlServer/Core/Notifications/UserNotificationSettingsMap.cs index c1302ab1..181efe93 100644 --- a/src/Server/Coderr.Server.SqlServer/Core/Notifications/UserNotificationSettingsMap.cs +++ b/src/Server/Coderr.Server.SqlServer/Core/Notifications/UserNotificationSettingsMap.cs @@ -17,9 +17,6 @@ public UserNotificationSettingsMap() Property(x => x.ReopenedIncident) .ToColumnValue(StringToEnum) .ToPropertyValue(EnumToString); - Property(x => x.NewReport) - .ToColumnValue(StringToEnum) - .ToPropertyValue(EnumToString); Property(x => x.UserFeedback) .ToColumnValue(StringToEnum) .ToPropertyValue(EnumToString); diff --git a/src/Server/Coderr.Server.Web/Boot/Cqs/CqsObjectMapper.cs b/src/Server/Coderr.Server.Web/Boot/Cqs/CqsObjectMapper.cs index a28b0115..7ab2a612 100644 --- a/src/Server/Coderr.Server.Web/Boot/Cqs/CqsObjectMapper.cs +++ b/src/Server/Coderr.Server.Web/Boot/Cqs/CqsObjectMapper.cs @@ -29,7 +29,11 @@ public class CqsObjectMapper ContractResolver = new IncludeNonPublicMembersContractResolver(), NullValueHandling = NullValueHandling.Ignore, ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor, - Converters = new List { new StringEnumConverter() } + + // Typescript requires numbers for easier enum handling + // otherwise we have to redefine all enums so that the keys are strings. + + //Converters = new List { new StringEnumConverter() } }; public bool IsEmpty => _cqsTypes.Count == 0; @@ -50,6 +54,16 @@ public object Deserialize(string dotNetTypeOrCqsName, string json) : JsonConvert.DeserializeObject(json, type, _jsonSerializerSettings); } + /// + /// We just have this method to make sure that the serialization is exactly the same in both directions. + /// + /// + /// + public string Serialize(object value) + { + return JsonConvert.SerializeObject(value, _jsonSerializerSettings); + } + /// /// Determines whether the type implements the command handler interface /// diff --git a/src/Server/Coderr.Server.Web/ClientApp/boot.ts b/src/Server/Coderr.Server.Web/ClientApp/boot.ts index 62c60dcb..f9ed3da3 100644 --- a/src/Server/Coderr.Server.Web/ClientApp/boot.ts +++ b/src/Server/Coderr.Server.Web/ClientApp/boot.ts @@ -198,6 +198,17 @@ const routes = [ } ] }, + { + path: "/manage/account/", + component: require("./components/manage/account/manage.vue.html").default, + children: [ + { + name: "manageAccount", + path: "", + component: require("./components/manage/account/home/home.vue.html").default + } + ] + }, { path: "/manage/", component: require("./components/manage/system/manage.vue.html").default, @@ -206,7 +217,6 @@ const routes = [ name: "manageHome", path: "", component: require("./components/manage/system/home/home.vue.html").default, - }, { name: "createApp", diff --git a/src/Server/Coderr.Server.Web/ClientApp/components/home/navmenu/navmenu.vue.html b/src/Server/Coderr.Server.Web/ClientApp/components/home/navmenu/navmenu.vue.html index 2e28f842..28ee3a00 100644 --- a/src/Server/Coderr.Server.Web/ClientApp/components/home/navmenu/navmenu.vue.html +++ b/src/Server/Coderr.Server.Web/ClientApp/components/home/navmenu/navmenu.vue.html @@ -42,7 +42,7 @@ Deployment insights --> - + +