mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-24 13:33:34 +08:00
IShellSettingsEventHandler to modify tenants in the running application
Added new methods for altering the tenants: Remove and Update --HG-- branch : dev
This commit is contained in:
@@ -16,6 +16,7 @@ namespace Orchard.MultiTenancy.Controllers {
|
|||||||
public AdminController(ITenantService tenantService, IOrchardServices orchardServices, ShellSettings shellSettings) {
|
public AdminController(ITenantService tenantService, IOrchardServices orchardServices, ShellSettings shellSettings) {
|
||||||
_tenantService = tenantService;
|
_tenantService = tenantService;
|
||||||
_thisShellSettings = shellSettings;
|
_thisShellSettings = shellSettings;
|
||||||
|
|
||||||
Services = orchardServices;
|
Services = orchardServices;
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
@@ -36,6 +37,7 @@ namespace Orchard.MultiTenancy.Controllers {
|
|||||||
try {
|
try {
|
||||||
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Couldn't create tenant")))
|
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Couldn't create tenant")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
_tenantService.CreateTenant(
|
_tenantService.CreateTenant(
|
||||||
new ShellSettings {
|
new ShellSettings {
|
||||||
Name = viewModel.Name,
|
Name = viewModel.Name,
|
||||||
|
@@ -66,6 +66,7 @@
|
|||||||
<Compile Include="Controllers\AdminController.cs" />
|
<Compile Include="Controllers\AdminController.cs" />
|
||||||
<Compile Include="Extensions\UrlHelperExtensions.cs" />
|
<Compile Include="Extensions\UrlHelperExtensions.cs" />
|
||||||
<Compile Include="Services\ITenantService.cs" />
|
<Compile Include="Services\ITenantService.cs" />
|
||||||
|
<Compile Include="Services\ShellSettingsEventHandler.cs" />
|
||||||
<Compile Include="Services\TenantService.cs" />
|
<Compile Include="Services\TenantService.cs" />
|
||||||
<Compile Include="ViewModels\TenantsAddViewModel.cs" />
|
<Compile Include="ViewModels\TenantsAddViewModel.cs" />
|
||||||
<Compile Include="ViewModels\TenantsIndexViewModel.cs" />
|
<Compile Include="ViewModels\TenantsIndexViewModel.cs" />
|
||||||
|
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using Orchard.Events;
|
||||||
|
using Orchard.Environment.Configuration;
|
||||||
|
using Orchard.Environment;
|
||||||
|
|
||||||
|
namespace Orchard.MultiTenancy.Services {
|
||||||
|
public class ShellSettingsEventHandler : IShellSettingsEventHandler, IDependency {
|
||||||
|
|
||||||
|
private readonly IRunningShellTable _runningShellTable;
|
||||||
|
|
||||||
|
public ShellSettingsEventHandler(IRunningShellTable runningShellTable) {
|
||||||
|
_runningShellTable = runningShellTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Created(ShellSettings settings) {
|
||||||
|
_runningShellTable.Add(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Deleted(ShellSettings settings) {
|
||||||
|
_runningShellTable.Remove(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Updated(ShellSettings settings) {
|
||||||
|
_runningShellTable.Update(settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -2,15 +2,18 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
|
using Orchard.Events;
|
||||||
|
|
||||||
namespace Orchard.MultiTenancy.Services {
|
namespace Orchard.MultiTenancy.Services {
|
||||||
public class TenantService : ITenantService {
|
public class TenantService : ITenantService {
|
||||||
private readonly IShellSettingsManager _shellSettingsManager;
|
private readonly IShellSettingsManager _shellSettingsManager;
|
||||||
private readonly IOrchardHost _orchardHost;
|
private readonly IOrchardHost _orchardHost;
|
||||||
|
private readonly IShellSettingsEventHandler _shellSettingsEventHandler;
|
||||||
|
|
||||||
public TenantService(IShellSettingsManager shellSettingsManager, IOrchardHost orchardHost) {
|
public TenantService(IShellSettingsManager shellSettingsManager, IOrchardHost orchardHost, IShellSettingsEventHandler shellSettingsEventHandler) {
|
||||||
_shellSettingsManager = shellSettingsManager;
|
_shellSettingsManager = shellSettingsManager;
|
||||||
_orchardHost = orchardHost;
|
_orchardHost = orchardHost;
|
||||||
|
_shellSettingsEventHandler = shellSettingsEventHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<ShellSettings> GetTenants() {
|
public IEnumerable<ShellSettings> GetTenants() {
|
||||||
@@ -19,12 +22,16 @@ namespace Orchard.MultiTenancy.Services {
|
|||||||
|
|
||||||
public void CreateTenant(ShellSettings settings) {
|
public void CreateTenant(ShellSettings settings) {
|
||||||
_shellSettingsManager.SaveSettings(settings);
|
_shellSettingsManager.SaveSettings(settings);
|
||||||
|
_shellSettingsEventHandler.Created(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateTenant(ShellSettings settings) {
|
public void UpdateTenant(ShellSettings settings) {
|
||||||
var tenant = GetTenants().FirstOrDefault(ss => ss.Name == settings.Name);
|
var tenant = GetTenants().FirstOrDefault(ss => ss.Name == settings.Name);
|
||||||
if (tenant != null)
|
if ( tenant != null ) {
|
||||||
_shellSettingsManager.SaveSettings(settings);
|
_shellSettingsManager.SaveSettings(settings);
|
||||||
|
_shellSettingsEventHandler.Updated(settings);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -8,6 +8,8 @@ using Orchard.Environment.Configuration;
|
|||||||
namespace Orchard.Environment {
|
namespace Orchard.Environment {
|
||||||
public interface IRunningShellTable {
|
public interface IRunningShellTable {
|
||||||
void Add(ShellSettings settings);
|
void Add(ShellSettings settings);
|
||||||
|
void Remove(ShellSettings settings);
|
||||||
|
void Update(ShellSettings settings);
|
||||||
ShellSettings Match(HttpContextBase httpContext);
|
ShellSettings Match(HttpContextBase httpContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,6 +24,30 @@ namespace Orchard.Environment {
|
|||||||
.Concat(new[] { settings })
|
.Concat(new[] { settings })
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
Organize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Remove(ShellSettings settings) {
|
||||||
|
_shells = _shells
|
||||||
|
.Where(s => s.Name != settings.Name)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
Organize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ShellSettings settings) {
|
||||||
|
_shells = _shells
|
||||||
|
.Where(s => s.Name != settings.Name)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
_shells = _shells
|
||||||
|
.Concat(new[] { settings })
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
Organize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Organize() {
|
||||||
var qualified =
|
var qualified =
|
||||||
_shells.Where(x => !string.IsNullOrEmpty(x.RequestUrlHost) || !string.IsNullOrEmpty(x.RequestUrlPrefix));
|
_shells.Where(x => !string.IsNullOrEmpty(x.RequestUrlHost) || !string.IsNullOrEmpty(x.RequestUrlPrefix));
|
||||||
|
|
||||||
@@ -50,7 +76,8 @@ namespace Orchard.Environment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ShellSettings Match(HttpContextBase httpContext) {
|
public ShellSettings Match(HttpContextBase httpContext) {
|
||||||
var host = httpContext.Request.ServerVariables.Get("HTTP_HOST") ?? "";
|
// use Host header to prevent proxy alteration of the orignal request
|
||||||
|
var host = httpContext.Request.Headers["Host"];
|
||||||
|
|
||||||
var hostLength = host.IndexOf(':');
|
var hostLength = host.IndexOf(':');
|
||||||
if (hostLength != -1)
|
if (hostLength != -1)
|
||||||
|
9
src/Orchard/Events/IShellSettingsEventHandler.cs
Normal file
9
src/Orchard/Events/IShellSettingsEventHandler.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using Orchard.Environment.Configuration;
|
||||||
|
|
||||||
|
namespace Orchard.Events {
|
||||||
|
public interface IShellSettingsEventHandler : IEventHandler {
|
||||||
|
void Created(ShellSettings settings);
|
||||||
|
void Deleted(ShellSettings settings);
|
||||||
|
void Updated(ShellSettings settings);
|
||||||
|
}
|
||||||
|
}
|
@@ -184,6 +184,7 @@
|
|||||||
<Compile Include="Events\EventsInterceptor.cs" />
|
<Compile Include="Events\EventsInterceptor.cs" />
|
||||||
<Compile Include="Events\EventsModule.cs" />
|
<Compile Include="Events\EventsModule.cs" />
|
||||||
<Compile Include="Events\EventsRegistrationSource.cs" />
|
<Compile Include="Events\EventsRegistrationSource.cs" />
|
||||||
|
<Compile Include="Events\IShellSettingsEventHandler.cs" />
|
||||||
<Compile Include="Events\IEventBus.cs" />
|
<Compile Include="Events\IEventBus.cs" />
|
||||||
<Compile Include="Events\IEventBusHandler.cs" />
|
<Compile Include="Events\IEventBusHandler.cs" />
|
||||||
<Compile Include="Environment\Extensions\Folders\AreaFolders.cs" />
|
<Compile Include="Environment\Extensions\Folders\AreaFolders.cs" />
|
||||||
|
Reference in New Issue
Block a user