mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-18 17:47:54 +08:00
Moving xmlrpc method to upload files into media module. Updating some localized string tests.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4040921
This commit is contained in:
@@ -44,7 +44,6 @@ namespace Orchard.Tests.Packages.Pages.Controllers {
|
||||
|
||||
_controller = _container.Resolve<AdminController>();
|
||||
_controller.ControllerContext = new ControllerContext(new StubHttpContext("~/admin/cmspages"), new RouteData(), _controller);
|
||||
_controller.T = new Localizer(StubLocalizer.Get);
|
||||
}
|
||||
|
||||
public override void Register(Autofac.Builder.ContainerBuilder builder) {
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using NUnit.Framework;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Tests.UI.Notify {
|
||||
@@ -12,13 +13,12 @@ namespace Orchard.Tests.UI.Notify {
|
||||
notifier.Information("More Info");
|
||||
notifier.Error("Boom");
|
||||
|
||||
Localizer T = NullLocalizer.Instance;
|
||||
|
||||
Assert.That(notifier.List(), Has.Count.EqualTo(3));
|
||||
foreach (var notifyEntries in notifier.List()) {
|
||||
Assert.That(new[] {notifyEntries.Message.ToString()}, Is.SubsetOf(new[]
|
||||
{
|
||||
"Hello world", "More Info", "Boom"
|
||||
}));
|
||||
}
|
||||
Assert.That(notifier.List(), Has.Some.Property("Message").EqualTo(T("Hello world")));
|
||||
Assert.That(notifier.List(), Has.Some.Property("Message").EqualTo(T("More Info")));
|
||||
Assert.That(notifier.List(), Has.Some.Property("Message").EqualTo(T("Boom")));
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@
|
||||
using System.Web.Routing;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Tests.Stubs;
|
||||
using Orchard.UI.Notify;
|
||||
@@ -73,14 +74,12 @@ namespace Orchard.Tests.UI.Notify {
|
||||
filter.OnActionExecuted(context);
|
||||
filter.OnResultExecuting(new ResultExecutingContext(context, context.Result));
|
||||
|
||||
var T = NullLocalizer.Instance;
|
||||
|
||||
Assert.That(model.Messages, Is.Not.Null);
|
||||
Assert.That(model.Messages, Has.Count.EqualTo(2));
|
||||
foreach (var notifyEntries in model.Messages) {
|
||||
Assert.That(new[] { notifyEntries.Message.ToString() }, Is.SubsetOf(new[]
|
||||
{
|
||||
"dont-destroy", "Working"
|
||||
}));
|
||||
}
|
||||
Assert.That(model.Messages, Has.Some.Property("Message").EqualTo(T("dont-destroy")));
|
||||
Assert.That(model.Messages, Has.Some.Property("Message").EqualTo(T("Working")));
|
||||
}
|
||||
}
|
||||
}
|
@@ -37,6 +37,7 @@ namespace Orchard.CmsPages.Controllers {
|
||||
_templateProvider = templateProvider;
|
||||
_notifier = notifier;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
// That's what it takes to get the CurrentUser for a module.
|
||||
@@ -290,7 +291,7 @@ namespace Orchard.CmsPages.Controllers {
|
||||
public ActionResult DeleteDraft(int id) {
|
||||
#warning UNIT TEST!!!!
|
||||
if (!_authorizer.Authorize(Permissions.DeleteDraftPages, T("Couldn't delete draft page")))
|
||||
return new HttpUnauthorizedResult();
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var lastRevision = _pageManager.GetLastRevision(id);
|
||||
if (!lastRevision.IsPublished())
|
||||
|
@@ -63,16 +63,6 @@ namespace Orchard.CmsPages.Services {
|
||||
Convert.ToBoolean(context.Request.Params[4].Value));
|
||||
context.Response = new XRpcMethodResponse().Add(result);
|
||||
}
|
||||
|
||||
if (context.Request.MethodName == "metaWeblog.newMediaObject") {
|
||||
var result = MetaWeblogNewMediaObject(
|
||||
uriBuilder,
|
||||
Convert.ToString(context.Request.Params[0].Value),
|
||||
Convert.ToString(context.Request.Params[1].Value),
|
||||
Convert.ToString(context.Request.Params[2].Value),
|
||||
(XRpcStruct)context.Request.Params[3].Value);
|
||||
context.Response = new XRpcMethodResponse().Add(result);
|
||||
}
|
||||
}
|
||||
|
||||
private int MetaWeblogNewPost(
|
||||
@@ -145,23 +135,5 @@ namespace Orchard.CmsPages.Services {
|
||||
|
||||
}
|
||||
|
||||
private XRpcStruct MetaWeblogNewMediaObject(
|
||||
UriBuilder uriBuilder,
|
||||
string blogId,
|
||||
string user,
|
||||
string password,
|
||||
XRpcStruct file) {
|
||||
var name = file.Optional<string>("name");
|
||||
var bits = file.Optional<byte[]>("bits");
|
||||
|
||||
var target = HttpContext.Current.Server.MapPath("~/Files/" + name);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(target));
|
||||
using (var stream = new FileStream(target, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) {
|
||||
stream.Write(bits, 0, bits.Length);
|
||||
}
|
||||
|
||||
uriBuilder.Path = uriBuilder.Path.TrimEnd('/') + "/Files/" + name.TrimStart('/');
|
||||
return new XRpcStruct().Set("url", uriBuilder.Uri.AbsoluteUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -78,6 +78,7 @@
|
||||
<Compile Include="Models\MediaFolder.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\MediaService.cs" />
|
||||
<Compile Include="Services\XmlRpcHandler.cs" />
|
||||
<Compile Include="ViewModels\MediaItemEditViewModel.cs" />
|
||||
<Compile Include="ViewModels\MediaFolderCreateViewModel.cs" />
|
||||
<Compile Include="ViewModels\MediaFolderEditPropertiesViewModel.cs" />
|
||||
@@ -103,6 +104,10 @@
|
||||
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
||||
<Name>Orchard</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.XmlRpc\Orchard.XmlRpc.csproj">
|
||||
<Project>{0DC6B598-6D03-4923-A6C2-274D09854117}</Project>
|
||||
<Name>Orchard.XmlRpc</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
|
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.Security;
|
||||
using Orchard.XmlRpc;
|
||||
using Orchard.XmlRpc.Models;
|
||||
|
||||
namespace Orchard.Media.Services {
|
||||
public class XmlRpcHandler : IXmlRpcHandler {
|
||||
private readonly IMembershipService _membershipService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly HttpContextBase _httpContext;
|
||||
|
||||
public XmlRpcHandler(
|
||||
IMembershipService membershipService,
|
||||
IAuthorizationService authorizationService,
|
||||
HttpContextBase httpContext) {
|
||||
_membershipService = membershipService;
|
||||
_authorizationService = authorizationService;
|
||||
_httpContext = httpContext;
|
||||
}
|
||||
|
||||
public void Process(XmlRpcContext context) {
|
||||
var uriBuilder = new UriBuilder(context.HttpContext.Request.Url) {
|
||||
Path = context.HttpContext.Request.ApplicationPath,
|
||||
Query = string.Empty
|
||||
};
|
||||
|
||||
|
||||
if (context.Request.MethodName == "metaWeblog.newMediaObject") {
|
||||
var result = MetaWeblogNewMediaObject(
|
||||
uriBuilder,
|
||||
Convert.ToString(context.Request.Params[0].Value),
|
||||
Convert.ToString(context.Request.Params[1].Value),
|
||||
Convert.ToString(context.Request.Params[2].Value),
|
||||
(XRpcStruct)context.Request.Params[3].Value);
|
||||
context.Response = new XRpcMethodResponse().Add(result);
|
||||
}
|
||||
}
|
||||
|
||||
private XRpcStruct MetaWeblogNewMediaObject(
|
||||
UriBuilder uriBuilder,
|
||||
string blogId,
|
||||
string userName,
|
||||
string password,
|
||||
XRpcStruct file) {
|
||||
|
||||
var user = _membershipService.ValidateUser(userName, password);
|
||||
if (!_authorizationService.CheckAccess(user, Permissions.UploadMedia)) {
|
||||
//TEMP: return appropriate access-denied response for user
|
||||
throw new ApplicationException("Access denied");
|
||||
}
|
||||
|
||||
|
||||
var name = file.Optional<string>("name");
|
||||
var bits = file.Optional<byte[]>("bits");
|
||||
|
||||
var target = HttpContext.Current.Server.MapPath("~/Files/" + name);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(target));
|
||||
using (var stream = new FileStream(target, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) {
|
||||
stream.Write(bits, 0, bits.Length);
|
||||
}
|
||||
|
||||
uriBuilder.Path = uriBuilder.Path.TrimEnd('/') + "/Files/" + name.TrimStart('/');
|
||||
return new XRpcStruct().Set("url", uriBuilder.Uri.AbsoluteUri);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -58,7 +58,7 @@
|
||||
ASP.NET to identify an incoming user.
|
||||
-->
|
||||
<authentication mode="Forms">
|
||||
<forms loginUrl="~/Account/LogOn" timeout="2880" />
|
||||
<forms loginUrl="~/Account/LogOn" timeout="2880" />
|
||||
</authentication>
|
||||
|
||||
<membership defaultProvider="OrchardMembershipProvider">
|
||||
|
@@ -13,5 +13,20 @@
|
||||
public override string ToString() {
|
||||
return _localized;
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
var hashCode = 0;
|
||||
if (_localized != null)
|
||||
hashCode ^= _localized.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
if (obj == null || obj.GetType() != GetType())
|
||||
return false;
|
||||
|
||||
var that = (LocalizedString) obj;
|
||||
return string.Equals(_localized, that._localized);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user