mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-19 17:51:45 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -21,6 +21,7 @@ using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Security;
|
||||
using Orchard.Tests.Modules;
|
||||
using System.Web.Mvc;
|
||||
@@ -45,6 +46,8 @@ namespace Orchard.Core.Tests.Routable.Services {
|
||||
builder.RegisterInstance(new Mock<IAuthorizer>().Object);
|
||||
builder.RegisterInstance(new Mock<INotifier>().Object);
|
||||
builder.RegisterInstance(new Mock<IContentDisplay>().Object);
|
||||
builder.RegisterType<StubHttpContextAccessor>().As<IHttpContextAccessor>();
|
||||
builder.RegisterType<DefaultWorkContextAccessor>().As<IWorkContextAccessor>();
|
||||
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
|
||||
|
||||
builder.RegisterType<ThingHandler>().As<IContentHandler>();
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Web;
|
||||
using System.Xml.Linq;
|
||||
using Autofac;
|
||||
using Moq;
|
||||
using NHibernate;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Caching;
|
||||
@@ -28,6 +29,7 @@ using Orchard.Environment.Descriptor;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Modules;
|
||||
using Orchard.Modules.Services;
|
||||
@@ -35,6 +37,7 @@ using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Tests.Stubs;
|
||||
using Orchard.Tests.Utility;
|
||||
using Orchard.Themes;
|
||||
using Orchard.Themes.Handlers;
|
||||
using Orchard.Themes.Models;
|
||||
@@ -42,12 +45,15 @@ using Orchard.Themes.Services;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Tests.Modules.Themes.Services {
|
||||
[TestFixture]
|
||||
#if REFACTORING
|
||||
[TestFixture, Ignore]
|
||||
public class ThemeServiceTests {
|
||||
private IThemeService _themeService;
|
||||
private ISiteThemeService _siteThemeService;
|
||||
private IContainer _container;
|
||||
private ISessionFactory _sessionFactory;
|
||||
private ISession _session;
|
||||
private IFeatureManager _featureManager;
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void InitFixture() {
|
||||
@@ -67,12 +73,11 @@ namespace Orchard.Tests.Modules.Themes.Services {
|
||||
public void Init() {
|
||||
var context = new DynamicProxyContext();
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterModule(new SettingsModule());
|
||||
builder.RegisterType<StubWorkContextAccessor>().As<IWorkContextAccessor>();
|
||||
builder.RegisterType<ThemeService>().EnableDynamicProxy(context).As<IThemeService>();
|
||||
builder.RegisterType<SettingsModuleInterceptor>().As<ISettingsModuleInterceptor>();
|
||||
builder.RegisterType<SiteService>().As<ISiteService>();
|
||||
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
|
||||
builder.RegisterType<Orchard.Localization.Text>().As<IText>();
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
|
||||
@@ -83,7 +88,8 @@ namespace Orchard.Tests.Modules.Themes.Services {
|
||||
builder.RegisterType<DefaultContentQuery>().As<IContentQuery>();
|
||||
builder.RegisterType<SiteSettingsPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<ThemeSiteSettingsPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<ModuleService>().As<IModuleService>();
|
||||
//builder.RegisterType<ModuleService>().As<IModuleService>();
|
||||
builder.RegisterType<ShellDescriptor>();
|
||||
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
|
||||
builder.RegisterType<StubShellDescriptorManager>().As<IShellDescriptorManager>().InstancePerLifetimeScope();
|
||||
builder.RegisterType<TransactionManager>().As<ITransactionManager>();
|
||||
@@ -95,68 +101,71 @@ namespace Orchard.Tests.Modules.Themes.Services {
|
||||
.As(typeof(IMapper<SettingsDictionary, XElement>));
|
||||
_session = _sessionFactory.OpenSession();
|
||||
builder.RegisterInstance(new TestSessionLocator(_session)).As<ISessionLocator>();
|
||||
builder.RegisterAutoMocking(MockBehavior.Loose);
|
||||
_container = builder.Build();
|
||||
_themeService = _container.Resolve<IThemeService>();
|
||||
_siteThemeService = _container.Resolve<ISiteThemeService>();
|
||||
_featureManager = _container.Resolve<IFeatureManager>();
|
||||
}
|
||||
|
||||
//todo: test theme feature enablement
|
||||
|
||||
[Test]
|
||||
public void ThemeWithNoBaseThemeCanBeSetAsSiteTheme() {
|
||||
_themeService.SetSiteTheme("ThemeOne");
|
||||
var siteTheme = _themeService.GetSiteTheme();
|
||||
Assert.That(siteTheme.ThemeName, Is.EqualTo("ThemeOne"));
|
||||
_siteThemeService.SetSiteTheme("ThemeOne");
|
||||
var siteTheme = _siteThemeService.GetSiteTheme();
|
||||
Assert.That(siteTheme.Name, Is.EqualTo("ThemeOne"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ThemeWithAvailableBaseThemeCanBeSetAsSiteTheme() {
|
||||
_themeService.SetSiteTheme("ThemeTwo");
|
||||
var siteTheme = _themeService.GetSiteTheme();
|
||||
Assert.That(siteTheme.ThemeName, Is.EqualTo("ThemeTwo"));
|
||||
_siteThemeService.SetSiteTheme("ThemeTwo");
|
||||
var siteTheme = _siteThemeService.GetSiteTheme();
|
||||
Assert.That(siteTheme.Name, Is.EqualTo("ThemeTwo"));
|
||||
Assert.That(siteTheme.BaseTheme, Is.EqualTo("ThemeOne"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ThemeWithUnavailableBaseThemeCanBeSetAsSiteTheme() {
|
||||
_themeService.SetSiteTheme("ThemeOne");
|
||||
_themeService.SetSiteTheme("ThemeThree");
|
||||
var siteTheme = _themeService.GetSiteTheme();
|
||||
Assert.That(siteTheme.ThemeName, Is.EqualTo("ThemeOne"));
|
||||
_siteThemeService.SetSiteTheme("ThemeOne");
|
||||
_siteThemeService.SetSiteTheme("ThemeThree");
|
||||
var siteTheme = _siteThemeService.GetSiteTheme();
|
||||
Assert.That(siteTheme.Name, Is.EqualTo("ThemeOne"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ThemeWithCircularBaseDepTrowsExceptionOnActivation() {
|
||||
_themeService.SetSiteTheme("ThemeOne");
|
||||
_siteThemeService.SetSiteTheme("ThemeOne");
|
||||
try {
|
||||
_themeService.SetSiteTheme("ThemeFourBasedOnFive");
|
||||
_siteThemeService.SetSiteTheme("ThemeFourBasedOnFive");
|
||||
} catch (InvalidOperationException ex) {
|
||||
Assert.That(ex.Message, Is.StringMatching("ThemeFiveBasedOnFour"));
|
||||
}
|
||||
var siteTheme = _themeService.GetSiteTheme();
|
||||
Assert.That(siteTheme.ThemeName, Is.EqualTo("ThemeOne"));
|
||||
var siteTheme = _siteThemeService.GetSiteTheme();
|
||||
Assert.That(siteTheme.Name, Is.EqualTo("ThemeOne"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanEnableAndDisableThemes() {
|
||||
_themeService.EnableTheme("ThemeOne");
|
||||
_featureManager.EnableFeature("ThemeOne");
|
||||
Assert.IsTrue(_themeService.GetThemeByName("ThemeOne").Enabled);
|
||||
Assert.IsTrue(_container.Resolve<IShellDescriptorManager>().GetShellDescriptor().Features.Any(sf => sf.Name == "ThemeOne"));
|
||||
_themeService.DisableTheme("ThemeOne");
|
||||
_featureManager.DisableFeature("ThemeOne");
|
||||
Assert.IsFalse(_themeService.GetThemeByName("ThemeOne").Enabled);
|
||||
Assert.IsFalse(_container.Resolve<IShellDescriptorManager>().GetShellDescriptor().Features.Any(sf => sf.Name == "ThemeOne"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ActivatingThemeEnablesIt() {
|
||||
_themeService.SetSiteTheme("ThemeOne");
|
||||
_siteThemeService.SetSiteTheme("ThemeOne");
|
||||
Assert.IsTrue(_themeService.GetThemeByName("ThemeOne").Enabled);
|
||||
Assert.IsTrue(_container.Resolve<IShellDescriptorManager>().GetShellDescriptor().Features.Any(sf => sf.Name == "ThemeOne"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ActivatingThemeDoesNotDisableOldTheme() {
|
||||
_themeService.SetSiteTheme("ThemeOne");
|
||||
_themeService.SetSiteTheme("ThemeTwo");
|
||||
_siteThemeService.SetSiteTheme("ThemeOne");
|
||||
_siteThemeService.SetSiteTheme("ThemeTwo");
|
||||
Assert.IsTrue(_themeService.GetThemeByName("ThemeOne").Enabled);
|
||||
Assert.IsTrue(_themeService.GetThemeByName("ThemeTwo").Enabled);
|
||||
Assert.IsTrue(_container.Resolve<IShellDescriptorManager>().GetShellDescriptor().Features.Any(sf => sf.Name == "ThemeOne"));
|
||||
@@ -269,4 +278,5 @@ namespace Orchard.Tests.Modules.Themes.Services {
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -54,6 +54,7 @@ namespace Orchard.Tests.Modules.Users.Controllers {
|
||||
builder.RegisterType<MembershipService>().As<IMembershipService>();
|
||||
builder.RegisterType<UserService>().As<IUserService>();
|
||||
builder.RegisterType<UserPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<StubWorkContextAccessor>().As<IWorkContextAccessor>();
|
||||
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
|
||||
builder.RegisterType<TransactionManager>().As<ITransactionManager>();
|
||||
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
|
||||
|
||||
@@ -17,11 +17,13 @@ using Orchard.ContentManagement.Records;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Messaging.Events;
|
||||
using Orchard.Messaging.Services;
|
||||
using Orchard.Security;
|
||||
using Orchard.Tests.Stubs;
|
||||
using Orchard.Tests.Utility;
|
||||
using Orchard.Users.Handlers;
|
||||
using Orchard.Users.Models;
|
||||
using Orchard.Users.Services;
|
||||
@@ -76,6 +78,9 @@ namespace Orchard.Tests.Modules.Users.Services {
|
||||
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterType<UserPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<StubWorkContextAccessor>().As<IWorkContextAccessor>();
|
||||
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
|
||||
builder.RegisterAutoMocking(MockBehavior.Loose);
|
||||
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
|
||||
builder.RegisterInstance(new Mock<IMessageEventHandler>().Object);
|
||||
builder.RegisterType<DefaultMessageManager>().As<IMessageManager>();
|
||||
|
||||
@@ -16,6 +16,8 @@ using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Security;
|
||||
using Orchard.Tests.Stubs;
|
||||
using Orchard.Themes;
|
||||
@@ -76,28 +78,32 @@ namespace Orchard.Tests.Modules.Widgets.Services {
|
||||
}
|
||||
|
||||
public override void Register(ContainerBuilder builder) {
|
||||
var mockFeatureManager = new Mock<IFeatureManager>();
|
||||
|
||||
var theme1 = new FeatureDescriptor {Extension = new ExtensionDescriptor {Zones = ThemeZoneName1}};
|
||||
var theme2 = new FeatureDescriptor {Extension = new ExtensionDescriptor {Zones = ThemeZoneName2}};
|
||||
mockFeatureManager.Setup(x => x.GetEnabledFeatures())
|
||||
.Returns(new[] { theme1, theme2 });
|
||||
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
|
||||
builder.RegisterInstance(new Mock<ITransactionManager>().Object);
|
||||
builder.RegisterInstance(new Mock<IAuthorizer>().Object);
|
||||
builder.RegisterInstance(new Mock<INotifier>().Object);
|
||||
builder.RegisterInstance(mockFeatureManager.Object);
|
||||
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
|
||||
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
|
||||
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
|
||||
builder.RegisterType<WidgetsService>().As<IWidgetsService>();
|
||||
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
|
||||
Theme theme1 = new Theme { Zones = ThemeZoneName1 };
|
||||
Theme theme2 = new Theme { Zones = ThemeZoneName2 };
|
||||
Mock<IThemeService> themeServiceMock = new Mock<IThemeService>();
|
||||
themeServiceMock.Setup(x => x.GetInstalledThemes()).Returns(
|
||||
(new ITheme[] { theme1, theme2 }));
|
||||
|
||||
builder.RegisterInstance(themeServiceMock.Object).As<IThemeService>();
|
||||
|
||||
builder.RegisterType<StubWidgetPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<StubLayerPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<DefaultContentQuery>().As<IContentQuery>();
|
||||
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -8,6 +8,7 @@ using NUnit.Framework;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.DisplayManagement.Shapes;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Themes;
|
||||
|
||||
namespace Orchard.Tests.DisplayManagement {
|
||||
@@ -22,7 +23,7 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
Bindings = new Dictionary<string, ShapeBinding>(StringComparer.OrdinalIgnoreCase)
|
||||
};
|
||||
_workContext = new TestWorkContext {
|
||||
CurrentTheme = new Theme { ThemeName = "Hello" }
|
||||
CurrentTheme = new ExtensionDescriptor { Name = "Hello" }
|
||||
};
|
||||
|
||||
|
||||
@@ -45,18 +46,6 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
void IShapeDisplayEvents.Displayed(ShapeDisplayedContext context) { Displayed(context); }
|
||||
}
|
||||
|
||||
public class Theme : ITheme {
|
||||
public bool Enabled { get; set; }
|
||||
public string ThemeName { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Version { get; set; }
|
||||
public string Author { get; set; }
|
||||
public string HomePage { get; set; }
|
||||
public string Tags { get; set; }
|
||||
public string Zones { get; set; }
|
||||
public string BaseTheme { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class TestShapeTableManager : IShapeTableManager {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.ContentManagement;
|
||||
@@ -83,6 +82,10 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
_availableFeautures = availableFeautures;
|
||||
}
|
||||
|
||||
public ExtensionDescriptor GetExtension(string name) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<ExtensionDescriptor> AvailableExtensions() {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
@@ -94,14 +97,6 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
public IEnumerable<Feature> LoadFeatures(IEnumerable<FeatureDescriptor> featureDescriptors) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public void UninstallExtension(string extensionType, string extensionName) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class TestShapeProvider : IShapeTableProvider {
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Orchard.Tests.DisplayManagement {
|
||||
|
||||
var workContext = new DefaultDisplayManagerTests.TestWorkContext
|
||||
{
|
||||
CurrentTheme = new DefaultDisplayManagerTests.Theme { ThemeName = "Hello" }
|
||||
CurrentTheme = new ExtensionDescriptor { Name = "Hello" }
|
||||
};
|
||||
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Autofac;
|
||||
@@ -81,9 +80,15 @@ namespace Orchard.Tests.Environment {
|
||||
_container.Mock<IOrchardShellEvents>()
|
||||
.Setup(e => e.Activated());
|
||||
|
||||
_container.Mock<IOrchardShellEvents>()
|
||||
.Setup(e => e.Terminating()).Callback(() => new object());
|
||||
}
|
||||
|
||||
public class StubExtensionManager : IExtensionManager {
|
||||
public ExtensionDescriptor GetExtension(string name) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<ExtensionDescriptor> AvailableExtensions() {
|
||||
var ext = new ExtensionDescriptor { Name = "Orchard.Framework" };
|
||||
ext.Features = new[] { new FeatureDescriptor { Extension = ext, Name = ext.Name } };
|
||||
@@ -114,14 +119,6 @@ namespace Orchard.Tests.Environment {
|
||||
};
|
||||
}
|
||||
|
||||
public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void UninstallExtension(string extensionType, string extensionName) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Monitor(Action<IVolatileToken> monitor) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -4,13 +4,24 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using Autofac;
|
||||
using Moq;
|
||||
using NHibernate;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Caching;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.Data;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Localization.Records;
|
||||
using Orchard.Localization.Services;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Security;
|
||||
using Orchard.Tests.ContentManagement;
|
||||
using Orchard.Tests.Stubs;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Tests.Localization {
|
||||
[TestFixture]
|
||||
@@ -32,6 +43,18 @@ namespace Orchard.Tests.Localization {
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
|
||||
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
|
||||
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
|
||||
builder.RegisterInstance(new Mock<ITransactionManager>().Object);
|
||||
builder.RegisterInstance(new Mock<IAuthorizer>().Object);
|
||||
builder.RegisterInstance(new Mock<INotifier>().Object);
|
||||
builder.RegisterInstance(new Mock<IContentDisplay>().Object);
|
||||
builder.RegisterType<StubHttpContextAccessor>().As<IHttpContextAccessor>();
|
||||
builder.RegisterType<DefaultWorkContextAccessor>().As<IWorkContextAccessor>();
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
|
||||
builder.RegisterType<TestCultureSelector>().As<ICultureSelector>();
|
||||
builder.RegisterType<DefaultCultureManager>().As<ICultureManager>();
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Reflection;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Tests.DisplayManagement;
|
||||
using Orchard.Tests.Stubs;
|
||||
@@ -28,7 +29,7 @@ namespace Orchard.Tests.Mvc {
|
||||
|
||||
var workContext = new DefaultDisplayManagerTests.TestWorkContext
|
||||
{
|
||||
CurrentTheme = new DefaultDisplayManagerTests.Theme { ThemeName = "Hello" },
|
||||
CurrentTheme = new ExtensionDescriptor { Name = "Hello" },
|
||||
ContainerProvider = _containerProvider
|
||||
};
|
||||
_workContextAccessor = new DefaultDisplayManagerTests.TestWorkContextAccessor(workContext);
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Tests.Stubs {
|
||||
public class StubExtensionManager : IExtensionManager {
|
||||
public ExtensionDescriptor GetExtension(string name) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<ExtensionDescriptor> AvailableExtensions() {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
@@ -18,13 +20,5 @@ namespace Orchard.Tests.Stubs {
|
||||
public IEnumerable<Feature> LoadFeatures(IEnumerable<FeatureDescriptor> featureDescriptors) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public void UninstallExtension(string extensionType, string extensionName) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using Autofac;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Security;
|
||||
using Orchard.Settings;
|
||||
|
||||
namespace Orchard.Tests.Stubs {
|
||||
public class StubWorkContextAccessor : IWorkContextAccessor {
|
||||
private readonly ILifetimeScope _lifetimeScope;
|
||||
private WorkContext _workContext;
|
||||
|
||||
public StubWorkContextAccessor(ILifetimeScope lifetimeScope) {
|
||||
_lifetimeScope = lifetimeScope;
|
||||
_workContext = new WorkContextImpl(_lifetimeScope);
|
||||
}
|
||||
|
||||
public class WorkContextImpl : WorkContext {
|
||||
private readonly ILifetimeScope _lifetimeScope;
|
||||
private Dictionary<string, object> _contextDictonary;
|
||||
|
||||
public WorkContextImpl(ILifetimeScope lifetimeScope) {
|
||||
_contextDictonary = new Dictionary<string, object>();
|
||||
CurrentUser = new StubUser();
|
||||
var ci = new ContentItem();
|
||||
ci.Weld(new StubSite());
|
||||
CurrentSite = ci.As<ISite>();
|
||||
_lifetimeScope = lifetimeScope;
|
||||
}
|
||||
|
||||
public class StubSite : ContentPart, ISite {
|
||||
public string PageTitleSeparator {
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public string SiteName {
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public string SiteSalt {
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public string SuperUser {
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public string HomePage {
|
||||
get { throw new NotImplementedException(); }
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public string SiteCulture {
|
||||
get { throw new NotImplementedException(); }
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public ResourceDebugMode ResourceDebugMode {
|
||||
get { throw new NotImplementedException(); }
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
}
|
||||
|
||||
public class StubUser : IUser {
|
||||
public ContentItem ContentItem {
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public int Id {
|
||||
get { return 5; }
|
||||
}
|
||||
|
||||
public string UserName {
|
||||
get { return "Fake"; }
|
||||
}
|
||||
|
||||
public string Email {
|
||||
get { return "Fake@fake.com"; }
|
||||
}
|
||||
}
|
||||
|
||||
public override T Resolve<T>() {
|
||||
return _lifetimeScope.Resolve<T>();
|
||||
}
|
||||
|
||||
public override bool TryResolve<T>(out T service) {
|
||||
return _lifetimeScope.TryResolve<T>(out service);
|
||||
}
|
||||
|
||||
public override T GetState<T>(string name) {
|
||||
return (T) _contextDictonary[name];
|
||||
}
|
||||
|
||||
public override void SetState<T>(string name, T value) {
|
||||
_contextDictonary[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public WorkContext GetContext(HttpContextBase httpContext) {
|
||||
throw new NotSupportedException();
|
||||
return _workContext;
|
||||
}
|
||||
|
||||
public IWorkContextScope CreateWorkContextScope(HttpContextBase httpContext) {
|
||||
@@ -12,7 +106,7 @@ namespace Orchard.Tests.Stubs {
|
||||
}
|
||||
|
||||
public WorkContext GetContext() {
|
||||
return null;
|
||||
return _workContext;
|
||||
}
|
||||
|
||||
public IWorkContextScope CreateWorkContextScope() {
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Data;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Tests.Stubs;
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Tests.UI.Navigation {
|
||||
[TestFixture]
|
||||
public class NavigationManagerTests {
|
||||
[Test]
|
||||
public void EmptyMenuIfNameDoesntMatch() {
|
||||
var manager = new NavigationManager(new[] { new StubProvider() }, new StubAuth(), new UrlHelper(new RequestContext(new StubHttpContext("~/"), new RouteData())));
|
||||
var manager = new NavigationManager(new[] { new StubProvider() }, new StubAuth(), new UrlHelper(new RequestContext(new StubHttpContext("~/"), new RouteData())), new StubOrchardServices());
|
||||
|
||||
var menuItems = manager.BuildMenu("primary");
|
||||
Assert.That(menuItems.Count(), Is.EqualTo(0));
|
||||
@@ -31,7 +36,7 @@ namespace Orchard.Tests.UI.Navigation {
|
||||
|
||||
[Test]
|
||||
public void NavigationManagerShouldUseProvidersToBuildNamedMenu() {
|
||||
var manager = new NavigationManager(new[] { new StubProvider() }, new StubAuth(), new UrlHelper(new RequestContext(new StubHttpContext("~/"), new RouteData())));
|
||||
var manager = new NavigationManager(new[] { new StubProvider() }, new StubAuth(), new UrlHelper(new RequestContext(new StubHttpContext("~/"), new RouteData())), new StubOrchardServices());
|
||||
|
||||
var menuItems = manager.BuildMenu("admin");
|
||||
Assert.That(menuItems.Count(), Is.EqualTo(2));
|
||||
@@ -43,7 +48,7 @@ namespace Orchard.Tests.UI.Navigation {
|
||||
|
||||
[Test]
|
||||
public void NavigationManagerShouldMergeAndOrderNavigation() {
|
||||
var manager = new NavigationManager(new INavigationProvider[] { new StubProvider(), new Stub2Provider() }, new StubAuth(), new UrlHelper(new RequestContext(new StubHttpContext("~/"), new RouteData())));
|
||||
var manager = new NavigationManager(new INavigationProvider[] { new StubProvider(), new Stub2Provider() }, new StubAuth(), new UrlHelper(new RequestContext(new StubHttpContext("~/"), new RouteData())), new StubOrchardServices());
|
||||
|
||||
var menuItems = manager.BuildMenu("admin");
|
||||
Assert.That(menuItems.Count(), Is.EqualTo(3));
|
||||
@@ -90,4 +95,38 @@ namespace Orchard.Tests.UI.Navigation {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class StubOrchardServices : IOrchardServices {
|
||||
private readonly ILifetimeScope _lifetimeScope;
|
||||
|
||||
public StubOrchardServices() {}
|
||||
|
||||
public StubOrchardServices(ILifetimeScope lifetimeScope) {
|
||||
_lifetimeScope = lifetimeScope;
|
||||
}
|
||||
|
||||
public IContentManager ContentManager {
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public ITransactionManager TransactionManager {
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public IAuthorizer Authorizer {
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public INotifier Notifier {
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public dynamic New {
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public WorkContext WorkContext {
|
||||
get { return new StubWorkContextAccessor(_lifetimeScope).GetContext(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,50 +147,5 @@ namespace Orchard.Core.Common.Handlers {
|
||||
if (part.ContainerField.Value != null)
|
||||
part.ContainerField.Value = part.ContainerField.Value;
|
||||
}
|
||||
|
||||
|
||||
//private void GetEditor(BuildEditorContext context, CommonPart instance) {
|
||||
// var currentUser = _authenticationService.GetAuthenticatedUser();
|
||||
// if (!_authorizationService.TryCheckAccess(Permissions.ChangeOwner, currentUser, instance)) {
|
||||
// return;
|
||||
// }
|
||||
// var viewModel = new OwnerEditorViewModel();
|
||||
// if (instance.Owner != null)
|
||||
// viewModel.Owner = instance.Owner.UserName;
|
||||
|
||||
// context.AddEditor(new TemplateViewModel(viewModel, "CommonPart") { TemplateName = "Parts/Common.Owner", ZoneName = "Content", Position = "999" });
|
||||
//}
|
||||
|
||||
|
||||
//private void UpdateEditor(UpdateEditorContext context, CommonPart instance) {
|
||||
// // this event is hooked so the modified timestamp is changed when an edit-post occurs.
|
||||
// // kind of a loose rule of thumb. may not be sufficient
|
||||
// instance.ModifiedUtc = _clock.UtcNow;
|
||||
// instance.VersionModifiedUtc = _clock.UtcNow;
|
||||
|
||||
// var currentUser = _authenticationService.GetAuthenticatedUser();
|
||||
// if (!_authorizationService.TryCheckAccess(Permissions.ChangeOwner, currentUser, instance)) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// var viewModel = new OwnerEditorViewModel();
|
||||
// if (instance.Owner != null)
|
||||
// viewModel.Owner = instance.Owner.UserName;
|
||||
|
||||
// var priorOwner = viewModel.Owner;
|
||||
// context.Updater.TryUpdateModel(viewModel, "CommonPart", null, null);
|
||||
|
||||
// if (viewModel.Owner != null && viewModel.Owner != priorOwner) {
|
||||
// var newOwner = _membershipService.GetUser(viewModel.Owner);
|
||||
// if (newOwner == null) {
|
||||
// context.Updater.AddModelError("CommonPart.Owner", T("Invalid user name"));
|
||||
// }
|
||||
// else {
|
||||
// instance.Owner = newOwner;
|
||||
// }
|
||||
// }
|
||||
|
||||
// context.AddEditor(new TemplateViewModel(viewModel, "CommonPart") { TemplateName = "Parts/Common.Owner", ZoneName = "Content", Position = "999" });
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Services;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Themes;
|
||||
|
||||
namespace Orchard.Core.HomePage.Controllers {
|
||||
[HandleError]
|
||||
public class HomeController : Controller {
|
||||
private readonly IEnumerable<IHomePageProvider> _homePageProviders;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
public HomeController(IEnumerable<IHomePageProvider> homePageProviders) {
|
||||
public HomeController(IEnumerable<IHomePageProvider> homePageProviders, IOrchardServices orchardServices) {
|
||||
_homePageProviders = homePageProviders;
|
||||
_orchardServices = orchardServices;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
[Themed]
|
||||
public ActionResult Index() {
|
||||
try {
|
||||
var homepage = CurrentSite.HomePage;
|
||||
var homepage = _orchardServices.WorkContext.CurrentSite.HomePage;
|
||||
if (String.IsNullOrEmpty(homepage))
|
||||
return View();
|
||||
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Messaging.Models;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Messaging.Events;
|
||||
using Orchard.Messaging.Models;
|
||||
using Orchard.Messaging.Services;
|
||||
using Orchard.Settings;
|
||||
using Orchard.ContentManagement.Records;
|
||||
|
||||
namespace Orchard.Core.Messaging.Services {
|
||||
public class DefaultMessageManager : IMessageManager {
|
||||
private readonly IMessageEventHandler _messageEventHandler;
|
||||
private readonly IEnumerable<IMessagingChannel> _channels;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public DefaultMessageManager(
|
||||
IMessageEventHandler messageEventHandler,
|
||||
IEnumerable<IMessagingChannel> channels) {
|
||||
IEnumerable<IMessagingChannel> channels,
|
||||
IOrchardServices orchardServices) {
|
||||
_messageEventHandler = messageEventHandler;
|
||||
_channels = channels;
|
||||
_orchardServices = orchardServices;
|
||||
}
|
||||
|
||||
public void Send(ContentItemRecord recipient, string type, string service = null, Dictionary<string, string> properties = null) {
|
||||
if ( !HasChannels() )
|
||||
return;
|
||||
|
||||
var messageSettings = CurrentSite.As<MessageSettingsPart>().Record;
|
||||
var messageSettings = _orchardServices.WorkContext.CurrentSite.As<MessageSettingsPart>().Record;
|
||||
|
||||
if ( messageSettings == null || String.IsNullOrWhiteSpace(messageSettings.DefaultChannelService) ) {
|
||||
return;
|
||||
|
||||
@@ -12,18 +12,19 @@ namespace Orchard.Core.Navigation.Drivers {
|
||||
public class MenuPartDriver : ContentPartDriver<MenuPart> {
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly INavigationManager _navigationManager;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
public MenuPartDriver(IAuthorizationService authorizationService, INavigationManager navigationManager) {
|
||||
public MenuPartDriver(IAuthorizationService authorizationService, INavigationManager navigationManager, IOrchardServices orchardServices) {
|
||||
_authorizationService = authorizationService;
|
||||
_navigationManager = navigationManager;
|
||||
_orchardServices = orchardServices;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public virtual IUser CurrentUser { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
protected override DriverResult Editor(MenuPart part, dynamic shapeHelper) {
|
||||
if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, CurrentUser, part))
|
||||
if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, _orchardServices.WorkContext.CurrentUser, part))
|
||||
return null;
|
||||
|
||||
return ContentShape("Parts_Navigation_Menu_Edit",
|
||||
@@ -31,7 +32,7 @@ namespace Orchard.Core.Navigation.Drivers {
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(MenuPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, CurrentUser, part))
|
||||
if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, _orchardServices.WorkContext.CurrentUser, part))
|
||||
return null;
|
||||
|
||||
if (string.IsNullOrEmpty(part.MenuPosition))
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
@@ -10,7 +9,6 @@ using Orchard.Core.Routable.Services;
|
||||
using Orchard.Core.Routable.ViewModels;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Services;
|
||||
using Orchard.Settings;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Core.Routable.Drivers {
|
||||
@@ -29,7 +27,6 @@ namespace Orchard.Core.Routable.Drivers {
|
||||
private const string TemplateName = "Parts/Routable.RoutePart";
|
||||
|
||||
public Localizer T { get; set; }
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
protected override string Prefix {
|
||||
get { return "Routable"; }
|
||||
@@ -70,7 +67,7 @@ namespace Orchard.Core.Routable.Drivers {
|
||||
: "";
|
||||
}
|
||||
|
||||
model.PromoteToHomePage = model.Id != 0 && part.Path != null && _routableHomePageProvider != null && CurrentSite.HomePage == _routableHomePageProvider.GetSettingValue(model.Id);
|
||||
model.PromoteToHomePage = model.Id != 0 && part.Path != null && _routableHomePageProvider != null && _services.WorkContext.CurrentSite.HomePage == _routableHomePageProvider.GetSettingValue(model.Id);
|
||||
return ContentShape("Parts_Routable_Edit",
|
||||
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));
|
||||
}
|
||||
@@ -102,7 +99,7 @@ namespace Orchard.Core.Routable.Drivers {
|
||||
part.Path = part.GetPathWithSlug(part.Slug);
|
||||
|
||||
if (part.ContentItem.Id != 0 && model.PromoteToHomePage && _routableHomePageProvider != null) {
|
||||
CurrentSite.HomePage = _routableHomePageProvider.GetSettingValue(part.ContentItem.Id);
|
||||
_services.WorkContext.CurrentSite.HomePage = _routableHomePageProvider.GetSettingValue(part.ContentItem.Id);
|
||||
}
|
||||
|
||||
return Editor(part, shapeHelper);
|
||||
|
||||
@@ -7,7 +7,7 @@ using Orchard.Mvc.Html;
|
||||
using Orchard.Services;
|
||||
|
||||
namespace Orchard.Core.Shapes {
|
||||
public class DateTimeShapes : IDependency {
|
||||
public class DateTimeShapes : ISingletonDependency {
|
||||
private readonly IClock _clock;
|
||||
|
||||
public DateTimeShapes(IClock clock) {
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace Orchard.Web {
|
||||
|
||||
protected void Application_EndRequest() {
|
||||
_host.EndRequest();
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
static void MvcSingletons(ContainerBuilder builder) {
|
||||
|
||||
@@ -3,16 +3,13 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web.Mvc;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Settings;
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Security;
|
||||
using Orchard.Comments.ViewModels;
|
||||
using Orchard.Comments.Services;
|
||||
|
||||
@@ -29,9 +26,6 @@ namespace Orchard.Comments.Controllers {
|
||||
Shape = shapeFactory;
|
||||
}
|
||||
|
||||
protected virtual IUser CurrentUser { get; [UsedImplicitly] private set; }
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
public IOrchardServices Services { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
@@ -1,37 +1,26 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.Comments.Services;
|
||||
using Orchard.Comments.ViewModels;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Security;
|
||||
using Orchard.Settings;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Comments.Controllers {
|
||||
public class CommentController : Controller {
|
||||
public IOrchardServices Services { get; set; }
|
||||
private readonly IAuthorizer _authorizer;
|
||||
private readonly ICommentService _commentService;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public CommentController(IOrchardServices services, ICommentService commentService, INotifier notifier, IAuthorizer authorizer) {
|
||||
public CommentController(IOrchardServices services, ICommentService commentService, INotifier notifier) {
|
||||
Services = services;
|
||||
_commentService = commentService;
|
||||
_notifier = notifier;
|
||||
_authorizer = authorizer;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
protected virtual IUser CurrentUser { get; [UsedImplicitly]
|
||||
private set; }
|
||||
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly]
|
||||
private set; }
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
[HttpPost]
|
||||
@@ -61,7 +50,7 @@ namespace Orchard.Comments.Controllers {
|
||||
CommentedOn = viewModel.CommentedOn
|
||||
};
|
||||
|
||||
CommentPart commentPart = _commentService.CreateComment(context, CurrentSite.As<CommentSettingsPart>().Record.ModerateComments);
|
||||
CommentPart commentPart = _commentService.CreateComment(context, Services.WorkContext.CurrentSite.As<CommentSettingsPart>().Record.ModerateComments);
|
||||
|
||||
if (commentPart.Record.Status == CommentStatus.Pending)
|
||||
Services.Notifier.Information(T("Your comment will appear after the site administrator approves it."));
|
||||
|
||||
@@ -5,7 +5,6 @@ using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Data;
|
||||
using Orchard.Logging;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Security;
|
||||
using Orchard.Services;
|
||||
|
||||
namespace Orchard.Comments.Services {
|
||||
@@ -14,55 +13,54 @@ namespace Orchard.Comments.Services {
|
||||
private readonly IRepository<ClosedCommentsRecord> _closedCommentsRepository;
|
||||
private readonly IClock _clock;
|
||||
private readonly ICommentValidator _commentValidator;
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
public CommentService(IRepository<ClosedCommentsRecord> closedCommentsRepository,
|
||||
IClock clock,
|
||||
ICommentValidator commentValidator,
|
||||
IContentManager contentManager) {
|
||||
IOrchardServices orchardServices) {
|
||||
_closedCommentsRepository = closedCommentsRepository;
|
||||
_clock = clock;
|
||||
_commentValidator = commentValidator;
|
||||
_contentManager = contentManager;
|
||||
_orchardServices = orchardServices;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
protected virtual IUser CurrentUser { get; [UsedImplicitly] private set; }
|
||||
|
||||
public IContentQuery<CommentPart, CommentPartRecord> GetComments() {
|
||||
return _contentManager
|
||||
return _orchardServices.ContentManager
|
||||
.Query<CommentPart, CommentPartRecord>();
|
||||
}
|
||||
|
||||
public IContentQuery<CommentPart, CommentPartRecord> GetComments(CommentStatus status) {
|
||||
return _contentManager
|
||||
return _orchardServices.ContentManager
|
||||
.Query<CommentPart, CommentPartRecord>()
|
||||
.Where(c => c.Status == status);
|
||||
}
|
||||
|
||||
public IContentQuery<CommentPart, CommentPartRecord> GetCommentsForCommentedContent(int id) {
|
||||
return _contentManager
|
||||
return _orchardServices.ContentManager
|
||||
.Query<CommentPart, CommentPartRecord>()
|
||||
.Where(c => c.CommentedOn == id || c.CommentedOnContainer == id);
|
||||
}
|
||||
|
||||
public IContentQuery<CommentPart, CommentPartRecord> GetCommentsForCommentedContent(int id, CommentStatus status) {
|
||||
return _contentManager
|
||||
return _orchardServices.ContentManager
|
||||
.Query<CommentPart, CommentPartRecord>()
|
||||
.Where(c => c.CommentedOn == id || c.CommentedOnContainer == id)
|
||||
.Where(ctx => ctx.Status == status);
|
||||
}
|
||||
|
||||
public CommentPart GetComment(int id) {
|
||||
return _contentManager.Get<CommentPart>(id);
|
||||
return _orchardServices.ContentManager.Get<CommentPart>(id);
|
||||
}
|
||||
|
||||
public ContentItemMetadata GetDisplayForCommentedContent(int id) {
|
||||
var content = _contentManager.Get(id);
|
||||
var content = _orchardServices.ContentManager.Get(id);
|
||||
if (content == null)
|
||||
return null;
|
||||
return _contentManager.GetItemMetadata(content);
|
||||
return _orchardServices.ContentManager.GetItemMetadata(content);
|
||||
}
|
||||
|
||||
public ContentItem GetCommentedContent(int id) {
|
||||
@@ -70,14 +68,14 @@ namespace Orchard.Comments.Services {
|
||||
}
|
||||
|
||||
public CommentPart CreateComment(CreateCommentContext context, bool moderateComments) {
|
||||
var comment = _contentManager.Create<CommentPart>("Comment");
|
||||
var comment = _orchardServices.ContentManager.Create<CommentPart>("Comment");
|
||||
|
||||
comment.Record.Author = context.Author;
|
||||
comment.Record.CommentDateUtc = _clock.UtcNow;
|
||||
comment.Record.CommentText = context.CommentText;
|
||||
comment.Record.Email = context.Email;
|
||||
comment.Record.SiteName = context.SiteName;
|
||||
comment.Record.UserName = (CurrentUser == null ? context.Author : CurrentUser.UserName);
|
||||
comment.Record.UserName = (_orchardServices.WorkContext.CurrentUser == null ? context.Author : _orchardServices.WorkContext.CurrentUser.UserName);
|
||||
comment.Record.CommentedOn = context.CommentedOn;
|
||||
|
||||
comment.Record.Status = _commentValidator.ValidateComment(comment)
|
||||
@@ -86,7 +84,7 @@ namespace Orchard.Comments.Services {
|
||||
|
||||
// store id of the next layer for large-grained operations, e.g. rss on blog
|
||||
//TODO:(rpaquay) Get rid of this (comment aspect takes care of container)
|
||||
var commentedOn = _contentManager.Get<ICommonPart>(comment.Record.CommentedOn);
|
||||
var commentedOn = _orchardServices.ContentManager.Get<ICommonPart>(comment.Record.CommentedOn);
|
||||
if (commentedOn != null && commentedOn.Container != null) {
|
||||
comment.Record.CommentedOnContainer = commentedOn.Container.ContentItem.Id;
|
||||
}
|
||||
@@ -119,7 +117,7 @@ namespace Orchard.Comments.Services {
|
||||
}
|
||||
|
||||
public void DeleteComment(int commentId) {
|
||||
_contentManager.Remove(_contentManager.Get(commentId));
|
||||
_orchardServices.ContentManager.Remove(_orchardServices.ContentManager.Get(commentId));
|
||||
}
|
||||
|
||||
public bool CommentsClosedForCommentedContent(int id) {
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
using System.Web;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Settings;
|
||||
using Orchard.UI.Notify;
|
||||
using Joel.Net;
|
||||
|
||||
@@ -15,18 +14,20 @@ namespace Orchard.Comments.Services {
|
||||
[UsedImplicitly]
|
||||
public class AkismetCommentValidator : ICommentValidator {
|
||||
private readonly INotifier _notifer;
|
||||
public AkismetCommentValidator(INotifier notifier) {
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
public AkismetCommentValidator(INotifier notifier, IOrchardServices orchardServices) {
|
||||
_notifer = notifier;
|
||||
_orchardServices = orchardServices;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
public bool ValidateComment(CommentPart commentPart) {
|
||||
CommentSettingsPartRecord commentSettingsPartRecord = CurrentSite.As<CommentSettingsPart>().Record;
|
||||
CommentSettingsPartRecord commentSettingsPartRecord = _orchardServices.WorkContext.CurrentSite.As<CommentSettingsPart>().Record;
|
||||
string akismetKey = commentSettingsPartRecord.AkismetKey;
|
||||
string akismetUrl = commentSettingsPartRecord.AkismetUrl;
|
||||
bool enableSpamProtection = commentSettingsPartRecord.EnableSpamProtection;
|
||||
|
||||
@@ -2,25 +2,24 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Email.Models;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Messaging.Services;
|
||||
using Orchard.Messaging.Models;
|
||||
|
||||
namespace Orchard.Email.Services {
|
||||
public class EmailMessagingChannel : IMessagingChannel {
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
public const string EmailService = "Email";
|
||||
|
||||
public EmailMessagingChannel() {
|
||||
public EmailMessagingChannel(IOrchardServices orchardServices) {
|
||||
_orchardServices = orchardServices;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
public ILogger Logger { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
@@ -28,7 +27,7 @@ namespace Orchard.Email.Services {
|
||||
if ( !context.Service.Equals(EmailService, StringComparison.InvariantCultureIgnoreCase) )
|
||||
return;
|
||||
|
||||
var smtpSettings = CurrentSite.As<SmtpSettingsPart>();
|
||||
var smtpSettings = _orchardServices.WorkContext.CurrentSite.As<SmtpSettingsPart>();
|
||||
|
||||
// can't process emails if the Smtp settings have not yet been set
|
||||
if ( smtpSettings == null || !smtpSettings.IsValid() ) {
|
||||
|
||||
@@ -1,33 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Messaging.Models;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Email.Models;
|
||||
using Orchard.Settings;
|
||||
using Orchard.UI.Admin.Notification;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Email.Services {
|
||||
public class MissingSettingsBanner: INotificationProvider {
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
public MissingSettingsBanner() {
|
||||
public MissingSettingsBanner(IOrchardServices orchardServices) {
|
||||
_orchardServices = orchardServices;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public IEnumerable<NotifyEntry> GetNotifications() {
|
||||
|
||||
var smtpSettings = CurrentSite.As<SmtpSettingsPart>();
|
||||
var smtpSettings = _orchardServices.WorkContext.CurrentSite.As<SmtpSettingsPart>();
|
||||
|
||||
if ( smtpSettings == null || !smtpSettings.IsValid() ) {
|
||||
yield return new NotifyEntry { Message = T("The SMTP settings needs to be configured." ), Type = NotifyType.Warning};
|
||||
}
|
||||
|
||||
var messageSettings = CurrentSite.As<MessageSettingsPart>().Record;
|
||||
var messageSettings = _orchardServices.WorkContext.CurrentSite.As<MessageSettingsPart>().Record;
|
||||
|
||||
if ( messageSettings == null || String.IsNullOrWhiteSpace(messageSettings.DefaultChannelService) ) {
|
||||
yield return new NotifyEntry { Message = T("The default channel service needs to be configured."), Type = NotifyType.Warning };
|
||||
|
||||
@@ -63,5 +63,16 @@ namespace Orchard.Experimental.Commands {
|
||||
|
||||
return "AddProfilingData completed";
|
||||
}
|
||||
|
||||
[CommandName("add users")]
|
||||
public string AddUsers() {
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
var user = _membershipService.CreateUser(new CreateUserParams("user" + i, "1234567", "user" + i + "@orchardproject.net", null, null, true));
|
||||
if (user == null)
|
||||
return "The authentication provider returned an error";
|
||||
|
||||
}
|
||||
return "Success";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Commands;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Modules.Services;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
@@ -8,10 +11,14 @@ namespace Orchard.Modules.Commands {
|
||||
public class FeatureCommands : DefaultOrchardCommandHandler {
|
||||
private readonly IModuleService _moduleService;
|
||||
private readonly INotifier _notifier;
|
||||
private readonly IFeatureManager _featureManager;
|
||||
private readonly ShellDescriptor _shellDescriptor;
|
||||
|
||||
public FeatureCommands(IModuleService moduleService, INotifier notifier) {
|
||||
public FeatureCommands(IModuleService moduleService, INotifier notifier, IFeatureManager featureManager, ShellDescriptor shellDescriptor) {
|
||||
_moduleService = moduleService;
|
||||
_notifier = notifier;
|
||||
_featureManager = featureManager;
|
||||
_shellDescriptor = shellDescriptor;
|
||||
}
|
||||
|
||||
[OrchardSwitch]
|
||||
@@ -21,25 +28,26 @@ namespace Orchard.Modules.Commands {
|
||||
[CommandName("feature list")]
|
||||
[OrchardSwitches("Summary")]
|
||||
public void List() {
|
||||
var enabled = _shellDescriptor.Features.Select(x => x.Name);
|
||||
if (Summary) {
|
||||
foreach (var feature in _moduleService.GetAvailableFeatures().OrderBy(f => f.Descriptor.Name)) {
|
||||
Context.Output.WriteLine(T("{0}, {1}", feature.Descriptor.Name, feature.IsEnabled ? T("Enabled") : T("Disabled")));
|
||||
foreach (var feature in _featureManager.GetAvailableFeatures().OrderBy(f => f.Name)) {
|
||||
Context.Output.WriteLine(T("{0}, {1}", feature.Name, enabled.Contains(feature.Name) ? T("Enabled") : T("Disabled")));
|
||||
}
|
||||
}
|
||||
else {
|
||||
Context.Output.WriteLine(T("List of available features"));
|
||||
Context.Output.WriteLine(T("--------------------------"));
|
||||
|
||||
var categories = _moduleService.GetAvailableFeatures().ToList().GroupBy(f => f.Descriptor.Category);
|
||||
var categories = _featureManager.GetAvailableFeatures().ToList().GroupBy(f => f.Category);
|
||||
foreach (var category in categories) {
|
||||
Context.Output.WriteLine(T("Category: {0}", category.Key.OrDefault(T("General"))));
|
||||
foreach (var feature in category.OrderBy(f => f.Descriptor.Name)) {
|
||||
Context.Output.WriteLine(T(" Name: {0}", feature.Descriptor.Name));
|
||||
Context.Output.WriteLine(T(" State: {0}", feature.IsEnabled ? T("Enabled") : T("Disabled")));
|
||||
Context.Output.WriteLine(T(" Description: {0}", feature.Descriptor.Description.OrDefault(T("<none>"))));
|
||||
Context.Output.WriteLine(T(" Category: {0}", feature.Descriptor.Category.OrDefault(T("<none>"))));
|
||||
Context.Output.WriteLine(T(" Module: {0}", feature.Descriptor.Extension.Name.OrDefault(T("<none>"))));
|
||||
Context.Output.WriteLine(T(" Dependencies: {0}", string.Join(", ", feature.Descriptor.Dependencies).OrDefault(T("<none>"))));
|
||||
foreach (var feature in category.OrderBy(f => f.Name)) {
|
||||
Context.Output.WriteLine(T(" Name: {0}", feature.Name));
|
||||
Context.Output.WriteLine(T(" State: {0}", enabled.Contains(feature.Name) ? T("Enabled") : T("Disabled")));
|
||||
Context.Output.WriteLine(T(" Description: {0}", feature.Description.OrDefault(T("<none>"))));
|
||||
Context.Output.WriteLine(T(" Category: {0}", feature.Category.OrDefault(T("<none>"))));
|
||||
Context.Output.WriteLine(T(" Module: {0}", feature.Extension.Name.OrDefault(T("<none>"))));
|
||||
Context.Output.WriteLine(T(" Dependencies: {0}", string.Join(", ", feature.Dependencies).OrDefault(T("<none>"))));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,7 +59,7 @@ namespace Orchard.Modules.Commands {
|
||||
Context.Output.WriteLine(T("Enabling features {0}", string.Join(",", featureNames)));
|
||||
bool listAvailableFeatures = false;
|
||||
List<string> featuresToEnable = new List<string>();
|
||||
string[] availableFeatures = _moduleService.GetAvailableFeatures().Select(x => x.Descriptor.Name).ToArray();
|
||||
string[] availableFeatures = _featureManager.GetAvailableFeatures().Select(x => x.Name).ToArray();
|
||||
foreach (var featureName in featureNames) {
|
||||
if (availableFeatures.Contains(featureName)) {
|
||||
featuresToEnable.Add(featureName);
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Modules.Services;
|
||||
using Orchard.Modules.ViewModels;
|
||||
using Orchard.Packaging.Services;
|
||||
using Orchard.Reports.Services;
|
||||
@@ -14,18 +18,27 @@ namespace Orchard.Modules.Controllers {
|
||||
private readonly IDataMigrationManager _dataMigrationManager;
|
||||
private readonly IPackageManager _packageManager;
|
||||
private readonly IReportsCoordinator _reportsCoordinator;
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly IFeatureManager _featureManager;
|
||||
private readonly ShellDescriptor _shellDescriptor;
|
||||
|
||||
public AdminController(IOrchardServices services,
|
||||
IModuleService moduleService,
|
||||
IDataMigrationManager dataMigrationManager,
|
||||
IPackageManager packageManager,
|
||||
IReportsCoordinator reportsCoordinator) {
|
||||
IReportsCoordinator reportsCoordinator,
|
||||
IExtensionManager extensionManager,
|
||||
IFeatureManager featureManager,
|
||||
ShellDescriptor shellDescriptor) {
|
||||
|
||||
Services = services;
|
||||
_moduleService = moduleService;
|
||||
_dataMigrationManager = dataMigrationManager;
|
||||
_packageManager = packageManager;
|
||||
_reportsCoordinator = reportsCoordinator;
|
||||
_extensionManager = extensionManager;
|
||||
_featureManager = featureManager;
|
||||
_shellDescriptor = shellDescriptor;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
@@ -37,7 +50,7 @@ namespace Orchard.Modules.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageModules, T("Not allowed to manage modules")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var modules = _moduleService.GetInstalledModules().ToList();
|
||||
var modules = _extensionManager.AvailableExtensions().Where(x => x.ExtensionType == "Module");
|
||||
return View(new ModulesIndexViewModel { Modules = modules });
|
||||
}
|
||||
|
||||
@@ -83,10 +96,16 @@ namespace Orchard.Modules.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var features = _moduleService.GetAvailableFeatures().Where(f => !f.Descriptor.Extension.ExtensionType.Equals("Theme", StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();
|
||||
|
||||
return View(new FeaturesViewModel { Features = features, FeaturesThatNeedUpdate = featuresThatNeedUpdate });
|
||||
var features = _featureManager.GetAvailableFeatures()
|
||||
.Where(f => !f.Extension.ExtensionType.Equals("Theme", StringComparison.OrdinalIgnoreCase))
|
||||
.Select(f=>new ModuleFeature{Descriptor=f,
|
||||
IsEnabled=_shellDescriptor.Features.Any(sf=>sf.Name==f.Name),
|
||||
NeedsUpdate=featuresThatNeedUpdate.Contains(f.Name)})
|
||||
.ToList();
|
||||
|
||||
return View(new FeaturesViewModel { Features = features });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Modules.Models {
|
||||
public class Module : IModule {
|
||||
public string ModuleName { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Version { get; set; }
|
||||
public string Author { get; set; }
|
||||
public string HomePage { get; set; }
|
||||
public string Tags { get; set; }
|
||||
public IEnumerable<FeatureDescriptor> Features { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -75,9 +75,8 @@
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Extensions\StringExtensions.cs" />
|
||||
<Compile Include="Models\DoghouseComparer.cs" />
|
||||
<Compile Include="Models\ModuleFeature.cs" />
|
||||
<Compile Include="ViewModels\ModuleFeature.cs" />
|
||||
<Compile Include="ViewModels\FeaturesViewModel.cs" />
|
||||
<Compile Include="Models\Module.cs" />
|
||||
<Compile Include="Permissions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\ModuleService.cs" />
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Environment.Descriptor;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Modules.Models;
|
||||
using Orchard.Modules.ViewModels;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Modules.Services {
|
||||
public interface IModuleService : IDependency {
|
||||
void EnableFeatures(IEnumerable<string> featureNames);
|
||||
void EnableFeatures(IEnumerable<string> featureNames, bool force);
|
||||
void DisableFeatures(IEnumerable<string> featureNames);
|
||||
void DisableFeatures(IEnumerable<string> featureNames, bool force);
|
||||
}
|
||||
|
||||
public class ModuleService : IModuleService {
|
||||
private const string ModuleExtensionType = "module";
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
@@ -32,31 +39,16 @@ namespace Orchard.Modules.Services {
|
||||
public Localizer T { get; set; }
|
||||
public IOrchardServices Services { get; set; }
|
||||
|
||||
public IModule GetModuleByName(string moduleName) {
|
||||
return _extensionManager
|
||||
.AvailableExtensions()
|
||||
.Where(e => string.Equals(e.Name, moduleName, StringComparison.OrdinalIgnoreCase))
|
||||
.Where(e => string.Equals(e.ExtensionType, ModuleExtensionType, StringComparison.OrdinalIgnoreCase))
|
||||
.Select(descriptor => AssembleModuleFromDescriptor(descriptor))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
//public IModule GetModuleByName(string moduleName) {
|
||||
// return _extensionManager
|
||||
// .AvailableExtensions()
|
||||
// .Where(e => string.Equals(e.Name, moduleName, StringComparison.OrdinalIgnoreCase))
|
||||
// .Where(e => string.Equals(e.ExtensionType, ModuleExtensionType, StringComparison.OrdinalIgnoreCase))
|
||||
// .Select(descriptor => AssembleModuleFromDescriptor(descriptor))
|
||||
// .FirstOrDefault();
|
||||
//}
|
||||
|
||||
public IEnumerable<IModule> GetInstalledModules() {
|
||||
return _extensionManager
|
||||
.AvailableExtensions()
|
||||
.Where(e => String.Equals(e.ExtensionType, ModuleExtensionType, StringComparison.OrdinalIgnoreCase))
|
||||
.Select(descriptor => AssembleModuleFromDescriptor(descriptor));
|
||||
}
|
||||
|
||||
public void InstallModule(HttpPostedFileBase file) {
|
||||
_extensionManager.InstallExtension(ModuleExtensionType, file);
|
||||
}
|
||||
|
||||
public void UninstallModule(string moduleName) {
|
||||
_extensionManager.UninstallExtension(ModuleExtensionType, moduleName);
|
||||
}
|
||||
|
||||
public IEnumerable<IModuleFeature> GetAvailableFeatures() {
|
||||
public IEnumerable<ModuleFeature> GetAvailableFeatures() {
|
||||
var enabledFeatures = _shellDescriptorManager.GetShellDescriptor().Features;
|
||||
return _extensionManager.AvailableExtensions()
|
||||
.SelectMany(m => _extensionManager.LoadFeatures(m.Features))
|
||||
@@ -114,25 +106,16 @@ namespace Orchard.Modules.Services {
|
||||
shellDescriptor.Parameters);
|
||||
}
|
||||
|
||||
public IModule GetModuleByFeatureName(string featureName) {
|
||||
return GetInstalledModules()
|
||||
.Where(
|
||||
m =>
|
||||
m.Features.FirstOrDefault(
|
||||
f => string.Equals(f.Name, featureName, StringComparison.OrdinalIgnoreCase)) !=
|
||||
null).FirstOrDefault();
|
||||
}
|
||||
|
||||
private IEnumerable<string> EnableFeature(string featureName, IEnumerable<IModuleFeature> features, bool force) {
|
||||
private IEnumerable<string> EnableFeature(string featureName, IEnumerable<ModuleFeature> features, bool force) {
|
||||
var featuresList = features.ToList();
|
||||
var getDisabledDependencies =
|
||||
new Func<string, IEnumerable<IModuleFeature>, IEnumerable<IModuleFeature>>(
|
||||
new Func<string, IEnumerable<ModuleFeature>, IEnumerable<ModuleFeature>>(
|
||||
(n, fs) => {
|
||||
var feature = fs.Single(f => f.Descriptor.Name == n);
|
||||
return feature.Descriptor.Dependencies != null
|
||||
? feature.Descriptor.Dependencies.Select(
|
||||
fn => fs.Single(f => f.Descriptor.Name == fn)).Where(f => !f.IsEnabled)
|
||||
: Enumerable.Empty<IModuleFeature>();
|
||||
: Enumerable.Empty<ModuleFeature>();
|
||||
});
|
||||
|
||||
var featuresToEnable = GetAffectedFeatures(featureName, featuresList, getDisabledDependencies);
|
||||
@@ -147,10 +130,10 @@ namespace Orchard.Modules.Services {
|
||||
return featuresToEnable;
|
||||
}
|
||||
|
||||
private IEnumerable<string> DisableFeature(string featureName, IEnumerable<IModuleFeature> features, bool force) {
|
||||
private IEnumerable<string> DisableFeature(string featureName, IEnumerable<ModuleFeature> features, bool force) {
|
||||
var featuresList = features.ToList();
|
||||
var getEnabledDependants =
|
||||
new Func<string, IEnumerable<IModuleFeature>, IEnumerable<IModuleFeature>>(
|
||||
new Func<string, IEnumerable<ModuleFeature>, IEnumerable<ModuleFeature>>(
|
||||
(n, fs) => fs.Where(f => f.IsEnabled && f.Descriptor.Dependencies != null && f.Descriptor.Dependencies.Contains(n)));
|
||||
|
||||
var featuresToDisable = GetAffectedFeatures(featureName, featuresList, getEnabledDependants);
|
||||
@@ -165,7 +148,7 @@ namespace Orchard.Modules.Services {
|
||||
return featuresToDisable;
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GetAffectedFeatures(string featureName, IEnumerable<IModuleFeature> features, Func<string, IEnumerable<IModuleFeature>, IEnumerable<IModuleFeature>> getAffectedDependencies) {
|
||||
private static IEnumerable<string> GetAffectedFeatures(string featureName, IEnumerable<ModuleFeature> features, Func<string, IEnumerable<ModuleFeature>, IEnumerable<ModuleFeature>> getAffectedDependencies) {
|
||||
var dependencies = new List<string> {featureName};
|
||||
|
||||
foreach (var dependency in getAffectedDependencies(featureName, features))
|
||||
@@ -204,30 +187,30 @@ namespace Orchard.Modules.Services {
|
||||
return localized;
|
||||
}
|
||||
|
||||
private IModule AssembleModuleFromDescriptor(ExtensionDescriptor extensionDescriptor) {
|
||||
//private IModule AssembleModuleFromDescriptor(ExtensionDescriptor extensionDescriptor) {
|
||||
|
||||
var localizer = LocalizationUtilities.Resolve(_workContextAccessor.GetContext(), String.Concat(extensionDescriptor.Location, "/", extensionDescriptor.Name, "/Module.txt"));
|
||||
// var localizer = LocalizationUtilities.Resolve(_workContextAccessor.GetContext(), String.Concat(extensionDescriptor.Location, "/", extensionDescriptor.Name, "/Module.txt"));
|
||||
|
||||
return new Module {
|
||||
ModuleName = extensionDescriptor.Name,
|
||||
DisplayName = TryLocalize("Name", extensionDescriptor.DisplayName, localizer),
|
||||
Description = TryLocalize("Description", extensionDescriptor.Description, localizer),
|
||||
Version = extensionDescriptor.Version,
|
||||
Author = TryLocalize("Author", extensionDescriptor.Author, localizer),
|
||||
HomePage = TryLocalize("Website", extensionDescriptor.WebSite, localizer),
|
||||
Tags = TryLocalize("Tags", extensionDescriptor.Tags, localizer),
|
||||
Features = extensionDescriptor.Features.Select(f => new FeatureDescriptor {
|
||||
Category = TryLocalize(f.Name + " Category", f.Category, localizer),
|
||||
Dependencies = f.Dependencies,
|
||||
Description = TryLocalize(f.Name + " Description", f.Description, localizer),
|
||||
DisplayName = TryLocalize(f.Name + " Name", f.DisplayName, localizer),
|
||||
Extension = f.Extension,
|
||||
Name = f.Name,
|
||||
})
|
||||
};
|
||||
}
|
||||
// return new Module {
|
||||
// //ModuleName = extensionDescriptor.Name,
|
||||
// //DisplayName = TryLocalize("Name", extensionDescriptor.DisplayName, localizer),
|
||||
// //Description = TryLocalize("Description", extensionDescriptor.Description, localizer),
|
||||
// //Version = extensionDescriptor.Version,
|
||||
// //Author = TryLocalize("Author", extensionDescriptor.Author, localizer),
|
||||
// //HomePage = TryLocalize("Website", extensionDescriptor.WebSite, localizer),
|
||||
// //Tags = TryLocalize("Tags", extensionDescriptor.Tags, localizer),
|
||||
// //Features = extensionDescriptor.Features.Select(f => new FeatureDescriptor {
|
||||
// // Category = TryLocalize(f.Name + " Category", f.Category, localizer),
|
||||
// // Dependencies = f.Dependencies,
|
||||
// // Description = TryLocalize(f.Name + " Description", f.Description, localizer),
|
||||
// // DisplayName = TryLocalize(f.Name + " Name", f.DisplayName, localizer),
|
||||
// // Extension = f.Extension,
|
||||
// // Name = f.Name,
|
||||
// //})
|
||||
// };
|
||||
//}
|
||||
|
||||
private static IModuleFeature AssembleModuleFromDescriptor(Feature feature, bool isEnabled) {
|
||||
private static ModuleFeature AssembleModuleFromDescriptor(Feature feature, bool isEnabled) {
|
||||
return new ModuleFeature {
|
||||
Descriptor = feature.Descriptor,
|
||||
IsEnabled = isEnabled
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Modules.ViewModels {
|
||||
public class FeaturesViewModel {
|
||||
public IEnumerable<IModuleFeature> Features { get; set; }
|
||||
public IEnumerable<string> FeaturesThatNeedUpdate { get; set; }
|
||||
public IEnumerable<ModuleFeature> Features { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Modules.Models {
|
||||
public class ModuleFeature : IModuleFeature {
|
||||
namespace Orchard.Modules.ViewModels {
|
||||
public class ModuleFeature {
|
||||
public FeatureDescriptor Descriptor { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
public bool NeedsUpdate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Modules.ViewModels {
|
||||
public class ModulesIndexViewModel {
|
||||
public IEnumerable<IModule> Modules { get; set; }
|
||||
public IEnumerable<ExtensionDescriptor> Modules { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@
|
||||
var featureId = feature.Descriptor.Name.AsFeatureId(n => T(n));
|
||||
var featureName = string.IsNullOrEmpty(feature.Descriptor.DisplayName) ? feature.Descriptor.Name : feature.Descriptor.DisplayName;
|
||||
var featureState = feature.IsEnabled ? "enabled" : "disabled";
|
||||
var featureClassName = string.Format("feature {0}", featureState + (Model.FeaturesThatNeedUpdate.Contains(feature.Descriptor.Name) ? " update" : String.Empty));
|
||||
var featureClassName = string.Format("feature {0}", featureState + (feature.NeedsUpdate ? " update" : String.Empty));
|
||||
if (feature == features.First()) {
|
||||
featureClassName += " first";
|
||||
}
|
||||
@@ -74,7 +74,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
@if(Model.FeaturesThatNeedUpdate.Contains(feature.Descriptor.Name)){
|
||||
@if(feature.NeedsUpdate){
|
||||
using (Html.BeginFormAntiForgeryPost(string.Format("{0}", Url.Action("Update", new { area = "Orchard.Modules" })), FormMethod.Post, new {@class = "inline link"})) {
|
||||
@Html.Hidden("id", feature.Descriptor.Name, new { id = "" })
|
||||
<button type="submit" class="update">@T("Update")</button>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<ul class="pageStatus" style="color:#666; margin:.6em 0 0 0;">
|
||||
<li>@T("Features: {0}", MvcHtmlString.Create(string.Join(", ", module.Features.Select(f => Html.Link(f.Name, string.Format("{0}#{1}", Url.Action("features", new { area = "Orchard.Modules" }), f.Name.AsFeatureId(n => T(n)))).ToString()).OrderBy(s => s).ToArray())))</li>
|
||||
<li> | @T("Author: {0}", !string.IsNullOrEmpty(module.Author) ? module.Author : (new []{"Bradley", "Bertrand", "Renaud", "Suha", "Sebastien", "Jon", "Nathan", "Erik", "Andre"})[(module.DisplayName.Length + (new Random()).Next()) % 7])</li>
|
||||
<li> | @T("Website: {0}", !string.IsNullOrEmpty(module.HomePage) ? module.HomePage : "http://orchardproject.net")</li>
|
||||
<li> | @T("Website: {0}", !string.IsNullOrEmpty(module.WebSite) ? module.WebSite : "http://orchardproject.net")</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -8,18 +8,19 @@ using Orchard.ContentManagement;
|
||||
using Orchard.Roles.Models;
|
||||
using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
using Orchard.Settings;
|
||||
|
||||
namespace Orchard.Roles.Services {
|
||||
[UsedImplicitly]
|
||||
public class RolesBasedAuthorizationService : IAuthorizationService {
|
||||
private readonly IRoleService _roleService;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
private readonly IAuthorizationServiceEventHandler _authorizationServiceEventHandler;
|
||||
private static readonly string[] AnonymousRole = new[] { "Anonymous" };
|
||||
private static readonly string[] AuthenticatedRole = new[] { "Authenticated" };
|
||||
|
||||
public RolesBasedAuthorizationService(IRoleService roleService, IAuthorizationServiceEventHandler authorizationServiceEventHandler) {
|
||||
public RolesBasedAuthorizationService(IRoleService roleService, IWorkContextAccessor workContextAccessor, IAuthorizationServiceEventHandler authorizationServiceEventHandler) {
|
||||
_roleService = roleService;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
_authorizationServiceEventHandler = authorizationServiceEventHandler;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
@@ -28,7 +29,6 @@ namespace Orchard.Roles.Services {
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
|
||||
public void CheckAccess(Permission permission, IUser user, IContent content) {
|
||||
@@ -47,8 +47,8 @@ namespace Orchard.Roles.Services {
|
||||
|
||||
for (var adjustmentLimiter = 0; adjustmentLimiter != 3; ++adjustmentLimiter) {
|
||||
if (!context.Granted && context.User != null) {
|
||||
if (!String.IsNullOrEmpty(CurrentSite.SuperUser) &&
|
||||
String.Equals(context.User.UserName, CurrentSite.SuperUser, StringComparison.OrdinalIgnoreCase)) {
|
||||
if (!String.IsNullOrEmpty(_workContextAccessor.GetContext().CurrentSite.SuperUser) &&
|
||||
String.Equals(context.User.UserName, _workContextAccessor.GetContext().CurrentSite.SuperUser, StringComparison.OrdinalIgnoreCase)) {
|
||||
context.Granted = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Indexing;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Search.Services;
|
||||
using Orchard.Search.ViewModels;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Search.Models;
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.UI.Notify;
|
||||
@@ -38,10 +36,8 @@ namespace Orchard.Search.Controllers {
|
||||
public Localizer T { get; set; }
|
||||
dynamic Shape { get; set; }
|
||||
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
public ActionResult Index(Pager pager, string q = "") {
|
||||
var searchFields = CurrentSite.As<SearchSettingsPart>().SearchedFields;
|
||||
var searchFields = Services.WorkContext.CurrentSite.As<SearchSettingsPart>().SearchedFields;
|
||||
|
||||
IPageOfItems<ISearchHit> searchHits;
|
||||
if (q.Trim().StartsWith("?") || q.Trim().StartsWith("*")) {
|
||||
@@ -50,7 +46,7 @@ namespace Orchard.Search.Controllers {
|
||||
}
|
||||
else {
|
||||
searchHits = _searchService.Query(q, pager.Page, pager.PageSize,
|
||||
CurrentSite.As<SearchSettingsPart>().Record.FilterCulture,
|
||||
Services.WorkContext.CurrentSite.As<SearchSettingsPart>().Record.FilterCulture,
|
||||
searchFields,
|
||||
searchHit => searchHit);
|
||||
}
|
||||
|
||||
@@ -97,6 +97,10 @@
|
||||
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
|
||||
<Name>Orchard.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Themes\Orchard.Themes.csproj">
|
||||
<Project>{CDE24A24-01D3-403C-84B9-37722E18DFB7}</Project>
|
||||
<Name>Orchard.Themes</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Widgets\Orchard.Widgets.csproj">
|
||||
<Project>{194D3CCC-1153-474D-8176-FDE8D7D0D0BD}</Project>
|
||||
<Name>Orchard.Widgets</Name>
|
||||
|
||||
@@ -28,6 +28,7 @@ using Orchard.Settings;
|
||||
using Orchard.Themes;
|
||||
using Orchard.Environment.State;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.Themes.Services;
|
||||
using Orchard.Widgets.Models;
|
||||
using Orchard.Widgets;
|
||||
|
||||
@@ -198,7 +199,7 @@ namespace Orchard.Setup.Services {
|
||||
siteSettings.Record.SiteCulture = "en-US";
|
||||
|
||||
// set site theme
|
||||
var themeService = environment.Resolve<IThemeService>();
|
||||
var themeService = environment.Resolve<ISiteThemeService>();
|
||||
themeService.SetSiteTheme("TheThemeMachine");
|
||||
|
||||
// add default culture
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Web.Routing;
|
||||
using Autofac;
|
||||
using JetBrains.Annotations;
|
||||
@@ -65,7 +64,7 @@ namespace Orchard.Setup {
|
||||
builder.RegisterType<ResourceFilter>().As<IFilterProvider>().InstancePerLifetimeScope();
|
||||
|
||||
// setup mode specific implementations of needed service interfaces
|
||||
builder.RegisterType<SafeModeThemeService>().As<IThemeService>().InstancePerLifetimeScope();
|
||||
builder.RegisterType<SafeModeThemeService>().As<IThemeManager>().InstancePerLifetimeScope();
|
||||
builder.RegisterType<SafeModeText>().As<IText>().InstancePerLifetimeScope();
|
||||
builder.RegisterType<SafeModeSiteService>().As<ISiteService>().InstancePerLifetimeScope();
|
||||
|
||||
@@ -102,38 +101,14 @@ namespace Orchard.Setup {
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
class SafeModeThemeService : IThemeService {
|
||||
class SafeModeTheme : ITheme {
|
||||
public ContentItem ContentItem { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
public string ThemeName { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Version { get; set; }
|
||||
public string Author { get; set; }
|
||||
public string HomePage { get; set; }
|
||||
public string Tags { get; set; }
|
||||
public string Zones { get; set; }
|
||||
public string BaseTheme { get; set; }
|
||||
}
|
||||
|
||||
private readonly SafeModeTheme _theme = new SafeModeTheme {
|
||||
Enabled = true,
|
||||
ThemeName = "SafeMode",
|
||||
class SafeModeThemeService : IThemeManager {
|
||||
private readonly ExtensionDescriptor _theme = new ExtensionDescriptor {
|
||||
Name = "SafeMode",
|
||||
DisplayName = "SafeMode",
|
||||
Location = "~/Themes",
|
||||
};
|
||||
|
||||
public ITheme GetThemeByName(string themeName) { return _theme; }
|
||||
public ITheme GetSiteTheme() { return _theme; }
|
||||
public void SetSiteTheme(string themeName) { }
|
||||
public ITheme GetRequestTheme(RequestContext requestContext) { return _theme; }
|
||||
public IEnumerable<ITheme> GetInstalledThemes() { return new[] { _theme }; }
|
||||
public IEnumerable<ITheme> GetEnabledThemes() { return new[] { _theme }; }
|
||||
|
||||
public void InstallTheme(HttpPostedFileBase file) { }
|
||||
public void UninstallTheme(string themeName) { }
|
||||
public void EnableTheme(string themeName) { }
|
||||
public void DisableTheme(string themeName) { }
|
||||
public ExtensionDescriptor GetRequestTheme(RequestContext requestContext) { return _theme; }
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Localization;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Tags.Models;
|
||||
using Orchard.Tags.ViewModels;
|
||||
using Orchard.Tags.Services;
|
||||
@@ -22,7 +20,6 @@ namespace Orchard.Tags.Controllers {
|
||||
}
|
||||
|
||||
public IOrchardServices Services { get; set; }
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Security;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Tags.Services;
|
||||
using Orchard.Tags.ViewModels;
|
||||
using Orchard.Themes;
|
||||
@@ -29,8 +25,6 @@ namespace Orchard.Tags.Controllers {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
|
||||
@@ -14,15 +14,16 @@ namespace Orchard.Tags.Drivers {
|
||||
private const string TemplateName = "Parts/Tags";
|
||||
private readonly ITagService _tagService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
public TagsPartDriver(ITagService tagService,
|
||||
IAuthorizationService authorizationService) {
|
||||
IAuthorizationService authorizationService,
|
||||
IOrchardServices orchardServices) {
|
||||
_tagService = tagService;
|
||||
_authorizationService = authorizationService;
|
||||
_orchardServices = orchardServices;
|
||||
}
|
||||
|
||||
public virtual IUser CurrentUser { get; set; }
|
||||
|
||||
protected override string Prefix {
|
||||
get { return "Tags"; }
|
||||
}
|
||||
@@ -33,7 +34,7 @@ namespace Orchard.Tags.Drivers {
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(TagsPart part, dynamic shapeHelper) {
|
||||
if (!_authorizationService.TryCheckAccess(Permissions.ApplyTag, CurrentUser, part))
|
||||
if (!_authorizationService.TryCheckAccess(Permissions.ApplyTag, _orchardServices.WorkContext.CurrentUser, part))
|
||||
return null;
|
||||
|
||||
return ContentShape("Parts_Tags_Edit",
|
||||
@@ -41,7 +42,7 @@ namespace Orchard.Tags.Drivers {
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(TagsPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
if (!_authorizationService.TryCheckAccess(Permissions.ApplyTag, CurrentUser, part))
|
||||
if (!_authorizationService.TryCheckAccess(Permissions.ApplyTag, _orchardServices.WorkContext.CurrentUser, part))
|
||||
return null;
|
||||
|
||||
var model = new EditTagsViewModel();
|
||||
|
||||
@@ -7,7 +7,6 @@ using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Security;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Tags.Models;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
@@ -16,27 +15,25 @@ namespace Orchard.Tags.Services {
|
||||
public class TagService : ITagService {
|
||||
private readonly IRepository<Tag> _tagRepository;
|
||||
private readonly IRepository<TagsContentItems> _tagsContentItemsRepository;
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly INotifier _notifier;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
public TagService(IRepository<Tag> tagRepository,
|
||||
IRepository<TagsContentItems> tagsContentItemsRepository,
|
||||
IContentManager contentManager,
|
||||
INotifier notifier,
|
||||
IAuthorizationService authorizationService) {
|
||||
IAuthorizationService authorizationService,
|
||||
IOrchardServices orchardServices) {
|
||||
_tagRepository = tagRepository;
|
||||
_tagsContentItemsRepository = tagsContentItemsRepository;
|
||||
_contentManager = contentManager;
|
||||
_notifier = notifier;
|
||||
_authorizationService = authorizationService;
|
||||
_orchardServices = orchardServices;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
public virtual ISite CurrentSite { get; set; }
|
||||
public virtual IUser CurrentUser { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public IEnumerable<Tag> GetTags() {
|
||||
@@ -53,7 +50,7 @@ namespace Orchard.Tags.Services {
|
||||
|
||||
public void CreateTag(string tagName) {
|
||||
if (_tagRepository.Get(x => x.TagName == tagName) == null) {
|
||||
_authorizationService.CheckAccess(Permissions.CreateTag, CurrentUser, null);
|
||||
_authorizationService.CheckAccess(Permissions.CreateTag, _orchardServices.WorkContext.CurrentUser, null);
|
||||
|
||||
Tag tag = new Tag { TagName = tagName };
|
||||
_tagRepository.Create(tag);
|
||||
@@ -104,7 +101,7 @@ namespace Orchard.Tags.Services {
|
||||
public IEnumerable<IContent> GetTaggedContentItems(int id) {
|
||||
return _tagsContentItemsRepository
|
||||
.Fetch(x => x.TagId == id)
|
||||
.Select(t =>_contentManager.Get(t.ContentItemId))
|
||||
.Select(t =>_orchardServices.ContentManager.Get(t.ContentItemId))
|
||||
.Where(c => c!= null);
|
||||
}
|
||||
|
||||
@@ -133,7 +130,7 @@ namespace Orchard.Tags.Services {
|
||||
|
||||
foreach (var tagContentItem in currentTagsForContentItem) {
|
||||
if (!newTagsForContentItem.Contains(tagContentItem.TagId)) {
|
||||
_authorizationService.CheckAccess(Permissions.ApplyTag, CurrentUser, null);
|
||||
_authorizationService.CheckAccess(Permissions.ApplyTag, _orchardServices.WorkContext.CurrentUser, null);
|
||||
|
||||
_tagsContentItemsRepository.Delete(tagContentItem);
|
||||
}
|
||||
@@ -143,7 +140,7 @@ namespace Orchard.Tags.Services {
|
||||
}
|
||||
|
||||
foreach (var newTagForContentItem in newTagsForContentItem) {
|
||||
_authorizationService.CheckAccess(Permissions.ApplyTag, CurrentUser, null);
|
||||
_authorizationService.CheckAccess(Permissions.ApplyTag, _orchardServices.WorkContext.CurrentUser, null);
|
||||
|
||||
_tagsContentItemsRepository.Create(new TagsContentItems { ContentItemId = contentItemId, TagId = newTagForContentItem });
|
||||
}
|
||||
|
||||
@@ -1,21 +1,29 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Reports.Services;
|
||||
using Orchard.Security;
|
||||
using Orchard.Themes.Preview;
|
||||
using Orchard.Themes.Services;
|
||||
using Orchard.Themes.ViewModels;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Themes.Controllers {
|
||||
[ValidateInput(false)]
|
||||
public class AdminController : Controller {
|
||||
private readonly IThemeService _themeService;
|
||||
private readonly ISiteThemeService _siteThemeService;
|
||||
private readonly IPreviewTheme _previewTheme;
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly ShellDescriptor _shellDescriptor;
|
||||
private readonly IThemeService _themeService;
|
||||
private readonly IDataMigrationManager _dataMigrationManager;
|
||||
private readonly IReportsCoordinator _reportsCoordinator;
|
||||
|
||||
@@ -23,27 +31,44 @@ namespace Orchard.Themes.Controllers {
|
||||
IDataMigrationManager dataMigraitonManager,
|
||||
IReportsCoordinator reportsCoordinator,
|
||||
IOrchardServices services,
|
||||
IThemeService themeService,
|
||||
IThemeManager themeManager,
|
||||
IFeatureManager featureManager,
|
||||
ISiteThemeService siteThemeService,
|
||||
IPreviewTheme previewTheme,
|
||||
IAuthorizer authorizer,
|
||||
INotifier notifier) {
|
||||
INotifier notifier,
|
||||
IExtensionManager extensionManager,
|
||||
ShellDescriptor shellDescriptor,
|
||||
IThemeService themeService) {
|
||||
Services = services;
|
||||
_dataMigrationManager = dataMigraitonManager;
|
||||
_reportsCoordinator = reportsCoordinator;
|
||||
_themeService = themeService;
|
||||
_siteThemeService = siteThemeService;
|
||||
_previewTheme = previewTheme;
|
||||
_extensionManager = extensionManager;
|
||||
_shellDescriptor = shellDescriptor;
|
||||
_themeService = themeService;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public IOrchardServices Services{ get; set; }
|
||||
public IOrchardServices Services { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
try {
|
||||
var themes = _themeService.GetInstalledThemes();
|
||||
var currentTheme = _themeService.GetSiteTheme();
|
||||
var currentTheme = _siteThemeService.GetSiteTheme();
|
||||
var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();
|
||||
var model = new ThemesIndexViewModel { CurrentTheme = currentTheme, Themes = themes, FeaturesThatNeedUpdate = featuresThatNeedUpdate };
|
||||
|
||||
var themes = _extensionManager.AvailableExtensions()
|
||||
.Where(d => d.ExtensionType == "Theme")
|
||||
.Select(d => new ThemeEntry {
|
||||
Descriptor = d,
|
||||
NeedsUpdate = featuresThatNeedUpdate.Contains(d.Name),
|
||||
Enabled = _shellDescriptor.Features.Any(sf => sf.Name == d.Name)
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
var model = new ThemesIndexViewModel { CurrentTheme = currentTheme, Themes = themes };
|
||||
return View(model);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
@@ -72,7 +97,7 @@ namespace Orchard.Themes.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't preview the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_previewTheme.SetPreviewTheme(null);
|
||||
_themeService.SetSiteTheme(themeName);
|
||||
_siteThemeService.SetSiteTheme(themeName);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Previewing theme failed: " + exception.Message));
|
||||
@@ -98,7 +123,8 @@ namespace Orchard.Themes.Controllers {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't enable the theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_themeService.EnableTheme(themeName);
|
||||
|
||||
_themeService.EnableThemeFeatures(themeName);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Enabling theme failed: " + exception.Message));
|
||||
@@ -111,7 +137,8 @@ namespace Orchard.Themes.Controllers {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't disable the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_themeService.DisableTheme(themeName);
|
||||
|
||||
_themeService.DisableThemeFeatures(themeName);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Disabling theme failed: " + exception.Message));
|
||||
@@ -124,7 +151,9 @@ namespace Orchard.Themes.Controllers {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't set the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_themeService.SetSiteTheme(themeName);
|
||||
|
||||
_themeService.EnableThemeFeatures(themeName);
|
||||
_siteThemeService.SetSiteTheme(themeName);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Activating theme failed: " + exception.Message));
|
||||
@@ -132,41 +161,6 @@ namespace Orchard.Themes.Controllers {
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
public ActionResult Install() {
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Install(FormCollection input) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageThemes, T("Couldn't install theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
foreach (string fileName in Request.Files) {
|
||||
HttpPostedFileBase file = Request.Files[fileName];
|
||||
_themeService.InstallTheme(file);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Installing theme failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Uninstall(string themeName) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageThemes, T("Couldn't uninstall theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_themeService.UninstallTheme(themeName);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Uninstalling theme failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Update(string themeName) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageThemes, T("Couldn't update theme")))
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
namespace Orchard.Themes.Models {
|
||||
public class Theme : ITheme {
|
||||
public bool Enabled { get; set; }
|
||||
public string ThemeName { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Version { get; set; }
|
||||
public string Author { get; set; }
|
||||
public string HomePage { get; set; }
|
||||
public string Tags { get; set; }
|
||||
public string Zones { get; set; }
|
||||
public string BaseTheme { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,6 @@
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Migrations.cs" />
|
||||
<Compile Include="Handlers\ThemeSiteSettingsPartHandler.cs" />
|
||||
<Compile Include="Models\Theme.cs" />
|
||||
<Compile Include="Models\ThemeSiteSettingsPart.cs" />
|
||||
<Compile Include="Models\ThemeSiteSettingsPartRecord.cs" />
|
||||
<Compile Include="Permissions.cs" />
|
||||
@@ -86,6 +85,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\SafeModeThemeSelector.cs" />
|
||||
<Compile Include="Services\SiteThemeSelector.cs" />
|
||||
<Compile Include="Services\SiteThemeService.cs" />
|
||||
<Compile Include="Services\ThemeService.cs" />
|
||||
<Compile Include="ViewModels\ThemesIndexViewModel.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Mvc.Filters;
|
||||
using Orchard.Themes.ViewModels;
|
||||
|
||||
namespace Orchard.Themes.Preview {
|
||||
public class PreviewThemeFilter : FilterProvider, IResultFilter {
|
||||
private readonly IThemeService _themeService;
|
||||
private readonly IThemeManager _themeManager;
|
||||
private readonly IPreviewTheme _previewTheme;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
private readonly dynamic _shapeFactory;
|
||||
private readonly IFeatureManager _featureManager;
|
||||
|
||||
public PreviewThemeFilter(
|
||||
IThemeService themeService,
|
||||
IThemeManager themeManager,
|
||||
IPreviewTheme previewTheme,
|
||||
IWorkContextAccessor workContextAccessor,
|
||||
IShapeFactory shapeFactory) {
|
||||
_themeService = themeService;
|
||||
IShapeFactory shapeFactory,
|
||||
IFeatureManager featureManager) {
|
||||
_themeManager = themeManager;
|
||||
_previewTheme = previewTheme;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
_shapeFactory = shapeFactory;
|
||||
_featureManager = featureManager;
|
||||
}
|
||||
|
||||
public void OnResultExecuting(ResultExecutingContext filterContext) {
|
||||
@@ -27,17 +31,19 @@ namespace Orchard.Themes.Preview {
|
||||
if (string.IsNullOrEmpty(previewThemeName))
|
||||
return;
|
||||
|
||||
var installedThemes = _themeService.GetInstalledThemes();
|
||||
var installedThemes = _featureManager.GetEnabledFeatures()
|
||||
.Select(x => x.Extension)
|
||||
.Where(x => x.ExtensionType == "Theme")
|
||||
.Distinct();
|
||||
|
||||
var themeListItems = installedThemes
|
||||
.Select(theme => new SelectListItem {
|
||||
Text = theme.DisplayName,
|
||||
Value = theme.ThemeName,
|
||||
Selected = theme.ThemeName == previewThemeName
|
||||
Value = theme.Name,
|
||||
Selected = theme.Name == previewThemeName
|
||||
})
|
||||
.ToList();
|
||||
|
||||
|
||||
|
||||
_workContextAccessor.GetContext(filterContext).Layout.Zones["Body"].Add(_shapeFactory.ThemePreview(Themes: themeListItems), ":before");
|
||||
}
|
||||
|
||||
|
||||
@@ -2,17 +2,21 @@
|
||||
using System.Web.Routing;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Themes.Models;
|
||||
|
||||
namespace Orchard.Themes.Services {
|
||||
[UsedImplicitly]
|
||||
public class SiteThemeSelector : IThemeSelector {
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
public SiteThemeSelector(IOrchardServices orchardServices) {
|
||||
_orchardServices = orchardServices;
|
||||
}
|
||||
|
||||
public ThemeSelectorResult GetTheme(RequestContext context) {
|
||||
string currentThemeName = CurrentSite.As<ThemeSiteSettingsPart>().Record.CurrentThemeName;
|
||||
string currentThemeName = _orchardServices.WorkContext.CurrentSite.As<ThemeSiteSettingsPart>().Record.CurrentThemeName;
|
||||
|
||||
if (String.IsNullOrEmpty(currentThemeName)) {
|
||||
return null;
|
||||
@@ -21,4 +25,5 @@ namespace Orchard.Themes.Services {
|
||||
return new ThemeSelectorResult { Priority = -5, ThemeName = currentThemeName };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Themes.Models;
|
||||
|
||||
namespace Orchard.Themes.Services {
|
||||
public interface ISiteThemeService : IDependency {
|
||||
ExtensionDescriptor GetSiteTheme();
|
||||
void SetSiteTheme(string themeName);
|
||||
}
|
||||
|
||||
public class SiteThemeService : ISiteThemeService {
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
|
||||
public SiteThemeService(IExtensionManager extensionManager, IWorkContextAccessor workContextAccessor) {
|
||||
_extensionManager = extensionManager;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public ExtensionDescriptor GetSiteTheme() {
|
||||
var site = _workContextAccessor.GetContext().CurrentSite;
|
||||
string currentThemeName = site.As<ThemeSiteSettingsPart>().CurrentThemeName;
|
||||
|
||||
if (string.IsNullOrEmpty(currentThemeName)) {
|
||||
return null;
|
||||
}
|
||||
return _extensionManager.GetExtension(currentThemeName);
|
||||
}
|
||||
|
||||
public void SetSiteTheme(string themeName) {
|
||||
var site = _workContextAccessor.GetContext().CurrentSite;
|
||||
site.As<ThemeSiteSettingsPart>().Record.CurrentThemeName = themeName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,74 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Routing;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Environment.Descriptor;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Modules;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Themes.Models;
|
||||
|
||||
namespace Orchard.Themes.Services {
|
||||
public interface IThemeService : IDependency {
|
||||
void DisableThemeFeatures(string themeName);
|
||||
void EnableThemeFeatures(string themeName);
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
public class ThemeService : IThemeService {
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly IFeatureManager _featureManager;
|
||||
private readonly IEnumerable<IThemeSelector> _themeSelectors;
|
||||
private readonly IModuleService _moduleService;
|
||||
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
private readonly ShellDescriptor _shellDescriptor;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
private readonly IShellDescriptorManager _shellDescriptorManager;
|
||||
|
||||
public ThemeService(
|
||||
IShellDescriptorManager shellDescriptorManager,
|
||||
IExtensionManager extensionManager,
|
||||
IFeatureManager featureManager,
|
||||
IEnumerable<IThemeSelector> themeSelectors,
|
||||
IModuleService moduleService,
|
||||
|
||||
IWorkContextAccessor workContextAccessor,
|
||||
ShellDescriptor shellDescriptor) {
|
||||
ShellDescriptor shellDescriptor,
|
||||
IOrchardServices orchardServices) {
|
||||
_shellDescriptorManager = shellDescriptorManager;
|
||||
_extensionManager = extensionManager;
|
||||
_featureManager = featureManager;
|
||||
_themeSelectors = themeSelectors;
|
||||
_moduleService = moduleService;
|
||||
|
||||
_workContextAccessor = workContextAccessor;
|
||||
_shellDescriptor = shellDescriptor;
|
||||
_orchardServices = orchardServices;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
public ITheme GetSiteTheme() {
|
||||
string currentThemeName = CurrentSite.As<ThemeSiteSettingsPart>().CurrentThemeName;
|
||||
|
||||
if (string.IsNullOrEmpty(currentThemeName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return GetThemeByName(currentThemeName);
|
||||
}
|
||||
|
||||
public void SetSiteTheme(string themeName) {
|
||||
if (DoEnableTheme(themeName)) {
|
||||
CurrentSite.As<ThemeSiteSettingsPart>().Record.CurrentThemeName = themeName;
|
||||
}
|
||||
}
|
||||
|
||||
public void EnableTheme(string themeName) {
|
||||
DoEnableTheme(themeName);
|
||||
}
|
||||
|
||||
public void DisableTheme(string themeName) {
|
||||
DisableThemeFeatures(themeName);
|
||||
}
|
||||
|
||||
private bool AllBaseThemesAreInstalled(string baseThemeName) {
|
||||
var themesSeen = new List<string>();
|
||||
@@ -78,7 +64,7 @@ namespace Orchard.Themes.Services {
|
||||
throw new InvalidOperationException(T("The theme \"{0}\" was already seen - looks like we're going around in circles.", baseThemeName).Text);
|
||||
themesSeen.Add(baseThemeName);
|
||||
|
||||
var baseTheme = GetThemeByName(baseThemeName);
|
||||
var baseTheme = _extensionManager.GetExtension(baseThemeName);
|
||||
if (baseTheme == null)
|
||||
return false;
|
||||
baseThemeName = baseTheme.BaseTheme;
|
||||
@@ -87,12 +73,12 @@ namespace Orchard.Themes.Services {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void DisableThemeFeatures(string themeName) {
|
||||
public void DisableThemeFeatures(string themeName) {
|
||||
var themes = new Queue<string>();
|
||||
while (themeName != null) {
|
||||
if (themes.Contains(themeName))
|
||||
throw new InvalidOperationException(T("The theme \"{0}\" is already in the stack of themes that need features disabled.", themeName).Text);
|
||||
var theme = GetThemeByName(themeName);
|
||||
var theme = _extensionManager.GetExtension(themeName);
|
||||
if (theme == null)
|
||||
break;
|
||||
themes.Enqueue(themeName);
|
||||
@@ -100,28 +86,27 @@ namespace Orchard.Themes.Services {
|
||||
themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
|
||||
? theme.BaseTheme
|
||||
: null;
|
||||
|
||||
}
|
||||
|
||||
while (themes.Count > 0)
|
||||
_moduleService.DisableFeatures(new[] { themes.Dequeue() });
|
||||
_featureManager.DisableFeatures(new[] { themes.Dequeue() });
|
||||
}
|
||||
|
||||
private void EnableThemeFeatures(string themeName) {
|
||||
public void EnableThemeFeatures(string themeName) {
|
||||
var themes = new Stack<string>();
|
||||
while(themeName != null) {
|
||||
if (themes.Contains(themeName))
|
||||
throw new InvalidOperationException(T("The theme \"{0}\" is already in the stack of themes that need features enabled.", themeName).Text);
|
||||
themes.Push(themeName);
|
||||
|
||||
var theme = GetThemeByName(themeName);
|
||||
var theme = _extensionManager.GetExtension(themeName);
|
||||
themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
|
||||
? theme.BaseTheme
|
||||
: null;
|
||||
}
|
||||
|
||||
while (themes.Count > 0)
|
||||
_moduleService.EnableFeatures(new[] {themes.Pop()});
|
||||
_featureManager.EnableFeatures(new[] {themes.Pop()});
|
||||
}
|
||||
|
||||
private bool DoEnableTheme(string themeName) {
|
||||
@@ -129,7 +114,7 @@ namespace Orchard.Themes.Services {
|
||||
return false;
|
||||
|
||||
//todo: (heskew) need messages given in addition to all of these early returns so something meaningful can be presented to the user
|
||||
var themeToEnable = GetThemeByName(themeName);
|
||||
var themeToEnable = _extensionManager.GetExtension(themeName);
|
||||
if (themeToEnable == null)
|
||||
return false;
|
||||
|
||||
@@ -139,11 +124,11 @@ namespace Orchard.Themes.Services {
|
||||
return false;
|
||||
|
||||
// enable all theme features
|
||||
EnableThemeFeatures(themeToEnable.ThemeName);
|
||||
EnableThemeFeatures(themeToEnable.Name);
|
||||
return true;
|
||||
}
|
||||
|
||||
public ITheme GetRequestTheme(RequestContext requestContext) {
|
||||
public ExtensionDescriptor GetRequestTheme(RequestContext requestContext) {
|
||||
var requestTheme = _themeSelectors
|
||||
.Select(x => x.GetTheme(requestContext))
|
||||
.Where(x => x != null)
|
||||
@@ -153,46 +138,30 @@ namespace Orchard.Themes.Services {
|
||||
return null;
|
||||
|
||||
foreach (var theme in requestTheme) {
|
||||
var t = GetThemeByName(theme.ThemeName);
|
||||
if (t != null && t.Enabled)
|
||||
var t = _extensionManager.GetExtension(theme.ThemeName);
|
||||
if (t != null)
|
||||
return t;
|
||||
}
|
||||
|
||||
return GetThemeByName("SafeMode");
|
||||
}
|
||||
|
||||
public ITheme GetThemeByName(string name) {
|
||||
foreach (var descriptor in _extensionManager.AvailableExtensions()) {
|
||||
if (string.Equals(descriptor.Name, name, StringComparison.OrdinalIgnoreCase)) {
|
||||
return CreateTheme(descriptor);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return _extensionManager.GetExtension("SafeMode");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads only installed themes
|
||||
/// </summary>
|
||||
public IEnumerable<ITheme> GetInstalledThemes() {
|
||||
public IEnumerable<ExtensionDescriptor> GetInstalledThemes() {
|
||||
return GetThemes(_extensionManager.AvailableExtensions());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads only enabled themes
|
||||
/// </summary>
|
||||
public IEnumerable<ITheme> GetEnabledThemes() {
|
||||
return GetThemes(_extensionManager.EnabledExtensions(_shellDescriptor));
|
||||
}
|
||||
|
||||
private IEnumerable<ITheme> GetThemes(IEnumerable<ExtensionDescriptor> extensions) {
|
||||
var themes = new List<ITheme>();
|
||||
private IEnumerable<ExtensionDescriptor> GetThemes(IEnumerable<ExtensionDescriptor> extensions) {
|
||||
var themes = new List<ExtensionDescriptor>();
|
||||
foreach (var descriptor in extensions) {
|
||||
|
||||
if (!string.Equals(descriptor.ExtensionType, "Theme", StringComparison.OrdinalIgnoreCase)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ITheme theme = CreateTheme(descriptor);
|
||||
ExtensionDescriptor theme = descriptor;
|
||||
|
||||
if (!theme.Tags.Contains("hidden")) {
|
||||
themes.Add(theme);
|
||||
@@ -201,14 +170,6 @@ namespace Orchard.Themes.Services {
|
||||
return themes;
|
||||
}
|
||||
|
||||
public void InstallTheme(HttpPostedFileBase file) {
|
||||
_extensionManager.InstallExtension("Theme", file);
|
||||
}
|
||||
|
||||
public void UninstallTheme(string themeName) {
|
||||
_extensionManager.UninstallExtension("Theme", themeName);
|
||||
}
|
||||
|
||||
private static string TryLocalize(string key, string original, Localizer localizer) {
|
||||
var localized = localizer(key).Text;
|
||||
|
||||
@@ -225,22 +186,23 @@ namespace Orchard.Themes.Services {
|
||||
_shellDescriptorManager.GetShellDescriptor().Features.Any(sf => sf.Name == descriptor.Name);
|
||||
}
|
||||
|
||||
private ITheme CreateTheme(ExtensionDescriptor descriptor) {
|
||||
//private ITheme CreateTheme(ExtensionDescriptor descriptor) {
|
||||
|
||||
var localizer = LocalizationUtilities.Resolve(_workContextAccessor.GetContext(), String.Concat(descriptor.Location, "/", descriptor.Name, "/Theme.txt"));
|
||||
// var localizer = LocalizationUtilities.Resolve(_workContextAccessor.GetContext(), String.Concat(descriptor.Location, "/", descriptor.Name, "/Theme.txt"));
|
||||
|
||||
return new Theme {
|
||||
Author = TryLocalize("Author", descriptor.Author, localizer) ?? "",
|
||||
Description = TryLocalize("Description", descriptor.Description, localizer) ?? "",
|
||||
DisplayName = TryLocalize("Name", descriptor.DisplayName, localizer) ?? "",
|
||||
HomePage = TryLocalize("Website", descriptor.WebSite, localizer) ?? "",
|
||||
ThemeName = descriptor.Name,
|
||||
Version = descriptor.Version ?? "",
|
||||
Tags = TryLocalize("Tags", descriptor.Tags, localizer) ?? "",
|
||||
Zones = descriptor.Zones ?? "",
|
||||
BaseTheme = descriptor.BaseTheme ?? "",
|
||||
Enabled = IsThemeEnabled(descriptor)
|
||||
};
|
||||
}
|
||||
// return new Theme {
|
||||
// //Author = TryLocalize("Author", descriptor.Author, localizer) ?? "",
|
||||
// //Description = TryLocalize("Description", descriptor.Description, localizer) ?? "",
|
||||
// DisplayName = TryLocalize("Name", descriptor.DisplayName, localizer) ?? "",
|
||||
// //HomePage = TryLocalize("Website", descriptor.WebSite, localizer) ?? "",
|
||||
// ThemeName = descriptor.Name,
|
||||
// //Version = descriptor.Version ?? "",
|
||||
// Tags = TryLocalize("Tags", descriptor.Tags, localizer) ?? "",
|
||||
// Zones = descriptor.Zones ?? "",
|
||||
// BaseTheme = descriptor.BaseTheme ?? "",
|
||||
// Enabled = IsThemeEnabled(descriptor)
|
||||
// };
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Themes.ViewModels {
|
||||
public class ThemesIndexViewModel {
|
||||
public ITheme CurrentTheme { get; set; }
|
||||
public IEnumerable<ITheme> Themes { get; set; }
|
||||
public IEnumerable<string> FeaturesThatNeedUpdate { get; set; }
|
||||
public ExtensionDescriptor CurrentTheme { get; set; }
|
||||
public IEnumerable<ThemeEntry> Themes { get; set; }
|
||||
}
|
||||
|
||||
public class ThemeEntry {
|
||||
public ExtensionDescriptor Descriptor { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
public bool NeedsUpdate { get; set; }
|
||||
|
||||
public string ThemeName { get { return Descriptor.Name; } }
|
||||
public string DisplayName { get { return Descriptor.DisplayName; } }
|
||||
public string ThemePath(string path) {
|
||||
return Descriptor.Location + "/" + Descriptor.Name + path;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
<p>
|
||||
@T("Version:") @Model.CurrentTheme.Version<br />
|
||||
@Model.CurrentTheme.Description<br />
|
||||
@Model.CurrentTheme.HomePage
|
||||
@Model.CurrentTheme.WebSite
|
||||
</p>
|
||||
|
||||
@Html.ActionLink(T("Install a new Theme").ToString(), "Install", null, new { @class = "button primaryAction" })
|
||||
@@ -24,11 +24,11 @@
|
||||
<h2>@T("Available Themes")</h2>
|
||||
<ul class="templates">
|
||||
@foreach (var theme in Model.Themes) {
|
||||
if (Model.CurrentTheme == null || theme.ThemeName != Model.CurrentTheme.ThemeName) {
|
||||
if (Model.CurrentTheme == null || theme.ThemeName != Model.CurrentTheme.Name) {
|
||||
<li>
|
||||
<div>
|
||||
<h3>@theme.DisplayName</h3>
|
||||
@Html.Image(Href(Html.ThemePath(theme, "/Theme.png")), Html.Encode(theme.DisplayName), null)
|
||||
@Html.Image(Href(theme.ThemePath("/Theme.png")), Html.Encode(theme.DisplayName), null)
|
||||
@using (Html.BeginFormAntiForgeryPost(Url.Action(theme.Enabled ? "Disable" : "Enable"), FormMethod.Post, new { @class = "inline" })) {
|
||||
@Html.Hidden("themeName", theme.ThemeName)
|
||||
<button type="submit" title="@T(theme.Enabled ? "Disable" : "Enable")">@T(theme.Enabled ? "Disable" : "Enable")</button>
|
||||
@@ -41,13 +41,13 @@
|
||||
@Html.Hidden("themeName", theme.ThemeName)
|
||||
<button type="submit" title="@T("Preview")">@T("Preview")</button>
|
||||
}
|
||||
<h5>@T("By") @theme.Author</h5>
|
||||
<h5>@T("By") @theme.Descriptor.Author</h5>
|
||||
<p>
|
||||
@T("Version:") @theme.Version<br />
|
||||
@theme.Description<br />
|
||||
@theme.HomePage
|
||||
@T("Version:") @theme.Descriptor.Version<br />
|
||||
@theme.Descriptor.Description<br />
|
||||
@theme.Descriptor.WebSite
|
||||
</p>
|
||||
@if(Model.FeaturesThatNeedUpdate.Contains(theme.ThemeName)){
|
||||
@if(theme.NeedsUpdate){
|
||||
using (Html.BeginFormAntiForgeryPost(Url.Action("Update"), FormMethod.Post, new { @class = "inline link" })) {
|
||||
@Html.Hidden("themeName", theme.ThemeName)
|
||||
<button type="submit" class="update">@T("Update")</button> <br/>
|
||||
|
||||
@@ -10,8 +10,6 @@ using Orchard.Security;
|
||||
using Orchard.Themes;
|
||||
using Orchard.Users.Services;
|
||||
using Orchard.Users.ViewModels;
|
||||
using Orchard.Settings;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Users.Models;
|
||||
|
||||
@@ -21,21 +19,23 @@ namespace Orchard.Users.Controllers {
|
||||
private readonly IAuthenticationService _authenticationService;
|
||||
private readonly IMembershipService _membershipService;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
public AccountController(
|
||||
IAuthenticationService authenticationService,
|
||||
IMembershipService membershipService,
|
||||
IUserService userService) {
|
||||
IUserService userService,
|
||||
IOrchardServices orchardServices) {
|
||||
_authenticationService = authenticationService;
|
||||
_membershipService = membershipService;
|
||||
_userService = userService;
|
||||
_orchardServices = orchardServices;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
public ActionResult AccessDenied() {
|
||||
var returnUrl = Request.QueryString["ReturnUrl"];
|
||||
@@ -93,7 +93,7 @@ namespace Orchard.Users.Controllers {
|
||||
|
||||
public ActionResult Register() {
|
||||
// ensure users can register
|
||||
var registrationSettings = CurrentSite.As<RegistrationSettingsPart>();
|
||||
var registrationSettings = _orchardServices.WorkContext.CurrentSite.As<RegistrationSettingsPart>();
|
||||
if ( !registrationSettings.UsersCanRegister ) {
|
||||
return HttpNotFound();
|
||||
}
|
||||
@@ -106,7 +106,7 @@ namespace Orchard.Users.Controllers {
|
||||
[HttpPost]
|
||||
public ActionResult Register(string userName, string email, string password, string confirmPassword) {
|
||||
// ensure users can register
|
||||
var registrationSettings = CurrentSite.As<RegistrationSettingsPart>();
|
||||
var registrationSettings = _orchardServices.WorkContext.CurrentSite.As<RegistrationSettingsPart>();
|
||||
if ( !registrationSettings.UsersCanRegister ) {
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Security;
|
||||
using Orchard.Settings;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Users.Models;
|
||||
using Orchard.Users.Services;
|
||||
@@ -33,7 +31,6 @@ namespace Orchard.Users.Controllers {
|
||||
dynamic Shape { get; set; }
|
||||
public IOrchardServices Services { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageUsers, T("Not authorized to list users")))
|
||||
@@ -201,7 +198,7 @@ namespace Orchard.Users.Controllers {
|
||||
var user = Services.ContentManager.Get(id);
|
||||
|
||||
if ( user != null ) {
|
||||
if ( CurrentSite.SuperUser.Equals(user.As<UserPart>().UserName) ) {
|
||||
if (Services.WorkContext.CurrentSite.SuperUser.Equals(user.As<UserPart>().UserName) ) {
|
||||
Services.Notifier.Error(T("Super user can't be moderated"));
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -11,7 +11,6 @@ using Orchard.ContentManagement;
|
||||
using Orchard.Security;
|
||||
using Orchard.Users.Events;
|
||||
using Orchard.Users.Models;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Messaging.Services;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -19,19 +18,18 @@ namespace Orchard.Users.Services {
|
||||
[UsedImplicitly]
|
||||
public class MembershipService : IMembershipService {
|
||||
private static readonly TimeSpan DelayToValidate = new TimeSpan(7, 0, 0, 0); // one week to validate email
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
private readonly IMessageManager _messageManager;
|
||||
private readonly IEnumerable<IUserEventHandler> _userEventHandlers;
|
||||
|
||||
public MembershipService(IContentManager contentManager, IMessageManager messageManager, IEnumerable<IUserEventHandler> userEventHandlers) {
|
||||
_contentManager = contentManager;
|
||||
public MembershipService(IOrchardServices orchardServices, IMessageManager messageManager, IEnumerable<IUserEventHandler> userEventHandlers) {
|
||||
_orchardServices = orchardServices;
|
||||
_messageManager = messageManager;
|
||||
_userEventHandlers = userEventHandlers;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
public MembershipSettings GetSettings() {
|
||||
var settings = new MembershipSettings();
|
||||
@@ -42,9 +40,9 @@ namespace Orchard.Users.Services {
|
||||
public IUser CreateUser(CreateUserParams createUserParams) {
|
||||
Logger.Information("CreateUser {0} {1}", createUserParams.Username, createUserParams.Email);
|
||||
|
||||
var registrationSettings = CurrentSite.As<RegistrationSettingsPart>();
|
||||
var registrationSettings = _orchardServices.WorkContext.CurrentSite.As<RegistrationSettingsPart>();
|
||||
|
||||
var user = _contentManager.New<UserPart>("User");
|
||||
var user = _orchardServices.ContentManager.New<UserPart>("User");
|
||||
|
||||
user.Record.UserName = createUserParams.Username;
|
||||
user.Record.Email = createUserParams.Email;
|
||||
@@ -71,14 +69,14 @@ namespace Orchard.Users.Services {
|
||||
return null;
|
||||
}
|
||||
|
||||
_contentManager.Create(user);
|
||||
_orchardServices.ContentManager.Create(user);
|
||||
|
||||
foreach ( var userEventHandler in _userEventHandlers ) {
|
||||
userEventHandler.Created(userContext);
|
||||
}
|
||||
|
||||
if ( registrationSettings != null && registrationSettings.UsersAreModerated && registrationSettings.NotifyModeration && !createUserParams.IsApproved ) {
|
||||
var superUser = GetUser(CurrentSite.SuperUser);
|
||||
var superUser = GetUser(_orchardServices.WorkContext.CurrentSite.SuperUser);
|
||||
if(superUser != null)
|
||||
_messageManager.Send(superUser.ContentItem.Record, MessageTypes.Moderation);
|
||||
}
|
||||
@@ -137,16 +135,16 @@ namespace Orchard.Users.Services {
|
||||
public IUser GetUser(string username) {
|
||||
var lowerName = username == null ? "" : username.ToLower();
|
||||
|
||||
return _contentManager.Query<UserPart, UserPartRecord>().Where(u => u.NormalizedUserName == lowerName).List().FirstOrDefault();
|
||||
return _orchardServices.ContentManager.Query<UserPart, UserPartRecord>().Where(u => u.NormalizedUserName == lowerName).List().FirstOrDefault();
|
||||
}
|
||||
|
||||
public IUser ValidateUser(string userNameOrEmail, string password) {
|
||||
var lowerName = userNameOrEmail == null ? "" : userNameOrEmail.ToLower();
|
||||
|
||||
var user = _contentManager.Query<UserPart, UserPartRecord>().Where(u => u.NormalizedUserName == lowerName).List().FirstOrDefault();
|
||||
var user = _orchardServices.ContentManager.Query<UserPart, UserPartRecord>().Where(u => u.NormalizedUserName == lowerName).List().FirstOrDefault();
|
||||
|
||||
if(user == null)
|
||||
user = _contentManager.Query<UserPart, UserPartRecord>().Where(u => u.Email == lowerName).List().FirstOrDefault();
|
||||
user = _orchardServices.ContentManager.Query<UserPart, UserPartRecord>().Where(u => u.Email == lowerName).List().FirstOrDefault();
|
||||
|
||||
if ( user == null || ValidatePassword(user.As<UserPart>().Record, password) == false )
|
||||
return null;
|
||||
|
||||
@@ -38,6 +38,10 @@
|
||||
<HintPath>..\..\..\..\lib\claysharp\ClaySharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Microsoft.Scripting, Version=1.1.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\lib\dlr\Microsoft.Scripting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Web.DynamicData" />
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.UI.Widgets;
|
||||
|
||||
namespace Orchard.Widgets.RuleEngine {
|
||||
|
||||
@@ -14,23 +14,24 @@ namespace Orchard.Widgets.RuleEngine {
|
||||
}
|
||||
|
||||
public bool Matches(string expression) {
|
||||
_scriptingManager.SetVariable("callbacks", new CallbackApi(this));
|
||||
dynamic execContext = _scriptingManager.ExecuteExpression(@"
|
||||
object execContextType = _scriptingManager.ExecuteExpression(@"
|
||||
class ExecContext
|
||||
def initialize(callbacks)
|
||||
def execute(callbacks, text)
|
||||
@callbacks = callbacks;
|
||||
end
|
||||
|
||||
def execute(text)
|
||||
instance_eval(text.to_s);
|
||||
temp = instance_eval(text.to_s);
|
||||
@callbacks = 0;
|
||||
return temp;
|
||||
end
|
||||
|
||||
def method_missing(name, *args, &block)
|
||||
@callbacks.send(name, args, &block);
|
||||
end
|
||||
end
|
||||
ExecContext.new(callbacks)");
|
||||
return execContext.execute(expression);
|
||||
ExecContext
|
||||
");
|
||||
|
||||
object execContext = _scriptingManager.ExecuteOperation(ops => ops.CreateInstance(execContextType));
|
||||
return _scriptingManager.ExecuteOperation(ops => ops.InvokeMember(execContext, "execute", new CallbackApi(this), expression));
|
||||
}
|
||||
|
||||
public class CallbackApi {
|
||||
@@ -46,7 +47,7 @@ namespace Orchard.Widgets.RuleEngine {
|
||||
}
|
||||
|
||||
private object Evaluate(string name, IList<object> args) {
|
||||
RuleContext ruleContext = new RuleContext {FunctionName = name, Arguments = args.ToArray()};
|
||||
RuleContext ruleContext = new RuleContext { FunctionName = name, Arguments = args.ToArray() };
|
||||
|
||||
foreach (var ruleProvider in _ruleProviders) {
|
||||
ruleProvider.Process(ruleContext);
|
||||
|
||||
@@ -3,23 +3,22 @@ using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Themes;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Widgets.Models;
|
||||
|
||||
namespace Orchard.Widgets.Services {
|
||||
|
||||
[UsedImplicitly]
|
||||
public class WidgetsService : IWidgetsService {
|
||||
private readonly IThemeService _themeService;
|
||||
private readonly IFeatureManager _featureManager;
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public WidgetsService(
|
||||
IContentManager contentManager,
|
||||
IThemeService themeService) {
|
||||
IFeatureManager featureManager) {
|
||||
|
||||
_contentManager = contentManager;
|
||||
_themeService = themeService;
|
||||
_featureManager = featureManager;
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetWidgetTypes() {
|
||||
@@ -41,15 +40,12 @@ namespace Orchard.Widgets.Services {
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetZones() {
|
||||
HashSet<string> zones = new HashSet<string>();
|
||||
|
||||
foreach (var theme in _themeService.GetEnabledThemes().Where(theme => theme.Zones != null && !theme.Zones.Trim().Equals(string.Empty))) {
|
||||
foreach (string zone in theme.Zones.Split(',').Where(zone => !zones.Contains(zone))) {
|
||||
zones.Add(zone.Trim());
|
||||
}
|
||||
}
|
||||
|
||||
return zones;
|
||||
return _featureManager.GetEnabledFeatures()
|
||||
.Select(x => x.Extension)
|
||||
.Where(x => x.ExtensionType == "Theme")
|
||||
.SelectMany(x => x.Zones.Split(','))
|
||||
.Distinct()
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public IEnumerable<WidgetPart> GetWidgets(int layerId) {
|
||||
|
||||
BIN
src/Orchard.Web/Themes/Primus/Theme.png
Normal file
BIN
src/Orchard.Web/Themes/Primus/Theme.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
7
src/Orchard.Web/Themes/Primus/Theme.txt
Normal file
7
src/Orchard.Web/Themes/Primus/Theme.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
Name: Primus
|
||||
Author: Lou
|
||||
Description: desc
|
||||
Version: 0.1
|
||||
Website: http://whereslou.com
|
||||
Zones: Main, Sidebar
|
||||
BaseTheme: TheThemeMachine
|
||||
BIN
src/Orchard.Web/Themes/Secundus/Theme.png
Normal file
BIN
src/Orchard.Web/Themes/Secundus/Theme.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
8
src/Orchard.Web/Themes/Secundus/Theme.txt
Normal file
8
src/Orchard.Web/Themes/Secundus/Theme.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
Name: Secundus
|
||||
Author: Lou
|
||||
Description: desc
|
||||
Version: 0.1
|
||||
Website: http://whereslou.com
|
||||
Zones: Main, Sidebar
|
||||
BaseTheme: Primus
|
||||
|
||||
@@ -49,6 +49,10 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Primus\Theme.png" />
|
||||
<Content Include="Primus\Theme.txt" />
|
||||
<Content Include="Secundus\Theme.png" />
|
||||
<Content Include="Secundus\Theme.txt" />
|
||||
<Content Include="TheAdmin\Scripts\admin.js" />
|
||||
<Content Include="TheAdmin\Styles\ie.css" />
|
||||
<Content Include="TheAdmin\Styles\images\menuClosed.gif" />
|
||||
|
||||
@@ -14,14 +14,14 @@ namespace Orchard.ContentManagement {
|
||||
private readonly Lazy<IEnumerable<IContentHandler>> _handlers;
|
||||
private readonly IShapeFactory _shapeFactory;
|
||||
private readonly IShapeTableManager _shapeTableManager;
|
||||
private readonly Lazy<IThemeService> _themeService;
|
||||
private readonly Lazy<IThemeManager> _themeService;
|
||||
private readonly RequestContext _requestContext;
|
||||
|
||||
public DefaultContentDisplay(
|
||||
Lazy<IEnumerable<IContentHandler>> handlers,
|
||||
IShapeFactory shapeFactory,
|
||||
IShapeTableManager shapeTableManager,
|
||||
Lazy<IThemeService> themeService,
|
||||
Lazy<IThemeManager> themeService,
|
||||
RequestContext requestContext) {
|
||||
_handlers = handlers;
|
||||
_shapeFactory = shapeFactory;
|
||||
@@ -99,7 +99,7 @@ namespace Orchard.ContentManagement {
|
||||
//var workContext = _workContextAccessor.GetContext();
|
||||
//var theme = workContext.CurrentTheme;
|
||||
var theme = _themeService.Value.GetRequestTheme(_requestContext);
|
||||
var shapeTable = _shapeTableManager.GetShapeTable(theme.ThemeName);
|
||||
var shapeTable = _shapeTableManager.GetShapeTable(theme.Name);
|
||||
ShapeDescriptor descriptor;
|
||||
if (shapeTable.Descriptors.TryGetValue(partShapeType, out descriptor)) {
|
||||
var placementContext = new ShapePlacementContext {
|
||||
|
||||
@@ -86,8 +86,7 @@ namespace Orchard.Data.Migration {
|
||||
Logger.Information("Updating feature: {0}", feature);
|
||||
|
||||
// proceed with dependent features first, whatever the module it's in
|
||||
var dependencies = ShellStateCoordinator.OrderByDependencies(_extensionManager.AvailableExtensions()
|
||||
.SelectMany(ext => ext.Features))
|
||||
var dependencies = _extensionManager.AvailableFeatures()
|
||||
.Where(f => String.Equals(f.Name, feature, StringComparison.OrdinalIgnoreCase))
|
||||
.Where(f => f.Dependencies != null)
|
||||
.SelectMany( f => f.Dependencies )
|
||||
|
||||
@@ -41,8 +41,7 @@ namespace Orchard.Data.Migration.Generator {
|
||||
/// Generates SchemaCommand instances in order to create the schema for a specific feature
|
||||
/// </summary>
|
||||
public IEnumerable<SchemaCommand> GetCreateFeatureCommands(string feature, bool drop) {
|
||||
var dependencies = ShellStateCoordinator.OrderByDependencies(_extensionManager.AvailableExtensions()
|
||||
.SelectMany(ext => ext.Features))
|
||||
var dependencies = _extensionManager.AvailableFeatures()
|
||||
.Where(f => String.Equals(f.Name, feature, StringComparison.OrdinalIgnoreCase))
|
||||
.Where(f => f.Dependencies != null)
|
||||
.SelectMany(f => f.Dependencies)
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Orchard.DisplayManagement.Implementation {
|
||||
return CoerceHtmlString(context.Value);
|
||||
|
||||
var workContext = _workContextAccessor.GetContext(context.ViewContext);
|
||||
var shapeTable = _shapeTableManager.GetShapeTable(workContext.CurrentTheme.ThemeName);
|
||||
var shapeTable = _shapeTableManager.GetShapeTable(workContext.CurrentTheme.Name);
|
||||
|
||||
var displayingContext = new ShapeDisplayingContext {
|
||||
Shape = shape,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Autofac.Core.Activators.Reflection;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Web.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Caching;
|
||||
using Orchard.Environment.Configuration;
|
||||
@@ -11,10 +10,7 @@ using Orchard.Environment.Descriptor;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Mvc.ViewEngines;
|
||||
using Orchard.Utility.Extensions;
|
||||
using Autofac;
|
||||
|
||||
namespace Orchard.Environment {
|
||||
public class DefaultOrchardHost : IOrchardHost, IShellSettingsManagerEventHandler, IShellDescriptorManagerEventHandler {
|
||||
@@ -62,7 +58,7 @@ namespace Orchard.Environment {
|
||||
}
|
||||
|
||||
void IOrchardHost.ReloadExtensions() {
|
||||
_current = null;
|
||||
DisposeShellContext();
|
||||
}
|
||||
|
||||
void IOrchardHost.BeginRequest() {
|
||||
@@ -145,11 +141,20 @@ namespace Orchard.Environment {
|
||||
ctx => {
|
||||
_extensionLoaderCoordinator.MonitorExtensions(ctx.Monitor);
|
||||
_hostLocalRestart.Monitor(ctx.Monitor);
|
||||
_current = null;
|
||||
DisposeShellContext();
|
||||
return "";
|
||||
});
|
||||
}
|
||||
|
||||
private void DisposeShellContext() {
|
||||
if (_current != null) {
|
||||
foreach (var shellContext in _current) {
|
||||
shellContext.Shell.Terminate();
|
||||
}
|
||||
_current = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void BeginRequest() {
|
||||
MonitorExtensions();
|
||||
BuildCurrent();
|
||||
@@ -176,11 +181,11 @@ namespace Orchard.Environment {
|
||||
}
|
||||
|
||||
void IShellSettingsManagerEventHandler.Saved(ShellSettings settings) {
|
||||
_current = null;
|
||||
DisposeShellContext();
|
||||
}
|
||||
|
||||
void IShellDescriptorManagerEventHandler.Changed(ShellDescriptor descriptor) {
|
||||
_current = null;
|
||||
DisposeShellContext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions.Folders;
|
||||
using Orchard.Environment.Extensions.Helpers;
|
||||
using Orchard.Environment.Extensions.Loaders;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Localization;
|
||||
@@ -18,6 +14,7 @@ namespace Orchard.Environment.Extensions {
|
||||
public class ExtensionManager : IExtensionManager {
|
||||
private readonly IEnumerable<IExtensionFolders> _folders;
|
||||
private readonly IEnumerable<IExtensionLoader> _loaders;
|
||||
private IEnumerable<FeatureDescriptor> _featureDescriptors;
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
@@ -31,14 +28,20 @@ namespace Orchard.Environment.Extensions {
|
||||
|
||||
// This method does not load extension types, simply parses extension manifests from
|
||||
// the filesystem.
|
||||
public ExtensionDescriptor GetExtension(string name) {
|
||||
return AvailableExtensions().FirstOrDefault(x => x.Name == name);
|
||||
}
|
||||
|
||||
public IEnumerable<ExtensionDescriptor> AvailableExtensions() {
|
||||
return _folders.SelectMany(folder => folder.AvailableExtensions());
|
||||
}
|
||||
|
||||
public IEnumerable<FeatureDescriptor> AvailableFeatures() {
|
||||
var featureDescriptors = AvailableExtensions().SelectMany(ext => ext.Features);
|
||||
var featureDescriptorsOrdered = featureDescriptors.OrderByDependencies(HasDependency);
|
||||
return featureDescriptorsOrdered.ToReadOnlyCollection();
|
||||
if (_featureDescriptors == null || _featureDescriptors.Count() == 0) {
|
||||
_featureDescriptors = AvailableExtensions().SelectMany(ext => ext.Features).OrderByDependencies(HasDependency).ToReadOnlyCollection();
|
||||
return _featureDescriptors;
|
||||
}
|
||||
return _featureDescriptors;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -65,7 +68,7 @@ namespace Orchard.Environment.Extensions {
|
||||
}
|
||||
|
||||
private IEnumerable<ExtensionEntry> LoadedExtensions() {
|
||||
foreach ( var descriptor in AvailableExtensions() ) {
|
||||
foreach (var descriptor in AvailableExtensions()) {
|
||||
ExtensionEntry entry = null;
|
||||
try {
|
||||
entry = BuildEntry(descriptor);
|
||||
@@ -138,65 +141,6 @@ namespace Orchard.Environment.Extensions {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) {
|
||||
if (String.IsNullOrEmpty(extensionType)) {
|
||||
throw new ArgumentException(T("extensionType was null or empty").ToString());
|
||||
}
|
||||
string targetFolder;
|
||||
if (String.Equals(extensionType, "Theme", StringComparison.OrdinalIgnoreCase)) {
|
||||
targetFolder = PathHelpers.GetPhysicalPath("~/Themes");
|
||||
}
|
||||
else if (String.Equals(extensionType, "Module", StringComparison.OrdinalIgnoreCase)) {
|
||||
targetFolder = PathHelpers.GetPhysicalPath("~/Modules");
|
||||
}
|
||||
else {
|
||||
throw new ArgumentException(T("extensionType was not recognized").ToString());
|
||||
}
|
||||
int postedFileLength = extensionBundle.ContentLength;
|
||||
Stream postedFileStream = extensionBundle.InputStream;
|
||||
byte[] postedFileData = new byte[postedFileLength];
|
||||
postedFileStream.Read(postedFileData, 0, postedFileLength);
|
||||
|
||||
using (var memoryStream = new MemoryStream(postedFileData)) {
|
||||
var fileInflater = new ZipInputStream(memoryStream);
|
||||
ZipEntry entry;
|
||||
while ((entry = fileInflater.GetNextEntry()) != null) {
|
||||
string directoryName = Path.GetDirectoryName(entry.Name);
|
||||
if (!Directory.Exists(Path.Combine(targetFolder, directoryName))) {
|
||||
Directory.CreateDirectory(Path.Combine(targetFolder, directoryName));
|
||||
}
|
||||
|
||||
if (!entry.IsDirectory && entry.Name.Length > 0) {
|
||||
var len = Convert.ToInt32(entry.Size);
|
||||
var extractedBytes = new byte[len];
|
||||
fileInflater.Read(extractedBytes, 0, len);
|
||||
File.WriteAllBytes(Path.Combine(targetFolder, entry.Name), extractedBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UninstallExtension(string extensionType, string extensionName) {
|
||||
if (String.IsNullOrEmpty(extensionType)) {
|
||||
throw new ArgumentException(T("extensionType was null or empty").ToString());
|
||||
}
|
||||
string targetFolder;
|
||||
if (String.Equals(extensionType, "Theme", StringComparison.OrdinalIgnoreCase)) {
|
||||
targetFolder = PathHelpers.GetPhysicalPath("~/Themes");
|
||||
}
|
||||
else if (String.Equals(extensionType, "Module", StringComparison.OrdinalIgnoreCase)) {
|
||||
targetFolder = PathHelpers.GetPhysicalPath("~/Modules");
|
||||
}
|
||||
else {
|
||||
throw new ArgumentException(T("extensionType was not recognized").ToString());
|
||||
}
|
||||
targetFolder = Path.Combine(targetFolder, extensionName);
|
||||
if (!Directory.Exists(targetFolder)) {
|
||||
throw new ArgumentException(T("extension was not found").ToString());
|
||||
}
|
||||
Directory.Delete(targetFolder, true);
|
||||
}
|
||||
|
||||
private ExtensionEntry BuildEntry(ExtensionDescriptor descriptor) {
|
||||
foreach (var loader in _loaders) {
|
||||
ExtensionEntry entry = loader.Load(descriptor);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
@@ -8,10 +7,10 @@ namespace Orchard.Environment.Extensions {
|
||||
public interface IExtensionManager {
|
||||
IEnumerable<ExtensionDescriptor> AvailableExtensions();
|
||||
IEnumerable<FeatureDescriptor> AvailableFeatures();
|
||||
IEnumerable<Feature> LoadFeatures(IEnumerable<FeatureDescriptor> featureDescriptors);
|
||||
|
||||
void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle);
|
||||
void UninstallExtension(string extensionType, string extensionName);
|
||||
ExtensionDescriptor GetExtension(string name);
|
||||
|
||||
IEnumerable<Feature> LoadFeatures(IEnumerable<FeatureDescriptor> featureDescriptors);
|
||||
}
|
||||
|
||||
public static class ExtensionManagerExtensions {
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
namespace Orchard.Environment.Extensions.Models {
|
||||
public class Extension {
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.Environment.Extensions.Models {
|
||||
public class ExtensionDescriptor {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Orchard.Environment.Extensions.Models {
|
||||
|
||||
124
src/Orchard/Environment/Features/FeatureManager.cs
Normal file
124
src/Orchard/Environment/Features/FeatureManager.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Environment.Descriptor;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Environment.Features {
|
||||
public interface IFeatureManager : IDependency {
|
||||
IEnumerable<FeatureDescriptor> GetAvailableFeatures();
|
||||
IEnumerable<FeatureDescriptor> GetEnabledFeatures();
|
||||
|
||||
void EnableFeatures(IEnumerable<string> featureNames);
|
||||
void DisableFeatures(IEnumerable<string> featureNames);
|
||||
}
|
||||
|
||||
public class FeatureManager : IFeatureManager {
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly ShellDescriptor _shellDescriptor;
|
||||
private readonly IShellDescriptorManager _shellDescriptorManager;
|
||||
|
||||
public FeatureManager(
|
||||
IExtensionManager extensionManager,
|
||||
ShellDescriptor shellDescriptor,
|
||||
IShellDescriptorManager shellDescriptorManager) {
|
||||
_extensionManager = extensionManager;
|
||||
_shellDescriptor = shellDescriptor;
|
||||
_shellDescriptorManager = shellDescriptorManager;
|
||||
}
|
||||
|
||||
public IEnumerable<FeatureDescriptor> GetAvailableFeatures() {
|
||||
return _extensionManager.AvailableFeatures();
|
||||
}
|
||||
|
||||
public IEnumerable<FeatureDescriptor> GetEnabledFeatures() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void EnableFeatures(IEnumerable<string> featureNames) {
|
||||
var currentShellDescriptor = _shellDescriptorManager.GetShellDescriptor();
|
||||
|
||||
var updatedFeatures = currentShellDescriptor.Features
|
||||
.Union(featureNames
|
||||
.Where(name => !currentShellDescriptor.Features.Any(sf => sf.Name == name))
|
||||
.Select(name => new ShellFeature {Name = name}));
|
||||
|
||||
_shellDescriptorManager.UpdateShellDescriptor(
|
||||
currentShellDescriptor.SerialNumber,
|
||||
updatedFeatures,
|
||||
currentShellDescriptor.Parameters);
|
||||
}
|
||||
|
||||
public void DisableFeatures(IEnumerable<string> featureNames) {
|
||||
var currentShellDescriptor = _shellDescriptorManager.GetShellDescriptor();
|
||||
|
||||
var updatedFeatures = currentShellDescriptor.Features
|
||||
.Where(sf => !featureNames.Contains(sf.Name));
|
||||
|
||||
_shellDescriptorManager.UpdateShellDescriptor(
|
||||
currentShellDescriptor.SerialNumber,
|
||||
updatedFeatures,
|
||||
currentShellDescriptor.Parameters);
|
||||
}
|
||||
|
||||
|
||||
//private void DisableThemeFeatures(string themeName) {
|
||||
// var themes = new Queue<string>();
|
||||
// while (themeName != null) {
|
||||
// if (themes.Contains(themeName))
|
||||
// throw new InvalidOperationException(T("The theme \"{0}\" is already in the stack of themes that need features disabled.", themeName).Text);
|
||||
// var theme = GetThemeByName(themeName);
|
||||
// if (theme == null)
|
||||
// break;
|
||||
// themes.Enqueue(themeName);
|
||||
|
||||
// themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
|
||||
// ? theme.BaseTheme
|
||||
// : null;
|
||||
|
||||
// }
|
||||
|
||||
// while (themes.Count > 0)
|
||||
// _moduleService.DisableFeatures(new[] { themes.Dequeue() });
|
||||
//}
|
||||
|
||||
//private void EnableThemeFeatures(string themeName) {
|
||||
// var themes = new Stack<string>();
|
||||
// while (themeName != null) {
|
||||
// if (themes.Contains(themeName))
|
||||
// throw new InvalidOperationException(T("The theme \"{0}\" is already in the stack of themes that need features enabled.", themeName).Text);
|
||||
// themes.Push(themeName);
|
||||
|
||||
// var theme = GetThemeByName(themeName);
|
||||
// themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
|
||||
// ? theme.BaseTheme
|
||||
// : null;
|
||||
// }
|
||||
|
||||
// while (themes.Count > 0)
|
||||
// _moduleService.EnableFeatures(new[] { themes.Pop() });
|
||||
//}
|
||||
|
||||
//private bool DoEnableTheme(string themeName) {
|
||||
// if (string.IsNullOrWhiteSpace(themeName))
|
||||
// return false;
|
||||
|
||||
// //todo: (heskew) need messages given in addition to all of these early returns so something meaningful can be presented to the user
|
||||
// var themeToEnable = GetThemeByName(themeName);
|
||||
// if (themeToEnable == null)
|
||||
// return false;
|
||||
|
||||
// // ensure all base themes down the line are present and accounted for
|
||||
// //todo: (heskew) dito on the need of a meaningful message
|
||||
// if (!AllBaseThemesAreInstalled(themeToEnable.BaseTheme))
|
||||
// return false;
|
||||
|
||||
// // enable all theme features
|
||||
// EnableThemeFeatures(themeToEnable.Name);
|
||||
// return true;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,17 @@ namespace Orchard.Environment {
|
||||
[UsedImplicitly]
|
||||
public class OrchardServices : IOrchardServices {
|
||||
private readonly Lazy<IShapeFactory> _shapeFactory;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
|
||||
public OrchardServices(
|
||||
IContentManager contentManager,
|
||||
ITransactionManager transactionManager,
|
||||
IAuthorizer authorizer,
|
||||
INotifier notifier,
|
||||
Lazy<IShapeFactory> shapeFactory) {
|
||||
Lazy<IShapeFactory> shapeFactory,
|
||||
IWorkContextAccessor workContextAccessor) {
|
||||
_shapeFactory = shapeFactory;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
ContentManager = contentManager;
|
||||
TransactionManager = transactionManager;
|
||||
Authorizer = authorizer;
|
||||
@@ -29,5 +32,6 @@ namespace Orchard.Environment {
|
||||
public IAuthorizer Authorizer { get; private set; }
|
||||
public INotifier Notifier { get; private set; }
|
||||
public dynamic New { get { return _shapeFactory.Value; } }
|
||||
public WorkContext WorkContext { get { return _workContextAccessor.GetContext(); } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ using System.Web.Mvc;
|
||||
using Autofac;
|
||||
using Autofac.Configuration;
|
||||
using Orchard.Caching;
|
||||
using Orchard.Environment.AutofacUtil;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Compilers;
|
||||
|
||||
@@ -7,7 +7,6 @@ using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Environment.State.Models;
|
||||
using Orchard.Environment.Descriptor;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Utility;
|
||||
|
||||
namespace Orchard.Environment.State {
|
||||
public class ShellStateCoordinator : IShellStateManagerEventHandler, IShellDescriptorManagerEventHandler {
|
||||
@@ -102,7 +101,7 @@ namespace Orchard.Environment.State {
|
||||
var shellState = _stateManager.GetShellState();
|
||||
|
||||
// start with description of all declared features in order - order preserved with all merging
|
||||
var orderedFeatureDescriptors = AllFeaturesInOrder();
|
||||
var orderedFeatureDescriptors = _extensionManager.AvailableFeatures();
|
||||
|
||||
// merge feature state into ordered list
|
||||
var orderedFeatureDescriptorsAndStates = orderedFeatureDescriptors
|
||||
@@ -176,19 +175,9 @@ namespace Orchard.Environment.State {
|
||||
FireApplyChangesIfNeeded();
|
||||
}
|
||||
|
||||
private IEnumerable<FeatureDescriptor> AllFeaturesInOrder() {
|
||||
return OrderByDependencies(_extensionManager.AvailableExtensions().SelectMany(ext => ext.Features));
|
||||
}
|
||||
|
||||
static bool IsRising(ShellFeatureState state) {
|
||||
return state.InstallState == ShellFeatureState.State.Rising ||
|
||||
state.EnableState == ShellFeatureState.State.Rising;
|
||||
}
|
||||
|
||||
public static IEnumerable<FeatureDescriptor> OrderByDependencies(IEnumerable<FeatureDescriptor> descriptors) {
|
||||
return descriptors.OrderByDependencies((item, dep) =>
|
||||
item.Dependencies != null &&
|
||||
item.Dependencies.Any(x => StringComparer.OrdinalIgnoreCase.Equals(x, dep.Name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.Events {
|
||||
public interface IEventBusHandler : IDependency {
|
||||
void Process(string messageName, IDictionary<string, string> eventData);
|
||||
}
|
||||
}
|
||||
@@ -10,5 +10,6 @@ namespace Orchard {
|
||||
IAuthorizer Authorizer { get; }
|
||||
INotifier Notifier { get; }
|
||||
dynamic New { get; }
|
||||
WorkContext WorkContext { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Commands;
|
||||
using Orchard.Localization.Services;
|
||||
using Orchard.Settings;
|
||||
|
||||
namespace Orchard.Localization.Commands {
|
||||
public class CultureCommands : DefaultOrchardCommandHandler {
|
||||
private readonly ICultureManager _cultureManager;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
public CultureCommands(ICultureManager cultureManager) {
|
||||
public CultureCommands(ICultureManager cultureManager, IOrchardServices orchardServices) {
|
||||
_cultureManager = cultureManager;
|
||||
_orchardServices = orchardServices;
|
||||
}
|
||||
|
||||
[CommandHelp("cultures list \r\n\t" + "List site cultures")]
|
||||
@@ -28,7 +26,7 @@ namespace Orchard.Localization.Commands {
|
||||
[CommandHelp("cultures get site culture \r\n\t" + "Get culture for the site")]
|
||||
[CommandName("cultures get site culture")]
|
||||
public void GetSiteCulture() {
|
||||
Context.Output.WriteLine(T("Site Culture is {0}", CurrentSite.SiteCulture));
|
||||
Context.Output.WriteLine(T("Site Culture is {0}", _orchardServices.WorkContext.CurrentSite.SiteCulture));
|
||||
}
|
||||
|
||||
[CommandHelp("cultures set site culture <culture-name> \r\n\t" + "Set culture for the site")]
|
||||
@@ -40,7 +38,7 @@ namespace Orchard.Localization.Commands {
|
||||
Context.Output.WriteLine(T("Supplied culture name {0} is not valid.", cultureName));
|
||||
return;
|
||||
}
|
||||
CurrentSite.SiteCulture = cultureName;
|
||||
_orchardServices.WorkContext.CurrentSite.SiteCulture = cultureName;
|
||||
|
||||
Context.Output.WriteLine(T("Site culture set to {0} successfully", cultureName));
|
||||
}
|
||||
|
||||
@@ -3,26 +3,27 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Caching;
|
||||
using Orchard.Data;
|
||||
using Orchard.Localization.Records;
|
||||
using Orchard.Settings;
|
||||
|
||||
namespace Orchard.Localization.Services {
|
||||
public class DefaultCultureManager : ICultureManager {
|
||||
private readonly IRepository<CultureRecord> _cultureRepository;
|
||||
private readonly IEnumerable<ICultureSelector> _cultureSelectors;
|
||||
private readonly ISignals _signals;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
|
||||
public DefaultCultureManager(IRepository<CultureRecord> cultureRepository, IEnumerable<ICultureSelector> cultureSelectors, ISignals signals) {
|
||||
public DefaultCultureManager(IRepository<CultureRecord> cultureRepository,
|
||||
IEnumerable<ICultureSelector> cultureSelectors,
|
||||
ISignals signals,
|
||||
IWorkContextAccessor workContextAccessor) {
|
||||
_cultureRepository = cultureRepository;
|
||||
_cultureSelectors = cultureSelectors;
|
||||
_signals = signals;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
}
|
||||
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
public IEnumerable<string> ListCultures() {
|
||||
var query = from culture in _cultureRepository.Table select culture.Culture;
|
||||
return query.ToList();
|
||||
@@ -75,7 +76,7 @@ namespace Orchard.Localization.Services {
|
||||
}
|
||||
|
||||
public string GetSiteCulture() {
|
||||
return CurrentSite == null ? null : CurrentSite.SiteCulture;
|
||||
return _workContextAccessor.GetContext().CurrentSite == null ? null : _workContextAccessor.GetContext().CurrentSite.SiteCulture;
|
||||
}
|
||||
|
||||
// "<languagecode2>" or
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Settings;
|
||||
|
||||
namespace Orchard.Localization.Services {
|
||||
public class SiteCultureSelector : ICultureSelector {
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
|
||||
public SiteCultureSelector(IWorkContextAccessor workContextAccessor) {
|
||||
_workContextAccessor = workContextAccessor;
|
||||
}
|
||||
|
||||
public CultureSelectorResult GetCulture(HttpContextBase context) {
|
||||
string currentCultureName = CurrentSite.SiteCulture;
|
||||
string currentCultureName = _workContextAccessor.GetContext().CurrentSite.SiteCulture;
|
||||
|
||||
if (String.IsNullOrEmpty(currentCultureName)) {
|
||||
return null;
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Modules {
|
||||
public interface IModule {
|
||||
string ModuleName { get; set; }
|
||||
string DisplayName { get; set; }
|
||||
string Description { get; set; }
|
||||
string Version { get; set; }
|
||||
string Author { get; set; }
|
||||
string HomePage { get; set; }
|
||||
string Tags { get; set; }
|
||||
IEnumerable<FeatureDescriptor> Features { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Modules {
|
||||
public interface IModuleFeature {
|
||||
FeatureDescriptor Descriptor { get; set; }
|
||||
bool IsEnabled { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard.Modules {
|
||||
public interface IModuleService : IDependency {
|
||||
IModule GetModuleByName(string moduleName);
|
||||
IEnumerable<IModule> GetInstalledModules();
|
||||
void InstallModule(HttpPostedFileBase file);
|
||||
void UninstallModule(string moduleName);
|
||||
IEnumerable<IModuleFeature> GetAvailableFeatures();
|
||||
void EnableFeatures(IEnumerable<string> featureNames);
|
||||
void EnableFeatures(IEnumerable<string> featureNames, bool force);
|
||||
void DisableFeatures(IEnumerable<string> featureNames);
|
||||
void DisableFeatures(IEnumerable<string> featureNames, bool force);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using System.Web.Mvc;
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Mvc.Html;
|
||||
using System.Web.UI;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Themes;
|
||||
using Orchard.Validation;
|
||||
|
||||
@@ -15,12 +17,13 @@ namespace Orchard.Mvc.Html {
|
||||
helper.RenderPartial(viewName);
|
||||
}
|
||||
|
||||
[Obsolete("How do you know the request theme is the same as the place the theme template is rendering from?")]
|
||||
public static string ThemePath(this HtmlHelper helper, string path) {
|
||||
return helper.ThemePath(helper.Resolve<IThemeService>().GetRequestTheme(helper.ViewContext.RequestContext), path);
|
||||
return helper.ThemePath(helper.Resolve<IThemeManager>().GetRequestTheme(helper.ViewContext.RequestContext), path);
|
||||
}
|
||||
|
||||
public static string ThemePath(this HtmlHelper helper, ITheme theme, string path) {
|
||||
return helper.Resolve<IExtensionManager>().GetThemeLocation(theme) + path;
|
||||
public static string ThemePath(this HtmlHelper helper, ExtensionDescriptor theme, string path) {
|
||||
return theme.Location + "/" + theme.Name + path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Themes;
|
||||
|
||||
namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
|
||||
@@ -64,15 +65,15 @@ namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
|
||||
return _configuredEnginesCache.BindBareEngines(() => new ViewEngineCollectionWrapper(_viewEngineProviders.Select(vep => vep.CreateBareViewEngine())));
|
||||
}
|
||||
|
||||
private IViewEngine ShallowEngines(ITheme theme) {
|
||||
private IViewEngine ShallowEngines(ExtensionDescriptor theme) {
|
||||
//return _configuredEnginesCache.BindShallowEngines(theme.ThemeName, () => new ViewEngineCollectionWrapper(_viewEngineProviders.Select(vep => vep.CreateBareViewEngine())));
|
||||
return DeepEngines(theme);
|
||||
}
|
||||
|
||||
private IViewEngine DeepEngines(ITheme theme) {
|
||||
return _configuredEnginesCache.BindDeepEngines(theme.ThemeName, () => {
|
||||
private IViewEngine DeepEngines(ExtensionDescriptor theme) {
|
||||
return _configuredEnginesCache.BindDeepEngines(theme.Name, () => {
|
||||
var engines = Enumerable.Empty<IViewEngine>();
|
||||
var themeLocation = _extensionManager.GetThemeLocation(theme);
|
||||
var themeLocation = theme.Location + "/" + theme.Name;
|
||||
|
||||
var themeParams = new CreateThemeViewEngineParams { VirtualPath = themeLocation };
|
||||
engines = engines.Concat(_viewEngineProviders.Select(vep => vep.CreateThemeViewEngine(themeParams)));
|
||||
|
||||
@@ -6,12 +6,12 @@ using Orchard.Themes;
|
||||
namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
|
||||
|
||||
public class ThemedViewResultFilter : FilterProvider, IResultFilter {
|
||||
private readonly IThemeService _themeService;
|
||||
private readonly IThemeManager _themeManager;
|
||||
private readonly WorkContext _workContext;
|
||||
private readonly ILayoutAwareViewEngine _layoutAwareViewEngine;
|
||||
|
||||
public ThemedViewResultFilter(IThemeService themeService, WorkContext workContext, ILayoutAwareViewEngine layoutAwareViewEngine) {
|
||||
_themeService = themeService;
|
||||
public ThemedViewResultFilter(IThemeManager themeManager, WorkContext workContext, ILayoutAwareViewEngine layoutAwareViewEngine) {
|
||||
_themeManager = themeManager;
|
||||
_workContext = workContext;
|
||||
_layoutAwareViewEngine = layoutAwareViewEngine;
|
||||
Logger = NullLogger.Instance;
|
||||
@@ -26,7 +26,7 @@ namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
|
||||
}
|
||||
|
||||
if (_workContext.CurrentTheme == null) {
|
||||
_workContext.CurrentTheme = _themeService.GetRequestTheme(filterContext.RequestContext);
|
||||
_workContext.CurrentTheme = _themeManager.GetRequestTheme(filterContext.RequestContext);
|
||||
}
|
||||
|
||||
viewResultBase.ViewEngineCollection = new ViewEngineCollection(new[] { _layoutAwareViewEngine });
|
||||
|
||||
@@ -174,6 +174,7 @@
|
||||
<Compile Include="DisplayManagement\Implementation\IShapeFactoryEvents.cs" />
|
||||
<Compile Include="DisplayManagement\Shapes\ITagBuilderFactory.cs" />
|
||||
<Compile Include="Environment\Extensions\Loaders\RawThemeExtensionLoader.cs" />
|
||||
<Compile Include="Environment\Features\FeatureManager.cs" />
|
||||
<Compile Include="Localization\Services\DefaultLocalizedStringManager.cs" />
|
||||
<Compile Include="Localization\Services\ILocalizedStringManager.cs" />
|
||||
<Compile Include="Mvc\IOrchardViewPage.cs" />
|
||||
@@ -185,6 +186,7 @@
|
||||
<Compile Include="Security\CurrentUserWorkContext.cs" />
|
||||
<Compile Include="Settings\CurrentSiteWorkContext.cs" />
|
||||
<Compile Include="Settings\ResourceDebugMode.cs" />
|
||||
<Compile Include="Themes\ThemeManager.cs" />
|
||||
<Compile Include="UI\FlatPositionComparer.cs" />
|
||||
<Compile Include="UI\Navigation\Pager.cs" />
|
||||
<Compile Include="UI\Resources\IResourceManifestProvider.cs" />
|
||||
@@ -658,18 +660,13 @@
|
||||
<Compile Include="Events\EventsRegistrationSource.cs" />
|
||||
<Compile Include="Environment\Configuration\IShellSettingsManagerEventHandler.cs" />
|
||||
<Compile Include="Events\IEventBus.cs" />
|
||||
<Compile Include="Events\IEventBusHandler.cs" />
|
||||
<Compile Include="Environment\Extensions\Folders\AreaFolders.cs" />
|
||||
<Compile Include="Environment\Extensions\Folders\ExtensionFolders.cs" />
|
||||
<Compile Include="Environment\Extensions\Models\Extension.cs" />
|
||||
<Compile Include="Environment\Extensions\Loaders\AreaExtensionLoader.cs" />
|
||||
<Compile Include="Environment\Extensions\Models\Feature.cs" />
|
||||
<Compile Include="Environment\Extensions\Models\FeatureDescriptor.cs" />
|
||||
<Compile Include="Environment\Extensions\OrchardFeatureAttribute.cs" />
|
||||
<Compile Include="Events\IEventHandler.cs" />
|
||||
<Compile Include="Modules\IModule.cs" />
|
||||
<Compile Include="Modules\IModuleFeature.cs" />
|
||||
<Compile Include="Modules\IModuleService.cs" />
|
||||
<Compile Include="Mvc\AntiForgery\ValidateAntiForgeryTokenOrchardAttribute.cs" />
|
||||
<Compile Include="Mvc\Extensions\ModelStateDictionaryExtensions.cs" />
|
||||
<Compile Include="Mvc\Html\FileRegistrationContextExtensions.cs" />
|
||||
@@ -712,7 +709,6 @@
|
||||
<Compile Include="Tasks\Scheduling\IScheduledTaskHandler.cs" />
|
||||
<Compile Include="Tasks\Scheduling\IScheduledTaskManager.cs" />
|
||||
<Compile Include="Tasks\Scheduling\ScheduledTaskContext.cs" />
|
||||
<Compile Include="Themes\ExtensionManagerExtensions.cs" />
|
||||
<Compile Include="Environment\Extensions\Helpers\PathHelpers.cs" />
|
||||
<Compile Include="Environment\Extensions\IExtensionManager.cs" />
|
||||
<Compile Include="Environment\Extensions\Folders\ModuleFolders.cs" />
|
||||
@@ -774,17 +770,13 @@
|
||||
<Compile Include="Security\Authorizer.cs" />
|
||||
<Compile Include="Security\Providers\FormsAuthenticationService.cs" />
|
||||
<Compile Include="Security\SecurityFilter.cs" />
|
||||
<Compile Include="Security\SecurityModule.cs" />
|
||||
<Compile Include="Settings\ISite.cs" />
|
||||
<Compile Include="Settings\ISiteService.cs" />
|
||||
<Compile Include="Settings\SettingsModule.cs" />
|
||||
<Compile Include="Tasks\BackgroundService.cs" />
|
||||
<Compile Include="Tasks\IBackgroundTask.cs" />
|
||||
<Compile Include="Tasks\SweepGenerator.cs" />
|
||||
<Compile Include="Themes\ITheme.cs" />
|
||||
<Compile Include="Themes\IThemeSelector.cs" />
|
||||
<Compile Include="Themes\IThemeService.cs" />
|
||||
<Compile Include="Themes\ThemesModule.cs" />
|
||||
<Compile Include="Themes\IThemeManager.cs" />
|
||||
<Compile Include="UI\Navigation\MenuFilter.cs" />
|
||||
<Compile Include="UI\Navigation\NavigationBuilder.cs" />
|
||||
<Compile Include="UI\Navigation\INavigationProvider.cs" />
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
namespace Orchard.Scripting {
|
||||
using System;
|
||||
using Microsoft.Scripting.Hosting;
|
||||
|
||||
namespace Orchard.Scripting {
|
||||
public interface IScriptingManager : IDependency {
|
||||
dynamic GetVariable(string name);
|
||||
void SetVariable(string name, object value);
|
||||
dynamic ExecuteExpression(string expression);
|
||||
void ExecuteFile(string fileName);
|
||||
dynamic ExecuteOperation(Func<ObjectOperations, object> invoke);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@ namespace Orchard.Scripting {
|
||||
public class ScriptingManager : IScriptingManager {
|
||||
private readonly IScriptingRuntime _scriptingRuntime;
|
||||
private Lazy<ScriptScope> _scope;
|
||||
private Lazy<ObjectOperations> _operations;
|
||||
|
||||
public ScriptingManager(IScriptingRuntime scriptingRuntime) {
|
||||
_scriptingRuntime = scriptingRuntime;
|
||||
_scope = new Lazy<ScriptScope>(()=>_scriptingRuntime.CreateScope());
|
||||
_operations = new Lazy<ObjectOperations>(()=>_scope.Value.Engine.CreateOperations());
|
||||
}
|
||||
|
||||
public dynamic GetVariable(string name) {
|
||||
@@ -23,6 +25,10 @@ namespace Orchard.Scripting {
|
||||
return _scriptingRuntime.ExecuteExpression(expression, _scope.Value);
|
||||
}
|
||||
|
||||
public dynamic ExecuteOperation(Func<ObjectOperations, dynamic> invoke) {
|
||||
return invoke(_operations.Value);
|
||||
}
|
||||
|
||||
public void ExecuteFile(string fileName) {
|
||||
_scriptingRuntime.ExecuteFile(fileName, _scope.Value);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Security.Permissions;
|
||||
using Orchard.UI.Notify;
|
||||
@@ -14,16 +13,18 @@ namespace Orchard.Security {
|
||||
public class Authorizer : IAuthorizer {
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly INotifier _notifier;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
|
||||
public Authorizer(
|
||||
IAuthorizationService authorizationService,
|
||||
INotifier notifier) {
|
||||
INotifier notifier,
|
||||
IWorkContextAccessor workContextAccessor) {
|
||||
_authorizationService = authorizationService;
|
||||
_notifier = notifier;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
protected virtual IUser CurrentUser { get; [UsedImplicitly] private set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public bool Authorize(Permission permission) {
|
||||
@@ -35,17 +36,17 @@ namespace Orchard.Security {
|
||||
}
|
||||
|
||||
public bool Authorize(Permission permission, IContent content, LocalizedString message) {
|
||||
if (_authorizationService.TryCheckAccess(permission, CurrentUser, content))
|
||||
if (_authorizationService.TryCheckAccess(permission, _workContextAccessor.GetContext().CurrentUser, content))
|
||||
return true;
|
||||
|
||||
if (message != null) {
|
||||
if (CurrentUser == null) {
|
||||
if (_workContextAccessor.GetContext().CurrentUser == null) {
|
||||
_notifier.Error(T("{0}. Anonymous users do not have {1} permission.",
|
||||
message, permission.Name));
|
||||
}
|
||||
else {
|
||||
_notifier.Error(T("{0}. Current user, {2}, does not have {1} permission.",
|
||||
message, permission.Name, CurrentUser.UserName));
|
||||
message, permission.Name, _workContextAccessor.GetContext().CurrentUser.UserName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Autofac.Core;
|
||||
using Castle.Core.Interceptor;
|
||||
using Orchard.Environment.AutofacUtil.DynamicProxy2;
|
||||
using Module = Autofac.Module;
|
||||
|
||||
namespace Orchard.Security {
|
||||
public class SecurityModule : Module {
|
||||
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration) {
|
||||
var implementationType = registration.Activator.LimitType;
|
||||
var property = FindProperty(implementationType);
|
||||
|
||||
if (property != null) {
|
||||
registration.InterceptedBy<ISecurityModuleInterceptor>();
|
||||
}
|
||||
}
|
||||
|
||||
private static PropertyInfo FindProperty(Type type) {
|
||||
return type.GetProperty("CurrentUser",
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
|
||||
null,
|
||||
typeof(IUser),
|
||||
new Type[0],
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
public interface ISecurityModuleInterceptor : IInterceptor, IDependency {
|
||||
|
||||
}
|
||||
|
||||
public class SecurityModuleInterceptor : ISecurityModuleInterceptor {
|
||||
private readonly IAuthenticationService _authenticationService;
|
||||
|
||||
public SecurityModuleInterceptor(IAuthenticationService authenticationService) {
|
||||
_authenticationService = authenticationService;
|
||||
}
|
||||
|
||||
public void Intercept(IInvocation invocation) {
|
||||
if (invocation.Method.ReturnType == typeof(IUser) && invocation.Method.Name == "get_CurrentUser") {
|
||||
invocation.ReturnValue = _authenticationService.GetAuthenticatedUser();
|
||||
}
|
||||
else {
|
||||
invocation.Proceed();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Autofac.Core;
|
||||
using Castle.Core.Interceptor;
|
||||
using Orchard.Environment.AutofacUtil.DynamicProxy2;
|
||||
using Module = Autofac.Module;
|
||||
|
||||
namespace Orchard.Settings {
|
||||
public class SettingsModule : Module {
|
||||
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration) {
|
||||
var implementationType = registration.Activator.LimitType;
|
||||
var property = FindProperty(implementationType);
|
||||
|
||||
if (property != null) {
|
||||
registration.InterceptedBy<ISettingsModuleInterceptor>();
|
||||
}
|
||||
}
|
||||
|
||||
private static PropertyInfo FindProperty(Type type) {
|
||||
return type.GetProperty("CurrentSite",
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
|
||||
null,
|
||||
typeof(ISite),
|
||||
new Type[0],
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
public interface ISettingsModuleInterceptor : IInterceptor, IDependency {
|
||||
|
||||
}
|
||||
|
||||
public class SettingsModuleInterceptor : ISettingsModuleInterceptor {
|
||||
private readonly ISiteService _siteService;
|
||||
|
||||
public SettingsModuleInterceptor(ISiteService siteService) {
|
||||
_siteService = siteService;
|
||||
}
|
||||
|
||||
public void Intercept(IInvocation invocation) {
|
||||
if (invocation.Method.ReturnType == typeof(ISite) && invocation.Method.Name == "get_CurrentSite") {
|
||||
invocation.ReturnValue = _siteService.GetSiteSettings();
|
||||
}
|
||||
else {
|
||||
invocation.Proceed();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user