From 317cba2a7af6db652e1b54d0194b36669c703391 Mon Sep 17 00:00:00 2001 From: Oleg Zhuk Date: Tue, 4 Jun 2024 11:43:27 +0200 Subject: [PATCH 1/3] VCST-1251: Add unregister notification feat: Adds method for unregister notification. --- .../Model/UnregisteredNotification.cs | 7 ++++++- .../Services/INotificationRegistrar.cs | 1 + .../Services/NotificationRegistrar.cs | 13 +++++++++++++ .../Services/NotificationService.cs | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/VirtoCommerce.NotificationsModule.Core/Model/UnregisteredNotification.cs b/src/VirtoCommerce.NotificationsModule.Core/Model/UnregisteredNotification.cs index 14c83a48..ecc13e71 100644 --- a/src/VirtoCommerce.NotificationsModule.Core/Model/UnregisteredNotification.cs +++ b/src/VirtoCommerce.NotificationsModule.Core/Model/UnregisteredNotification.cs @@ -6,12 +6,17 @@ namespace VirtoCommerce.NotificationsModule.Core.Model //The special type for handle cases when the system have stored the notification objects with unregistered types. public class UnregisteredNotification : Notification { + public UnregisteredNotification(string type) : base(type) + { + + } + public UnregisteredNotification() : base(nameof(UnregisteredNotification)) { Templates = new List(); } public override string Kind => "undef"; - + public override void SetFromToMembers(string from, string to) { diff --git a/src/VirtoCommerce.NotificationsModule.Core/Services/INotificationRegistrar.cs b/src/VirtoCommerce.NotificationsModule.Core/Services/INotificationRegistrar.cs index 8def6d46..f3a0f78b 100644 --- a/src/VirtoCommerce.NotificationsModule.Core/Services/INotificationRegistrar.cs +++ b/src/VirtoCommerce.NotificationsModule.Core/Services/INotificationRegistrar.cs @@ -13,5 +13,6 @@ public interface INotificationRegistrar NotificationBuilder Notification() where TNotification : Notification; NotificationBuilder RegisterNotification(Func factory = null) where TNotification : Notification; NotificationBuilder OverrideNotificationType(Func factory = null) where TOldNotificationType : Notification where TNewNotificationType : Notification; + void UnregisterNotification() where TNotification : Notification; } } diff --git a/src/VirtoCommerce.NotificationsModule.Data/Services/NotificationRegistrar.cs b/src/VirtoCommerce.NotificationsModule.Data/Services/NotificationRegistrar.cs index b7c547bd..a95ef93e 100644 --- a/src/VirtoCommerce.NotificationsModule.Data/Services/NotificationRegistrar.cs +++ b/src/VirtoCommerce.NotificationsModule.Data/Services/NotificationRegistrar.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.DependencyInjection; using VirtoCommerce.NotificationsModule.Core.Model; using VirtoCommerce.NotificationsModule.Core.Services; +using VirtoCommerce.NotificationsModule.Data.Repositories; using VirtoCommerce.Platform.Core.Common; namespace VirtoCommerce.NotificationsModule.Data.Services @@ -48,5 +50,16 @@ public NotificationBuilder OverrideNotificationType() where TNotification : Notification + { + var repositoryFactory = _serviceProvider.GetService>(); + using var repository = repositoryFactory(); + var notificationType = nameof(TNotification); + foreach (var item in repository.Notifications.Where(n => n.Type == notificationType)) + { + repository.Remove(item); + } + repository.UnitOfWork.Commit(); + } } } diff --git a/src/VirtoCommerce.NotificationsModule.Data/Services/NotificationService.cs b/src/VirtoCommerce.NotificationsModule.Data/Services/NotificationService.cs index 810ee948..33eca82d 100644 --- a/src/VirtoCommerce.NotificationsModule.Data/Services/NotificationService.cs +++ b/src/VirtoCommerce.NotificationsModule.Data/Services/NotificationService.cs @@ -174,7 +174,7 @@ private static Notification ToModel(NotificationEntity entity) entity.ToModel(result); } - return result ?? new UnregisteredNotification(); + return result ?? new UnregisteredNotification(typeName); } } } From 27a4f3f83c6d17d9c981f3cd88d3c8a3feec2ca6 Mon Sep 17 00:00:00 2001 From: Oleg Zhuk Date: Tue, 4 Jun 2024 12:14:25 +0200 Subject: [PATCH 2/3] fix: Improve Unregistered Notification UX --- .../Services/INotificationRegistrar.cs | 1 - .../Services/NotificationRegistrar.cs | 14 -------------- 2 files changed, 15 deletions(-) diff --git a/src/VirtoCommerce.NotificationsModule.Core/Services/INotificationRegistrar.cs b/src/VirtoCommerce.NotificationsModule.Core/Services/INotificationRegistrar.cs index f3a0f78b..8def6d46 100644 --- a/src/VirtoCommerce.NotificationsModule.Core/Services/INotificationRegistrar.cs +++ b/src/VirtoCommerce.NotificationsModule.Core/Services/INotificationRegistrar.cs @@ -13,6 +13,5 @@ public interface INotificationRegistrar NotificationBuilder Notification() where TNotification : Notification; NotificationBuilder RegisterNotification(Func factory = null) where TNotification : Notification; NotificationBuilder OverrideNotificationType(Func factory = null) where TOldNotificationType : Notification where TNewNotificationType : Notification; - void UnregisterNotification() where TNotification : Notification; } } diff --git a/src/VirtoCommerce.NotificationsModule.Data/Services/NotificationRegistrar.cs b/src/VirtoCommerce.NotificationsModule.Data/Services/NotificationRegistrar.cs index a95ef93e..5de9eab5 100644 --- a/src/VirtoCommerce.NotificationsModule.Data/Services/NotificationRegistrar.cs +++ b/src/VirtoCommerce.NotificationsModule.Data/Services/NotificationRegistrar.cs @@ -1,10 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.Extensions.DependencyInjection; using VirtoCommerce.NotificationsModule.Core.Model; using VirtoCommerce.NotificationsModule.Core.Services; -using VirtoCommerce.NotificationsModule.Data.Repositories; using VirtoCommerce.Platform.Core.Common; namespace VirtoCommerce.NotificationsModule.Data.Services @@ -49,17 +47,5 @@ public NotificationBuilder OverrideNotificationType() where TNotification : Notification - { - var repositoryFactory = _serviceProvider.GetService>(); - using var repository = repositoryFactory(); - var notificationType = nameof(TNotification); - foreach (var item in repository.Notifications.Where(n => n.Type == notificationType)) - { - repository.Remove(item); - } - repository.UnitOfWork.Commit(); - } } } From 56277b0f27ed05cd1735025f3783eb24526b88ce Mon Sep 17 00:00:00 2001 From: Oleg Zhuk Date: Tue, 4 Jun 2024 12:36:27 +0200 Subject: [PATCH 3/3] fix: Improve error message --- .../Localizations/en.VirtoCommerce.Notifications.json | 2 +- .../Localizations/ru.VirtoCommerce.Notifications.json | 2 +- .../Scripts/blades/notification-templates-list.js | 7 ++++--- .../Scripts/blades/notifications-list.js | 9 +++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/VirtoCommerce.NotificationsModule.Web/Localizations/en.VirtoCommerce.Notifications.json b/src/VirtoCommerce.NotificationsModule.Web/Localizations/en.VirtoCommerce.Notifications.json index 109197e2..5dbc5c94 100644 --- a/src/VirtoCommerce.NotificationsModule.Web/Localizations/en.VirtoCommerce.Notifications.json +++ b/src/VirtoCommerce.NotificationsModule.Web/Localizations/en.VirtoCommerce.Notifications.json @@ -210,7 +210,7 @@ "dialogs": { "unknown-kind": { "title": "Error", - "message": "Unable to edit template of an unknown type: '{{kind}}'." + "message": "Unable to open '{{type}}' notification. Please contact your Site Administrator(s) for information." }, "notification-details-save": { "title": "Save changes", diff --git a/src/VirtoCommerce.NotificationsModule.Web/Localizations/ru.VirtoCommerce.Notifications.json b/src/VirtoCommerce.NotificationsModule.Web/Localizations/ru.VirtoCommerce.Notifications.json index e9f8dbc0..88ff62f9 100644 --- a/src/VirtoCommerce.NotificationsModule.Web/Localizations/ru.VirtoCommerce.Notifications.json +++ b/src/VirtoCommerce.NotificationsModule.Web/Localizations/ru.VirtoCommerce.Notifications.json @@ -207,7 +207,7 @@ "dialogs": { "unknown-kind": { "title": "Ошибка", - "message": "Невозможно изменить шаблон неопределенного типа:: '{{kind}}'." + "message": "Невозможно открыть уведомление '{{type}}'. Обратитесь к администратору(ам) вашего сайта за информацией." }, "notification-details-save": { "title": "Сохранить изменения", diff --git a/src/VirtoCommerce.NotificationsModule.Web/Scripts/blades/notification-templates-list.js b/src/VirtoCommerce.NotificationsModule.Web/Scripts/blades/notification-templates-list.js index 4c764732..a7562e42 100644 --- a/src/VirtoCommerce.NotificationsModule.Web/Scripts/blades/notification-templates-list.js +++ b/src/VirtoCommerce.NotificationsModule.Web/Scripts/blades/notification-templates-list.js @@ -40,7 +40,7 @@ angular.module('virtoCommerce.notificationsModule') return _.toArray(templatesToDisplay); } - function resolveType(kind) { + function resolveType(kind, type) { var foundTemplate = notificationTemplatesResolverService.resolve(kind); if (foundTemplate && foundTemplate.knownChildrenTypes && foundTemplate.knownChildrenTypes.length) { return foundTemplate; @@ -49,13 +49,14 @@ angular.module('virtoCommerce.notificationsModule') id: "error", title: "notifications.dialogs.unknown-kind.title", message: "notifications.dialogs.unknown-kind.message", - messageValues: { kind: kind }, + messageValues: { kind: kind, type: type }, }); + return null; } } blade.openTemplate = function (template) { - var foundTemplate = resolveType(blade.currentEntity.kind); + var foundTemplate = resolveType(blade.currentEntity.kind, blade.currentEntity.type); if (foundTemplate) { var newBlade = { id: foundTemplate.detailBlade.id, diff --git a/src/VirtoCommerce.NotificationsModule.Web/Scripts/blades/notifications-list.js b/src/VirtoCommerce.NotificationsModule.Web/Scripts/blades/notifications-list.js index 949f66ae..1bb0f2fe 100644 --- a/src/VirtoCommerce.NotificationsModule.Web/Scripts/blades/notifications-list.js +++ b/src/VirtoCommerce.NotificationsModule.Web/Scripts/blades/notifications-list.js @@ -49,7 +49,7 @@ angular.module('virtoCommerce.notificationsModule') }); } - function resolveType(kind) { + function resolveType(kind, type) { var foundNotification = notificationTypesResolverService.resolve(kind); if (foundNotification && foundNotification.knownChildrenTypes && foundNotification.knownChildrenTypes.length) { return foundNotification; @@ -58,14 +58,15 @@ angular.module('virtoCommerce.notificationsModule') id: "error", title: "notifications.dialogs.unknown-kind.title", message: "notifications.dialogs.unknown-kind.message", - messageValues: { kind: kind }, - }); + messageValues: { kind: kind, type: type }, + }); + return null; } } if (authService.checkPermission('notifications:access')) { blade.editNotification = function (item) { - var foundNotification = resolveType(item.kind); + var foundNotification = resolveType(item.kind, item.type); var newBlade = { id: 'editNotification', title: 'notifications.blades.notification-details.title',