Removes legacy 'Notification' business logic, adds new SetNotifications method to INotificationService
This commit is contained in:
@@ -13,5 +13,6 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
int DeleteNotifications(IUser user, IEntity entity);
|
||||
IEnumerable<Notification> GetEntityNotifications(IEntity entity);
|
||||
IEnumerable<Notification> GetUserNotifications(IUser user);
|
||||
IEnumerable<Notification> SetNotifications(IUser user, IEntity entity, string[] actions);
|
||||
}
|
||||
}
|
||||
@@ -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<Notification> SetNotifications(IUser user, IEntity entity, string[] actions)
|
||||
{
|
||||
var notifications = new List<Notification>();
|
||||
using (var t = _unitOfWork.Database.GetTransaction())
|
||||
{
|
||||
DeleteNotifications(user, entity);
|
||||
notifications.AddRange(actions.Select(action => CreateNotification(user, entity, action)));
|
||||
t.Complete();
|
||||
}
|
||||
return notifications;
|
||||
}
|
||||
|
||||
public IEnumerable<Notification> GetEntityNotifications(IEntity entity)
|
||||
{
|
||||
var sql = new Sql()
|
||||
|
||||
@@ -72,6 +72,17 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="entity"></param>
|
||||
void DeleteNotifications(IUser user, IEntity entity);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the specific notifications for the user and entity
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="actions"></param>
|
||||
/// <remarks>
|
||||
/// This performs a full replace
|
||||
/// </remarks>
|
||||
IEnumerable<Notification> SetNotifications(IUser user, IEntity entity, string[] actions);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new notification
|
||||
/// </summary>
|
||||
|
||||
@@ -174,6 +174,22 @@ namespace Umbraco.Core.Services
|
||||
repository.DeleteNotifications(user, entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the specific notifications for the user and entity
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="actions"></param>
|
||||
/// <remarks>
|
||||
/// This performs a full replace
|
||||
/// </remarks>
|
||||
public IEnumerable<Notification> SetNotifications(IUser user, IEntity entity, string[] actions)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
var repository = _repositoryFactory.CreateNotificationsRepository(uow);
|
||||
return repository.SetNotifications(user, entity, actions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new notification
|
||||
/// </summary>
|
||||
|
||||
@@ -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") + "</p><p><a href='#' class='btn btn-primary' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + Services.TextService.Localize("closeThisWindow") + "</a>";
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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!
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public class Notification
|
||||
{
|
||||
/// <summary>
|
||||
/// Private constructor as this object should not be allowed to be created currently
|
||||
/// </summary>
|
||||
private Notification()
|
||||
{
|
||||
}
|
||||
|
||||
public int NodeId { get; private set; }
|
||||
public int UserId { get; private set; }
|
||||
public char ActionId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the SQL helper.
|
||||
/// </summary>
|
||||
/// <value>The SQL helper.</value>
|
||||
[Obsolete("Obsolete, For querying the database use the new UmbracoDatabase object ApplicationContext.Current.DatabaseContext.Database", false)]
|
||||
protected static ISqlHelper SqlHelper
|
||||
{
|
||||
get { return LegacySqlHelper.SqlHelper; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the notifications for a user
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Notification> GetUserNotifications(IUser user)
|
||||
{
|
||||
var items = new List<Notification>();
|
||||
var dtos = ApplicationContext.Current.DatabaseContext.Database.Fetch<User2NodeNotifyDto>(
|
||||
"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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the notifications for a node
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Notification> GetNodeNotifications(CMSNode node)
|
||||
{
|
||||
var items = new List<Notification>();
|
||||
var dtos = ApplicationContext.Current.DatabaseContext.Database.Fetch<User2NodeNotifyDto>(
|
||||
"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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes notifications by node
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
public static void DeleteNotifications(CMSNode node)
|
||||
{
|
||||
// delete all settings on the node for this node id
|
||||
ApplicationContext.Current.DatabaseContext.Database.Delete<User2NodeNotifyDto>("WHERE nodeId = @nodeId",
|
||||
new {nodeId = node.Id});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete notifications by user
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
public static void DeleteNotifications(IUser user)
|
||||
{
|
||||
// delete all settings on the node for this node id
|
||||
ApplicationContext.Current.DatabaseContext.Database.Delete<User2NodeNotifyDto>("WHERE userId = @userId",
|
||||
new { userId = user.Id });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete notifications by user and node
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="node"></param>
|
||||
public static void DeleteNotifications(IUser user, CMSNode node)
|
||||
{
|
||||
// delete all settings on the node for this user
|
||||
ApplicationContext.Current.DatabaseContext.Database.Delete<User2NodeNotifyDto>(
|
||||
"WHERE userId = @userId AND nodeId = @nodeId", new {userId = user.Id, nodeId = node.Id});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new notification
|
||||
/// </summary>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="node">The node.</param>
|
||||
/// <param name="actionLetter">The action letter.</param>
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
public static void MakeNew(IUser user, CMSNode node, char actionLetter)
|
||||
{
|
||||
bool exists = ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar<int>(
|
||||
"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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the notifications.
|
||||
/// </summary>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="node">The node.</param>
|
||||
/// <param name="notifications">The notifications.</param>
|
||||
[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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -270,9 +270,6 @@
|
||||
<Compile Include="businesslogic\web\StylesheetProperty.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="businesslogic\workflow\Notification.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="businesslogic\Packager\FileResources\Packages.config" />
|
||||
|
||||
Reference in New Issue
Block a user