diff --git a/src/Umbraco.Core/XmlExtensions.cs b/src/Umbraco.Core/XmlExtensions.cs index ab526f6532..9039ab4b58 100644 --- a/src/Umbraco.Core/XmlExtensions.cs +++ b/src/Umbraco.Core/XmlExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Xml; namespace Umbraco.Core @@ -9,6 +10,10 @@ namespace Umbraco.Core /// internal static class XmlExtensions { + public static bool HasAttribute(this XmlAttributeCollection attributes, string attributeName) + { + return attributes.Cast().Any(x => x.Name == attributeName); + } public static T AttributeValue(this XmlNode xml, string attributeName) { diff --git a/src/Umbraco.Core/XmlHelper.cs b/src/Umbraco.Core/XmlHelper.cs index 0a3d16e9c8..754a632dd2 100644 --- a/src/Umbraco.Core/XmlHelper.cs +++ b/src/Umbraco.Core/XmlHelper.cs @@ -13,7 +13,7 @@ namespace Umbraco.Core /// public class XmlHelper { - + /// /// Imports a XML node from text. /// diff --git a/src/Umbraco.Tests/UI/LegacyDialogTests.cs b/src/Umbraco.Tests/UI/LegacyDialogTests.cs new file mode 100644 index 0000000000..a9a2a608e3 --- /dev/null +++ b/src/Umbraco.Tests/UI/LegacyDialogTests.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; +using Umbraco.Core; +using Umbraco.Web.UI; +using umbraco; +using umbraco.BusinessLogic; +using umbraco.cms.presentation.user; +using umbraco.interfaces; + +namespace Umbraco.Tests.UI +{ + [TestFixture] + public class LegacyDialogTests + { + + [Test] + public void Ensure_All_Tasks_Are_Secured() + { + var allTasks = TypeFinder.FindClassesOfType(); + + foreach (var t in allTasks) + { + Assert.IsTrue(TypeHelper.IsTypeAssignableFrom(t), "The type " + t + " is not of type " + typeof(LegacyDialogTask)); + } + } + + [TestCase(typeof(UserTypeTasks), DefaultApps.users)] + [TestCase(typeof(contentItemTypeTasks), DefaultApps.member)] + [TestCase(typeof(contentItemTasks), DefaultApps.member)] + [TestCase(typeof(XsltTasks), DefaultApps.developer)] + [TestCase(typeof(userTasks), DefaultApps.users)] + [TestCase(typeof(templateTasks), DefaultApps.settings)] + [TestCase(typeof(StylesheetTasks), DefaultApps.settings)] + [TestCase(typeof(stylesheetPropertyTasks), DefaultApps.settings)] + [TestCase(typeof(ScriptTasks), DefaultApps.settings)] + [TestCase(typeof(nodetypeTasks), DefaultApps.settings)] + [TestCase(typeof(PythonTasks), DefaultApps.developer)] + [TestCase(typeof(MemberTypeTasks), DefaultApps.member)] + [TestCase(typeof(memberTasks), DefaultApps.member)] + [TestCase(typeof(MemberGroupTasks), DefaultApps.member)] + [TestCase(typeof(MediaTypeTasks), DefaultApps.settings)] + [TestCase(typeof(mediaTasks), DefaultApps.media)] + [TestCase(typeof(dictionaryTasks), DefaultApps.settings)] + [TestCase(typeof(macroTasks), DefaultApps.developer)] + [TestCase(typeof(languageTasks), DefaultApps.settings)] + [TestCase(typeof(DLRScriptingTasks), DefaultApps.developer)] + [TestCase(typeof(DataTypeTasks), DefaultApps.developer)] + [TestCase(typeof(CreatedPackageTasks), DefaultApps.developer)] + [TestCase(typeof(contentTasks), DefaultApps.content)] + public void Check_Assigned_Apps_For_Tasks(Type taskType, DefaultApps app) + { + var task = (LegacyDialogTask)Activator.CreateInstance(taskType); + Assert.AreEqual(task.AssignedApp, app.ToString()); + } + + } +} diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 59b7c6751e..431316cabe 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -121,6 +121,7 @@ ExamineResources.resx + diff --git a/src/Umbraco.Web.UI/umbraco/Create.aspx.cs b/src/Umbraco.Web.UI/umbraco/Create.aspx.cs index b30e2a3f3b..7c19450e0b 100644 --- a/src/Umbraco.Web.UI/umbraco/Create.aspx.cs +++ b/src/Umbraco.Web.UI/umbraco/Create.aspx.cs @@ -12,33 +12,28 @@ namespace Umbraco.Web.UI.Umbraco public partial class Create : global::umbraco.cms.presentation.Create { - //protected override void OnLoad(EventArgs e) - //{ - // if (SecurityCheck(Request.QueryString["nodeType"])) - // { - // //if we're allowed, then continue - // base.OnLoad(e); - // } - // else - // { - // //otherwise show an error - // UI.Visible = false; - // AccessError.Visible = true; - // } - //} + protected override void OnLoad(EventArgs e) + { + if (SecurityCheck(Request.QueryString["nodeType"])) + { + //if we're allowed, then continue + base.OnLoad(e); + } + else + { + //otherwise show an error + UI.Visible = false; + AccessError.Visible = true; + } + } - //private bool SecurityCheck(string treeAlias) - //{ - // var tree = TreeDefinitionCollection.Instance.FindTree(treeAlias); - // if (tree != null) - // { - // //does the current user have access to the current app? - // var user = this.getUser(); - // var userApps = user.Applications; - // return userApps.Any(x => x.alias.InvariantEquals(tree.App.alias)); - // } - // return false; - //} + private bool SecurityCheck(string nodeTypeAlias) + { + return LegacyDialogHandler.UserHasCreateAccess( + new HttpContextWrapper(Context), + getUser(), + nodeTypeAlias); + } } } \ No newline at end of file diff --git a/src/Umbraco.Web.UI/umbraco/config/create/UI.Release.xml b/src/Umbraco.Web.UI/umbraco/config/create/UI.Release.xml index b988bb864a..910efdaa5d 100644 --- a/src/Umbraco.Web.UI/umbraco/config/create/UI.Release.xml +++ b/src/Umbraco.Web.UI/umbraco/config/create/UI.Release.xml @@ -64,7 +64,6 @@ /create/content.ascx - @@ -181,7 +180,7 @@ - + +
Stylesheet editor egenskab
/create/simple.ascx diff --git a/src/Umbraco.Web.UI/umbraco/config/create/UI.xml b/src/Umbraco.Web.UI/umbraco/config/create/UI.xml index eaa028c34b..a73607aa3a 100644 --- a/src/Umbraco.Web.UI/umbraco/config/create/UI.xml +++ b/src/Umbraco.Web.UI/umbraco/config/create/UI.xml @@ -64,7 +64,6 @@ /create/content.ascx -
@@ -181,7 +180,7 @@
- + +
Stylesheet editor egenskab
/create/simple.ascx diff --git a/src/Umbraco.Web/UI/IAssignedApp.cs b/src/Umbraco.Web/UI/IAssignedApp.cs new file mode 100644 index 0000000000..3be16f138f --- /dev/null +++ b/src/Umbraco.Web/UI/IAssignedApp.cs @@ -0,0 +1,17 @@ +namespace Umbraco.Web.UI +{ + /// + /// This is used for anything that is assigned to an app + /// + /// + /// Currently things that need to be assigned to an app in order for user security to work are: + /// dialogs, ITasks, editors + /// + public interface IAssignedApp + { + /// + /// Returns the app alias that this element belongs to + /// + string AssignedApp { get; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/UI/LegacyDialogHandler.cs b/src/Umbraco.Web/UI/LegacyDialogHandler.cs index 0e6d3aeca8..7e45c401d2 100644 --- a/src/Umbraco.Web/UI/LegacyDialogHandler.cs +++ b/src/Umbraco.Web/UI/LegacyDialogHandler.cs @@ -3,10 +3,14 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; +using System.Web; using System.Xml; +using Umbraco.Core; using Umbraco.Core.IO; using umbraco.BasePages; +using umbraco.BusinessLogic; using umbraco.interfaces; +using System.Linq; namespace Umbraco.Web.UI { @@ -20,53 +24,161 @@ namespace Umbraco.Web.UI /// public static class LegacyDialogHandler { - public static void Delete(string nodeType, int nodeId, string text) + private enum Operation { - // Load task settings - var createDef = GetXmlDoc(); + Create, + Delete + } - // Create an instance of the type by loading it from the assembly + private const string ContextKeyCreate = "LegacyDialogHandler-Create-"; + private const string ContextKeyDelete = "LegacyDialogHandler-Delete-"; + + /// + /// Gets the ITask for the operation for the node Type + /// + /// + /// + /// + /// + /// + /// + /// This will first check if we've already created the ITask in the current Http request + /// + private static ITask GetTaskForOperation(HttpContextBase httpContext, User umbracoUser, Operation op, string nodeType) + { + if (httpContext == null) throw new ArgumentNullException("httpContext"); + if (umbracoUser == null) throw new ArgumentNullException("umbracoUser"); + if (nodeType == null) throw new ArgumentNullException("nodeType"); + + var ctxKey = op == Operation.Create ? ContextKeyCreate : ContextKeyDelete; + + //check contextual cache + if (httpContext.Items[ctxKey] != null) + { + return (ITask) httpContext.Items[ctxKey]; + } + + var operationNode = op == Operation.Create ? "create" : "delete"; + var createDef = GetXmlDoc(); var def = createDef.SelectSingleNode("//nodeType [@alias = '" + nodeType + "']"); - var taskAssembly = def.SelectSingleNode("./tasks/delete").Attributes.GetNamedItem("assembly").Value; - var taskType = def.SelectSingleNode("./tasks/delete").Attributes.GetNamedItem("type").Value; + if (def == null) + { + throw new InvalidOperationException("Cannot find an item that matches node type " + nodeType); + } + var del = def.SelectSingleNode("./tasks/" + operationNode); + if (del == null) + { + throw new InvalidOperationException("No delete task found for node type " + nodeType); + } + if (!del.Attributes.HasAttribute("assembly")) + { + throw new InvalidOperationException("No assembly attribute found for delete task for node type " + nodeType); + } + var taskAssembly = del.AttributeValue("assembly"); + if (!del.Attributes.HasAttribute("type")) + { + throw new InvalidOperationException("No type attribute found for delete task for node type " + nodeType); + } + var taskType = del.AttributeValue("type"); + var assembly = Assembly.LoadFrom(IOHelper.MapPath(SystemDirectories.Bin + "/" + taskAssembly + ".dll")); var type = assembly.GetType(taskAssembly + "." + taskType); var typeInstance = Activator.CreateInstance(type) as ITask; - if (typeInstance == null) return; + if (typeInstance == null) + { + throw new InvalidOperationException("The type returned (" + type + ") is not an " + typeof(ITask)); + } + + //set the user/user id for the instance + var dialogTask = typeInstance as LegacyDialogTask; + if (dialogTask != null) + { + dialogTask.User = umbracoUser; + } + else + { + typeInstance.UserId = umbracoUser.Id; + } + + //put in contextual cache + httpContext.Items[ctxKey] = typeInstance; + + return typeInstance; + } + + /// + /// Checks if the user has access to launch the ITask that matches the node type based on the app assigned + /// + /// + /// + /// + /// + /// + /// If the ITask doesn't implement LegacyDialogTask then we will return 'true' since we cannot validate + /// the application assigned. + /// + /// TODO: Create an API to assign a nodeType to an app so developers can manually secure it + /// + internal static bool UserHasCreateAccess(HttpContextBase httpContext, User umbracoUser, string nodeType) + { + var task = GetTaskForOperation(httpContext, umbracoUser, Operation.Create, nodeType); + var dialogTask = task as LegacyDialogTask; + if (dialogTask != null) + { + return dialogTask.ValidateUserForApplication(); + } + return true; + } + + /// + /// Checks if the user has access to launch the ITask that matches the node type based on the app assigned + /// + /// + /// + /// + /// + /// + /// If the ITask doesn't implement LegacyDialogTask then we will return 'true' since we cannot validate + /// the application assigned. + /// + /// TODO: Create an API to assign a nodeType to an app so developers can manually secure it + /// + internal static bool UserHasDeleteAccess(HttpContextBase httpContext, User umbracoUser, string nodeType) + { + var task = GetTaskForOperation(httpContext, umbracoUser, Operation.Delete, nodeType); + var dialogTask = task as LegacyDialogTask; + if (dialogTask != null) + { + return dialogTask.ValidateUserForApplication(); + } + return true; + } + + public static void Delete(HttpContextBase httpContext, User umbracoUser, string nodeType, int nodeId, string text) + { + var typeInstance = GetTaskForOperation(httpContext, umbracoUser, Operation.Delete, nodeType); + typeInstance.ParentID = nodeId; typeInstance.Alias = text; + typeInstance.Delete(); } - public static string Create(string nodeType, int nodeId, string text, int typeId = 0) + public static string Create(HttpContextBase httpContext, User umbracoUser, string nodeType, int nodeId, string text, int typeId = 0) { - // Load task settings - var createDef = GetXmlDoc(); + var typeInstance = GetTaskForOperation(httpContext, umbracoUser, Operation.Create, nodeType); + + typeInstance.TypeID = typeId; + typeInstance.ParentID = nodeId; + typeInstance.Alias = text; - // Create an instance of the type by loading it from the assembly - var def = createDef.SelectSingleNode("//nodeType [@alias = '" + nodeType + "']"); - var taskAssembly = def.SelectSingleNode("./tasks/create").Attributes.GetNamedItem("assembly").Value; - var taskType = def.SelectSingleNode("./tasks/create").Attributes.GetNamedItem("type").Value; + typeInstance.Save(); - var assembly = Assembly.LoadFrom(IOHelper.MapPath(SystemDirectories.Bin + "/" + taskAssembly + ".dll")); - var type = assembly.GetType(taskAssembly + "." + taskType); - var typeInstance = Activator.CreateInstance(type) as ITask; - if (typeInstance != null) - { - typeInstance.TypeID = typeId; - typeInstance.ParentID = nodeId; - typeInstance.Alias = text; - typeInstance.UserId = BasePage.GetUserId(BasePage.umbracoUserContextID); - typeInstance.Save(); - - // check for returning url - var returnUrlTask = typeInstance as ITaskReturnUrl; - return returnUrlTask != null - ? returnUrlTask.ReturnUrl - : ""; - } - - return ""; + // check for returning url + var returnUrlTask = typeInstance as ITaskReturnUrl; + return returnUrlTask != null + ? returnUrlTask.ReturnUrl + : ""; } private static XmlDocument GetXmlDoc() diff --git a/src/Umbraco.Web/UI/LegacyDialogTask.cs b/src/Umbraco.Web/UI/LegacyDialogTask.cs new file mode 100644 index 0000000000..824d753ebe --- /dev/null +++ b/src/Umbraco.Web/UI/LegacyDialogTask.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Authentication; +using System.Text; +using Umbraco.Core; +using umbraco.BusinessLogic; +using umbraco.businesslogic.Exceptions; +using umbraco.interfaces; + +namespace Umbraco.Web.UI +{ + /// + /// An abstract class that is used to implement all secure ITasks + /// + /// + /// In the near future we will overhaul how create dialogs work and how deletions work as well. In the meantime + /// if you ever need to create an ITask you should just inherit from this class and do not manually implement + /// ITask or ITaskReturnUrl. If you do, you MUST also implement IAppTask which associates an ITask to an app + /// so we can validate the current user's security with the implementation. If you do not do this then your + /// implementation will not be secure. It means that if someone is logged in and doesn't have access to a + /// specific app, they'd still be able to execute code to create/delete for any ITask regardless of what app + /// they have access to. + /// + public abstract class LegacyDialogTask : ITaskReturnUrl, IAssignedApp + { + public virtual int ParentID { get; set; } + public int TypeID { get; set; } + public string Alias { get; set; } + + /// + /// Base class first performs authentication for the current app before proceeding + /// + /// + public bool Save() + { + if (ValidateUserForApplication()) + { + return PerformSave(); + } + throw new AuthenticationException("The current user does not have access to the required application that this task belongs to"); + } + + public abstract bool PerformSave(); + + /// + /// Base class first performs authentication for the current app before proceeding + /// + /// + public bool Delete() + { + if (ValidateUserForApplication()) + { + return PerformDelete(); + } + throw new AuthenticationException("The current user does not have access to the required application that this task belongs to"); + } + + public abstract bool PerformDelete(); + + /// + /// Gets/sets the user object for this Task + /// + /// + /// accessible by inheritors but can only be set internally + /// + protected internal User User { get; internal set; } + + /// + /// Implemented explicitly as we don't want to expose this + /// + int ITask.UserId + { + set { User = User.GetUser(value); } + } + + /// + /// Checks if the currently assigned user has access to the assigned app + /// + /// + protected internal bool ValidateUserForApplication() + { + if (User == null) + throw new InvalidOperationException("Cannot authenticate, no User object assigned"); + + return User.Applications.Any(app => app.alias.InvariantEquals(AssignedApp)); + } + + public abstract string ReturnUrl { get; } + public abstract string AssignedApp { get; } + } +} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index a400ea3dc3..b82b8b5746 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -323,9 +323,12 @@ + + + ASPXCodeBehind diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadcontentItemType.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadcontentItemType.cs index 2eec11bdb2..48e5a507bc 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadcontentItemType.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadcontentItemType.cs @@ -25,6 +25,7 @@ using umbraco.cms.presentation.Trees; namespace umbraco { + [Obsolete("This class is no longer used and will be removed from the codebase in future versions")] public class loadcontentItemType : BaseTree { public loadcontentItemType(string application) : base(application) { } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/CreatedPackageTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/CreatedPackageTasks.cs index c2e53fe9a1..8f3a330b37 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/CreatedPackageTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/CreatedPackageTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -9,47 +10,17 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class CreatedPackageTasks : interfaces.ITaskReturnUrl + public class CreatedPackageTasks : LegacyDialogTask { - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId + + public override bool PerformSave() { - set { _userID = value; } - } - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set { _parentID = value; } - get { return _parentID; } - } - - public bool Save() - { - - umbraco.BusinessLogic.User myUser = new umbraco.BusinessLogic.User(0); - umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Delete, myUser, 0, "Xml save started"); - int id = cms.businesslogic.packager.CreatedPackage.MakeNew(Alias).Data.Id; - m_returnUrl = string.Format("developer/packages/editPackage.aspx?id={0}", id); + var id = cms.businesslogic.packager.CreatedPackage.MakeNew(Alias).Data.Id; + _returnUrl = string.Format("developer/packages/editPackage.aspx?id={0}", id); return true; } - public bool Delete() + public override bool PerformDelete() { // we need to grab the id from the alias as the new tree needs to prefix the NodeID with "package_" if (ParentID == 0) @@ -60,13 +31,16 @@ namespace umbraco return true; } - #region ITaskReturnUrl Members - private string m_returnUrl = ""; - public string ReturnUrl + private string _returnUrl = ""; + + public override string ReturnUrl { - get { return m_returnUrl; } + get { return _returnUrl; } } - #endregion + public override string AssignedApp + { + get { return DefaultApps.developer.ToString(); } + } } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/DLRScripting.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/DLRScripting.ascx.cs index 55512371f3..a3473f1f64 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/DLRScripting.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/DLRScripting.ascx.cs @@ -10,6 +10,7 @@ using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; +using Umbraco.Web.UI; using umbraco.cms.businesslogic.macro; using umbraco.scripting; using umbraco.BasePages; @@ -36,11 +37,14 @@ namespace umbraco.presentation.create { if (Page.IsValid) { - int createMacroVal = 0; + var createMacroVal = 0; if (createMacro.Checked) createMacroVal = 1; - string returnUrl = dialogHandler_temp.Create(UmbracoContext.Current.Request["nodeType"], + var returnUrl = LegacyDialogHandler.Create( + new HttpContextWrapper(Context), + BasePage.Current.getUser(), + helper.Request("nodeType"), createMacroVal, template.SelectedValue + "|||" + rename.Text + "." + filetype.SelectedValue); BasePage.Current.ClientTools diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/DLRScriptingTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/DLRScriptingTasks.cs index aba25ebdef..424c71e76c 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/DLRScriptingTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/DLRScriptingTasks.cs @@ -1,143 +1,86 @@ using System; -using System.Data; -using System.Web.Security; +using Umbraco.Core.IO; +using Umbraco.Core.Logging; +using Umbraco.Web.UI; using umbraco.BusinessLogic; -using umbraco.DataLayer; -using umbraco.BasePages; -using umbraco.IO; -using umbraco.cms.businesslogic.member; namespace umbraco { - public class DLRScriptingTasks : interfaces.ITaskReturnUrl + public class DLRScriptingTasks : LegacyDialogTask { - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId + + public override bool PerformSave() { - set - { - _userID = value; - } - } - - public int TypeID - { - get - { - return _typeID; - } - set - { - _typeID = value; - } - } - - public string Alias - { - get - { - return _alias; - } - set - { - _alias = value; - } - } - - public int ParentID - { - get - { - return _parentID; - } - set - { - _parentID = value; - } - } - - public bool Save() - { - - string template = _alias.Substring(0, _alias.IndexOf("|||")).Trim(); - string fileName = _alias.Substring(_alias.IndexOf("|||") + 3, _alias.Length - _alias.IndexOf("|||") - 3).Replace(" ", ""); + var template = Alias.Substring(0, Alias.IndexOf("|||")).Trim(); + var fileName = Alias.Substring(Alias.IndexOf("|||") + 3, Alias.Length - Alias.IndexOf("|||") - 3).Replace(" ", ""); if (!fileName.Contains(".")) - fileName = _alias + ".py"; + fileName = Alias + ".py"; - string scriptContent = ""; + var scriptContent = ""; if (!string.IsNullOrEmpty(template)) { - System.IO.StreamReader templateFile = System.IO.File.OpenText(IOHelper.MapPath(IO.SystemDirectories.Umbraco + "/scripting/templates/" + template)); + var templateFile = System.IO.File.OpenText(IOHelper.MapPath(SystemDirectories.Umbraco + "/scripting/templates/" + template)); scriptContent = templateFile.ReadToEnd(); templateFile.Close(); } - string abFileName = IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + fileName); + var abFileName = IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + fileName); if (!System.IO.File.Exists(abFileName)) { if (fileName.Contains("/")) //if there's a / create the folder structure for it { - string[] folders = fileName.Split("/".ToCharArray()); - string basePath = IOHelper.MapPath(SystemDirectories.MacroScripts); - for (int i = 0; i < folders.Length - 1; i++) + var folders = fileName.Split("/".ToCharArray()); + var basePath = IOHelper.MapPath(SystemDirectories.MacroScripts); + for (var i = 0; i < folders.Length - 1; i++) { basePath = System.IO.Path.Combine(basePath, folders[i]); System.IO.Directory.CreateDirectory(basePath); } } - System.IO.StreamWriter scriptWriter = System.IO.File.CreateText(abFileName); + var scriptWriter = System.IO.File.CreateText(abFileName); scriptWriter.Write(scriptContent); scriptWriter.Flush(); scriptWriter.Close(); - if (ParentID == 1) { - cms.businesslogic.macro.Macro m = cms.businesslogic.macro.Macro.MakeNew( + var m = cms.businesslogic.macro.Macro.MakeNew( helper.SpaceCamelCasing(fileName.Substring(0, (fileName.LastIndexOf('.') + 1)).Trim('.'))); m.ScriptingFile = fileName; } } - m_returnUrl = string.Format(SystemDirectories.Umbraco + "/developer/python/editPython.aspx?file={0}", fileName); + _returnUrl = string.Format(SystemDirectories.Umbraco + "/developer/python/editPython.aspx?file={0}", fileName); return true; } - public bool Delete() + public override bool PerformDelete() { - - string path = IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + Alias.TrimStart('/')); - - System.Web.HttpContext.Current.Trace.Warn("", "*" + path + "*"); + var path = IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + Alias.TrimStart('/')); try { System.IO.File.Delete(path); } catch (Exception ex) { - Log.Add(LogTypes.Error, UmbracoEnsuredPage.CurrentUser, -1, "Could not remove XSLT file " + Alias + ". ERROR: " + ex.Message); + LogHelper.Error("Could not remove XSLT file " + Alias, ex); } return true; } + + private string _returnUrl = ""; - public DLRScriptingTasks() + public override string ReturnUrl { + get { return _returnUrl; } } - #region ITaskReturnUrl Members - private string m_returnUrl = ""; - public string ReturnUrl + public override string AssignedApp { - get { return m_returnUrl; } + get { return DefaultApps.developer.ToString(); } } - - #endregion } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/DataTypeTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/DataTypeTasks.cs index 303e3e8803..fcde3d2e43 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/DataTypeTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/DataTypeTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -9,66 +10,32 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class DataTypeTasks : interfaces.ITaskReturnUrl + public class DataTypeTasks : LegacyDialogTask { - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId + public override bool PerformSave() { - set { _userID = value; } - } - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set { _parentID = value; } - get { return _parentID; } - } - - public bool Save() - { - - int id = cms.businesslogic.datatype.DataTypeDefinition.MakeNew(BusinessLogic.User.GetUser(_userID), Alias).Id; - m_returnUrl = string.Format("developer/datatypes/editDataType.aspx?id={0}", id); + var id = cms.businesslogic.datatype.DataTypeDefinition.MakeNew(User, Alias).Id; + _returnUrl = string.Format("developer/datatypes/editDataType.aspx?id={0}", id); return true; } - public bool Delete() + public override bool PerformDelete() { cms.businesslogic.datatype.DataTypeDefinition.GetDataTypeDefinition(ParentID).delete(); return true; } + + private string _returnUrl = ""; - public DataTypeTasks() + public override string ReturnUrl { - // - // TODO: Add constructor logic here - // + get { return _returnUrl; } } - #region ITaskReturnUrl Members - private string m_returnUrl = ""; - public string ReturnUrl + public override string AssignedApp { - get { return m_returnUrl; } + get { return DefaultApps.developer.ToString(); } } - - #endregion - } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/MediaTypeTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/MediaTypeTasks.cs index 269215d8fc..35e51fba86 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/MediaTypeTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/MediaTypeTasks.cs @@ -1,73 +1,34 @@ -using System; -using System.Data; -using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; -using umbraco.DataLayer; -using umbraco.BasePages; -using umbraco.IO; -using umbraco.cms.businesslogic.member; namespace umbraco { - public class MediaTypeTasks : interfaces.ITaskReturnUrl + public class MediaTypeTasks : LegacyDialogTask { - - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId + + public override bool PerformSave() { - set { _userID = value; } - } - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set { _parentID = value; } - get { return _parentID; } - } - - public bool Save() - { - int id = cms.businesslogic.media.MediaType.MakeNew(BusinessLogic.User.GetUser(_userID), Alias.Replace("'", "''")).Id; - m_returnUrl = string.Format("settings/editMediaType.aspx?id={0}", id); + var id = cms.businesslogic.media.MediaType.MakeNew(User, Alias.Replace("'", "''")).Id; + _returnUrl = string.Format("settings/editMediaType.aspx?id={0}", id); return true; } - public bool Delete() + public override bool PerformDelete() { - new cms.businesslogic.media.MediaType(_parentID).delete(); + new cms.businesslogic.media.MediaType(ParentID).delete(); return false; } + + private string _returnUrl = ""; - public MediaTypeTasks() + public override string ReturnUrl { - // - // TODO: Add constructor logic here - // + get { return _returnUrl; } } - #region ITaskReturnUrl Members - private string m_returnUrl = ""; - public string ReturnUrl + public override string AssignedApp { - get { return m_returnUrl; } + get { return DefaultApps.settings.ToString(); } } - - #endregion - } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/MemberGroupTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/MemberGroupTasks.cs index 1d8d874332..ac51e788aa 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/MemberGroupTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/MemberGroupTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -9,85 +10,36 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class MemberGroupTasks : interfaces.ITaskReturnUrl + public class MemberGroupTasks : LegacyDialogTask { - - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId + public override bool PerformSave() { - set { _userID = value; } - } - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set { _parentID = value; } - get { return _parentID; } - } - - public bool Save() - { - System.Web.Security.Roles.CreateRole(Alias); - // int id = cms.businesslogic.member.MemberGroup.MakeNew(Alias, BusinessLogic.User.GetUser(_userID)).Id; - m_returnUrl = string.Format("members/EditMemberGroup.aspx?id={0}", System.Web.HttpContext.Current.Server.UrlEncode(Alias)); + Roles.CreateRole(Alias); + _returnUrl = string.Format("members/EditMemberGroup.aspx?id={0}", System.Web.HttpContext.Current.Server.UrlEncode(Alias)); return true; } - public bool Delete() + public override bool PerformDelete() { // only build-in roles can be deleted - if (cms.businesslogic.member.Member.IsUsingUmbracoRoles()) + if (Member.IsUsingUmbracoRoles()) { - cms.businesslogic.member.MemberGroup.GetByName(Alias).delete(); + MemberGroup.GetByName(Alias).delete(); return true; } - else - { - return false; - } - //try - //{ - - // MembershipUser u = Membership.GetUser(_parentID); - // Membership.DeleteUser(u.UserName); - // return true; - - //}catch - //{ - // Log.Add(LogTypes.Error, _parentID, "Member cannot be deleted."); - // return false; - //} + return false; } - public MemberGroupTasks() + private string _returnUrl = ""; + + public override string ReturnUrl { - // - // TODO: Add constructor logic here - // + get { return _returnUrl; } } - #region ITaskReturnUrl Members - private string m_returnUrl = ""; - public string ReturnUrl + public override string AssignedApp { - get { return m_returnUrl; } + get { return DefaultApps.member.ToString(); } } - - #endregion } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/MemberTypeTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/MemberTypeTasks.cs index 50c863977e..0f74ff4496 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/MemberTypeTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/MemberTypeTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -9,65 +10,31 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class MemberTypeTasks : interfaces.ITaskReturnUrl + public class MemberTypeTasks : LegacyDialogTask { - - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId - { - set { _userID = value; } - } - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set { _parentID = value; } - get { return _parentID; } - } - - public bool Save() + public override bool PerformSave() { - int id = cms.businesslogic.member.MemberType.MakeNew(BusinessLogic.User.GetUser(_userID), Alias).Id; - m_returnUrl = string.Format("members/EditMemberType.aspx?id={0}", id); + var id = MemberType.MakeNew(User, Alias).Id; + _returnUrl = string.Format("members/EditMemberType.aspx?id={0}", id); return true; } - public bool Delete() + public override bool PerformDelete() { - new cms.businesslogic.member.MemberType(_parentID).delete(); + new MemberType(ParentID).delete(); return true; } - public MemberTypeTasks() + private string _returnUrl = ""; + public override string ReturnUrl { - // - // TODO: Add constructor logic here - // + get { return _returnUrl; } } - #region ITaskReturnUrl Members - private string m_returnUrl = ""; - public string ReturnUrl + public override string AssignedApp { - get { return m_returnUrl; } + get { return DefaultApps.member.ToString(); } } - - #endregion } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/PythonTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/PythonTasks.cs index ec1814ff07..defba78e19 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/PythonTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/PythonTasks.cs @@ -9,5 +9,6 @@ using umbraco.cms.businesslogic.member; namespace umbraco { + [Obsolete("Use DLRScriptingTasks instead")] public class PythonTasks : DLRScriptingTasks { } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/ScriptTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/ScriptTasks.cs index db562364cc..8a8ddcb0b9 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/ScriptTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/ScriptTasks.cs @@ -1,98 +1,66 @@ -using System; -using System.Data; -using System.Web.Security; +using Umbraco.Core.IO; +using Umbraco.Web.UI; using umbraco.BusinessLogic; -using umbraco.DataLayer; using umbraco.BasePages; -using umbraco.IO; -using umbraco.cms.businesslogic.member; namespace umbraco { - public class ScriptTasks : interfaces.ITaskReturnUrl + public class ScriptTasks : LegacyDialogTask { - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId + + public override bool PerformSave() { - set { _userID = value; } - } - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } + var scriptFileAr = Alias.Split('¤'); + + var relPath = scriptFileAr[0]; + var fileName = scriptFileAr[1]; + var fileType = scriptFileAr[2]; + var createFolder = ParentID; - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set { _parentID = value; } - get { return _parentID; } - } - - public bool Save() - { - string[] scriptFileAr = _alias.Split('¤'); - - - - string relPath = scriptFileAr[0]; - string fileName = scriptFileAr[1]; - string fileType = scriptFileAr[2]; - - int createFolder = ParentID; - - string basePath = IOHelper.MapPath(SystemDirectories.Scripts + "/" + relPath + fileName); + var basePath = IOHelper.MapPath(SystemDirectories.Scripts + "/" + relPath + fileName); if (System.IO.File.Exists(basePath)) { - m_returnUrl = string.Format("settings/scripts/editScript.aspx?file={0}{1}.{2}", relPath, fileName, fileType); + _returnUrl = string.Format("settings/scripts/editScript.aspx?file={0}{1}.{2}", relPath, fileName, fileType); return true; } + + if (createFolder == 1) + { + System.IO.Directory.CreateDirectory(basePath); + } else { - if (createFolder == 1) - { - System.IO.Directory.CreateDirectory(basePath); - } - else - { - System.IO.File.Create(basePath + "." + fileType).Close(); - m_returnUrl = string.Format("settings/scripts/editScript.aspx?file={0}{1}.{2}", relPath, fileName, - fileType); - } + System.IO.File.Create(basePath + "." + fileType).Close(); + _returnUrl = string.Format("settings/scripts/editScript.aspx?file={0}{1}.{2}", relPath, fileName, + fileType); } return true; } - public bool Delete() + public override bool PerformDelete() { - string path = IOHelper.MapPath(SystemDirectories.Scripts + "/" + _alias.TrimStart('/')); + var path = IOHelper.MapPath(SystemDirectories.Scripts + "/" + Alias.TrimStart('/')); if (System.IO.File.Exists(path)) System.IO.File.Delete(path); else if (System.IO.Directory.Exists(path)) System.IO.Directory.Delete(path, true); - BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Delete, umbraco.BasePages.UmbracoEnsuredPage.CurrentUser, -1, _alias + " Deleted"); + Log.Add(LogTypes.Delete, UmbracoEnsuredPage.CurrentUser, -1, Alias + " Deleted"); return true; } - #region ITaskReturnUrl Members - private string m_returnUrl = ""; - public string ReturnUrl + private string _returnUrl = ""; + + public override string ReturnUrl { - get { return m_returnUrl; } + get { return _returnUrl; } } - #endregion + public override string AssignedApp + { + get { return DefaultApps.settings.ToString(); } + } } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/StylesheetTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/StylesheetTasks.cs index ca02f78496..594ae2b039 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/StylesheetTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/StylesheetTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -9,64 +10,37 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class StylesheetTasks : interfaces.ITaskReturnUrl + public class StylesheetTasks : LegacyDialogTask { - - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId - { - set { _userID = value; } - } - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set { _parentID = value; } - get { return _parentID; } - } - - public bool Save() + public override bool PerformSave() { int id = -1; - umbraco.cms.businesslogic.web.StyleSheet checkingSheet =umbraco.cms.businesslogic.web.StyleSheet.GetByName(Alias); - if (checkingSheet != null) - id = checkingSheet.Id; - else - id =cms.businesslogic.web.StyleSheet.MakeNew(BusinessLogic.User.GetUser(_userID), Alias, "", "").Id; - m_returnUrl = string.Format("settings/stylesheet/editStylesheet.aspx?id={0}", id); + var checkingSheet = cms.businesslogic.web.StyleSheet.GetByName(Alias); + id = checkingSheet != null + ? checkingSheet.Id + : cms.businesslogic.web.StyleSheet.MakeNew(User, Alias, "", "").Id; + _returnUrl = string.Format("settings/stylesheet/editStylesheet.aspx?id={0}", id); return true; } - public bool Delete() + public override bool PerformDelete() { - cms.businesslogic.web.StyleSheet s = new cms.businesslogic.web.StyleSheet(ParentID); + var s = new cms.businesslogic.web.StyleSheet(ParentID); s.delete(); return true; } - #region ITaskReturnUrl Members - private string m_returnUrl = ""; - public string ReturnUrl + private string _returnUrl = ""; + + public override string ReturnUrl { - get { return m_returnUrl; } + get { return _returnUrl; } } - #endregion + public override string AssignedApp + { + get { return DefaultApps.settings.ToString(); } + } } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/XsltTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/XsltTasks.cs index 57046ef64b..d2d14cae1e 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/XsltTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/XsltTasks.cs @@ -1,10 +1,12 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Core.IO; +using Umbraco.Core.Logging; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; -using umbraco.IO; using umbraco.cms.businesslogic.member; namespace umbraco @@ -14,71 +16,40 @@ namespace umbraco /// /// - public class XsltTasks : interfaces.ITaskReturnUrl + public class XsltTasks : LegacyDialogTask { - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId + public override bool PerformSave() { - set { _userID = value; } - } - - - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set { _parentID = value; } - get { return _parentID; } - } - - public bool Save() - { - string template = _alias.Substring(0, _alias.IndexOf("|||")); - string fileName = _alias.Substring(_alias.IndexOf("|||") + 3, _alias.Length - _alias.IndexOf("|||") - 3).Replace(" ", ""); - string xsltTemplateSource = IOHelper.MapPath(SystemDirectories.Umbraco + "/xslt/templates/" + template); - string xsltNewFilename = IOHelper.MapPath(SystemDirectories.Xslt + "/" + fileName + ".xslt"); - - + var template = Alias.Substring(0, Alias.IndexOf("|||")); + var fileName = Alias.Substring(Alias.IndexOf("|||") + 3, Alias.Length - Alias.IndexOf("|||") - 3).Replace(" ", ""); + var xsltTemplateSource = IOHelper.MapPath(SystemDirectories.Umbraco + "/xslt/templates/" + template); + var xsltNewFilename = IOHelper.MapPath(SystemDirectories.Xslt + "/" + fileName + ".xslt"); + if (!System.IO.File.Exists(xsltNewFilename)) { if (fileName.Contains("/")) //if there's a / create the folder structure for it { - string[] folders = fileName.Split("/".ToCharArray()); - string xsltBasePath = IOHelper.MapPath(SystemDirectories.Xslt); - for (int i = 0; i < folders.Length - 1; i++) + var folders = fileName.Split("/".ToCharArray()); + var xsltBasePath = IOHelper.MapPath(SystemDirectories.Xslt); + for (var i = 0; i < folders.Length - 1; i++) { xsltBasePath = System.IO.Path.Combine(xsltBasePath, folders[i]); System.IO.Directory.CreateDirectory(xsltBasePath); } } - // System.IO.File.Copy(xsltTemplateSource, xsltNewFilename, false); - // update with xslt references - string xslt = ""; - System.IO.StreamReader xsltFile = System.IO.File.OpenText(xsltTemplateSource); - xslt = xsltFile.ReadToEnd(); - xsltFile.Close(); + var xslt = ""; + using (var xsltFile = System.IO.File.OpenText(xsltTemplateSource)) + { + xslt = xsltFile.ReadToEnd(); + xsltFile.Close(); + } // prepare support for XSLT extensions xslt = macro.AddXsltExtensionsToHeader(xslt); - System.IO.StreamWriter xsltWriter = System.IO.File.CreateText(xsltNewFilename); + var xsltWriter = System.IO.File.CreateText(xsltNewFilename); xsltWriter.Write(xslt); xsltWriter.Flush(); xsltWriter.Close(); @@ -86,23 +57,20 @@ namespace umbraco // Create macro? if (ParentID == 1) { - cms.businesslogic.macro.Macro m = - cms.businesslogic.macro.Macro.MakeNew( - helper.SpaceCamelCasing(_alias.Substring(_alias.IndexOf("|||") + 3, _alias.Length - _alias.IndexOf("|||") - 3))); + var m = cms.businesslogic.macro.Macro.MakeNew( + helper.SpaceCamelCasing(Alias.Substring(Alias.IndexOf("|||") + 3, Alias.Length - Alias.IndexOf("|||") - 3))); m.Xslt = fileName + ".xslt"; } } - m_returnUrl = string.Format(SystemDirectories.Umbraco + "/developer/xslt/editXslt.aspx?file={0}.xslt", fileName); + _returnUrl = string.Format(SystemDirectories.Umbraco + "/developer/xslt/editXslt.aspx?file={0}.xslt", fileName); return true; } - public bool Delete() + public override bool PerformDelete() { - string path = IOHelper.MapPath(SystemDirectories.Xslt + "/" + Alias.TrimStart('/')); - - System.Web.HttpContext.Current.Trace.Warn("", "*" + path + "*"); + var path = IOHelper.MapPath(SystemDirectories.Xslt + "/" + Alias.TrimStart('/')); try { @@ -113,26 +81,21 @@ namespace umbraco } catch (Exception ex) { - Log.Add(LogTypes.Error, UmbracoEnsuredPage.CurrentUser, -1, "Could not remove XSLT file " + Alias + ". ERROR: " + ex.Message); + LogHelper.Error("Could not remove XSLT file " + Alias, ex); } return true; } - public XsltTasks() + private string _returnUrl = ""; + + public override string ReturnUrl { - // - // TODO: Add constructor logic here - // + get { return _returnUrl; } } - #region ITaskReturnUrl Members - private string m_returnUrl = ""; - public string ReturnUrl + public override string AssignedApp { - get { return m_returnUrl; } + get { return DefaultApps.developer.ToString(); } } - - #endregion - } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/content.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/content.ascx.cs index e39bef550f..041a581f3e 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/content.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/content.ascx.cs @@ -1,7 +1,9 @@ using System; using System.Text; +using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using Umbraco.Web.UI; using umbraco.cms.businesslogic.web; using umbraco.presentation.create; using Content=umbraco.cms.businesslogic.Content; @@ -121,11 +123,13 @@ namespace umbraco.cms.presentation.create.controls { if (Page.IsValid) { - string returnUrl = dialogHandler_temp.Create( + var returnUrl = LegacyDialogHandler.Create( + new HttpContextWrapper(Context), + BasePage.Current.getUser(), helper.Request("nodeType"), int.Parse(nodeType.SelectedValue), - int.Parse(Request["nodeID"]), - rename.Text); + rename.Text, + int.Parse(Request["nodeID"])); BasePage.Current.ClientTools .ChangeContentFrameUrl(returnUrl) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/contentItemTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/contentItemTasks.cs index 4951a3cfff..1e18d40910 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/contentItemTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/contentItemTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -9,70 +10,38 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class contentItemTasks : interfaces.ITask + //This was only referenced from the tree : loadMember which is trying to load this node type alias + // to show pages that are owned by members but this tree is also trying to show an editor that doesn't exist + // and I've never even heard of this functionality and think it was an idea that never got completed. + // I'm nearly positive this is not used and should be un-referenced. + [Obsolete("This class is no longer used and will be removed from the codebase in future versions")] + public class contentItemTasks : LegacyDialogTask { - - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId - { - set { _userID = value; } - } - - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set - { - _parentID = value; - } - get - { - return _parentID; - } - } - - public bool Save() + + public override bool PerformSave() { // TODO : fix it!! return true; } - public bool Delete() + public override bool PerformDelete() { - cms.businesslogic.contentitem.ContentItem d = new cms.businesslogic.contentitem.ContentItem(ParentID); + var d = new cms.businesslogic.contentitem.ContentItem(ParentID); // Version3.0 - moving to recycle bin instead of deletion //d.delete(); d.Move(-20); return true; - } - public bool Sort() + public override string ReturnUrl { - return false; + get { return string.Empty; } } - public contentItemTasks() + public override string AssignedApp { - // - // TODO: Add constructor logic here - // + get { return DefaultApps.member.ToString(); } } } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/contentItemTypeTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/contentItemTypeTasks.cs index 24fba8215a..12de0b4efb 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/contentItemTypeTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/contentItemTypeTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -9,55 +10,32 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class contentItemTypeTasks : interfaces.ITask + //This was only referenced from the obsolete tree that is not used: loadcontentItemType which is trying to load + // pages that don't even exist so I'm nearly positive this isn't used and should be removed. + [Obsolete("This class is no longer used and will be removed from the codebase in future versions")] + public class contentItemTypeTasks : LegacyDialogTask { - - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId - { - set { _userID = value; } - } - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set { _parentID = value; } - get { return _parentID; } - } - - public bool Save() + public override bool PerformSave() { - cms.businesslogic.contentitem.ContentItemType.MakeNew(BusinessLogic.User.GetUser(_userID), Alias); + cms.businesslogic.contentitem.ContentItemType.MakeNew(User, Alias); return true; } - public bool Delete() + public override bool PerformDelete() { - new cms.businesslogic.contentitem.ContentItemType(_parentID).delete(); + new cms.businesslogic.contentitem.ContentItemType(ParentID).delete(); return true; } - public contentItemTypeTasks() + public override string ReturnUrl { - // - // TODO: Add constructor logic here - // + get { return string.Empty; } + } + + public override string AssignedApp + { + get { return DefaultApps.member.ToString(); } } } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/contentTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/contentTasks.cs index 40a43291dc..061d9849ed 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/contentTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/contentTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -9,72 +10,41 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class contentTasks : interfaces.ITaskReturnUrl + public class contentTasks : LegacyDialogTask { - - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; private string _returnUrl = ""; - public int UserId - { - set { _userID = value; } - } - - public string ReturnUrl + public override string ReturnUrl { get { return _returnUrl; } } - public int TypeID + public override string AssignedApp { - set { _typeID = value; } - get { return _typeID; } + get { return DefaultApps.content.ToString(); } } - public string Alias + public override bool PerformSave() { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set - { - _parentID = value; - } - get - { - return _parentID; - } - } - - public bool Save() - { - cms.businesslogic.web.DocumentType dt = new cms.businesslogic.web.DocumentType(TypeID); - cms.businesslogic.web.Document d = cms.businesslogic.web.Document.MakeNew(Alias, dt, BusinessLogic.User.GetUser(_userID), ParentID); + var dt = new cms.businesslogic.web.DocumentType(TypeID); + var d = cms.businesslogic.web.Document.MakeNew(Alias, dt, User, ParentID); if (d == null) { //TODO: Slace - Fix this to use the language files BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.error, "Document Creation", "Document creation was canceled"); return false; } - else - { - _returnUrl = "editContent.aspx?id=" + d.Id.ToString() + "&isNew=true"; - return true; - } + + _returnUrl = "editContent.aspx?id=" + d.Id.ToString() + "&isNew=true"; + return true; } - public bool Delete() + public override bool PerformDelete() { - cms.businesslogic.web.Document d = new cms.businesslogic.web.Document(ParentID); + var d = new cms.businesslogic.web.Document(ParentID); // Log - BusinessLogic.Log.Add(BusinessLogic.LogTypes.Delete, User.GetCurrent(), d.Id, ""); + Log.Add(LogTypes.Delete, User.GetCurrent(), d.Id, ""); library.UnPublishSingleNode(d.Id); @@ -84,16 +54,5 @@ namespace umbraco } - public bool Sort() - { - return false; - } - - public contentTasks() - { - // - // TODO: Add constructor logic here - // - } } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/dialogHandler_temp.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/dialogHandler_temp.cs index 90004061e6..df1aadc690 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/dialogHandler_temp.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/dialogHandler_temp.cs @@ -1,5 +1,5 @@ using System; - +using System.Web; using System.Xml; using System.Xml.XPath; using System.Reflection; @@ -22,7 +22,10 @@ namespace umbraco.presentation.create } public static void Delete(string NodeType, int NodeId, string Text) { - LegacyDialogHandler.Delete(NodeType, NodeId, Text); + LegacyDialogHandler.Delete( + new HttpContextWrapper(HttpContext.Current), + BasePage.Current.getUser(), + NodeType, NodeId, Text); } public static string Create(string NodeType, int NodeId, string Text) @@ -32,7 +35,10 @@ namespace umbraco.presentation.create public static string Create(string NodeType, int TypeId, int NodeId, string Text) { - return LegacyDialogHandler.Create(NodeType, NodeId, Text, TypeId); + return LegacyDialogHandler.Create( + new HttpContextWrapper(HttpContext.Current), + BasePage.Current.getUser(), + NodeType, NodeId, Text, TypeId); } } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/dictionaryTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/dictionaryTasks.cs index a8ac6aecea..dc14b25dde 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/dictionaryTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/dictionaryTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -9,46 +10,9 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class dictionaryTasks : interfaces.ITaskReturnUrl + public class dictionaryTasks : LegacyDialogTask { - - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId - { - set { _userID = value; } - } - - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set - { - _parentID = value; - // NASTY HACK ON NASTY HACK§!! - // if (_parentID == 1) _parentID = -1; - } - get - { - return _parentID; - } - } - - public bool Save() + public override bool PerformSave() { //check to see if key is already there if (cms.businesslogic.Dictionary.DictionaryItem.hasKey(Alias)) @@ -57,44 +21,33 @@ namespace umbraco // Create new dictionary item if name no already exist if (ParentID > 0) { - int id = cms.businesslogic.Dictionary.DictionaryItem.addKey(Alias, "", new cms.businesslogic.Dictionary.DictionaryItem(ParentID).key); - m_returnUrl = string.Format("settings/editDictionaryItem.aspx?id={0}", id); + var id = cms.businesslogic.Dictionary.DictionaryItem.addKey(Alias, "", new cms.businesslogic.Dictionary.DictionaryItem(ParentID).key); + _returnUrl = string.Format("settings/editDictionaryItem.aspx?id={0}", id); } else { - int id = cms.businesslogic.Dictionary.DictionaryItem.addKey(Alias, ""); - m_returnUrl = string.Format("settings/editDictionaryItem.aspx?id={0}", id); + var id = cms.businesslogic.Dictionary.DictionaryItem.addKey(Alias, ""); + _returnUrl = string.Format("settings/editDictionaryItem.aspx?id={0}", id); } return true; } - public bool Delete() + public override bool PerformDelete() { - BusinessLogic.Log.Add(LogTypes.Debug, ParentID, _typeID.ToString() + " " + _parentID.ToString() + " deleting " + Alias); - new cms.businesslogic.Dictionary.DictionaryItem(ParentID).delete(); return true; } - public bool Sort() + private string _returnUrl = ""; + + public override string ReturnUrl { - return false; + get { return _returnUrl; } } - public dictionaryTasks() + public override string AssignedApp { - // - // TODO: Add constructor logic here - // + get { return DefaultApps.settings.ToString(); } } - - #region ITaskReturnUrl Members - private string m_returnUrl = ""; - public string ReturnUrl - { - get { return m_returnUrl; } - } - - #endregion } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/language.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/language.ascx.cs index 8b98a600c3..ab53b80f82 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/language.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/language.ascx.cs @@ -1,8 +1,10 @@ using System; using System.Collections; using System.Globalization; +using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using Umbraco.Web.UI; using umbraco.presentation.create; using umbraco.cms.businesslogic.language; using umbraco.cms.helpers; @@ -72,7 +74,9 @@ namespace umbraco.cms.presentation.create.controls protected void sbmt_Click(object sender, EventArgs e) { - dialogHandler_temp.Create( + LegacyDialogHandler.Create( + new HttpContextWrapper(Context), + BasePage.Current.getUser(), helper.Request("nodeType"), -1, Cultures.SelectedValue); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/languageTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/languageTasks.cs index d716c566ba..19d50a1228 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/languageTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/languageTasks.cs @@ -2,6 +2,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -10,54 +11,29 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class languageTasks : interfaces.ITask + public class languageTasks : LegacyDialogTask { - - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId - { - set { _userID = value; } - } - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set { _parentID = value; } - get { return _parentID; } - } - - public bool Save() + + public override bool PerformSave() { cms.businesslogic.language.Language.MakeNew(Alias); return true; } - public bool Delete() + public override bool PerformDelete() { new cms.businesslogic.language.Language(ParentID).Delete(); return false; } - public languageTasks() + public override string ReturnUrl { - // - // TODO: Add constructor logic here - // + get { return string.Empty; } + } + + public override string AssignedApp + { + get { return DefaultApps.settings.ToString(); } } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/macroTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/macroTasks.cs index be15eaea5f..5ee0d4a1a8 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/macroTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/macroTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -9,57 +10,25 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class macroTasks : interfaces.ITaskReturnUrl + public class macroTasks : LegacyDialogTask { - - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - + protected static ISqlHelper SqlHelper { get { return Application.SqlHelper; } } - - public int UserId + + public override bool PerformSave() { - set { _userID = value; } - } - - - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set { _parentID = value; } - get { return _parentID; } - } - - public bool Save() - { - int id = -1; - umbraco.cms.businesslogic.macro.Macro checkingMacro =umbraco.cms.businesslogic.macro.Macro.GetByAlias(_alias); - if (checkingMacro!=null) - id =checkingMacro.Id; - else - id = umbraco.cms.businesslogic.macro.Macro.MakeNew(_alias).Id; - m_returnUrl = string.Format("developer/Macros/editMacro.aspx?macroID={0}", id); + var checkingMacro =cms.businesslogic.macro.Macro.GetByAlias(Alias); + var id = checkingMacro != null + ? checkingMacro.Id + : cms.businesslogic.macro.Macro.MakeNew(Alias).Id; + _returnUrl = string.Format("developer/Macros/editMacro.aspx?macroID={0}", id); return true; } - public bool Delete() + public override bool PerformDelete() { // Clear cache! macro.GetMacro(ParentID).removeFromCache(); @@ -67,20 +36,16 @@ namespace umbraco return true; } - public macroTasks() + private string _returnUrl = ""; + + public override string ReturnUrl { - // - // TODO: Add constructor logic here - // + get { return _returnUrl; } } - #region ITaskReturnUrl Members - private string m_returnUrl = ""; - public string ReturnUrl + public override string AssignedApp { - get { return m_returnUrl; } + get { return DefaultApps.developer.ToString(); } } - - #endregion } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/media.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/media.ascx.cs index 2ae91676a5..4cd7cadbf7 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/media.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/media.ascx.cs @@ -1,3 +1,5 @@ +using Umbraco.Web.UI; + namespace umbraco.cms.presentation.create.controls { using System; @@ -65,13 +67,15 @@ namespace umbraco.cms.presentation.create.controls protected void sbmt_Click(object sender, System.EventArgs e) { - if (Page.IsValid) + if (Page.IsValid) { - string returnUrl = umbraco.presentation.create.dialogHandler_temp.Create( - umbraco.helper.Request("nodeType"), - int.Parse(nodeType.SelectedValue), - int.Parse(Request["nodeID"]), - rename.Text); + var returnUrl = LegacyDialogHandler.Create( + new HttpContextWrapper(Context), + BasePage.Current.getUser(), + helper.Request("nodeType"), + int.Parse(nodeType.SelectedValue), + rename.Text, + int.Parse(Request["nodeID"])); BasePage.Current.ClientTools .ChangeContentFrameUrl(returnUrl) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/mediaTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/mediaTasks.cs index afee28e600..d417a71910 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/mediaTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/mediaTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -9,80 +10,40 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class mediaTasks : interfaces.ITaskReturnUrl + public class mediaTasks : LegacyDialogTask { - - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; private string _returnUrl = ""; - public int UserId - { - set { _userID = value; } - } - - public string ReturnUrl + public override string ReturnUrl { get { return _returnUrl; } } - public int TypeID + public override string AssignedApp { - set { _typeID = value; } - get { return _typeID; } + get { return DefaultApps.media.ToString(); } } - public string Alias + public override bool PerformSave() { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set - { - _parentID = value; - } - get - { - return _parentID; - } - } - - public bool Save() - { - cms.businesslogic.media.MediaType dt = new cms.businesslogic.media.MediaType(TypeID); - cms.businesslogic.media.Media m = cms.businesslogic.media.Media.MakeNew(Alias, dt, BusinessLogic.User.GetUser(_userID), ParentID); + var dt = new cms.businesslogic.media.MediaType(TypeID); + var m = cms.businesslogic.media.Media.MakeNew(Alias, dt, User, ParentID); _returnUrl = "editMedia.aspx?id=" + m.Id.ToString() + "&isNew=true"; return true; } - public bool Delete() + public override bool PerformDelete() { - cms.businesslogic.media.Media d = new cms.businesslogic.media.Media(ParentID); + var d = new cms.businesslogic.media.Media(ParentID); // Log - BusinessLogic.Log.Add(BusinessLogic.LogTypes.Delete, User.GetCurrent(), d.Id, ""); + Log.Add(LogTypes.Delete, User, d.Id, ""); d.delete(); return true; } - public bool Sort() - { - return false; - } - - public mediaTasks() - { - // - // TODO: Add constructor logic here - // - } } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/member.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/member.ascx.cs index 1dc60aad93..19e86021c3 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/member.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/member.ascx.cs @@ -1,3 +1,5 @@ +using Umbraco.Web.UI; + namespace umbraco.cms.presentation.create.controls { using System; @@ -85,13 +87,15 @@ namespace umbraco.cms.presentation.create.controls { if (Page.IsValid) { - int memberType = memberChooser.Visible ? int.Parse(nodeType.SelectedValue) : -1; - string emailAppend = String.IsNullOrEmpty(Email.Text) ? "" : String.Format("|{0}|{1}|{2}", Email.Text, Password.Text,Login.Text); - string returnUrl = umbraco.presentation.create.dialogHandler_temp.Create( - umbraco.helper.Request("nodeType"), + var memberType = memberChooser.Visible ? int.Parse(nodeType.SelectedValue) : -1; + var emailAppend = String.IsNullOrEmpty(Email.Text) ? "" : String.Format("|{0}|{1}|{2}", Email.Text, Password.Text,Login.Text); + var returnUrl = LegacyDialogHandler.Create( + new HttpContextWrapper(Context), + BasePage.Current.getUser(), + helper.Request("nodeType"), memberType, - -1, - rename.Text + emailAppend); + rename.Text + emailAppend, + -1); BasePage.Current.ClientTools .ChangeContentFrameUrl(returnUrl) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/memberTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/memberTasks.cs index 7570bee69a..0b5928d0ad 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/memberTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/memberTasks.cs @@ -1,6 +1,8 @@ using System; using System.Data; +using System.Web; using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -9,7 +11,7 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class memberTasks : interfaces.ITaskReturnUrl + public class memberTasks : LegacyDialogTask { /// /// The new event handler @@ -17,111 +19,80 @@ namespace umbraco public delegate void NewUIMemberEventHandler(Member sender, string unencryptedPassword, NewMemberUIEventArgs e); public static event NewUIMemberEventHandler NewMember; - new protected virtual void OnNewMember(NewMemberUIEventArgs e, string unencryptedPassword, Member m) + + protected virtual void OnNewMember(NewMemberUIEventArgs e, string unencryptedPassword, Member m) { if (NewMember != null) { NewMember(m, unencryptedPassword, e); } } - - - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; + + private int _parentId; private string _returnUrl = ""; - public int UserId - { - set { _userID = value; } - } - - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - public string ReturnUrl + public override string ReturnUrl { get { return _returnUrl; } } - public string Alias + public override string AssignedApp { - set { _alias = value; } - get { return _alias; } + get { return DefaultApps.member.ToString(); } } - public int ParentID + public override int ParentID { set { - _parentID = value; - if (_parentID == 1) _parentID = -1; + _parentId = value; + if (_parentId == 1) _parentId = -1; } get { - return _parentID; + return _parentId; } } - public bool Save() + public override bool PerformSave() { - string[] nameAndMail = Alias.Split("|".ToCharArray()); - string name = nameAndMail[0]; - string email = nameAndMail.Length > 0 ? nameAndMail[1] : ""; - string password = nameAndMail.Length > 1 ? nameAndMail[2] : ""; - string loginName = nameAndMail.Length > 2 ? nameAndMail[3] : ""; - if (cms.businesslogic.member.Member.InUmbracoMemberMode() && TypeID != -1) + var nameAndMail = Alias.Split("|".ToCharArray()); + var name = nameAndMail[0]; + var email = nameAndMail.Length > 0 ? nameAndMail[1] : ""; + var password = nameAndMail.Length > 1 ? nameAndMail[2] : ""; + var loginName = nameAndMail.Length > 2 ? nameAndMail[3] : ""; + if (Member.InUmbracoMemberMode() && TypeID != -1) { - cms.businesslogic.member.MemberType dt = new cms.businesslogic.member.MemberType(TypeID); - cms.businesslogic.member.Member m = cms.businesslogic.member.Member.MakeNew(name, loginName, email, dt, BusinessLogic.User.GetUser(_userID)); + var dt = new MemberType(TypeID); + var m = Member.MakeNew(name, loginName, email, dt, User); m.Password = password; m.LoginName = loginName.Replace(" ", "").ToLower(); - NewMemberUIEventArgs e = new NewMemberUIEventArgs(); - this.OnNewMember(e, password, m); + var e = new NewMemberUIEventArgs(); + OnNewMember(e, password, m); _returnUrl = "members/editMember.aspx?id=" + m.Id.ToString(); } else { - MembershipCreateStatus mc = new MembershipCreateStatus(); + var mc = new MembershipCreateStatus(); Membership.CreateUser(name, password, email, "empty", "empty", true, out mc); if (mc != MembershipCreateStatus.Success) { throw new Exception("Error creating Member: " + mc.ToString()); } - _returnUrl = "members/editMember.aspx?id=" + System.Web.HttpContext.Current.Server.UrlEncode(name); + _returnUrl = "members/editMember.aspx?id=" + HttpUtility.UrlEncode(name); } return true; } - public bool Delete() - { - //cms.businesslogic.member.Member d = new cms.businesslogic.member.Member(ParentID); - //d.delete(); - //return true; - MembershipUser u = Membership.GetUser(Alias); + public override bool PerformDelete() + { + var u = Membership.GetUser(Alias); Membership.DeleteUser(u.UserName, true); return true; - - } - public bool Sort() - { - return false; - } - - public memberTasks() - { - // - // TODO: Add constructor logic here - // - } } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodeType.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodeType.ascx.cs index 0eabddaae2..13913f29e9 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodeType.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodeType.ascx.cs @@ -1,3 +1,5 @@ +using Umbraco.Web.UI; + namespace umbraco.cms.presentation.create.controls { using System; @@ -53,18 +55,20 @@ namespace umbraco.cms.presentation.create.controls { if (Page.IsValid) { - int createTemplateVal = 0; + var createTemplateVal = 0; if (createTemplate.Checked) createTemplateVal = 1; // check master type - string masterTypeVal = String.IsNullOrEmpty(umbraco.helper.Request("nodeId")) || umbraco.helper.Request("nodeId") == "init" ? masterType.SelectedValue : umbraco.helper.Request("nodeId"); + var masterTypeVal = String.IsNullOrEmpty(umbraco.helper.Request("nodeId")) || umbraco.helper.Request("nodeId") == "init" ? masterType.SelectedValue : umbraco.helper.Request("nodeId"); - string returnUrl = umbraco.presentation.create.dialogHandler_temp.Create( - umbraco.helper.Request("nodeType"), + var returnUrl = LegacyDialogHandler.Create( + new HttpContextWrapper(Context), + BasePage.Current.getUser(), + helper.Request("nodeType"), int.Parse(masterTypeVal), - createTemplateVal, - rename.Text); + rename.Text, + createTemplateVal); BasePage.Current.ClientTools .ChangeContentFrameUrl(returnUrl) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs index 4655bdf11e..07807be7fd 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -9,46 +10,18 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class nodetypeTasks : interfaces.ITaskReturnUrl + public class nodetypeTasks : LegacyDialogTask { - - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId + + public override bool PerformSave() { - set { _userID = value; } - } - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set { _parentID = value; } - get { return _parentID; } - } - - public bool Save() - { - cms.businesslogic.web.DocumentType dt = cms.businesslogic.web.DocumentType.MakeNew(BusinessLogic.User.GetUser(_userID), Alias.Replace("'", "''")); + var dt = cms.businesslogic.web.DocumentType.MakeNew(User, Alias.Replace("'", "''")); dt.IconUrl = "folder.gif"; // Create template? if (ParentID == 1) { - cms.businesslogic.template.Template[] t = { cms.businesslogic.template.Template.MakeNew(_alias, BusinessLogic.User.GetUser(_userID)) }; + cms.businesslogic.template.Template[] t = { cms.businesslogic.template.Template.MakeNew(Alias, User) }; dt.allowedTemplates = t; dt.DefaultTemplate = t[0].Id; } @@ -59,12 +32,12 @@ namespace umbraco dt.MasterContentType = TypeID; } - m_returnUrl = "settings/editNodeTypeNew.aspx?id=" + dt.Id.ToString(); + _returnUrl = "settings/editNodeTypeNew.aspx?id=" + dt.Id.ToString(); return true; } - public bool Delete() + public override bool PerformDelete() { new cms.businesslogic.web.DocumentType(ParentID).delete(); @@ -73,21 +46,16 @@ namespace umbraco return false; } - - public nodetypeTasks() + + private string _returnUrl = ""; + public override string ReturnUrl { - // - // TODO: Add constructor logic here - // + get { return _returnUrl; } } - #region ITaskReturnUrl Members - private string m_returnUrl = ""; - public string ReturnUrl + public override string AssignedApp { - get { return m_returnUrl; } + get { return DefaultApps.settings.ToString(); } } - - #endregion } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/script.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/script.ascx.cs index 89b73e27a3..940d206561 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/script.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/script.ascx.cs @@ -8,6 +8,7 @@ using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; +using Umbraco.Web.UI; using umbraco.cms.helpers; using umbraco.BasePages; using umbraco.IO; @@ -37,7 +38,9 @@ namespace umbraco.presentation.umbraco.create if (scriptType.SelectedValue == "") createFolder = 1; - string returnUrl = presentation.create.dialogHandler_temp.Create( + string returnUrl = LegacyDialogHandler.Create( + new HttpContextWrapper(Context), + BasePage.Current.getUser(), helper.Request("nodeType"), createFolder, relativepath + "¤" + rename.Text + "¤" + scriptType.SelectedValue); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/simple.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/simple.ascx.cs index 4d2c5a3950..f430f0e557 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/simple.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/simple.ascx.cs @@ -1,3 +1,6 @@ +using Umbraco.Core.Logging; +using Umbraco.Web.UI; + namespace umbraco.cms.presentation.create.controls { using System; @@ -46,17 +49,17 @@ namespace umbraco.cms.presentation.create.controls { if (Page.IsValid) { - int nodeId = -1; - if (umbraco.helper.Request("nodeId") != "init") - nodeId = int.Parse(umbraco.helper.Request("nodeId")); + var nodeId = -1; + if (helper.Request("nodeId") != "init") + nodeId = int.Parse(helper.Request("nodeId")); - string returnUrl = umbraco.presentation.create.dialogHandler_temp.Create( - umbraco.helper.Request("nodeType"), + var returnUrl = LegacyDialogHandler.Create( + new HttpContextWrapper(Context), + BasePage.Current.getUser(), + helper.Request("nodeType"), nodeId, rename.Text); - Log.Add(LogTypes.Debug, -1, "return:" + returnUrl); - BasePage.Current.ClientTools .ChangeContentFrameUrl(returnUrl) .ChildNodeCreated() diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/stylesheetPropertyTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/stylesheetPropertyTasks.cs index 0a9c94cd58..ef00c4902a 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/stylesheetPropertyTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/stylesheetPropertyTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -9,44 +10,16 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class stylesheetPropertyTasks : interfaces.ITaskReturnUrl + public class stylesheetPropertyTasks : LegacyDialogTask { - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId - { - set { _userID = value; } - } - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set { _parentID = value; } - get { return _parentID; } - } - - public bool Save() + public override bool PerformSave() { try { - cms.businesslogic.web.StyleSheet s = new cms.businesslogic.web.StyleSheet(ParentID); - int id = s.AddProperty(Alias, BusinessLogic.User.GetUser(_userID)).Id; - m_returnUrl = string.Format("settings/stylesheet/property/EditStyleSheetProperty.aspx?id={0}", id); + var s = new cms.businesslogic.web.StyleSheet(ParentID); + var id = s.AddProperty(Alias, User).Id; + _returnUrl = string.Format("settings/stylesheet/property/EditStyleSheetProperty.aspx?id={0}", id); } catch { @@ -55,23 +28,26 @@ namespace umbraco return true; } - public bool Delete() + public override bool PerformDelete() { - cms.businesslogic.web.StylesheetProperty sp = new cms.businesslogic.web.StylesheetProperty(ParentID); - cms.businesslogic.web.StyleSheet s = sp.StyleSheet(); + var sp = new cms.businesslogic.web.StylesheetProperty(ParentID); + var s = sp.StyleSheet(); s.saveCssToFile(); sp.delete(); return true; } - #region ITaskReturnUrl Members - private string m_returnUrl = ""; - public string ReturnUrl + private string _returnUrl = ""; + + public override string ReturnUrl { - get { return m_returnUrl; } + get { return _returnUrl; } } - #endregion + public override string AssignedApp + { + get { return DefaultApps.settings.ToString(); } + } } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/templateTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/templateTasks.cs index 03887b2cce..ea1feda139 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/templateTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/templateTasks.cs @@ -2,6 +2,7 @@ using System; using System.Data; using System.Web.Security; using Umbraco.Core; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -10,80 +11,47 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class templateTasks : interfaces.ITaskReturnUrl + public class templateTasks : LegacyDialogTask { - - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; - - public int UserId + + public override bool PerformSave() { - set { _userID = value; } - } - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } - } - - - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - - public int ParentID - { - set { _parentID = value; } - get { return _parentID; } - } - - public bool Save() - { - int masterId = ParentID; - BusinessLogic.Log.Add(LogTypes.Debug, -1, "tp id:" + masterId.ToString()); - + var masterId = ParentID; + var editor = "settings/editTemplate.aspx"; if(Umbraco.Core.Configuration.UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc) editor = "settings/views/editView.aspx"; if (masterId > 0) { - int id = cms.businesslogic.template.Template.MakeNew(Alias, BusinessLogic.User.GetUser(_userID), new cms.businesslogic.template.Template(masterId)).Id; - m_returnUrl = string.Format("{1}?templateID={0}", id, editor); + var id = cms.businesslogic.template.Template.MakeNew(Alias, User, new cms.businesslogic.template.Template(masterId)).Id; + _returnUrl = string.Format("{1}?templateID={0}", id, editor); } else { - int id = cms.businesslogic.template.Template.MakeNew(Alias, BusinessLogic.User.GetUser(_userID)).Id; - m_returnUrl = string.Format("{1}?templateID={0}", id, editor); + var id = cms.businesslogic.template.Template.MakeNew(Alias, User).Id; + _returnUrl = string.Format("{1}?templateID={0}", id, editor); } return true; } - public bool Delete() + public override bool PerformDelete() { - new cms.businesslogic.template.Template(_parentID).delete(); + new cms.businesslogic.template.Template(ParentID).delete(); return false; } - public templateTasks() + private string _returnUrl = ""; + + public override string ReturnUrl { - // - // TODO: Add constructor logic here - // + get { return _returnUrl; } } - #region ITaskReturnUrl Members - private string m_returnUrl = ""; - public string ReturnUrl + public override string AssignedApp { - get { return m_returnUrl; } + get { return DefaultApps.settings.ToString(); } } - - #endregion } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/userTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/userTasks.cs index e169d1ee8e..eef317507b 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/userTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/userTasks.cs @@ -2,6 +2,7 @@ using System; using System.Data; using System.Web.Security; using Umbraco.Core.Logging; +using Umbraco.Web.UI; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -10,28 +11,21 @@ using umbraco.cms.businesslogic.member; namespace umbraco { - public class userTasks : interfaces.ITaskReturnUrl + public class userTasks : LegacyDialogTask { private string _returnUrl = ""; - public int UserId - { - set { } - } - - public int TypeID { get; set; } - - - public string Alias { get; set; } - - public int ParentID { get; set; } - - public string ReturnUrl + public override string ReturnUrl { get { return _returnUrl; } } - public bool Save() + public override string AssignedApp + { + get { return DefaultApps.users.ToString(); } + } + + public override bool PerformSave() { // Hot damn HACK > user is allways UserType with id = 1 = administrator ??? // temp password deleted by NH @@ -48,7 +42,7 @@ namespace umbraco Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].MinRequiredNonAlphanumericCharacters), "", "", "", true, null, out status); - _returnUrl = string.Format("users/EditUser.aspx?id={0}", u.ProviderUserKey.ToString()); + _returnUrl = string.Format("users/EditUser.aspx?id={0}", u.ProviderUserKey); return status == MembershipCreateStatus.Success; } @@ -59,7 +53,7 @@ namespace umbraco } } - public bool Delete() + public override bool PerformDelete() { var u = User.GetUser(ParentID); u.disable(); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/xslt.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/xslt.ascx.cs index 358265a098..416825e63c 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/xslt.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/xslt.ascx.cs @@ -5,6 +5,7 @@ using System.Web; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.IO; +using Umbraco.Web.UI; using umbraco.cms.helpers; using umbraco.BasePages; using umbraco.IO; @@ -66,14 +67,16 @@ namespace umbraco.presentation.create { if (Page.IsValid) { - int createMacroVal = 0; + var createMacroVal = 0; if (createMacro.Checked) createMacroVal = 1; - string xsltName = UmbracoSettings.UseLegacyXmlSchema ? xsltTemplate.SelectedValue : + var xsltName = UmbracoSettings.UseLegacyXmlSchema ? xsltTemplate.SelectedValue : Path.Combine("schema2", xsltTemplate.SelectedValue); - string returnUrl = dialogHandler_temp.Create( + var returnUrl = LegacyDialogHandler.Create( + new HttpContextWrapper(Context), + BasePage.Current.getUser(), helper.Request("nodeType"), createMacroVal, xsltName + "|||" + rename.Text); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/users/UserTypeTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/users/UserTypeTasks.cs index a65a0a6c1b..0a8e02341a 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/users/UserTypeTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/users/UserTypeTasks.cs @@ -7,63 +7,20 @@ using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; +using Umbraco.Web.UI; using umbraco.interfaces; using umbraco.BusinessLogic; namespace umbraco.cms.presentation.user { - public class UserTypeTasks : ITaskReturnUrl + public class UserTypeTasks : LegacyDialogTask { - private int m_parentID; - private int m_typeID; - private string m_alias; - private int m_userID; - - #region ITaskReturnUrl Members - - public int ParentID - { - get - { - return m_parentID; - } - set - { - m_parentID = value; - } - } - - public int TypeID - { - get - { - return m_typeID; - } - set - { - m_typeID = value; - } - } - - public string Alias - { - get - { - return m_alias; - } - set - { - m_alias = value; - } - } - - public bool Save() + public override bool PerformSave() { try { - UserType u = UserType.MakeNew(this.m_alias, "", this.m_alias); - - m_returnUrl = string.Format("users/EditUserType.aspx?id={0}", u.Id); + var u = UserType.MakeNew(Alias, "", Alias); + _returnUrl = string.Format("users/EditUserType.aspx?id={0}", u.Id); return true; } catch @@ -72,27 +29,24 @@ namespace umbraco.cms.presentation.user } } - public bool Delete() + public override bool PerformDelete() { - UserType userType = UserType.GetUserType(this.m_parentID); + var userType = UserType.GetUserType(ParentID); if (userType == null) return false; userType.Delete(); return true; } - public int UserId + private string _returnUrl = ""; + public override string ReturnUrl { - set { m_userID = value; } + get { return _returnUrl; } } - - private string m_returnUrl = ""; - public string ReturnUrl + public override string AssignedApp { - get { return m_returnUrl; } + get { return DefaultApps.users.ToString(); } } - - #endregion } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/legacyAjaxCalls.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/legacyAjaxCalls.asmx.cs index 8e330009ff..e7989febd0 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/legacyAjaxCalls.asmx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/legacyAjaxCalls.asmx.cs @@ -11,6 +11,7 @@ using System.Net; using System.Web.UI; using Umbraco.Core.IO; using Umbraco.Web.UI; +using umbraco.BusinessLogic; using umbraco.businesslogic.Exceptions; using umbraco.cms.businesslogic.web; using umbraco.cms.businesslogic.media; @@ -28,6 +29,8 @@ namespace umbraco.presentation.webservices [ScriptService] public class legacyAjaxCalls : WebService { + private User _currentUser; + [WebMethod] public bool ValidateUser(string username, string password) { @@ -52,18 +55,25 @@ namespace umbraco.presentation.webservices [ScriptMethod] public void Delete(string nodeId, string alias, string nodeType) { - Authorize(); - + if (!AuthorizeUser()) + return; + //check which parameters to pass depending on the types passed in int intNodeId; // Fix for #26965 - numeric member login gets parsed as nodeId if (int.TryParse(nodeId, out intNodeId) && nodeType != "member") { - LegacyDialogHandler.Delete(nodeType, intNodeId, alias); + LegacyDialogHandler.Delete( + new HttpContextWrapper(HttpContext.Current), + CurrentUser, + nodeType, intNodeId, alias); } else { - LegacyDialogHandler.Delete(nodeType, 0, nodeId); + LegacyDialogHandler.Delete( + new HttpContextWrapper(HttpContext.Current), + CurrentUser, + nodeType, 0, nodeId); } } @@ -421,7 +431,41 @@ namespace umbraco.presentation.webservices return "true"; } + private User CurrentUser + { + get + { + if (_currentUser == null) + { + throw new InvalidOperationException("The CurrentUser property has not been set, ensure a successful call is made to AuthorizeUser()"); + } + return _currentUser; + } + set { _currentUser = value; } + } + /// + /// Authorizes the current user and ensures we don't have to re-lookup the business logic for the current + /// web service instance. + /// + private bool AuthorizeUser() + { + // check for secure connection + if (GlobalSettings.UseSSL && !HttpContext.Current.Request.IsSecureConnection) + throw new UserAuthorizationException("This installation requires a secure connection (via SSL). Please update the URL to include https://"); + + if (!BasePage.ValidateUserContextID(BasePages.BasePage.umbracoUserContextID)) + return false; + + _currentUser = global::umbraco.BusinessLogic.User.GetUser( + BasePage.GetUserId(BasePage.umbracoUserContextID)); + + return true; + } + + /// + /// Authorizes the current user based on the cookie value + /// public static void Authorize() {