mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 20:13:52 +08:00
Only the "Default" tenant is able to manage tenants
- Don't show links in other tenants - Protected controller actions --HG-- branch : dev
This commit is contained in:
@@ -1,13 +1,23 @@
|
|||||||
using Orchard.Localization;
|
using Orchard.Environment.Configuration;
|
||||||
|
using Orchard.Localization;
|
||||||
using Orchard.UI.Navigation;
|
using Orchard.UI.Navigation;
|
||||||
|
|
||||||
namespace Orchard.MultiTenancy {
|
namespace Orchard.MultiTenancy {
|
||||||
public class AdminMenu : INavigationProvider {
|
public class AdminMenu : INavigationProvider {
|
||||||
|
private readonly ShellSettings _shellSettings;
|
||||||
|
|
||||||
|
public AdminMenu(ShellSettings shellSettings) {
|
||||||
|
_shellSettings = shellSettings;
|
||||||
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
public string MenuName { get { return "admin"; } }
|
public string MenuName { get { return "admin"; } }
|
||||||
|
|
||||||
public void GetNavigation(NavigationBuilder builder) {
|
public void GetNavigation(NavigationBuilder builder) {
|
||||||
|
if ( _shellSettings.Name != "Default" )
|
||||||
|
return;
|
||||||
|
|
||||||
builder.Add(T("Tenants"), "22",
|
builder.Add(T("Tenants"), "22",
|
||||||
menu => menu
|
menu => menu
|
||||||
.Add(T("Manage Tenants"), "1.0", item => item.Action("Index", "Admin", new { area = "Orchard.MultiTenancy" }).Permission(Permissions.ManageTenants))
|
.Add(T("Manage Tenants"), "1.0", item => item.Action("Index", "Admin", new { area = "Orchard.MultiTenancy" }).Permission(Permissions.ManageTenants))
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ namespace Orchard.MultiTenancy.Controllers {
|
|||||||
public ActionResult Add() {
|
public ActionResult Add() {
|
||||||
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Cannot create tenant")))
|
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Cannot create tenant")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
|
if ( !EnsureDefaultTenant() )
|
||||||
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
return View(new TenantAddViewModel());
|
return View(new TenantAddViewModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +44,10 @@ 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();
|
||||||
|
|
||||||
|
if ( !EnsureDefaultTenant() )
|
||||||
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
_tenantService.CreateTenant(
|
_tenantService.CreateTenant(
|
||||||
new ShellSettings {
|
new ShellSettings {
|
||||||
Name = viewModel.Name,
|
Name = viewModel.Name,
|
||||||
@@ -64,6 +71,9 @@ namespace Orchard.MultiTenancy.Controllers {
|
|||||||
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Cannot edit tenant")))
|
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Cannot edit tenant")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
|
if ( !EnsureDefaultTenant() )
|
||||||
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == name);
|
var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == name);
|
||||||
if (tenant == null)
|
if (tenant == null)
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
@@ -85,6 +95,9 @@ namespace Orchard.MultiTenancy.Controllers {
|
|||||||
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Couldn't edit tenant")))
|
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Couldn't edit tenant")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
|
if ( !EnsureDefaultTenant() )
|
||||||
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == viewModel.Name);
|
var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == viewModel.Name);
|
||||||
if (tenant == null)
|
if (tenant == null)
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
@@ -113,6 +126,9 @@ namespace Orchard.MultiTenancy.Controllers {
|
|||||||
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Couldn't disable tenant")))
|
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Couldn't disable tenant")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
|
if ( !EnsureDefaultTenant() )
|
||||||
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == name);
|
var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == name);
|
||||||
|
|
||||||
if (tenant != null && tenant.Name != _thisShellSettings.Name) {
|
if (tenant != null && tenant.Name != _thisShellSettings.Name) {
|
||||||
@@ -120,7 +136,7 @@ namespace Orchard.MultiTenancy.Controllers {
|
|||||||
_tenantService.UpdateTenant(tenant);
|
_tenantService.UpdateTenant(tenant);
|
||||||
}
|
}
|
||||||
|
|
||||||
return RedirectToAction("index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
@@ -128,6 +144,9 @@ namespace Orchard.MultiTenancy.Controllers {
|
|||||||
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Couldn't enable tenant")))
|
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Couldn't enable tenant")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
|
if ( !EnsureDefaultTenant() )
|
||||||
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == name);
|
var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == name);
|
||||||
|
|
||||||
if (tenant != null && tenant.Name != _thisShellSettings.Name) {
|
if (tenant != null && tenant.Name != _thisShellSettings.Name) {
|
||||||
@@ -135,7 +154,11 @@ namespace Orchard.MultiTenancy.Controllers {
|
|||||||
_tenantService.UpdateTenant(tenant);
|
_tenantService.UpdateTenant(tenant);
|
||||||
}
|
}
|
||||||
|
|
||||||
return RedirectToAction("index");
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool EnsureDefaultTenant() {
|
||||||
|
return _thisShellSettings.Name == "Default";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user