mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 19:44:02 +08:00
More MT UI wor
- added edit tenant --HG-- branch : dev
This commit is contained in:
@@ -5,6 +5,7 @@ using Orchard.Environment.Configuration;
|
||||
using Orchard.Localization;
|
||||
using Orchard.MultiTenancy.Services;
|
||||
using Orchard.MultiTenancy.ViewModels;
|
||||
using Orchard.Mvc.Results;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.MultiTenancy.Controllers {
|
||||
@@ -29,11 +30,13 @@ namespace Orchard.MultiTenancy.Controllers {
|
||||
}
|
||||
|
||||
public ActionResult Add() {
|
||||
return View(new TenantsAddViewModel());
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Cannot create tenant")))
|
||||
return new HttpUnauthorizedResult();
|
||||
return View(new TenantAddViewModel());
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Add")]
|
||||
public ActionResult AddPOST(TenantsAddViewModel viewModel) {
|
||||
public ActionResult AddPOST(TenantAddViewModel viewModel) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Couldn't create tenant")))
|
||||
return new HttpUnauthorizedResult();
|
||||
@@ -43,7 +46,7 @@ namespace Orchard.MultiTenancy.Controllers {
|
||||
Name = viewModel.Name,
|
||||
RequestUrlHost = viewModel.RequestUrlHost,
|
||||
RequestUrlPrefix = viewModel.RequestUrlPrefix,
|
||||
DataProvider = viewModel.DatabaseOptions != null ? ((bool)viewModel.DatabaseOptions ? "SQLite" : "SqlServer") : null,
|
||||
DataProvider = viewModel.DataProvider,
|
||||
DataConnectionString = viewModel.DatabaseConnectionString,
|
||||
DataTablePrefix = viewModel.DatabaseTablePrefix,
|
||||
State = new TenantState("Uninitialized")
|
||||
@@ -57,12 +60,60 @@ namespace Orchard.MultiTenancy.Controllers {
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult Edit(string name) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Cannot edit tenant")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == name);
|
||||
if (tenant == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
return View(new TenantEditViewModel {
|
||||
Name = tenant.Name,
|
||||
RequestUrlHost = tenant.RequestUrlHost,
|
||||
RequestUrlPrefix = tenant.RequestUrlPrefix,
|
||||
DataProvider = tenant.DataProvider,
|
||||
DatabaseConnectionString = tenant.DataConnectionString,
|
||||
DatabaseTablePrefix = tenant.DataTablePrefix,
|
||||
State = tenant.State
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Edit")]
|
||||
public ActionResult EditPost(TenantEditViewModel viewModel) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Couldn't edit tenant")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == viewModel.Name);
|
||||
if (tenant == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
_tenantService.UpdateTenant(
|
||||
new ShellSettings {
|
||||
Name = tenant.Name,
|
||||
RequestUrlHost = viewModel.RequestUrlHost,
|
||||
RequestUrlPrefix = viewModel.RequestUrlPrefix,
|
||||
DataProvider = viewModel.DataProvider,
|
||||
DataConnectionString = viewModel.DatabaseConnectionString,
|
||||
DataTablePrefix = viewModel.DatabaseTablePrefix,
|
||||
State = tenant.State
|
||||
});
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Failed to edit tenant: ") + exception.Message);
|
||||
return View(viewModel);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Disable(ShellSettings shellSettings) {
|
||||
public ActionResult Disable(string name) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Couldn't disable tenant")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == shellSettings.Name);
|
||||
var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == name);
|
||||
|
||||
if (tenant != null && tenant.Name != _thisShellSettings.Name) {
|
||||
tenant.State.CurrentState = TenantState.State.Disabled;
|
||||
@@ -73,11 +124,11 @@ namespace Orchard.MultiTenancy.Controllers {
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Enable(ShellSettings shellSettings) {
|
||||
public ActionResult Enable(string name) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageTenants, T("Couldn't enable tenant")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == shellSettings.Name);
|
||||
var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == name);
|
||||
|
||||
if (tenant != null && tenant.Name != _thisShellSettings.Name) {
|
||||
tenant.State.CurrentState = TenantState.State.Running;
|
||||
|
||||
@@ -65,9 +65,11 @@
|
||||
<Compile Include="Commands\TenantCommand.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Extensions\UrlHelperExtensions.cs" />
|
||||
<Compile Include="Routes.cs" />
|
||||
<Compile Include="Services\ITenantService.cs" />
|
||||
<Compile Include="Services\TenantService.cs" />
|
||||
<Compile Include="ViewModels\TenantsAddViewModel.cs" />
|
||||
<Compile Include="ViewModels\TenantEditViewModel.cs" />
|
||||
<Compile Include="ViewModels\TenantAddViewModel.cs" />
|
||||
<Compile Include="ViewModels\TenantsIndexViewModel.cs" />
|
||||
<Compile Include="Permissions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
@@ -77,6 +79,7 @@
|
||||
<Content Include="Content\Admin\images\enabled.gif" />
|
||||
<Content Include="Module.txt" />
|
||||
<Content Include="Views\Admin\Add.ascx" />
|
||||
<Content Include="Views\Admin\Edit.ascx" />
|
||||
<Content Include="Views\Admin\DisplayTemplates\ActionsForUninitialized.ascx" />
|
||||
<Content Include="Views\Admin\DisplayTemplates\ActionsForDisabled.ascx" />
|
||||
<Content Include="Views\Admin\DisplayTemplates\ActionsForInvalid.ascx" />
|
||||
|
||||
35
src/Orchard.Web/Modules/Orchard.MultiTenancy/Routes.cs
Normal file
35
src/Orchard.Web/Modules/Orchard.MultiTenancy/Routes.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Orchard.Mvc.Routes;
|
||||
|
||||
namespace Orchard.MultiTenancy {
|
||||
public class Routes : IRouteProvider {
|
||||
public IEnumerable<RouteDescriptor> GetRoutes() {
|
||||
return new[] {
|
||||
new RouteDescriptor {
|
||||
Route = new Route(
|
||||
"Admin/MultiTenancy/Edit/{name}",
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.MultiTenancy"},
|
||||
{"controller", "Admin"},
|
||||
{"action", "Edit"}
|
||||
},
|
||||
new RouteValueDictionary {
|
||||
{"name", ".+"}
|
||||
},
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.MultiTenancy"}
|
||||
},
|
||||
new MvcRouteHandler())
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void GetRoutes(ICollection<RouteDescriptor> routes) {
|
||||
foreach (RouteDescriptor routeDescriptor in GetRoutes()) {
|
||||
routes.Add(routeDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,14 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.MultiTenancy.Annotations;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.MultiTenancy.ViewModels {
|
||||
public class TenantsAddViewModel : BaseViewModel {
|
||||
public class TenantAddViewModel : BaseViewModel {
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
public string RequestUrlHost { get; set; }
|
||||
public string RequestUrlPrefix { get; set; }
|
||||
public bool? DatabaseOptions { get; set; }
|
||||
public string DataProvider { get; set; }
|
||||
[SqlDatabaseConnectionString]
|
||||
public string DatabaseConnectionString { get; set; }
|
||||
public string DatabaseTablePrefix { get; set; }
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.MultiTenancy.Annotations;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.MultiTenancy.ViewModels {
|
||||
public class TenantEditViewModel : BaseViewModel {
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
public string RequestUrlHost { get; set; }
|
||||
public string RequestUrlPrefix { get; set; }
|
||||
public string DataProvider { get; set; }
|
||||
[SqlDatabaseConnectionString]
|
||||
public string DatabaseConnectionString { get; set; }
|
||||
public string DatabaseTablePrefix { get; set; }
|
||||
public TenantState State { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<TenantsAddViewModel>" %>
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<TenantAddViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<%@ Import Namespace="Orchard.MultiTenancy.ViewModels"%>
|
||||
<h1><%=Html.TitleForPage(T("Add New Tenant").ToString()) %></h1>
|
||||
@@ -18,15 +18,15 @@
|
||||
<fieldset>
|
||||
<legend><%=_Encoded("Database Setup") %></legend>
|
||||
<div>
|
||||
<input type="radio" name="<%=Html.NameOf(m => m.DatabaseOptions) %>" value="" id="tenantDatabaseOption" <%=Model.DatabaseOptions == null ? " checked=\"checked\"" : "" %>/>
|
||||
<%=Html.RadioButtonFor(svm => svm.DataProvider, "", new { id = "tenantDatabaseOption" })%>
|
||||
<label for="tenantDatabaseOption" class="forcheckbox"><%=_Encoded("Allow the client to set up the database") %></label>
|
||||
</div>
|
||||
<div>
|
||||
<%=Html.RadioButtonFor(svm => svm.DatabaseOptions, true, new { id = "builtinDatabaseOption" })%>
|
||||
<%=Html.RadioButtonFor(svm => svm.DataProvider, "SQLite", new { id = "builtinDatabaseOption" })%>
|
||||
<label for="builtinDatabaseOption" class="forcheckbox"><%=_Encoded("Use built-in data storage (SQLite)") %></label>
|
||||
</div>
|
||||
<div>
|
||||
<%=Html.RadioButtonFor(svm => svm.DatabaseOptions, false, new { id = "sqlDatabaseOption" })%>
|
||||
<%=Html.RadioButtonFor(svm => svm.DataProvider, "SqlServer", new { id = "sqlDatabaseOption" })%>
|
||||
<label for="sqlDatabaseOption" class="forcheckbox"><%=_Encoded("Use an existing SQL Server (or SQL Express) database") %></label>
|
||||
<span data-controllerid="sqlDatabaseOption">
|
||||
<label for="DatabaseConnectionString"><%=_Encoded("Connection string") %></label>
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<TenantEditViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Environment.Configuration" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<%@ Import Namespace="Orchard.MultiTenancy.ViewModels"%>
|
||||
<h1><%=Html.TitleForPage(T("Edit Tenant").ToString()) %></h1>
|
||||
<%using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%=Html.ValidationSummary() %>
|
||||
<fieldset>
|
||||
<div>
|
||||
<h2><%=Html.Encode(Model.Name) %></h2>
|
||||
</div>
|
||||
<div>
|
||||
<label for="RequestUrlHost"><%=_Encoded("Host") %></label>
|
||||
<%=Html.TextBoxFor(m => m.RequestUrlHost, new {@class = "textMedium"}) %>
|
||||
<span class="hint"><%=_Encoded("Example: If host is \"orchardproject.net\", the tenant site URL is \"http://orchardproject.net/\"") %></span>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend><%=_Encoded("Database Setup") %></legend><%
|
||||
if (Model.State.CurrentState != TenantState.State.Uninitialized) { %>
|
||||
<div class="warning message"><%=_Encoded("Warning: If you don't know what you're doing you *will* (likely) send this tenant into a downward spiral of irrecoverable disrepair. Have a nice day.")%></div><%
|
||||
} else { %>
|
||||
<div>
|
||||
<%=Html.RadioButtonFor(svm => svm.DataProvider, "", new { id = "tenantDatabaseOption" })%>
|
||||
<label for="tenantDatabaseOption" class="forcheckbox"><%=_Encoded("Allow the client to set up the database") %></label>
|
||||
</div><%
|
||||
} %>
|
||||
<div>
|
||||
<%=Html.RadioButtonFor(svm => svm.DataProvider, "SQLite", new { id = "builtinDatabaseOption" })%>
|
||||
<label for="builtinDatabaseOption" class="forcheckbox"><%=_Encoded("Use built-in data storage (SQLite)") %></label>
|
||||
</div>
|
||||
<div>
|
||||
<%=Html.RadioButtonFor(svm => svm.DataProvider, "SqlServer", new { id = "sqlDatabaseOption" })%>
|
||||
<label for="sqlDatabaseOption" class="forcheckbox"><%=_Encoded("Use an existing SQL Server (or SQL Express) database") %></label>
|
||||
<span data-controllerid="sqlDatabaseOption">
|
||||
<label for="DatabaseConnectionString"><%=_Encoded("Connection string") %></label>
|
||||
<%=Html.TextBoxFor(svm => svm.DatabaseConnectionString, new {@class = "large text"})%>
|
||||
<span class="hint"><%=_Encoded("Example:") %><br /><%=_Encoded("Data Source=sqlServerName;Initial Catalog=dbName;Persist Security Info=True;User ID=userName;Password=password") %></span>
|
||||
</span>
|
||||
<span data-controllerid="sqlDatabaseOption">
|
||||
<label for="DatabaseTablePrefix"><%=_Encoded("Database Table Prefix") %></label>
|
||||
<%=Html.EditorFor(svm => svm.DatabaseTablePrefix)%>
|
||||
</span>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<input type="submit" class="button primaryAction" value="<%=_Encoded("Save") %>" />
|
||||
</fieldset>
|
||||
<% } %>
|
||||
@@ -1,5 +1,4 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<TenantsIndexViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Environment.Configuration" %>
|
||||
<%@ Import Namespace="Orchard.MultiTenancy.Extensions" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<%@ Import Namespace="Orchard.MultiTenancy.ViewModels"%>
|
||||
@@ -20,7 +19,7 @@
|
||||
var t = tenant; %>
|
||||
<%=Html.DisplayFor(m => t, string.Format("ActionsFor{0}", tenant.State.CurrentState), "") %><%=_Encoded(" | ")%><%
|
||||
} %>
|
||||
<%=Html.ActionLink(T("Edit").ToString(), "edit", new {tenantName = tenant.Name, area = "Orchard.MultiTenancy"}) %><%
|
||||
<%=Html.ActionLink(T("Edit").ToString(), "Edit", new {name = tenant.Name, area = "Orchard.MultiTenancy"}) %><%
|
||||
if (!string.Equals(tenant.Name, "default", StringComparison.OrdinalIgnoreCase)) { //todo: (heskew) base this off the view model so logic on what can be removed and have its state changed stays in the controller
|
||||
%><%--
|
||||
delete not implemented! <%=_Encoded(" | ")%>
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Orchard.Setup.Controllers {
|
||||
|
||||
public ActionResult Index() {
|
||||
var initialSettings = _setupService.Prime();
|
||||
return IndexViewResult(new SetupViewModel { AdminUsername = "admin", DatabaseIsPreconfigured = !string.IsNullOrEmpty(initialSettings.DataProvider)});
|
||||
return IndexViewResult(new SetupViewModel { AdminUsername = "admin", DatabaseIsPreconfigured = !(string.IsNullOrEmpty(initialSettings.DataProvider) || string.Equals(initialSettings.DataProvider, "none", StringComparison.OrdinalIgnoreCase))});
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Index")]
|
||||
|
||||
Reference in New Issue
Block a user