Files
Umbraco-CMS/src/Umbraco.Web/Editors/LegacyController.cs
perploug da3269e970 Fixes: U4-3426 Can't delete any contentnode, media, document type or template from back end, Umbraco 7.0.0-RC
Replaces $http.delete with $http.post enables httppost on the
server-side, its not the best solution, but has way fewer unknowns then
adding extensive VERB and origin support in the web.config
2013-12-06 13:12:18 +01:00

79 lines
2.8 KiB
C#

using System;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using Umbraco.Core;
using Umbraco.Web.Mvc;
using Umbraco.Web.UI;
using Umbraco.Web.WebApi;
using Umbraco.Web.WebApi.Filters;
namespace Umbraco.Web.Editors
{
/// <summary>
/// The API controller used for dealing with legacy content
/// </summary>
[PluginController("UmbracoApi")]
[ValidationFilter]
public class LegacyController : UmbracoAuthorizedJsonController
{
/// <summary>
/// Constructor
/// </summary>
public LegacyController()
: this(UmbracoContext.Current)
{
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="umbracoContext"></param>
internal LegacyController(UmbracoContext umbracoContext)
: base(umbracoContext)
{
}
/// <summary>
/// This will perform the delete operation for legacy items which include any item that
/// has functionality included in the ui.xml structure.
/// </summary>
/// <returns></returns>
[HttpPost]
public HttpResponseMessage DeleteLegacyItem(string nodeId, string alias, string nodeType)
{
//U4-2686 - alias is html encoded, make sure to decode
alias = HttpUtility.HtmlDecode(alias);
//In order to process this request we MUST have an HttpContext available
var httpContextAttempt = TryGetHttpContext();
if (httpContextAttempt.Success)
{
//this is a hack check based on legacy
if (nodeType == "memberGroup")
{
LegacyDialogHandler.Delete(httpContextAttempt.Result, UmbracoUser, nodeType, 0, alias);
return Request.CreateResponse(HttpStatusCode.OK);
}
int id;
if (int.TryParse(nodeId, out id))
{
LegacyDialogHandler.Delete(httpContextAttempt.Result, UmbracoUser, nodeType, id, alias);
return Request.CreateResponse(HttpStatusCode.OK);
}
//the way this legacy stuff used to work is that if the node id didn't parse, we would
//pass the node id as the alias with an id of zero = sure whatevs.
LegacyDialogHandler.Delete(httpContextAttempt.Result, UmbracoUser, nodeType, 0, nodeId);
return Request.CreateResponse(HttpStatusCode.OK);
}
//We must have an HttpContext available for this to work.
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, new InvalidOperationException("No HttpContext found in the current request"));
}
}
}