From 5c5f546317e0265898b0e9be02fd1874cee346b9 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Sun, 25 Sep 2011 15:03:01 -0700 Subject: [PATCH] #18106, #18061: Fixing XmlRpc urls Work Items: 18061, 18106 --HG-- branch : 1.x --- .../Orchard.Blogs/Services/XmlRpcHandler.cs | 8 +++++++- .../Orchard.Media/Services/XmlRpcHandler.cs | 19 +++++++++++++++---- .../Mvc/Extensions/UrlHelperExtensions.cs | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs index 0cbeadf4f..832756bc3 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs @@ -18,6 +18,7 @@ using Orchard.Logging; using Orchard.Mvc.Extensions; using Orchard.Security; using Orchard.Blogs.Extensions; +using Orchard.Mvc.Html; namespace Orchard.Blogs.Services { [UsedImplicitly] @@ -321,7 +322,12 @@ namespace Orchard.Blogs.Services { BlogPostPart blogPostPart, UrlHelper urlHelper) { - var url = urlHelper.AbsoluteAction(() => urlHelper.BlogPost(blogPostPart)); + var url = urlHelper.AbsoluteAction(() => urlHelper.ItemDisplayUrl(blogPostPart)); + + if (blogPostPart.HasDraft()) { + url = urlHelper.AbsoluteAction("Preview", "Item", new { area = "Contents", id = blogPostPart.ContentItem.Id }); + } + var blogStruct = new XRpcStruct() .Set("postid", blogPostPart.Id) .Set("title", blogPostPart.Title) diff --git a/src/Orchard.Web/Modules/Orchard.Media/Services/XmlRpcHandler.cs b/src/Orchard.Web/Modules/Orchard.Media/Services/XmlRpcHandler.cs index 2d71b1c4f..4ba79adaa 100644 --- a/src/Orchard.Web/Modules/Orchard.Media/Services/XmlRpcHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Media/Services/XmlRpcHandler.cs @@ -1,9 +1,13 @@ using System; using System.IO; +using System.Web.Mvc; +using System.Web.Routing; using System.Xml.Linq; using JetBrains.Annotations; using Orchard.Core.XmlRpc; using Orchard.Core.XmlRpc.Models; +using Orchard.Mvc.Extensions; +using Orchard.Utility.Extensions; using Orchard.Security; namespace Orchard.Media.Services { @@ -12,14 +16,17 @@ namespace Orchard.Media.Services { private readonly IMembershipService _membershipService; private readonly IAuthorizationService _authorizationService; private readonly IMediaService _mediaService; + private readonly RouteCollection _routeCollection; public XmlRpcHandler( IMembershipService membershipService, IAuthorizationService authorizationService, - IMediaService mediaService) { + IMediaService mediaService, + RouteCollection routeCollection) { _membershipService = membershipService; _authorizationService = authorizationService; _mediaService = mediaService; + _routeCollection = routeCollection; } public void SetCapabilities(XElement options) { @@ -28,11 +35,14 @@ namespace Orchard.Media.Services { } public void Process(XmlRpcContext context) { + var urlHelper = new UrlHelper(context.ControllerContext.RequestContext, _routeCollection); + if (context.Request.MethodName == "metaWeblog.newMediaObject") { var result = MetaWeblogNewMediaObject( Convert.ToString(context.Request.Params[1].Value), Convert.ToString(context.Request.Params[2].Value), - (XRpcStruct)context.Request.Params[3].Value); + (XRpcStruct)context.Request.Params[3].Value, + urlHelper); context.Response = new XRpcMethodResponse().Add(result); } } @@ -40,7 +50,8 @@ namespace Orchard.Media.Services { private XRpcStruct MetaWeblogNewMediaObject( string userName, string password, - XRpcStruct file) { + XRpcStruct file, + UrlHelper url) { var user = _membershipService.ValidateUser(userName, password); if (!_authorizationService.TryCheckAccess(Permissions.ManageMedia, user, null)) { @@ -52,7 +63,7 @@ namespace Orchard.Media.Services { var bits = file.Optional("bits"); string publicUrl = _mediaService.UploadMediaFile(Path.GetDirectoryName(name), Path.GetFileName(name), bits, true); - return new XRpcStruct().Set("url", publicUrl); + return new XRpcStruct().Set("url", url.MakeAbsolute(publicUrl)); } } } \ No newline at end of file diff --git a/src/Orchard/Mvc/Extensions/UrlHelperExtensions.cs b/src/Orchard/Mvc/Extensions/UrlHelperExtensions.cs index 42c70136c..27fc1a04b 100644 --- a/src/Orchard/Mvc/Extensions/UrlHelperExtensions.cs +++ b/src/Orchard/Mvc/Extensions/UrlHelperExtensions.cs @@ -24,7 +24,7 @@ namespace Orchard.Mvc.Extensions { return urlHelper.MakeAbsolute(urlHelper.Action(actionName, controller, routeValues)); } - private static string MakeAbsolute(this UrlHelper urlHelper, string url) { + public static string MakeAbsolute(this UrlHelper urlHelper, string url) { var siteUrl = urlHelper.RequestContext.HttpContext.Request.ToRootUrlString(); return siteUrl + url; }