mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-19 01:57:55 +08:00
refactoring model editors, permissions, and adding rough localization
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4040294
This commit is contained in:
@@ -90,6 +90,9 @@
|
||||
<Compile Include="Roles\Services\RoleServiceTests.cs" />
|
||||
<Compile Include="Users\Controllers\AdminControllerTests.cs" />
|
||||
<Compile Include="Users\Services\MembershipServiceTests.cs" />
|
||||
<Compile Include="XmlRpc\Controllers\HomeControllerTests.cs" />
|
||||
<Compile Include="XmlRpc\Services\XmlRpcReaderTests.cs" />
|
||||
<Compile Include="XmlRpc\Services\XmlRpcWriterTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Orchard.Tests\Orchard.Tests.csproj">
|
||||
@@ -104,6 +107,10 @@
|
||||
<Project>{79AED36E-ABD0-4747-93D3-8722B042454B}</Project>
|
||||
<Name>Orchard.Users</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Web\Packages\Orchard.XmlRpc\Orchard.XmlRpc.csproj">
|
||||
<Project>{0DC6B598-6D03-4923-A6C2-274D09854117}</Project>
|
||||
<Name>Orchard.XmlRpc</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard\Orchard.csproj">
|
||||
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
||||
<Name>Orchard</Name>
|
||||
|
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Autofac.Builder;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Roles.Models;
|
||||
using Orchard.Roles.Records;
|
||||
using Orchard.Roles.Services;
|
||||
|
||||
namespace Orchard.Tests.Packages.Roles.Services {
|
||||
|
@@ -0,0 +1,49 @@
|
||||
using System.Xml.Linq;
|
||||
using Autofac.Builder;
|
||||
using Autofac.Modules;
|
||||
using NUnit.Framework;
|
||||
using Orchard.XmlRpc;
|
||||
using Orchard.XmlRpc.Controllers;
|
||||
using Orchard.XmlRpc.Models;
|
||||
using Orchard.XmlRpc.Services;
|
||||
|
||||
namespace Orchard.Tests.Packages.XmlRpc.Controllers {
|
||||
[TestFixture]
|
||||
public class HomeControllerTests {
|
||||
[Test]
|
||||
public void RequestShouldBeDispatchedToAllHandlers() {
|
||||
var thing1 = new StubHandler();
|
||||
var thing2 = new StubHandler();
|
||||
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterModule(new ImplicitCollectionSupportModule()); ;
|
||||
builder.Register<HomeController>();
|
||||
builder.Register<XmlRpcReader>().As<IMapper<XElement, XRpcMethodCall>>();
|
||||
builder.Register<XmlRpcWriter>().As<IMapper<XRpcMethodResponse, XElement>>();
|
||||
builder.Register(thing1).As<IXmlRpcHandler>();
|
||||
builder.Register(thing2).As<IXmlRpcHandler>();
|
||||
|
||||
var container = builder.Build();
|
||||
|
||||
var controller = container.Resolve<HomeController>();
|
||||
|
||||
Assert.That(thing1.ProcessCalls, Is.EqualTo(0));
|
||||
Assert.That(thing2.ProcessCalls, Is.EqualTo(0));
|
||||
|
||||
var result = controller.ServiceEndpoint(new XRpcMethodCall());
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(thing1.ProcessCalls, Is.EqualTo(1));
|
||||
Assert.That(thing2.ProcessCalls, Is.EqualTo(1));
|
||||
|
||||
}
|
||||
|
||||
public class StubHandler : IXmlRpcHandler {
|
||||
public void Process(XmlRpcContext context) {
|
||||
ProcessCalls++;
|
||||
context.Response = new XRpcMethodResponse();
|
||||
}
|
||||
|
||||
public int ProcessCalls { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
111
src/Orchard.Tests.Packages/XmlRpc/Services/XmlRpcReaderTests.cs
Normal file
111
src/Orchard.Tests.Packages/XmlRpc/Services/XmlRpcReaderTests.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
using NUnit.Framework;
|
||||
using Orchard.XmlRpc.Models;
|
||||
using Orchard.XmlRpc.Services;
|
||||
|
||||
namespace Orchard.Tests.Packages.XmlRpc.Services {
|
||||
[TestFixture]
|
||||
public class XmlRpcReaderTests {
|
||||
private IMapper<XElement, XRpcMethodCall> _methodCallMapper;
|
||||
private IMapper<XElement, XRpcStruct> _structMapper;
|
||||
private IMapper<XElement, XRpcArray> _arrayMapper;
|
||||
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
var mapper = new XmlRpcReader();
|
||||
_methodCallMapper = mapper;
|
||||
_structMapper = mapper;
|
||||
_arrayMapper = mapper;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MethodCallShouldMapName() {
|
||||
var source = XElement.Parse(@"
|
||||
<methodCall>
|
||||
<methodName>hello world</methodName>
|
||||
</methodCall>");
|
||||
|
||||
var methodCall = _methodCallMapper.Map(source);
|
||||
Assert.That(methodCall, Is.Not.Null);
|
||||
Assert.That(methodCall.MethodName, Is.EqualTo("hello world"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CallWithParametersShouldMapValuesAccordingToSpec() {
|
||||
var source = XElement.Parse(@"
|
||||
<methodCall>
|
||||
<methodName>hello world</methodName>
|
||||
<params>
|
||||
<param><value><i4>-12</i4></value></param>
|
||||
<param><value><int>42</int></value></param>
|
||||
<param><value><boolean>1</boolean></value></param>
|
||||
<param><value><boolean>0</boolean></value></param>
|
||||
<param><value><string>hello world</string></value></param>
|
||||
<param><value><double>-12.214</double></value></param>
|
||||
<param><value><dateTime.iso8601>1998-07-17T14:08:55</dateTime.iso8601></value></param>
|
||||
<param><value><base64>eW91IGNhbid0IHJlYWQgdGhpcyE=</base64></value></param>
|
||||
</params>
|
||||
</methodCall>");
|
||||
|
||||
var methodCall = _methodCallMapper.Map(source);
|
||||
Assert.That(methodCall, Is.Not.Null);
|
||||
Assert.That(methodCall.Params, Has.Count.EqualTo(8));
|
||||
Assert.That(methodCall.Params[0].Value, Is.EqualTo(-12));
|
||||
Assert.That(methodCall.Params[1].Value, Is.EqualTo(42));
|
||||
Assert.That(methodCall.Params[2].Value, Is.EqualTo(true));
|
||||
Assert.That(methodCall.Params[3].Value, Is.EqualTo(false));
|
||||
Assert.That(methodCall.Params[4].Value, Is.EqualTo("hello world"));
|
||||
Assert.That(methodCall.Params[5].Value, Is.EqualTo(-12.214));
|
||||
Assert.That(methodCall.Params[6].Value, Is.EqualTo(new DateTime(1998,7,17,14,8,55)));
|
||||
Assert.That(methodCall.Params[7].Value, Is.EqualTo(Convert.FromBase64String("eW91IGNhbid0IHJlYWQgdGhpcyE=")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StructShouldMapAllMembersByNameWithCorrectType() {
|
||||
var source = XElement.Parse(@"
|
||||
<struct>
|
||||
<member><name>one</name><value><i4>-12</i4></value></member>
|
||||
<member><name>two</name><value><int>42</int></value></member>
|
||||
<member><name>three</name><value><boolean>1</boolean></value></member>
|
||||
<member><name>four</name><value><boolean>0</boolean></value></member>
|
||||
<member><name>five</name><value><string>hello world</string></value></member>
|
||||
<member><name>six</name><value><double>-12.214</double></value></member>
|
||||
<member><name>seven</name><value><dateTime.iso8601>1998-07-17T14:08:55</dateTime.iso8601></value></member>
|
||||
<member><name>eight</name><value><base64>eW91IGNhbid0IHJlYWQgdGhpcyE=</base64></value></member>
|
||||
</struct>");
|
||||
|
||||
var xmlStruct = _structMapper.Map(source);
|
||||
Assert.That(xmlStruct["one"], Is.EqualTo(-12));
|
||||
Assert.That(xmlStruct["two"], Is.EqualTo(42));
|
||||
Assert.That(xmlStruct["three"], Is.EqualTo(true));
|
||||
Assert.That(xmlStruct["four"], Is.EqualTo(false));
|
||||
Assert.That(xmlStruct["five"], Is.EqualTo("hello world"));
|
||||
Assert.That(xmlStruct["six"], Is.EqualTo(-12.214));
|
||||
Assert.That(xmlStruct["seven"], Is.EqualTo(new DateTime(1998, 7, 17, 14, 8, 55)));
|
||||
Assert.That(xmlStruct["eight"], Is.EqualTo(Convert.FromBase64String("eW91IGNhbid0IHJlYWQgdGhpcyE=")));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ArrayShouldBringDataItemsWithCorrectType() {
|
||||
var source = XElement.Parse(@"
|
||||
<array>
|
||||
<data>
|
||||
<value><i4>12</i4></value>
|
||||
<value><string>Egypt</string></value>
|
||||
<value><boolean>0</boolean></value>
|
||||
<value><i4>-31</i4></value>
|
||||
</data>
|
||||
</array>
|
||||
");
|
||||
|
||||
var xmlArray = _arrayMapper.Map(source);
|
||||
Assert.That(xmlArray.Data, Has.Count.EqualTo(4));
|
||||
Assert.That(xmlArray[0], Is.EqualTo(12));
|
||||
Assert.That(xmlArray[1], Is.EqualTo("Egypt"));
|
||||
Assert.That(xmlArray[2], Is.EqualTo(false));
|
||||
Assert.That(xmlArray[3], Is.EqualTo(-31));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
using System.Xml.Linq;
|
||||
using NUnit.Framework;
|
||||
using Orchard.XmlRpc.Models;
|
||||
using Orchard.XmlRpc.Services;
|
||||
|
||||
namespace Orchard.Tests.Packages.XmlRpc.Services {
|
||||
[TestFixture]
|
||||
public class XmlRpcWriterTests {
|
||||
[Test]
|
||||
public void MethodResponseWriterShouldSendParametersWithValues() {
|
||||
var mapper = new XmlRpcWriter();
|
||||
IMapper<XRpcMethodResponse, XElement> resposeMapper = mapper;
|
||||
|
||||
var response = new XRpcMethodResponse();
|
||||
response.Params.Add(new XRpcData<int> { Value = 42 });
|
||||
var element = resposeMapper.Map(response);
|
||||
|
||||
Assert.That(NoSpace(element.ToString()), Is.EqualTo("<methodResponse><params><param><value><int>42</int></value></param></params></methodResponse>"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ArrayAndStructShouldWorkAsExpected() {
|
||||
var mapper = new XmlRpcWriter();
|
||||
IMapper<XRpcArray, XElement> arrayMapper = mapper;
|
||||
|
||||
var arr = new XRpcArray();
|
||||
var structParam = XRpcData.For(new XRpcStruct());
|
||||
|
||||
arr.Data.Add(structParam);
|
||||
arr.Data.Add(XRpcData.For(19));
|
||||
|
||||
structParam.Value.Members.Add("Hello", XRpcData.For("world"));
|
||||
|
||||
var element = arrayMapper.Map(arr);
|
||||
|
||||
Assert.That(NoSpace(element.ToString()), Is.EqualTo(NoSpace(@"
|
||||
<array><data>
|
||||
<value><struct>
|
||||
<member><name>Hello</name><value><string>world</string></value></member>
|
||||
</struct></value>
|
||||
<value><int>19</int></value>
|
||||
</data></array>
|
||||
")));
|
||||
}
|
||||
|
||||
private static string NoSpace(string text) {
|
||||
return text.Replace(" ", "").Replace("\r", "").Replace("\n", "").Replace("\t", "");
|
||||
}
|
||||
}
|
||||
}
|
@@ -156,8 +156,8 @@
|
||||
<Content Include="Content\Images\title_background.gif" />
|
||||
<Content Include="Content\Site2.css" />
|
||||
<Content Include="Content\Site3.css" />
|
||||
<Content Include="Views\Admin\EditorTemplates\UserRolesViewModel.ascx" />
|
||||
<Content Include="Views\Admin\Messages.ascx" />
|
||||
<Content Include="Views\Admin\UserRoles.ascx" />
|
||||
<Content Include="Views\Shared\ExtraUserControl.ascx" />
|
||||
<Content Include="Views\Shared\Footer.ascx" />
|
||||
<Content Include="Views\Shared\Header.ascx" />
|
||||
|
@@ -9,6 +9,7 @@ using Orchard.CmsPages.Services;
|
||||
using Orchard.CmsPages.Services.Templates;
|
||||
using Orchard.CmsPages.ViewModels;
|
||||
using Orchard.Data;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Security;
|
||||
@@ -43,6 +44,7 @@ namespace Orchard.CmsPages.Controllers {
|
||||
public IUser CurrentUser { get; set; }
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
protected override void OnActionExecuting(ActionExecutingContext filterContext) {
|
||||
//TEMP: this is a hack until a cron system is in place
|
||||
@@ -95,10 +97,10 @@ namespace Orchard.CmsPages.Controllers {
|
||||
|
||||
case PageIndexBulkAction.PublishNow:
|
||||
//TODO: Transaction
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, CmsPagesPermissionsProvider.PublishPagesPermission)) {
|
||||
_notifier.Error("Couldn't publish page, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
CmsPagesPermissionsProvider.PublishPagesPermission.Name);
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.PublishPagesPermission)) {
|
||||
_notifier.Error(T("Couldn't publish page, user {0} doesn't have {1}",
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty),
|
||||
Permissions.PublishPagesPermission.Name));
|
||||
//return new HttpUnauthorizedResult();
|
||||
break;
|
||||
}
|
||||
@@ -111,10 +113,10 @@ namespace Orchard.CmsPages.Controllers {
|
||||
break;
|
||||
|
||||
case PageIndexBulkAction.PublishLater:
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, CmsPagesPermissionsProvider.SchedulePagesPermission)) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.SchedulePagesPermission)) {
|
||||
_notifier.Error("Couldn't publish page, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
CmsPagesPermissionsProvider.SchedulePagesPermission.Name);
|
||||
Permissions.SchedulePagesPermission.Name);
|
||||
//return new HttpUnauthorizedResult();
|
||||
break;
|
||||
}
|
||||
@@ -133,10 +135,10 @@ namespace Orchard.CmsPages.Controllers {
|
||||
break;
|
||||
|
||||
case PageIndexBulkAction.Unpublish:
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, CmsPagesPermissionsProvider.UnpublishPagesPermission)) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.UnpublishPagesPermission)) {
|
||||
_notifier.Error("Couldn't unpublish page, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
CmsPagesPermissionsProvider.UnpublishPagesPermission.Name);
|
||||
Permissions.UnpublishPagesPermission.Name);
|
||||
//return new HttpUnauthorizedResult();
|
||||
break;
|
||||
}
|
||||
@@ -147,10 +149,10 @@ namespace Orchard.CmsPages.Controllers {
|
||||
break;
|
||||
|
||||
case PageIndexBulkAction.Delete:
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, CmsPagesPermissionsProvider.DeletePagesPermission)) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.DeletePagesPermission)) {
|
||||
_notifier.Error("Couldn't delete page, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
CmsPagesPermissionsProvider.DeletePagesPermission.Name);
|
||||
Permissions.DeletePagesPermission.Name);
|
||||
//return new HttpUnauthorizedResult();
|
||||
break;
|
||||
}
|
||||
@@ -212,10 +214,10 @@ namespace Orchard.CmsPages.Controllers {
|
||||
var viewModel = new PageCreateViewModel { Templates = _templateProvider.List() };
|
||||
try {
|
||||
UpdateModel(viewModel, input.ToValueProvider());
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, CmsPagesPermissionsProvider.CreatePagesPermission)) {
|
||||
_notifier.Error("Couldn't create page, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
CmsPagesPermissionsProvider.CreatePagesPermission.Name);
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.CreatePagesPermission)) {
|
||||
_notifier.Error(T("Couldn't create page, user {0} doesn't have {1}",
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty),
|
||||
Permissions.CreatePagesPermission.Name));
|
||||
//return new HttpUnauthorizedResult();
|
||||
return View(viewModel);
|
||||
}
|
||||
@@ -268,29 +270,29 @@ namespace Orchard.CmsPages.Controllers {
|
||||
RemoveUnusedContentItems(model.Revision, model.Template);
|
||||
|
||||
_pageScheduler.ClearTasks(model.Revision.Page);
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, CmsPagesPermissionsProvider.ModifyPagesPermission)) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.ModifyPagesPermission)) {
|
||||
_notifier.Error("Couldn't edit page, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
CmsPagesPermissionsProvider.ModifyPagesPermission.Name);
|
||||
Permissions.ModifyPagesPermission.Name);
|
||||
//return new HttpUnauthorizedResult();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
switch (model.Command) {
|
||||
case PageEditCommand.PublishNow:
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, CmsPagesPermissionsProvider.PublishPagesPermission)) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.PublishPagesPermission)) {
|
||||
_notifier.Error("Couldn't publish page, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
CmsPagesPermissionsProvider.PublishPagesPermission.Name);
|
||||
Permissions.PublishPagesPermission.Name);
|
||||
//return new HttpUnauthorizedResult();
|
||||
break;
|
||||
}
|
||||
_pageManager.Publish(model.Revision, new PublishOptions());
|
||||
break;
|
||||
case PageEditCommand.PublishLater:
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, CmsPagesPermissionsProvider.SchedulePagesPermission)) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.SchedulePagesPermission)) {
|
||||
_notifier.Error("Couldn't publish page, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
CmsPagesPermissionsProvider.SchedulePagesPermission.Name);
|
||||
Permissions.SchedulePagesPermission.Name);
|
||||
//return new HttpUnauthorizedResult();
|
||||
break;
|
||||
}
|
||||
@@ -319,10 +321,10 @@ namespace Orchard.CmsPages.Controllers {
|
||||
[FormValueRequired("submit.DeleteDraft")]
|
||||
public ActionResult DeleteDraft(int id) {
|
||||
#warning UNIT TEST!!!!
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, CmsPagesPermissionsProvider.DeleteDraftPagesPermission)) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.DeleteDraftPagesPermission)) {
|
||||
_notifier.Error("Couldn't delete draft page, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
CmsPagesPermissionsProvider.DeleteDraftPagesPermission.Name);
|
||||
Permissions.DeleteDraftPagesPermission.Name);
|
||||
//return new HttpUnauthorizedResult();
|
||||
return RedirectToAction("Edit", new { id });
|
||||
}
|
||||
|
36
src/Orchard.Web/Packages/Orchard.CmsPages/Permissions.cs
Normal file
36
src/Orchard.Web/Packages/Orchard.CmsPages/Permissions.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
namespace Orchard.CmsPages {
|
||||
public class Permissions : IPermissionProvider {
|
||||
public static readonly Permission ViewPagesPermission = new Permission { Description = "Viewing CMS Pages", Name = "ViewPagesPermission" };
|
||||
public static readonly Permission CreatePagesPermission = new Permission { Description = "Creating CMS Pages", Name = "CreatePagesPermission" };
|
||||
public static readonly Permission CreateDraftPagesPermission = new Permission { Description = "Creating CMS Page Drafts", Name = "CreateDraftPagesPermission" };
|
||||
public static readonly Permission DeleteDraftPagesPermission = new Permission { Description = "Deleting CMS Page Drafts", Name = "DeleteDraftPagesPermission" };
|
||||
public static readonly Permission ModifyPagesPermission = new Permission { Description = "Modifying CMS Pages", Name = "ModifyPagesPermission" };
|
||||
public static readonly Permission DeletePagesPermission = new Permission { Description = "Deleting CMS Pages", Name = "DeletePagesPermission" };
|
||||
public static readonly Permission PublishPagesPermission = new Permission { Description = "Publishing CMS Pages", Name = "PublishPagesPermission" };
|
||||
public static readonly Permission UnpublishPagesPermission = new Permission { Description = "Unpublishing CMS Pages", Name = "UnpublishPagesPermission" };
|
||||
public static readonly Permission SchedulePagesPermission = new Permission { Description = "Scheduling CMS Pages", Name = "SchedulePagesPermission" };
|
||||
|
||||
public string PackageName {
|
||||
get {
|
||||
return "CmsPages";
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Permission> GetPermissions() {
|
||||
return new List<Permission> {
|
||||
ViewPagesPermission,
|
||||
CreatePagesPermission,
|
||||
CreateDraftPagesPermission,
|
||||
DeleteDraftPagesPermission,
|
||||
ModifyPagesPermission,
|
||||
DeletePagesPermission,
|
||||
PublishPagesPermission,
|
||||
UnpublishPagesPermission,
|
||||
SchedulePagesPermission
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Orchard.CmsPages.ViewModels.PageEditViewModel>" %>
|
||||
<%@ Page Language="C#" Inherits="Orchard.Mvc.ViewPage<Orchard.CmsPages.ViewModels.PageEditViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.CmsPages.Models"%>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
|
||||
@@ -21,26 +21,21 @@
|
||||
<body>
|
||||
<% Html.Include("Header"); %>
|
||||
<div class="yui-g">
|
||||
<h2>
|
||||
Edit Page</h2>
|
||||
<p class="bottomSpacer">
|
||||
Possible text about setting up a page goes here. Lorem ipsum dolor sit amet, consectetur
|
||||
adipiscing elit. Nulla erat turpis, blandit eget feugiat nec, tempus vel quam. Mauris
|
||||
et neque eget justo suscipit blandit.</p>
|
||||
<h2><%=T("Edit Page")%></h2>
|
||||
<p class="bottomSpacer"><%=T("about setting up a page")%></p>
|
||||
<%=Html.ValidationSummary() %>
|
||||
</div>
|
||||
<div class="yui-gc">
|
||||
<%using (Html.BeginForm()) {%>
|
||||
<div class="yui-u first">
|
||||
<h3>
|
||||
Page Content</h3>
|
||||
<h3><%= T("Page Content") %></h3>
|
||||
<ol>
|
||||
<%=Html.EditorFor(m => m.Revision.Title, "inputTextLarge")%>
|
||||
<%=Html.EditorFor(m => m.Revision.Slug, "inputTextPermalink")%>
|
||||
|
||||
<%foreach (ContentItem content in Model.Revision.Contents) {%>
|
||||
<label for="<%="Revision.Contents[" + content.ZoneName + "].Content" %>">
|
||||
Zone Name: <%= content.ZoneName %></label>
|
||||
<%=T("Zone Name")%>: <%= content.ZoneName %></label>
|
||||
<%if (Model.Template != null && Model.Template.Zones.Contains(content.ZoneName) == false) {%>
|
||||
<div class="warning">These contents are assigned to a zone that does not exist in the current template. Please delete it or copy it to another zone.</div>
|
||||
<%}%>
|
||||
@@ -59,7 +54,7 @@
|
||||
</ol>
|
||||
</div>
|
||||
<div class="yui-u sideBar">
|
||||
<h3>Publish Settings</h3>
|
||||
<h3><%=T("Publish Settings") %></h3>
|
||||
<fieldset>
|
||||
<ol class="formList">
|
||||
<li><label for="Command_PublishNow"><%=Html.RadioButton("Command", "PublishNow", new { id = "Command_PublishNow" })%> Publish Now</label></li>
|
||||
|
@@ -58,10 +58,10 @@ namespace Orchard.Media.Controllers {
|
||||
var viewModel = new MediaFolderCreateViewModel();
|
||||
try {
|
||||
UpdateModel(viewModel, input.ToValueProvider());
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, MediaPermissionsProvider.CreateMediaFolderPermission)) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.CreateMediaFolderPermission)) {
|
||||
_notifier.Error("Couldn't create media folder, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
MediaPermissionsProvider.CreateMediaFolderPermission.Name);
|
||||
Permissions.CreateMediaFolderPermission.Name);
|
||||
//return new HttpUnauthorizedResult();
|
||||
return View(viewModel);
|
||||
}
|
||||
@@ -88,10 +88,10 @@ namespace Orchard.Media.Controllers {
|
||||
if (key.StartsWith("Checkbox.File.") && input[key] == "true") {
|
||||
string fileName = key.Substring("Checkbox.File.".Length);
|
||||
string folderName = input[fileName];
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, MediaPermissionsProvider.DeleteMediaPermission)) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.DeleteMediaPermission)) {
|
||||
_notifier.Error("Couldn't delete media file, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
MediaPermissionsProvider.DeleteMediaPermission.Name);
|
||||
Permissions.DeleteMediaPermission.Name);
|
||||
//return new HttpUnauthorizedResult();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
@@ -100,10 +100,10 @@ namespace Orchard.Media.Controllers {
|
||||
else if (key.StartsWith("Checkbox.Folder.") && input[key] == "true") {
|
||||
string folderName = key.Substring("Checkbox.Folder.".Length);
|
||||
string folderPath = input[folderName];
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, MediaPermissionsProvider.DeleteMediaFolderPermission)) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.DeleteMediaFolderPermission)) {
|
||||
_notifier.Error("Couldn't delete media folder, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
MediaPermissionsProvider.DeleteMediaFolderPermission.Name);
|
||||
Permissions.DeleteMediaFolderPermission.Name);
|
||||
//return new HttpUnauthorizedResult();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
@@ -131,10 +131,10 @@ namespace Orchard.Media.Controllers {
|
||||
//TODO: There may be better ways to do this.
|
||||
// Delete
|
||||
if (!String.IsNullOrEmpty(HttpContext.Request.Form["submit.Delete"])) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, MediaPermissionsProvider.DeleteMediaFolderPermission)) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.DeleteMediaFolderPermission)) {
|
||||
_notifier.Error("Couldn't delete media folder, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
MediaPermissionsProvider.DeleteMediaFolderPermission.Name);
|
||||
Permissions.DeleteMediaFolderPermission.Name);
|
||||
//return new HttpUnauthorizedResult();
|
||||
return View(viewModel);
|
||||
}
|
||||
@@ -142,10 +142,10 @@ namespace Orchard.Media.Controllers {
|
||||
}
|
||||
// Save
|
||||
else {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, MediaPermissionsProvider.RenameMediaFolderPermission)) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.RenameMediaFolderPermission)) {
|
||||
_notifier.Error("Couldn't rename media folder, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
MediaPermissionsProvider.RenameMediaFolderPermission.Name);
|
||||
Permissions.RenameMediaFolderPermission.Name);
|
||||
//return new HttpUnauthorizedResult();
|
||||
return View(viewModel);
|
||||
}
|
||||
@@ -171,10 +171,10 @@ namespace Orchard.Media.Controllers {
|
||||
try {
|
||||
UpdateModel(viewModel, input.ToValueProvider());
|
||||
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, MediaPermissionsProvider.UploadMediaPermission)) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.UploadMediaPermission)) {
|
||||
_notifier.Error("Couldn't upload media file, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
MediaPermissionsProvider.UploadMediaPermission.Name);
|
||||
Permissions.UploadMediaPermission.Name);
|
||||
//return new HttpUnauthorizedResult();
|
||||
return View(viewModel);
|
||||
}
|
||||
@@ -208,20 +208,20 @@ namespace Orchard.Media.Controllers {
|
||||
var viewModel = new MediaItemEditViewModel();
|
||||
try {
|
||||
UpdateModel(viewModel, input.ToValueProvider());
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, MediaPermissionsProvider.ModifyMediaPermission)) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.ModifyMediaPermission)) {
|
||||
_notifier.Error("Couldn't modify media file, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
MediaPermissionsProvider.ModifyMediaPermission.Name);
|
||||
Permissions.ModifyMediaPermission.Name);
|
||||
//return new HttpUnauthorizedResult();
|
||||
return View(viewModel);
|
||||
}
|
||||
//TODO: There may be better ways to do this.
|
||||
// Delete
|
||||
if (!String.IsNullOrEmpty(HttpContext.Request.Form["submit.Delete"])) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, MediaPermissionsProvider.DeleteMediaPermission)) {
|
||||
if (!_authorizationService.CheckAccess(CurrentUser, Permissions.DeleteMediaPermission)) {
|
||||
_notifier.Error("Couldn't delete media file, user " +
|
||||
(CurrentUser != null ? CurrentUser.UserName : String.Empty) + " doesn't have " +
|
||||
MediaPermissionsProvider.DeleteMediaPermission.Name);
|
||||
Permissions.DeleteMediaPermission.Name);
|
||||
//return new HttpUnauthorizedResult();
|
||||
return View(viewModel);
|
||||
}
|
||||
|
@@ -72,7 +72,7 @@
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Helpers\MediaHelpers.cs" />
|
||||
<Compile Include="MediaPermissions.cs" />
|
||||
<Compile Include="Permissions.cs" />
|
||||
<Compile Include="Models\FolderNavigation.cs" />
|
||||
<Compile Include="Models\MediaFile.cs" />
|
||||
<Compile Include="Models\MediaFolder.cs" />
|
||||
|
@@ -2,7 +2,7 @@
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
namespace Orchard.Media {
|
||||
public class MediaPermissionsProvider : IPermissionProvider {
|
||||
public class Permissions : IPermissionProvider {
|
||||
public static readonly Permission UploadMediaPermission = new Permission { Description = "Uploading Media Files", Name = "UploadMediaPermission" };
|
||||
public static readonly Permission ModifyMediaPermission = new Permission { Description = "Modifying Media Files", Name = "ModifyMediaPermission" };
|
||||
public static readonly Permission DeleteMediaPermission = new Permission { Description = "Deleting Media Files", Name = "DeleteMediaPermission" };
|
||||
@@ -10,8 +10,6 @@ namespace Orchard.Media {
|
||||
public static readonly Permission DeleteMediaFolderPermission = new Permission { Description = "Deleting Media Folders", Name = "DeleteMediaFolderPermission" };
|
||||
public static readonly Permission RenameMediaFolderPermission = new Permission { Description = "Renaming Media Folders", Name = "RenameMediaFolderPermission" };
|
||||
|
||||
#region Implementation of IPermissionProvider
|
||||
|
||||
public string PackageName {
|
||||
get {
|
||||
return "Media";
|
||||
@@ -28,7 +26,5 @@ namespace Orchard.Media {
|
||||
RenameMediaFolderPermission
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Roles.Models;
|
||||
using Orchard.Roles.Records;
|
||||
using Orchard.Roles.Services;
|
||||
using Orchard.Roles.ViewModels;
|
||||
using Orchard.UI.Notify;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
using System.Linq;
|
||||
using Orchard.Data;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.Roles.Models.NoRecord;
|
||||
using Orchard.Roles.Records;
|
||||
using Orchard.Roles.Services;
|
||||
using Orchard.Roles.ViewModels;
|
||||
using Orchard.Security;
|
||||
@@ -10,12 +10,12 @@ using Orchard.UI.Models;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Roles.Models {
|
||||
public class UserRolesModelDriver : ModelDriver {
|
||||
public class UserRolesDriver : ModelDriver {
|
||||
private readonly IRepository<UserRolesRecord> _userRolesRepository;
|
||||
private readonly IRoleService _roleService;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public UserRolesModelDriver(IRepository<UserRolesRecord> userRolesRepository, IRoleService roleService, INotifier notifier) {
|
||||
public UserRolesDriver(IRepository<UserRolesRecord> userRolesRepository, IRoleService roleService, INotifier notifier) {
|
||||
_userRolesRepository = userRolesRepository;
|
||||
_roleService = roleService;
|
||||
_notifier = notifier;
|
||||
@@ -58,7 +58,7 @@ namespace Orchard.Roles.Models {
|
||||
Roles = roles.ToList(),
|
||||
};
|
||||
|
||||
context.Editors.Add(ModelEditor.For("UserRoles", viewModel));
|
||||
context.Editors.Add(ModelTemplate.For(viewModel, "UserRoles"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace Orchard.Roles.Models {
|
||||
var userRoles = context.Instance.As<UserRolesModel>();
|
||||
if (userRoles != null) {
|
||||
var viewModel = new UserRolesViewModel();
|
||||
if (context.Updater.TryUpdateModel(viewModel, null, null, null)) {
|
||||
if (context.Updater.TryUpdateModel(viewModel, "UserRoles", null, null)) {
|
||||
|
||||
var currentUserRoleRecords = _userRolesRepository.Fetch(x => x.UserId == userRoles.Id);
|
||||
var currentRoleRecords = currentUserRoleRecords.Select(x => x.Role);
|
||||
@@ -83,7 +83,7 @@ namespace Orchard.Roles.Models {
|
||||
}
|
||||
|
||||
}
|
||||
context.Editors.Add(ModelEditor.For("UserRoles", viewModel));
|
||||
context.Editors.Add(ModelTemplate.For(viewModel, "UserRoles"));
|
||||
}
|
||||
}
|
||||
}
|
@@ -63,12 +63,12 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Models\PermissionRecord.cs" />
|
||||
<Compile Include="Models\RoleRecord.cs" />
|
||||
<Compile Include="Records\PermissionRecord.cs" />
|
||||
<Compile Include="Records\RoleRecord.cs" />
|
||||
<Compile Include="Models\UserRolesModel.cs" />
|
||||
<Compile Include="Models\UserRolesModelDriver.cs" />
|
||||
<Compile Include="Models\RolesPermissions.cs" />
|
||||
<Compile Include="Models\UserRolesRecord.cs" />
|
||||
<Compile Include="Models\UserRolesDriver.cs" />
|
||||
<Compile Include="Records\RolesPermissions.cs" />
|
||||
<Compile Include="Records\UserRolesRecord.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\RolesBasedAuthorizationService.cs" />
|
||||
<Compile Include="Services\RoleService.cs" />
|
||||
@@ -82,6 +82,7 @@
|
||||
<Content Include="Views\Admin\Create.aspx" />
|
||||
<Content Include="Views\Admin\Edit.aspx" />
|
||||
<Content Include="Views\Admin\Index.aspx" />
|
||||
<Content Include="Views\Shared\EditorTemplates\broken_UserRolesViewModel.ascx" />
|
||||
<Content Include="Web.config" />
|
||||
<Content Include="Content\Site.css" />
|
||||
<Content Include="Views\Web.config" />
|
||||
|
@@ -1,4 +1,4 @@
|
||||
namespace Orchard.Roles.Models {
|
||||
namespace Orchard.Roles.Records {
|
||||
public class PermissionRecord {
|
||||
public virtual int Id { get; set; }
|
||||
public virtual string Name { get; set; }
|
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Data.Conventions;
|
||||
|
||||
namespace Orchard.Roles.Models {
|
||||
namespace Orchard.Roles.Records {
|
||||
public class RoleRecord {
|
||||
public RoleRecord() {
|
||||
RolesPermissions = new List<RolesPermissions>();
|
@@ -1,4 +1,4 @@
|
||||
namespace Orchard.Roles.Models {
|
||||
namespace Orchard.Roles.Records {
|
||||
public class RolesPermissions {
|
||||
public virtual int Id { get; set; }
|
||||
public virtual RoleRecord Role { get; set; }
|
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard.Roles.Models {
|
||||
namespace Orchard.Roles.Records {
|
||||
public class UserRolesRecord {
|
||||
public virtual int Id { get; set; }
|
||||
public virtual int UserId { get; set; }
|
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Data;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Roles.Models;
|
||||
using Orchard.Roles.Records;
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
namespace Orchard.Roles.Services {
|
||||
|
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Roles.Models;
|
||||
using Orchard.Roles.Models.NoRecord;
|
||||
using Orchard.Roles.Records;
|
||||
using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Roles.Models;
|
||||
using Orchard.Roles.Records;
|
||||
|
||||
namespace Orchard.Roles.ViewModels {
|
||||
public class RolesIndexViewModel : AdminViewModel {
|
||||
|
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Data;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.Security;
|
||||
@@ -10,6 +11,7 @@ using Orchard.Users.Models;
|
||||
using Orchard.Users.ViewModels;
|
||||
|
||||
namespace Orchard.Users.Controllers {
|
||||
|
||||
public class AdminController : Controller, IModelUpdater {
|
||||
private readonly IModelManager _modelManager;
|
||||
private readonly IRepository<UserRecord> _userRepository;
|
||||
@@ -25,6 +27,9 @@ namespace Orchard.Users.Controllers {
|
||||
}
|
||||
|
||||
public IUser CurrentUser { get; set; }
|
||||
//public IText T { get; set; }
|
||||
|
||||
public Func<string, LocalizedString> T { get; set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
var model = new UsersIndexViewModel();
|
||||
@@ -67,7 +72,8 @@ namespace Orchard.Users.Controllers {
|
||||
if (!TryUpdateModel(model, input.ToValueProvider())) {
|
||||
return View(model);
|
||||
}
|
||||
_notifier.Information("User information updated");
|
||||
|
||||
_notifier.Information(T("User information updated"));
|
||||
return RedirectToAction("Edit", new { id });
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@ using Orchard.Users.Models;
|
||||
namespace Orchard.Users.ViewModels {
|
||||
public class UserEditViewModel : AdminViewModel {
|
||||
public IModel User { get; set; }
|
||||
public IEnumerable<ModelEditor> Editors { get; set; }
|
||||
public IEnumerable<ModelTemplate> Editors { get; set; }
|
||||
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int Id {
|
||||
|
@@ -7,6 +7,6 @@
|
||||
<%=Html.EditorFor(m=>m.Email, "inputTextLarge") %>
|
||||
</ol>
|
||||
|
||||
<% foreach(var editor in Model.Editors) {
|
||||
Html.RenderPartial(editor.PartialName, editor.ViewData);
|
||||
} %>
|
||||
<% foreach(var e in Model.Editors) {%>
|
||||
<%=Html.EditorFor(m => e.Model, e.TemplateName, e.Prefix)%>
|
||||
<%} %>
|
||||
|
@@ -0,0 +1,16 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Orchard.Roles.ViewModels.UserRolesViewModel>" %>
|
||||
<h3>
|
||||
Roles</h3>
|
||||
<ol>
|
||||
<%
|
||||
var index = 0; foreach (var entry in Model.Roles) {%>
|
||||
<li>
|
||||
|
||||
<%= Html.Hidden("Roles[" + index + "].RoleId", entry.RoleId)%>
|
||||
|
||||
<label for="<%="Roles[" + index + "]_Granted"%>"><%= Html.CheckBox("Roles[" + index + "].Granted", entry.Granted)%> <%=Html.Encode(entry.Name)%></label>
|
||||
</li>
|
||||
<%++index;
|
||||
} %>
|
||||
</ol>
|
||||
|
@@ -19,12 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TinyMce", "Orchard.Web\Pack
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.Media", "Orchard.Web\Packages\Orchard.Media\Orchard.Media.csproj", "{D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.Media.Tests", "Orchard.Web\Packages\Orchard.Media.Tests\Orchard.Media.Tests.csproj", "{15CFEF40-F2C2-44DD-ADAF-18A26DA2320C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.XmlRpc", "Orchard.Web\Packages\Orchard.XmlRpc\Orchard.XmlRpc.csproj", "{0DC6B598-6D03-4923-A6C2-274D09854117}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.XmlRpc.Tests", "Orchard.Web\Packages\Orchard.XmlRpc.Tests\Orchard.XmlRpc.Tests.csproj", "{58506223-CB7D-474F-B936-6E17D53B0FB8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.Users", "Orchard.Web\Packages\Orchard.Users\Orchard.Users.csproj", "{79AED36E-ABD0-4747-93D3-8722B042454B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.Tests.Packages", "Orchard.Tests.Packages\Orchard.Tests.Packages.csproj", "{6CB3EB30-F725-45C0-9742-42599BA8E8D2}"
|
||||
@@ -69,18 +65,10 @@ Global
|
||||
{D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{15CFEF40-F2C2-44DD-ADAF-18A26DA2320C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{15CFEF40-F2C2-44DD-ADAF-18A26DA2320C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{15CFEF40-F2C2-44DD-ADAF-18A26DA2320C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{15CFEF40-F2C2-44DD-ADAF-18A26DA2320C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0DC6B598-6D03-4923-A6C2-274D09854117}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0DC6B598-6D03-4923-A6C2-274D09854117}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0DC6B598-6D03-4923-A6C2-274D09854117}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0DC6B598-6D03-4923-A6C2-274D09854117}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{58506223-CB7D-474F-B936-6E17D53B0FB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{58506223-CB7D-474F-B936-6E17D53B0FB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{58506223-CB7D-474F-B936-6E17D53B0FB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{58506223-CB7D-474F-B936-6E17D53B0FB8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{79AED36E-ABD0-4747-93D3-8722B042454B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{79AED36E-ABD0-4747-93D3-8722B042454B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{79AED36E-ABD0-4747-93D3-8722B042454B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@@ -102,9 +90,7 @@ Global
|
||||
{0BF56F10-3023-4465-B273-026D22206355} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
|
||||
{954CA994-D204-468B-9D69-51F6AD3E1C29} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
|
||||
{D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
|
||||
{15CFEF40-F2C2-44DD-ADAF-18A26DA2320C} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
|
||||
{0DC6B598-6D03-4923-A6C2-274D09854117} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
|
||||
{58506223-CB7D-474F-B936-6E17D53B0FB8} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
|
||||
{79AED36E-ABD0-4747-93D3-8722B042454B} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
|
||||
{D10AD48F-407D-4DB5-A328-173EC7CB010F} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
|
||||
EndGlobalSection
|
||||
|
19
src/Orchard/Localization/IText.cs
Normal file
19
src/Orchard/Localization/IText.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Orchard.Localization {
|
||||
public interface IText : IDependency {
|
||||
LocalizedString Get(string textHint, params object[] args);
|
||||
}
|
||||
|
||||
|
||||
public class Text : IText {
|
||||
public LocalizedString Get(string textHint, params object[] args) {
|
||||
var localizedFormat = textHint;
|
||||
var localizedText = string.Format(localizedFormat, args);
|
||||
return new LocalizedString(localizedText);
|
||||
}
|
||||
}
|
||||
}
|
30
src/Orchard/Localization/LocalizationModule.cs
Normal file
30
src/Orchard/Localization/LocalizationModule.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Module=Autofac.Builder.Module;
|
||||
|
||||
namespace Orchard.Localization {
|
||||
public class LocalizationModule : Module{
|
||||
protected override void AttachToComponentRegistration(Autofac.IContainer container, Autofac.IComponentRegistration registration) {
|
||||
|
||||
var userProperty = FindUserProperty(registration.Descriptor.BestKnownImplementationType);
|
||||
|
||||
if (userProperty != null) {
|
||||
registration.Activated += (sender, e) => {
|
||||
//var authenticationService = e.Context.Resolve<IAuthenticationService>();
|
||||
//var currentUser = authenticationService.GetAuthenticatedUser();
|
||||
|
||||
var text = e.Context.Resolve<IText>();
|
||||
var textDelegate = new Localizer(text.Get);
|
||||
userProperty.SetValue(e.Instance, textDelegate, null);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static PropertyInfo FindUserProperty(Type type) {
|
||||
return type.GetProperty("T", typeof(Localizer));
|
||||
}
|
||||
}
|
||||
}
|
17
src/Orchard/Localization/LocalizedString.cs
Normal file
17
src/Orchard/Localization/LocalizedString.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace Orchard.Localization {
|
||||
public class LocalizedString {
|
||||
private readonly string _localized;
|
||||
|
||||
public LocalizedString(string localized) {
|
||||
_localized = localized;
|
||||
}
|
||||
|
||||
public static implicit operator LocalizedString(string x) {
|
||||
return new LocalizedString(x);
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return _localized;
|
||||
}
|
||||
}
|
||||
}
|
3
src/Orchard/Localization/Localizer.cs
Normal file
3
src/Orchard/Localization/Localizer.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace Orchard.Localization {
|
||||
public delegate LocalizedString Localizer(string text, params object[] args);
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Logging {
|
||||
public enum LogLevel {
|
||||
|
@@ -84,7 +84,7 @@ namespace Orchard.Models {
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ModelEditor> GetEditors(IModel model) {
|
||||
public IEnumerable<ModelTemplate> GetEditors(IModel model) {
|
||||
var context = new GetModelEditorsContext(model);
|
||||
foreach (var driver in _drivers) {
|
||||
driver.GetEditors(context);
|
||||
@@ -92,7 +92,7 @@ namespace Orchard.Models {
|
||||
return context.Editors;
|
||||
}
|
||||
|
||||
public IEnumerable<ModelEditor> UpdateEditors(IModel model, IModelUpdater updater) {
|
||||
public IEnumerable<ModelTemplate> UpdateEditors(IModel model, IModelUpdater updater) {
|
||||
var context = new UpdateModelContext(model, updater);
|
||||
foreach (var driver in _drivers) {
|
||||
driver.UpdateEditors(context);
|
||||
|
@@ -5,9 +5,9 @@ namespace Orchard.Models.Driver {
|
||||
public class GetModelEditorsContext {
|
||||
public GetModelEditorsContext(IModel model) {
|
||||
Instance = model;
|
||||
Editors= new List<ModelEditor>();
|
||||
Editors= new List<ModelTemplate>();
|
||||
}
|
||||
public IModel Instance { get; set; }
|
||||
public IList<ModelEditor> Editors { get; set; }
|
||||
public IList<ModelTemplate> Editors { get; set; }
|
||||
}
|
||||
}
|
@@ -8,7 +8,7 @@ namespace Orchard.Models {
|
||||
IModel New(string modelType);
|
||||
IModel Get(int id);
|
||||
void Create(IModel model);
|
||||
IEnumerable<ModelEditor> GetEditors(IModel model);
|
||||
IEnumerable<ModelEditor> UpdateEditors(IModel model, IModelUpdater updater);
|
||||
IEnumerable<ModelTemplate> GetEditors(IModel model);
|
||||
IEnumerable<ModelTemplate> UpdateEditors(IModel model, IModelUpdater updater);
|
||||
}
|
||||
}
|
||||
|
15
src/Orchard/Mvc/ViewPage.cs
Normal file
15
src/Orchard/Mvc/ViewPage.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Mvc {
|
||||
public class ViewPage<TModel> : System.Web.Mvc.ViewPage<TModel> {
|
||||
public MvcHtmlString T(string textHint) {
|
||||
return MvcHtmlString.Create(
|
||||
Html.Encode(new LocalizedString(textHint)));
|
||||
}
|
||||
}
|
||||
}
|
@@ -117,6 +117,10 @@
|
||||
<Compile Include="Controllers\HomeController.cs" />
|
||||
<Compile Include="Data\Conventions\AttributeCollectionConvention.cs" />
|
||||
<Compile Include="Data\Conventions\CascadeAllDeleteOrphanAttribute.cs" />
|
||||
<Compile Include="Localization\IText.cs" />
|
||||
<Compile Include="Localization\LocalizationModule.cs" />
|
||||
<Compile Include="Localization\Localizer.cs" />
|
||||
<Compile Include="Localization\LocalizedString.cs" />
|
||||
<Compile Include="Models\Driver\IModelUpdater.cs" />
|
||||
<Compile Include="Environment\ServiceLocator.cs" />
|
||||
<Compile Include="Logging\CastleLogger.cs" />
|
||||
@@ -157,12 +161,15 @@
|
||||
<Compile Include="Mvc\Routes\RouteExtensions.cs" />
|
||||
<Compile Include="Mvc\ViewModels\AdminViewModel.cs" />
|
||||
<Compile Include="Mvc\ViewModels\BaseViewModel.cs" />
|
||||
<Compile Include="Mvc\ViewPage.cs">
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Security\IAuthenticationService.cs" />
|
||||
<Compile Include="Security\Providers\FormsAuthenticationService.cs" />
|
||||
<Compile Include="Security\SecurityFilter.cs" />
|
||||
<Compile Include="Security\SecurityModule.cs" />
|
||||
<Compile Include="UI\Menus\AdminMenuFilter.cs" />
|
||||
<Compile Include="UI\Models\ModelEditor.cs" />
|
||||
<Compile Include="UI\Models\ModelTemplate.cs" />
|
||||
<Compile Include="UI\Navigation\NavigationBuilder.cs" />
|
||||
<Compile Include="UI\Navigation\INavigationProvider.cs" />
|
||||
<Compile Include="UI\Navigation\MenuItem.cs" />
|
||||
|
@@ -4,6 +4,6 @@ namespace Orchard.Security {
|
||||
public interface IAuthenticationService : IDependency {
|
||||
void SignIn(IUser user, bool createPersistentCookie);
|
||||
void SignOut();
|
||||
IUser Authenticated();
|
||||
IUser GetAuthenticatedUser();
|
||||
}
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@ namespace Orchard.Security.Providers {
|
||||
FormsAuthentication.SignOut();
|
||||
}
|
||||
|
||||
public IUser Authenticated() {
|
||||
public IUser GetAuthenticatedUser() {
|
||||
if (!_httpContext.Request.IsAuthenticated || !(_httpContext.User.Identity is FormsIdentity)) {
|
||||
return null;
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ namespace Orchard.Security {
|
||||
return;
|
||||
|
||||
if (baseViewModel.CurrentUser == null)
|
||||
baseViewModel.CurrentUser = _authenticationService.Authenticated();
|
||||
baseViewModel.CurrentUser = _authenticationService.GetAuthenticatedUser();
|
||||
}
|
||||
|
||||
public void OnResultExecuted(ResultExecutedContext filterContext) {
|
||||
|
@@ -11,7 +11,7 @@ namespace Orchard.Security {
|
||||
if (userProperty != null) {
|
||||
registration.Activated += (sender, e) => {
|
||||
var authenticationService = e.Context.Resolve<IAuthenticationService>();
|
||||
var currentUser = authenticationService.Authenticated();
|
||||
var currentUser = authenticationService.GetAuthenticatedUser();
|
||||
userProperty.SetValue(e.Instance, currentUser, null);
|
||||
};
|
||||
}
|
||||
|
@@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Orchard.UI.Models {
|
||||
public class ModelEditor {
|
||||
public string PartialName { get; set; }
|
||||
public ViewDataDictionary ViewData { get; set; }
|
||||
|
||||
public static ModelEditor For<TModel>(string partialName, TModel model) {
|
||||
return new ModelEditor {
|
||||
PartialName = partialName,
|
||||
ViewData = new ViewDataDictionary<TModel>(model)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
22
src/Orchard/UI/Models/ModelTemplate.cs
Normal file
22
src/Orchard/UI/Models/ModelTemplate.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace Orchard.UI.Models {
|
||||
public class ModelTemplate {
|
||||
public object Model { get; set; }
|
||||
public string Prefix { get; set; }
|
||||
public string TemplateName { get; set; }
|
||||
|
||||
public static ModelTemplate For<TModel>(TModel model, string prefix) {
|
||||
return new ModelTemplate {
|
||||
Model = model,
|
||||
Prefix = prefix,
|
||||
};
|
||||
}
|
||||
|
||||
public static ModelTemplate For<TModel>(TModel model, string prefix, string editorTemplateName) {
|
||||
return new ModelTemplate {
|
||||
Model = model,
|
||||
Prefix = prefix,
|
||||
TemplateName = editorTemplateName,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,9 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
|
||||
namespace Orchard.UI.Notify {
|
||||
public interface INotifier : IDependency {
|
||||
void Add(NotifyType type, string message);
|
||||
void Add(NotifyType type, LocalizedString message);
|
||||
IEnumerable<NotifyEntry> List();
|
||||
}
|
||||
|
||||
@@ -17,7 +18,7 @@ namespace Orchard.UI.Notify {
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public void Add(NotifyType type, string message) {
|
||||
public void Add(NotifyType type, LocalizedString message) {
|
||||
Logger.Information("Notification {0} message: {1}", type, message);
|
||||
_entries.Add(new NotifyEntry { Type = type, Message = message });
|
||||
}
|
||||
|
@@ -1,12 +1,14 @@
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.UI.Notify {
|
||||
public static class NotifierExtensions {
|
||||
public static void Information(this INotifier notifier, string message) {
|
||||
public static void Information(this INotifier notifier, LocalizedString message) {
|
||||
notifier.Add(NotifyType.Information, message);
|
||||
}
|
||||
public static void Warning(this INotifier notifier, string message) {
|
||||
public static void Warning(this INotifier notifier, LocalizedString message) {
|
||||
notifier.Add(NotifyType.Warning, message);
|
||||
}
|
||||
public static void Error(this INotifier notifier, string message) {
|
||||
public static void Error(this INotifier notifier, LocalizedString message) {
|
||||
notifier.Add(NotifyType.Error, message);
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.UI.Notify {
|
||||
public enum NotifyType {
|
||||
Information,
|
||||
@@ -7,6 +9,6 @@ namespace Orchard.UI.Notify {
|
||||
|
||||
public class NotifyEntry {
|
||||
public NotifyType Type { get; set; }
|
||||
public string Message { get; set; }
|
||||
public LocalizedString Message { get; set; }
|
||||
}
|
||||
}
|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Filters;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
@@ -36,7 +37,7 @@ namespace Orchard.UI.Notify {
|
||||
foreach (var entry in _notifier.List()) {
|
||||
sb.Append(Convert.ToString(entry.Type))
|
||||
.Append(':')
|
||||
.AppendLine(entry.Message);
|
||||
.AppendLine(entry.Message.ToString());
|
||||
}
|
||||
|
||||
// assign values into temp data
|
||||
@@ -67,13 +68,13 @@ namespace Orchard.UI.Notify {
|
||||
var type = (NotifyType)Enum.Parse(typeof(NotifyType), line.Substring(0, delimiterIndex));
|
||||
messageEntries.Add(new NotifyEntry {
|
||||
Type = type,
|
||||
Message = line.Substring(delimiterIndex + 1)
|
||||
Message = new LocalizedString(line.Substring(delimiterIndex + 1))
|
||||
});
|
||||
}
|
||||
else {
|
||||
messageEntries.Add(new NotifyEntry {
|
||||
Type = NotifyType.Information,
|
||||
Message = line.Substring(delimiterIndex + 1)
|
||||
Message = new LocalizedString(line.Substring(delimiterIndex + 1))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user