From d296bf80ff2068ce7fc1a54b6218c05d12981f63 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 22 Mar 2016 14:39:08 +0100 Subject: [PATCH] Removes legacy 'Notification' business logic, adds new SetNotifications method to INotificationService --- .../Interfaces/INotificationsRepository.cs | 1 + .../Repositories/NotificationsRepository.cs | 12 ++ .../Services/INotificationService.cs | 11 ++ .../Services/NotificationService.cs | 16 ++ .../umbraco/dialogs/notifications.aspx.cs | 15 +- src/umbraco.cms/businesslogic/CMSNode.cs | 7 +- .../businesslogic/workflow/Notification.cs | 174 ------------------ src/umbraco.cms/umbraco.cms.csproj | 3 - 8 files changed, 48 insertions(+), 191 deletions(-) delete mode 100644 src/umbraco.cms/businesslogic/workflow/Notification.cs diff --git a/src/Umbraco.Core/Persistence/Repositories/Interfaces/INotificationsRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Interfaces/INotificationsRepository.cs index 5db035ee8d..1f31a9bc80 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Interfaces/INotificationsRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Interfaces/INotificationsRepository.cs @@ -13,5 +13,6 @@ namespace Umbraco.Core.Persistence.Repositories int DeleteNotifications(IUser user, IEntity entity); IEnumerable GetEntityNotifications(IEntity entity); IEnumerable GetUserNotifications(IUser user); + IEnumerable SetNotifications(IUser user, IEntity entity, string[] actions); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Repositories/NotificationsRepository.cs b/src/Umbraco.Core/Persistence/Repositories/NotificationsRepository.cs index 4a7b0a808c..668fdf4b5b 100644 --- a/src/Umbraco.Core/Persistence/Repositories/NotificationsRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/NotificationsRepository.cs @@ -36,6 +36,18 @@ namespace Umbraco.Core.Persistence.Repositories return dtos.Select(d => new Notification(d.id, d.userId, d.action, d.nodeObjectType)).ToList(); } + public IEnumerable SetNotifications(IUser user, IEntity entity, string[] actions) + { + var notifications = new List(); + using (var t = _unitOfWork.Database.GetTransaction()) + { + DeleteNotifications(user, entity); + notifications.AddRange(actions.Select(action => CreateNotification(user, entity, action))); + t.Complete(); + } + return notifications; + } + public IEnumerable GetEntityNotifications(IEntity entity) { var sql = new Sql() diff --git a/src/Umbraco.Core/Services/INotificationService.cs b/src/Umbraco.Core/Services/INotificationService.cs index fce334141b..e508026a02 100644 --- a/src/Umbraco.Core/Services/INotificationService.cs +++ b/src/Umbraco.Core/Services/INotificationService.cs @@ -72,6 +72,17 @@ namespace Umbraco.Core.Services /// void DeleteNotifications(IUser user, IEntity entity); + /// + /// Sets the specific notifications for the user and entity + /// + /// + /// + /// + /// + /// This performs a full replace + /// + IEnumerable SetNotifications(IUser user, IEntity entity, string[] actions); + /// /// Creates a new notification /// diff --git a/src/Umbraco.Core/Services/NotificationService.cs b/src/Umbraco.Core/Services/NotificationService.cs index 4d676d66e9..4ac1b64a40 100644 --- a/src/Umbraco.Core/Services/NotificationService.cs +++ b/src/Umbraco.Core/Services/NotificationService.cs @@ -174,6 +174,22 @@ namespace Umbraco.Core.Services repository.DeleteNotifications(user, entity); } + /// + /// Sets the specific notifications for the user and entity + /// + /// + /// + /// + /// + /// This performs a full replace + /// + public IEnumerable SetNotifications(IUser user, IEntity entity, string[] actions) + { + var uow = _uowProvider.GetUnitOfWork(); + var repository = _repositoryFactory.CreateNotificationsRepository(uow); + return repository.SetNotifications(user, entity, actions); + } + /// /// Creates a new notification /// diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/notifications.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/notifications.aspx.cs index 48420d34ee..0b5bebc114 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/notifications.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/notifications.aspx.cs @@ -2,16 +2,12 @@ using Umbraco.Core.Services; using System; using System.Collections; using System.Linq; -using System.Web.UI; -using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; -using umbraco.cms.businesslogic; -using umbraco.cms.businesslogic.workflow; using Umbraco.Core; +using Umbraco.Core.Models.EntityBase; using Umbraco.Web; using Umbraco.Web.UI.Pages; using Umbraco.Web._Legacy.Actions; -using Action = Umbraco.Web._Legacy.Actions.Action; namespace umbraco.dialogs { @@ -21,7 +17,7 @@ namespace umbraco.dialogs public partial class notifications : UmbracoEnsuredPage { private ArrayList actions = new ArrayList(); - private CMSNode node; + private IUmbracoEntity node; public notifications() { @@ -32,7 +28,7 @@ namespace umbraco.dialogs protected void Page_Load(object sender, EventArgs e) { Button1.Text = Services.TextService.Localize("update"); - pane_form.Text = Services.TextService.Localize("notifications/editNotifications", new[] { node.Text}); + pane_form.Text = Services.TextService.Localize("notifications/editNotifications", new[] { node.Name}); } #region Web Form Designer generated code @@ -45,7 +41,7 @@ namespace umbraco.dialogs InitializeComponent(); base.OnInit(e); - node = new cms.businesslogic.CMSNode(int.Parse(Request.GetItemAsString("id"))); + node = Services.EntityService.Get(int.Parse(Request.GetItemAsString("id"))); var actionList = ActionsResolver.Current.Actions; @@ -96,7 +92,8 @@ namespace umbraco.dialogs if (c.Checked) notifications += c.ID; } - Notification.UpdateNotifications(Security.CurrentUser, node, notifications); + + ApplicationContext.Current.Services.NotificationService.SetNotifications(Security.CurrentUser, node, notifications.ToCharArray().Select(x => x.ToString()).ToArray()); var feedback = new umbraco.uicontrols.Feedback(); feedback.Text = Services.TextService.Localize("notifications") + " " + Services.TextService.Localize("ok") + "

" + Services.TextService.Localize("closeThisWindow") + ""; diff --git a/src/umbraco.cms/businesslogic/CMSNode.cs b/src/umbraco.cms/businesslogic/CMSNode.cs index f96601aac0..e1458bcddc 100644 --- a/src/umbraco.cms/businesslogic/CMSNode.cs +++ b/src/umbraco.cms/businesslogic/CMSNode.cs @@ -18,7 +18,7 @@ using System.Collections; using umbraco.cms.businesslogic.task; using Umbraco.Core.Models.Membership; using File = System.IO.File; -using Notification = umbraco.cms.businesslogic.workflow.Notification; + using Task = umbraco.cms.businesslogic.task.Task; namespace umbraco.cms.businesslogic @@ -527,10 +527,7 @@ order by level,sortOrder"; { t.Delete(); } - - //remove notifications - Notification.DeleteNotifications(this); - + //remove permissions Permission.DeletePermissions(this); diff --git a/src/umbraco.cms/businesslogic/workflow/Notification.cs b/src/umbraco.cms/businesslogic/workflow/Notification.cs deleted file mode 100644 index 860e55600c..0000000000 --- a/src/umbraco.cms/businesslogic/workflow/Notification.cs +++ /dev/null @@ -1,174 +0,0 @@ -using Umbraco.Core.Models; -using Umbraco.Core.Services; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Web; -using Umbraco.Core; -using Umbraco.Core.Configuration; -using Umbraco.Core.Logging; -using umbraco.BusinessLogic; -using umbraco.cms.businesslogic.web; -using Umbraco.Core.Models.Rdbms; -using umbraco.DataLayer; -using Umbraco.Core.Models; -using Umbraco.Core.Models.Membership; - -namespace umbraco.cms.businesslogic.workflow -{ - //TODO: Update this to wrap new services/repo! - - ///

- /// Notifications are a part of the umbraco workflow. - /// A notification is created every time an action on a node occurs and a umbraco user has subscribed to this specific action on this specific node. - /// Notifications generates an email, which is send to the subscribing users. - /// - public class Notification - { - /// - /// Private constructor as this object should not be allowed to be created currently - /// - private Notification() - { - } - - public int NodeId { get; private set; } - public int UserId { get; private set; } - public char ActionId { get; private set; } - - /// - /// Gets the SQL helper. - /// - /// The SQL helper. - [Obsolete("Obsolete, For querying the database use the new UmbracoDatabase object ApplicationContext.Current.DatabaseContext.Database", false)] - protected static ISqlHelper SqlHelper - { - get { return LegacySqlHelper.SqlHelper; } - } - - /// - /// Returns the notifications for a user - /// - /// - /// - public static IEnumerable GetUserNotifications(IUser user) - { - var items = new List(); - var dtos = ApplicationContext.Current.DatabaseContext.Database.Fetch( - "WHERE userId = @UserId ORDER BY nodeId", new { UserId = user.Id }); - - foreach (var dto in dtos) - { - items.Add(new Notification - { - NodeId = dto.NodeId, - ActionId = Convert.ToChar(dto.Action), - UserId = dto.UserId - }); - } - - return items; - } - - /// - /// Returns the notifications for a node - /// - /// - /// - public static IEnumerable GetNodeNotifications(CMSNode node) - { - var items = new List(); - var dtos = ApplicationContext.Current.DatabaseContext.Database.Fetch( - "WHERE userId = @UserId ORDER BY nodeId", new { nodeId = node.Id }); - - foreach (var dto in dtos) - { - items.Add(new Notification - { - NodeId = dto.NodeId, - ActionId = Convert.ToChar(dto.Action), - UserId = dto.UserId - }); - } - return items; - } - - /// - /// Deletes notifications by node - /// - /// - public static void DeleteNotifications(CMSNode node) - { - // delete all settings on the node for this node id - ApplicationContext.Current.DatabaseContext.Database.Delete("WHERE nodeId = @nodeId", - new {nodeId = node.Id}); - } - - /// - /// Delete notifications by user - /// - /// - public static void DeleteNotifications(IUser user) - { - // delete all settings on the node for this node id - ApplicationContext.Current.DatabaseContext.Database.Delete("WHERE userId = @userId", - new { userId = user.Id }); - } - - /// - /// Delete notifications by user and node - /// - /// - /// - public static void DeleteNotifications(IUser user, CMSNode node) - { - // delete all settings on the node for this user - ApplicationContext.Current.DatabaseContext.Database.Delete( - "WHERE userId = @userId AND nodeId = @nodeId", new {userId = user.Id, nodeId = node.Id}); - } - - /// - /// Creates a new notification - /// - /// The user. - /// The node. - /// The action letter. - [MethodImpl(MethodImplOptions.Synchronized)] - public static void MakeNew(IUser user, CMSNode node, char actionLetter) - { - bool exists = ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar( - "SELECT COUNT(userId) FROM umbracoUser2nodeNotify WHERE userId = @userId AND nodeId = @nodeId AND action = @action", - new { userId = user.Id, nodeId = node.Id, action = actionLetter.ToString()}) > 0; - - if (exists == false) - { - ApplicationContext.Current.DatabaseContext.Database.Insert(new User2NodeNotifyDto - { - Action = actionLetter.ToString(), - NodeId = node.Id, - UserId = user.Id - }); - } - } - - /// - /// Updates the notifications. - /// - /// The user. - /// The node. - /// The notifications. - [MethodImpl(MethodImplOptions.Synchronized)] - public static void UpdateNotifications(IUser user, CMSNode node, string notifications) - { - // delete all settings on the node for this user - DeleteNotifications(user, node); - - // Loop through the permissions and create them - foreach (char c in notifications) - MakeNew(user, node, c); - } - - } -} \ No newline at end of file diff --git a/src/umbraco.cms/umbraco.cms.csproj b/src/umbraco.cms/umbraco.cms.csproj index 1b9e6509f1..0a8682dee0 100644 --- a/src/umbraco.cms/umbraco.cms.csproj +++ b/src/umbraco.cms/umbraco.cms.csproj @@ -270,9 +270,6 @@ Code - - Code -