Work items: 30724
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Mail;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Collections.Generic;
|
||||
using umbraco.BusinessLogic;
|
||||
using umbraco.cms.businesslogic.property;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
using umbraco.interfaces;
|
||||
using umbraco.DataLayer;
|
||||
using umbraco.interfaces;
|
||||
using umbraco.IO;
|
||||
using System.Collections;
|
||||
|
||||
namespace umbraco.cms.businesslogic.workflow
|
||||
{
|
||||
@@ -22,16 +20,17 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
/// </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>
|
||||
/// Private constructor as this object should not be allowed to be created currently
|
||||
/// </summary>
|
||||
private Notification() { }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the SQL helper.
|
||||
/// </summary>
|
||||
@@ -59,7 +58,7 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
Log.Add(LogTypes.Notify, User.GetUser(0), Node.Id,
|
||||
"Notification about " + ui.Text(Action.Alias, u) + " sent to " + u.Name + " (" + u.Email +
|
||||
")");
|
||||
sendNotification(user, u, (Document) Node, Action);
|
||||
sendNotification(user, u, (Document)Node, Action);
|
||||
}
|
||||
}
|
||||
catch (Exception notifyExp)
|
||||
@@ -68,7 +67,7 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///TODO: Include update with html mail notification and document contents
|
||||
private static void sendNotification(User performingUser, User mailingUser, Document documentObject,
|
||||
IAction Action)
|
||||
@@ -76,11 +75,11 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
// retrieve previous version of the document
|
||||
DocumentVersionList[] versions = documentObject.GetVersions();
|
||||
int versionCount = (versions.Length > 1) ? (versions.Length - 2) : (versions.Length - 1);
|
||||
Document oldDoc = new Document(documentObject.Id, versions[versionCount].Version);
|
||||
var oldDoc = new Document(documentObject.Id, versions[versionCount].Version);
|
||||
|
||||
// build summary
|
||||
StringBuilder summary = new StringBuilder();
|
||||
var props = documentObject.getProperties;
|
||||
var summary = new StringBuilder();
|
||||
Property[] props = documentObject.getProperties;
|
||||
foreach (Property p in props)
|
||||
{
|
||||
// check if something was changed and display the changes otherwise display the fields
|
||||
@@ -94,51 +93,72 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
|
||||
// make sure to only highlight changes done using TinyMCE editor... other changes will be displayed using default summary
|
||||
///TODO PPH: Had to change this, as a reference to the editorcontrols is not allowed, so a string comparison is the only way, this should be a DIFF or something instead..
|
||||
if (p.PropertyType.DataTypeDefinition.DataType.ToString() == "umbraco.editorControls.tinymce.TinyMCEDataType" &&
|
||||
string.Compare( oldText, newText ) != 0)
|
||||
if (p.PropertyType.DataTypeDefinition.DataType.ToString() ==
|
||||
"umbraco.editorControls.tinymce.TinyMCEDataType" &&
|
||||
string.Compare(oldText, newText) != 0)
|
||||
{
|
||||
summary.Append("<tr>");
|
||||
summary.Append("<th style='text-align: left; vertical-align: top; width: 25%;'> Note: </th>");
|
||||
summary.Append("<td style='text-align: left; vertical-align: top;'> <span style='background-color:red;'>Red for deleted characters</span> <span style='background-color:yellow;'>Yellow for inserted characters</span></td>");
|
||||
summary.Append(
|
||||
"<td style='text-align: left; vertical-align: top;'> <span style='background-color:red;'>Red for deleted characters</span> <span style='background-color:yellow;'>Yellow for inserted characters</span></td>");
|
||||
summary.Append("</tr>");
|
||||
summary.Append("<tr>");
|
||||
summary.Append("<th style='text-align: left; vertical-align: top; width: 25%;'> New " + p.PropertyType.Name + "</th>");
|
||||
summary.Append("<td style='text-align: left; vertical-align: top;'>" + replaceLinks(CompareText(oldText, newText, true, false, "<span style='background-color:yellow;'>", string.Empty)) + "</td>");
|
||||
summary.Append("<th style='text-align: left; vertical-align: top; width: 25%;'> New " +
|
||||
p.PropertyType.Name + "</th>");
|
||||
summary.Append("<td style='text-align: left; vertical-align: top;'>" +
|
||||
replaceLinks(CompareText(oldText, newText, true, false,
|
||||
"<span style='background-color:yellow;'>", string.Empty)) +
|
||||
"</td>");
|
||||
summary.Append("</tr>");
|
||||
summary.Append("<tr>");
|
||||
summary.Append("<th style='text-align: left; vertical-align: top; width: 25%;'> Old " + oldProperty.PropertyType.Name + "</th>");
|
||||
summary.Append("<td style='text-align: left; vertical-align: top;'>" + replaceLinks(CompareText(newText, oldText, true, false, "<span style='background-color:red;'>", string.Empty)) + "</td>");
|
||||
summary.Append("<th style='text-align: left; vertical-align: top; width: 25%;'> Old " +
|
||||
oldProperty.PropertyType.Name + "</th>");
|
||||
summary.Append("<td style='text-align: left; vertical-align: top;'>" +
|
||||
replaceLinks(CompareText(newText, oldText, true, false,
|
||||
"<span style='background-color:red;'>", string.Empty)) +
|
||||
"</td>");
|
||||
summary.Append("</tr>");
|
||||
}
|
||||
else
|
||||
{
|
||||
summary.Append("<tr>");
|
||||
summary.Append("<th style='text-align: left; vertical-align: top; width: 25%;'>" + p.PropertyType.Name + "</th>");
|
||||
summary.Append("<style='text-align: left; vertical-align: top;'>" + p.Value.ToString() + "</td>");
|
||||
summary.Append("<th style='text-align: left; vertical-align: top; width: 25%;'>" +
|
||||
p.PropertyType.Name + "</th>");
|
||||
summary.Append("<style='text-align: left; vertical-align: top;'>" + p.Value + "</td>");
|
||||
summary.Append("</tr>");
|
||||
}
|
||||
summary.Append("<tr><td colspan=\"2\" style=\"border-bottom: 1px solid #CCC; font-size: 2px;\"> </td></tr>");
|
||||
summary.Append(
|
||||
"<tr><td colspan=\"2\" style=\"border-bottom: 1px solid #CCC; font-size: 2px;\"> </td></tr>");
|
||||
}
|
||||
|
||||
string protocol = GlobalSettings.UseSSL ? "https" : "http";
|
||||
|
||||
|
||||
string[] subjectVars = {
|
||||
HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + ":" + HttpContext.Current.Request.Url.Port.ToString() + IOHelper.ResolveUrl(SystemDirectories.Umbraco), ui.Text(Action.Alias)
|
||||
HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + ":" +
|
||||
HttpContext.Current.Request.Url.Port +
|
||||
IOHelper.ResolveUrl(SystemDirectories.Umbraco), ui.Text(Action.Alias)
|
||||
,
|
||||
documentObject.Text
|
||||
};
|
||||
string[] bodyVars = {
|
||||
mailingUser.Name, ui.Text(Action.Alias), documentObject.Text, performingUser.Name,
|
||||
HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + ":" + HttpContext.Current.Request.Url.Port.ToString() +IOHelper.ResolveUrl(SystemDirectories.Umbraco),
|
||||
documentObject.Id.ToString(), summary.ToString(),
|
||||
String.Format("http://{0}/{1}",
|
||||
HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + ":" + HttpContext.Current.Request.Url.Port.ToString(),
|
||||
/*umbraco.library.NiceUrl(documentObject.Id))*/ documentObject.Id.ToString() + ".aspx")
|
||||
///TODO: PPH removed the niceURL reference... cms.dll cannot reference the presentation project...
|
||||
///TODO: This should be moved somewhere else..
|
||||
HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + ":" +
|
||||
HttpContext.Current.Request.Url.Port +
|
||||
IOHelper.ResolveUrl(SystemDirectories.Umbraco),
|
||||
documentObject.Id.ToString(), summary.ToString(),
|
||||
String.Format("{2}://{0}/{1}",
|
||||
HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + ":" +
|
||||
HttpContext.Current.Request.Url.Port,
|
||||
/*umbraco.library.NiceUrl(documentObject.Id))*/
|
||||
documentObject.Id + ".aspx",
|
||||
protocol)
|
||||
///TODO: PPH removed the niceURL reference... cms.dll cannot reference the presentation project...
|
||||
///TODO: This should be moved somewhere else..
|
||||
};
|
||||
|
||||
// create the mail message
|
||||
MailMessage mail = new MailMessage(UmbracoSettings.NotificationEmailSender, mailingUser.Email);
|
||||
var mail = new MailMessage(UmbracoSettings.NotificationEmailSender, mailingUser.Email);
|
||||
|
||||
// populate the message
|
||||
mail.Subject = ui.Text("notifications", "mailSubject", subjectVars, mailingUser);
|
||||
@@ -146,7 +166,8 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
{
|
||||
mail.IsBodyHtml = false;
|
||||
mail.Body = ui.Text("notifications", "mailBody", bodyVars, mailingUser);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
mail.IsBodyHtml = true;
|
||||
mail.Body =
|
||||
@@ -157,13 +178,26 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
ui.Text("notifications", "mailBodyHtml", bodyVars, mailingUser) + "</body></html>";
|
||||
}
|
||||
|
||||
// nh, issue 30724. Due to hardcoded http strings in resource files, we need to check for https replacements here
|
||||
// adding the server name to make sure we don't replace external links
|
||||
if (GlobalSettings.UseSSL && !String.IsNullOrEmpty(mail.Body))
|
||||
{
|
||||
string serverName = HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
|
||||
mail.Body = mail.Body.Replace(
|
||||
string.Format("http://{0}", serverName),
|
||||
string.Format("https://{0}", serverName));
|
||||
}
|
||||
|
||||
// send it
|
||||
SmtpClient sender = new SmtpClient();
|
||||
var sender = new SmtpClient();
|
||||
sender.Send(mail);
|
||||
}
|
||||
|
||||
private static string replaceLinks(string text) {
|
||||
string domain = "http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + ":" + HttpContext.Current.Request.Url.Port.ToString() + "/";
|
||||
private static string replaceLinks(string text)
|
||||
{
|
||||
string domain = GlobalSettings.UseSSL ? "https://" : "http://";
|
||||
domain += HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + ":" +
|
||||
HttpContext.Current.Request.Url.Port + "/";
|
||||
text = text.Replace("href=\"/", "href=\"" + domain);
|
||||
text = text.Replace("src=\"/", "src=\"" + domain);
|
||||
return text;
|
||||
@@ -177,16 +211,20 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
public static IEnumerable<Notification> GetUserNotifications(User user)
|
||||
{
|
||||
var items = new List<Notification>();
|
||||
using (IRecordsReader dr = SqlHelper.ExecuteReader("select * from umbracoUser2NodeNotify where userId = @userId order by nodeId", SqlHelper.CreateParameter("@userId", user.Id)))
|
||||
using (
|
||||
IRecordsReader dr =
|
||||
SqlHelper.ExecuteReader(
|
||||
"select * from umbracoUser2NodeNotify where userId = @userId order by nodeId",
|
||||
SqlHelper.CreateParameter("@userId", user.Id)))
|
||||
{
|
||||
while (dr.Read())
|
||||
{
|
||||
items.Add(new Notification()
|
||||
{
|
||||
NodeId = dr.GetInt("nodeId"),
|
||||
ActionId = Convert.ToChar(dr.GetString("action")),
|
||||
UserId = dr.GetInt("userId")
|
||||
});
|
||||
items.Add(new Notification
|
||||
{
|
||||
NodeId = dr.GetInt("nodeId"),
|
||||
ActionId = Convert.ToChar(dr.GetString("action")),
|
||||
UserId = dr.GetInt("userId")
|
||||
});
|
||||
}
|
||||
}
|
||||
return items;
|
||||
@@ -200,16 +238,20 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
public static IEnumerable<Notification> GetNodeNotifications(CMSNode node)
|
||||
{
|
||||
var items = new List<Notification>();
|
||||
using (IRecordsReader dr = SqlHelper.ExecuteReader("select * from umbracoUser2NodeNotify where nodeId = @nodeId order by nodeId", SqlHelper.CreateParameter("@nodeId", node.Id)))
|
||||
using (
|
||||
IRecordsReader dr =
|
||||
SqlHelper.ExecuteReader(
|
||||
"select * from umbracoUser2NodeNotify where nodeId = @nodeId order by nodeId",
|
||||
SqlHelper.CreateParameter("@nodeId", node.Id)))
|
||||
{
|
||||
while (dr.Read())
|
||||
{
|
||||
items.Add(new Notification()
|
||||
{
|
||||
NodeId = dr.GetInt("nodeId"),
|
||||
ActionId = Convert.ToChar(dr.GetString("action")),
|
||||
UserId = dr.GetInt("userId")
|
||||
});
|
||||
items.Add(new Notification
|
||||
{
|
||||
NodeId = dr.GetInt("nodeId"),
|
||||
ActionId = Convert.ToChar(dr.GetString("action")),
|
||||
UserId = dr.GetInt("userId")
|
||||
});
|
||||
}
|
||||
}
|
||||
return items;
|
||||
@@ -246,7 +288,8 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
{
|
||||
// delete all settings on the node for this user
|
||||
SqlHelper.ExecuteNonQuery("delete from umbracoUser2NodeNotify where userId = @userId and nodeId = @nodeId",
|
||||
SqlHelper.CreateParameter("@userId", user.Id), SqlHelper.CreateParameter("@nodeId", node.Id));
|
||||
SqlHelper.CreateParameter("@userId", user.Id),
|
||||
SqlHelper.CreateParameter("@nodeId", node.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -258,17 +301,21 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
public static void MakeNew(User User, CMSNode Node, char ActionLetter)
|
||||
{
|
||||
IParameter[] parameters = new IParameter[] {
|
||||
SqlHelper.CreateParameter("@userId", User.Id),
|
||||
SqlHelper.CreateParameter("@nodeId", Node.Id),
|
||||
SqlHelper.CreateParameter("@action", ActionLetter.ToString()) };
|
||||
var parameters = new[]
|
||||
{
|
||||
SqlHelper.CreateParameter("@userId", User.Id),
|
||||
SqlHelper.CreateParameter("@nodeId", Node.Id),
|
||||
SqlHelper.CreateParameter("@action", ActionLetter.ToString())
|
||||
};
|
||||
|
||||
// Method is synchronized so exists remains consistent (avoiding race condition)
|
||||
bool exists = SqlHelper.ExecuteScalar<int>("SELECT COUNT(userId) FROM umbracoUser2nodeNotify WHERE userId = @userId AND nodeId = @nodeId AND action = @action",
|
||||
parameters) > 0;
|
||||
bool exists = SqlHelper.ExecuteScalar<int>(
|
||||
"SELECT COUNT(userId) FROM umbracoUser2nodeNotify WHERE userId = @userId AND nodeId = @nodeId AND action = @action",
|
||||
parameters) > 0;
|
||||
if (!exists)
|
||||
SqlHelper.ExecuteNonQuery("INSERT INTO umbracoUser2nodeNotify (userId, nodeId, action) VALUES (@userId, @nodeId, @action)",
|
||||
parameters);
|
||||
SqlHelper.ExecuteNonQuery(
|
||||
"INSERT INTO umbracoUser2nodeNotify (userId, nodeId, action) VALUES (@userId, @nodeId, @action)",
|
||||
parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -284,7 +331,7 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
DeleteNotifications(User, Node);
|
||||
|
||||
// Loop through the permissions and create them
|
||||
foreach (char c in Notifications.ToCharArray())
|
||||
foreach (char c in Notifications)
|
||||
MakeNew(User, Node, c);
|
||||
}
|
||||
|
||||
@@ -321,9 +368,11 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
/// <param name="displayInsertedText">if set to <c>true</c> [display inserted text].</param>
|
||||
/// <param name="displayDeletedText">if set to <c>true</c> [display deleted text].</param>
|
||||
/// <returns></returns>
|
||||
private static string CompareText(string oldText, string newText, bool displayInsertedText, bool displayDeletedText)
|
||||
private static string CompareText(string oldText, string newText, bool displayInsertedText,
|
||||
bool displayDeletedText)
|
||||
{
|
||||
return CompareText(oldText, newText, displayInsertedText, displayDeletedText, "<span style='background-color:red;'>", "<span style='background-color:yellow;'>");
|
||||
return CompareText(oldText, newText, displayInsertedText, displayDeletedText,
|
||||
"<span style='background-color:red;'>", "<span style='background-color:yellow;'>");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -336,9 +385,10 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
/// <param name="insertedStyle">The inserted style.</param>
|
||||
/// <param name="deletedStyle">The deleted style.</param>
|
||||
/// <returns></returns>
|
||||
private static string CompareText(string oldText, string newText, bool displayInsertedText, bool displayDeletedText, string insertedStyle, string deletedStyle)
|
||||
private static string CompareText(string oldText, string newText, bool displayInsertedText,
|
||||
bool displayDeletedText, string insertedStyle, string deletedStyle)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
Diff.Item[] diffs = Diff.DiffText1(oldText, newText);
|
||||
|
||||
int pos = 0;
|
||||
@@ -355,7 +405,7 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
|
||||
// write deleted chars
|
||||
if (displayDeletedText && it.deletedA > 0)
|
||||
{
|
||||
{
|
||||
sb.Append(deletedStyle);
|
||||
for (int m = 0; m < it.deletedA; m++)
|
||||
{
|
||||
@@ -366,7 +416,7 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
|
||||
// write inserted chars
|
||||
if (displayInsertedText && pos < it.StartB + it.insertedB)
|
||||
{
|
||||
{
|
||||
sb.Append(insertedStyle);
|
||||
while (pos < it.StartB + it.insertedB)
|
||||
{
|
||||
@@ -386,5 +436,5 @@ namespace umbraco.cms.businesslogic.workflow
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user