diff --git a/umbraco/cms/businesslogic/workflow/Notification.cs b/umbraco/cms/businesslogic/workflow/Notification.cs index 8d1e7c07a2..71faa2b6ed 100644 --- a/umbraco/cms/businesslogic/workflow/Notification.cs +++ b/umbraco/cms/businesslogic/workflow/Notification.cs @@ -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 /// 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; } - /// - /// Private constructor as this object should not be allowed to be created currently - /// - private Notification() { } - /// /// Gets the SQL helper. /// @@ -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(""); summary.Append(" Note: "); - summary.Append(" Red for deleted characters Yellow for inserted characters"); + summary.Append( + " Red for deleted characters Yellow for inserted characters"); summary.Append(""); summary.Append(""); - summary.Append(" New " + p.PropertyType.Name + ""); - summary.Append("" + replaceLinks(CompareText(oldText, newText, true, false, "", string.Empty)) + ""); + summary.Append(" New " + + p.PropertyType.Name + ""); + summary.Append("" + + replaceLinks(CompareText(oldText, newText, true, false, + "", string.Empty)) + + ""); summary.Append(""); summary.Append(""); - summary.Append(" Old " + oldProperty.PropertyType.Name + ""); - summary.Append("" + replaceLinks(CompareText(newText, oldText, true, false, "", string.Empty)) + ""); + summary.Append(" Old " + + oldProperty.PropertyType.Name + ""); + summary.Append("" + + replaceLinks(CompareText(newText, oldText, true, false, + "", string.Empty)) + + ""); summary.Append(""); } else { summary.Append(""); - summary.Append("" + p.PropertyType.Name + ""); - summary.Append("" + p.Value.ToString() + ""); + summary.Append("" + + p.PropertyType.Name + ""); + summary.Append("" + p.Value + ""); summary.Append(""); } - summary.Append(" "); + summary.Append( + " "); } + 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) + ""; } + // 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 GetUserNotifications(User user) { var items = new List(); - 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 GetNodeNotifications(CMSNode node) { var items = new List(); - 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)); } /// @@ -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("SELECT COUNT(userId) FROM umbracoUser2nodeNotify WHERE userId = @userId AND nodeId = @nodeId AND action = @action", - parameters) > 0; + bool exists = SqlHelper.ExecuteScalar( + "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); } /// @@ -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 /// if set to true [display inserted text]. /// if set to true [display deleted text]. /// - 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, "", ""); + return CompareText(oldText, newText, displayInsertedText, displayDeletedText, + "", ""); } /// @@ -336,9 +385,10 @@ namespace umbraco.cms.businesslogic.workflow /// The inserted style. /// The deleted style. /// - 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(); } - } + } } \ No newline at end of file