#18106, #18061: Fixing XmlRpc urls

Work Items: 18061, 18106

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-09-25 15:03:01 -07:00
parent 36b8a8911c
commit 5c5f546317
3 changed files with 23 additions and 6 deletions

View File

@@ -18,6 +18,7 @@ using Orchard.Logging;
using Orchard.Mvc.Extensions; using Orchard.Mvc.Extensions;
using Orchard.Security; using Orchard.Security;
using Orchard.Blogs.Extensions; using Orchard.Blogs.Extensions;
using Orchard.Mvc.Html;
namespace Orchard.Blogs.Services { namespace Orchard.Blogs.Services {
[UsedImplicitly] [UsedImplicitly]
@@ -321,7 +322,12 @@ namespace Orchard.Blogs.Services {
BlogPostPart blogPostPart, BlogPostPart blogPostPart,
UrlHelper urlHelper) { 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() var blogStruct = new XRpcStruct()
.Set("postid", blogPostPart.Id) .Set("postid", blogPostPart.Id)
.Set("title", blogPostPart.Title) .Set("title", blogPostPart.Title)

View File

@@ -1,9 +1,13 @@
using System; using System;
using System.IO; using System.IO;
using System.Web.Mvc;
using System.Web.Routing;
using System.Xml.Linq; using System.Xml.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.Core.XmlRpc; using Orchard.Core.XmlRpc;
using Orchard.Core.XmlRpc.Models; using Orchard.Core.XmlRpc.Models;
using Orchard.Mvc.Extensions;
using Orchard.Utility.Extensions;
using Orchard.Security; using Orchard.Security;
namespace Orchard.Media.Services { namespace Orchard.Media.Services {
@@ -12,14 +16,17 @@ namespace Orchard.Media.Services {
private readonly IMembershipService _membershipService; private readonly IMembershipService _membershipService;
private readonly IAuthorizationService _authorizationService; private readonly IAuthorizationService _authorizationService;
private readonly IMediaService _mediaService; private readonly IMediaService _mediaService;
private readonly RouteCollection _routeCollection;
public XmlRpcHandler( public XmlRpcHandler(
IMembershipService membershipService, IMembershipService membershipService,
IAuthorizationService authorizationService, IAuthorizationService authorizationService,
IMediaService mediaService) { IMediaService mediaService,
RouteCollection routeCollection) {
_membershipService = membershipService; _membershipService = membershipService;
_authorizationService = authorizationService; _authorizationService = authorizationService;
_mediaService = mediaService; _mediaService = mediaService;
_routeCollection = routeCollection;
} }
public void SetCapabilities(XElement options) { public void SetCapabilities(XElement options) {
@@ -28,11 +35,14 @@ namespace Orchard.Media.Services {
} }
public void Process(XmlRpcContext context) { public void Process(XmlRpcContext context) {
var urlHelper = new UrlHelper(context.ControllerContext.RequestContext, _routeCollection);
if (context.Request.MethodName == "metaWeblog.newMediaObject") { if (context.Request.MethodName == "metaWeblog.newMediaObject") {
var result = MetaWeblogNewMediaObject( var result = MetaWeblogNewMediaObject(
Convert.ToString(context.Request.Params[1].Value), Convert.ToString(context.Request.Params[1].Value),
Convert.ToString(context.Request.Params[2].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); context.Response = new XRpcMethodResponse().Add(result);
} }
} }
@@ -40,7 +50,8 @@ namespace Orchard.Media.Services {
private XRpcStruct MetaWeblogNewMediaObject( private XRpcStruct MetaWeblogNewMediaObject(
string userName, string userName,
string password, string password,
XRpcStruct file) { XRpcStruct file,
UrlHelper url) {
var user = _membershipService.ValidateUser(userName, password); var user = _membershipService.ValidateUser(userName, password);
if (!_authorizationService.TryCheckAccess(Permissions.ManageMedia, user, null)) { if (!_authorizationService.TryCheckAccess(Permissions.ManageMedia, user, null)) {
@@ -52,7 +63,7 @@ namespace Orchard.Media.Services {
var bits = file.Optional<byte[]>("bits"); var bits = file.Optional<byte[]>("bits");
string publicUrl = _mediaService.UploadMediaFile(Path.GetDirectoryName(name), Path.GetFileName(name), bits, true); 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));
} }
} }
} }

View File

@@ -24,7 +24,7 @@ namespace Orchard.Mvc.Extensions {
return urlHelper.MakeAbsolute(urlHelper.Action(actionName, controller, routeValues)); 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(); var siteUrl = urlHelper.RequestContext.HttpContext.Request.ToRootUrlString();
return siteUrl + url; return siteUrl + url;
} }