Removing some obsolete install/feature state code

Changing blog/page slug updater to use orchard shell events interface
Changing default role/permission to use feature install event
Renaming state manager/provider to be consistent with other components

--HG--
branch : dev
This commit is contained in:
Louis DeJardin
2010-05-28 14:01:10 -07:00
parent 13f44990ca
commit 52ef9f3c8c
22 changed files with 77 additions and 163 deletions

View File

@@ -1,12 +1,12 @@
using System.Linq;
using JetBrains.Annotations;
using Orchard.Blogs.Services;
using Orchard.Environment.Extensions;
using Orchard.Environment;
using Orchard.Tasks;
namespace Orchard.Blogs.Routing {
[UsedImplicitly]
public class BlogSlugConstraintUpdator : ExtensionManagerEvents, IBackgroundTask {
public class BlogSlugConstraintUpdator : IOrchardShellEvents, IBackgroundTask {
private readonly IBlogSlugConstraint _blogSlugConstraint;
private readonly IBlogService _blogService;
@@ -14,14 +14,15 @@ namespace Orchard.Blogs.Routing {
_blogSlugConstraint = blogSlugConstraint;
_blogService = blogService;
}
public override void Activated(ExtensionEventContext context) {
if (context.Extension.Descriptor.Name == "Orchard.Blogs") {
Refresh();
}
void IOrchardShellEvents.Activated() {
Refresh();
}
public void Sweep() {
void IOrchardShellEvents.Terminating() {
}
void IBackgroundTask.Sweep() {
Refresh();
}

View File

@@ -1,12 +1,12 @@
using System.Linq;
using JetBrains.Annotations;
using Orchard.Environment.Extensions;
using Orchard.Environment;
using Orchard.Pages.Services;
using Orchard.Tasks;
namespace Orchard.Pages.Routing {
[UsedImplicitly]
public class PageSlugConstraintUpdator : ExtensionManagerEvents, IBackgroundTask {
public class PageSlugConstraintUpdator : IOrchardShellEvents, IBackgroundTask {
private readonly IPageSlugConstraint _pageSlugConstraint;
private readonly IPageService _pageService;
@@ -15,18 +15,20 @@ namespace Orchard.Pages.Routing {
_pageService = pageService;
}
public override void Activated(ExtensionEventContext context) {
if (context.Extension.Descriptor.Name == "Orchard.Pages") {
Refresh();
}
void IOrchardShellEvents.Activated() {
Refresh();
}
public void Sweep() {
void IOrchardShellEvents.Terminating() {
}
void IBackgroundTask.Sweep() {
Refresh();
}
private void Refresh() {
_pageSlugConstraint.SetSlugs(_pageService.Get(PageStatus.Published).Select(p => p.Slug));
}
}
}

View File

@@ -1,18 +1,19 @@
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Orchard.Environment.Extensions;
using Orchard.Environment;
using Orchard.Environment.Extensions.Models;
using Orchard.Logging;
using Orchard.Roles.Services;
using Orchard.Security.Permissions;
namespace Orchard.Roles {
[UsedImplicitly]
public class Extension : ExtensionManagerEvents {
public class DefaultRoleUpdater : IFeatureEventHandler {
private readonly IRoleService _roleService;
private readonly IEnumerable<IPermissionProvider> _permissionProviders;
public Extension(
public DefaultRoleUpdater(
IRoleService roleService,
IEnumerable<IPermissionProvider> permissionProviders) {
_roleService = roleService;
@@ -23,18 +24,27 @@ namespace Orchard.Roles {
public ILogger Logger { get; set; }
public override void Enabled(ExtensionEventContext context) {
var extensionDisplayName = context.Extension.Descriptor.DisplayName ?? context.Extension.Descriptor.Name;
void IFeatureEventHandler.Install(Feature feature) {
AddDefaultRolesForFeature(feature);
}
void IFeatureEventHandler.Enable(Feature feature) {}
void IFeatureEventHandler.Disable(Feature feature) {}
void IFeatureEventHandler.Uninstall(Feature feature) {}
public void AddDefaultRolesForFeature(Feature feature) {
var featureName = feature.Descriptor.Name;
// when another module is being enabled, locate matching permission providers
var providersForEnabledModule =
_permissionProviders.Where(x => x.ModuleName == extensionDisplayName);
var providersForEnabledModule = _permissionProviders.Where(x => x.ModuleName == featureName);
if (providersForEnabledModule.Any()) {
Logger.Debug("Configuring default roles for module {0}", extensionDisplayName);
Logger.Debug("Configuring default roles for module {0}", featureName);
}
else {
Logger.Debug("No default roles for module {0}", extensionDisplayName);
Logger.Debug("No default roles for module {0}", featureName);
}
foreach (var permissionProvider in providersForEnabledModule) {

View File

@@ -68,7 +68,7 @@
<Compile Include="AdminMenu.cs" />
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="Drivers\UserRolesDriver.cs" />
<Compile Include="Extension.cs" />
<Compile Include="DefaultRoleUpdater.cs" />
<Compile Include="Models\IUserRoles.cs" />
<Compile Include="Models\UserSimulation.cs" />
<Compile Include="Permissions.cs" />

View File

@@ -80,7 +80,6 @@
</ItemGroup>
<ItemGroup>
<Content Include="Module.txt" />
<Content Include="Views\DisplayTemplates\Fields\Sandbox.BingMap.ascx" />
<Content Include="Views\Page\Edit.aspx" />
<Content Include="Views\Page\Create.aspx" />
<Content Include="Views\Page\Show.aspx" />

View File

@@ -132,9 +132,10 @@ namespace Orchard.Setup.Services {
var contentManager = environment.Resolve<IContentManager>();
// this needs to exit the standalone environment? rework this process entirely?
// simulate installation-time module activation events
var hackInstallationGenerator = environment.Resolve<IHackInstallationGenerator>();
hackInstallationGenerator.GenerateInstallEvents();
//var hackInstallationGenerator = environment.Resolve<IHackInstallationGenerator>();
//hackInstallationGenerator.GenerateInstallEvents();
// create home page as a CMS page
var page = contentManager.Create("page", VersionOptions.Draft);

View File

@@ -45,7 +45,6 @@ namespace Orchard.Setup {
builder.RegisterType<HelpCommand>().As<ICommandHandler>().InstancePerLifetimeScope();
// setup mode specific implementations of needed service interfaces
builder.RegisterType<NullHackInstallationGenerator>().As<IHackInstallationGenerator>().InstancePerLifetimeScope();
builder.RegisterType<SafeModeThemeService>().As<IThemeService>().InstancePerLifetimeScope();
builder.RegisterType<SafeModeText>().As<IText>().InstancePerLifetimeScope();
builder.RegisterType<SafeModeSiteService>().As<ISiteService>().InstancePerLifetimeScope();
@@ -88,10 +87,6 @@ namespace Orchard.Setup {
public void UninstallTheme(string themeName) { }
}
class NullHackInstallationGenerator : IHackInstallationGenerator {
public void GenerateInstallEvents() { }
public void GenerateActivateEvents() { }
}
class SafeModeSiteService : ISiteService {
public ISite GetSiteSettings() {