mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#18040: Adding a list of available themes per tenant
Work Item: 18040 --HG-- branch : 1.x
This commit is contained in:
@@ -31,7 +31,7 @@ namespace Orchard.Azure.Environment.Configuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void IShellSettingsManager.SaveSettings(ShellSettings settings) {
|
void IShellSettingsManager.SaveSettings(ShellSettings settings) {
|
||||||
var content = ComposeSettings(settings);
|
var content = ShellSettingsSerializer.ComposeSettings(settings);
|
||||||
var filePath = _fileSystem.Combine(settings.Name, SettingsFilename);
|
var filePath = _fileSystem.Combine(settings.Name, SettingsFilename);
|
||||||
|
|
||||||
var file = _fileSystem.FileExists(filePath)
|
var file = _fileSystem.FileExists(filePath)
|
||||||
@@ -55,83 +55,8 @@ namespace Orchard.Azure.Environment.Configuration {
|
|||||||
|
|
||||||
using (var stream = file.OpenRead())
|
using (var stream = file.OpenRead())
|
||||||
using (var reader = new StreamReader(stream))
|
using (var reader = new StreamReader(stream))
|
||||||
yield return ParseSettings(reader.ReadToEnd());
|
yield return ShellSettingsSerializer.ParseSettings(reader.ReadToEnd());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ShellSettings ParseSettings(string text) {
|
|
||||||
var shellSettings = new ShellSettings();
|
|
||||||
if (String.IsNullOrEmpty(text))
|
|
||||||
return shellSettings;
|
|
||||||
|
|
||||||
var settings = text.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
foreach (var setting in settings) {
|
|
||||||
var separatorIndex = setting.IndexOf(Separator);
|
|
||||||
if(separatorIndex == -1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
string key = setting.Substring(0, separatorIndex).Trim();
|
|
||||||
string value = setting.Substring(separatorIndex + 1).Trim();
|
|
||||||
|
|
||||||
if (value != EmptyValue) {
|
|
||||||
switch (key) {
|
|
||||||
case "Name":
|
|
||||||
shellSettings.Name = value;
|
|
||||||
break;
|
|
||||||
case "DataProvider":
|
|
||||||
shellSettings.DataProvider = value;
|
|
||||||
break;
|
|
||||||
case "State":
|
|
||||||
shellSettings.State = new TenantState(value);
|
|
||||||
break;
|
|
||||||
case "DataConnectionString":
|
|
||||||
shellSettings.DataConnectionString = value;
|
|
||||||
break;
|
|
||||||
case "DataPrefix":
|
|
||||||
shellSettings.DataTablePrefix = value;
|
|
||||||
break;
|
|
||||||
case "RequestUrlHost":
|
|
||||||
shellSettings.RequestUrlHost = value;
|
|
||||||
break;
|
|
||||||
case "RequestUrlPrefix":
|
|
||||||
shellSettings.RequestUrlPrefix = value;
|
|
||||||
break;
|
|
||||||
case "EncryptionAlgorithm":
|
|
||||||
shellSettings.EncryptionAlgorithm = value;
|
|
||||||
break;
|
|
||||||
case "EncryptionKey":
|
|
||||||
shellSettings.EncryptionKey = value;
|
|
||||||
break;
|
|
||||||
case "HashAlgorithm":
|
|
||||||
shellSettings.HashAlgorithm = value;
|
|
||||||
break;
|
|
||||||
case "HashKey":
|
|
||||||
shellSettings.HashKey = value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return shellSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
static string ComposeSettings(ShellSettings settings) {
|
|
||||||
if (settings == null)
|
|
||||||
return "";
|
|
||||||
|
|
||||||
return string.Format("Name: {0}\r\nDataProvider: {1}\r\nDataConnectionString: {2}\r\nDataPrefix: {3}\r\nRequestUrlHost: {4}\r\nRequestUrlPrefix: {5}\r\nState: {6}\r\nEncryptionAlgorithm: {7}\r\nEncryptionKey: {8}\r\nHashAlgorithm: {9}\r\nHashKey: {10}\r\n",
|
|
||||||
settings.Name,
|
|
||||||
settings.DataProvider,
|
|
||||||
settings.DataConnectionString ?? EmptyValue,
|
|
||||||
settings.DataTablePrefix ?? EmptyValue,
|
|
||||||
settings.RequestUrlHost ?? EmptyValue,
|
|
||||||
settings.RequestUrlPrefix ?? EmptyValue,
|
|
||||||
settings.State != null ? settings.State.ToString() : String.Empty,
|
|
||||||
settings.EncryptionAlgorithm ?? EmptyValue,
|
|
||||||
settings.EncryptionKey ?? EmptyValue,
|
|
||||||
settings.HashAlgorithm ?? EmptyValue,
|
|
||||||
settings.HashKey ?? EmptyValue
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,12 @@ namespace Orchard.MultiTenancy.Controllers {
|
|||||||
if ( !EnsureDefaultTenant() )
|
if ( !EnsureDefaultTenant() )
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
return View(new TenantAddViewModel());
|
var model = new TenantAddViewModel();
|
||||||
|
|
||||||
|
// fetches all available themes
|
||||||
|
model.Themes = _tenantService.GetInstalledThemes().Select(x => new ThemeEntry { ThemeId = x.Id, ThemeName = x.Name }).ToList();
|
||||||
|
|
||||||
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost, ActionName("Add")]
|
[HttpPost, ActionName("Add")]
|
||||||
@@ -70,7 +75,8 @@ namespace Orchard.MultiTenancy.Controllers {
|
|||||||
DataProvider = viewModel.DataProvider,
|
DataProvider = viewModel.DataProvider,
|
||||||
DataConnectionString = viewModel.DatabaseConnectionString,
|
DataConnectionString = viewModel.DatabaseConnectionString,
|
||||||
DataTablePrefix = viewModel.DatabaseTablePrefix,
|
DataTablePrefix = viewModel.DatabaseTablePrefix,
|
||||||
State = new TenantState("Uninitialized")
|
State = new TenantState("Uninitialized"),
|
||||||
|
Themes = viewModel.Themes.Where(x => x.Checked).Select(x => x.ThemeId).ToArray()
|
||||||
});
|
});
|
||||||
|
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
@@ -89,6 +95,7 @@ namespace Orchard.MultiTenancy.Controllers {
|
|||||||
return new HttpUnauthorizedResult();
|
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 HttpNotFound();
|
return HttpNotFound();
|
||||||
|
|
||||||
@@ -99,7 +106,12 @@ namespace Orchard.MultiTenancy.Controllers {
|
|||||||
DataProvider = tenant.DataProvider,
|
DataProvider = tenant.DataProvider,
|
||||||
DatabaseConnectionString = tenant.DataConnectionString,
|
DatabaseConnectionString = tenant.DataConnectionString,
|
||||||
DatabaseTablePrefix = tenant.DataTablePrefix,
|
DatabaseTablePrefix = tenant.DataTablePrefix,
|
||||||
State = tenant.State
|
State = tenant.State,
|
||||||
|
Themes = _tenantService.GetInstalledThemes().Select(x => new ThemeEntry {
|
||||||
|
ThemeId = x.Id,
|
||||||
|
ThemeName = x.Name,
|
||||||
|
Checked = tenant.Themes.Contains(x.Id)
|
||||||
|
}).ToList()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +144,8 @@ namespace Orchard.MultiTenancy.Controllers {
|
|||||||
EncryptionAlgorithm = tenant.EncryptionAlgorithm,
|
EncryptionAlgorithm = tenant.EncryptionAlgorithm,
|
||||||
EncryptionKey = tenant.EncryptionKey,
|
EncryptionKey = tenant.EncryptionKey,
|
||||||
HashAlgorithm = tenant.HashAlgorithm,
|
HashAlgorithm = tenant.HashAlgorithm,
|
||||||
HashKey = tenant.HashKey
|
HashKey = tenant.HashKey,
|
||||||
|
Themes = viewModel.Themes.Where(x => x.Checked).Select(x => x.ThemeId).ToArray()
|
||||||
});
|
});
|
||||||
|
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
<OldToolsVersion>3.5</OldToolsVersion>
|
<OldToolsVersion>3.5</OldToolsVersion>
|
||||||
<UpgradeBackupLocation />
|
<UpgradeBackupLocation />
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
|
<UseIISExpress>false</UseIISExpress>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@@ -64,6 +65,7 @@
|
|||||||
<Compile Include="ViewModels\TenantAddViewModel.cs" />
|
<Compile Include="ViewModels\TenantAddViewModel.cs" />
|
||||||
<Compile Include="ViewModels\TenantsIndexViewModel.cs" />
|
<Compile Include="ViewModels\TenantsIndexViewModel.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="ViewModels\ThemeEntry.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Content\Admin\images\disabled.gif" />
|
<Content Include="Content\Admin\images\disabled.gif" />
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
|
using Orchard.Environment.Extensions.Models;
|
||||||
|
|
||||||
namespace Orchard.MultiTenancy.Services {
|
namespace Orchard.MultiTenancy.Services {
|
||||||
public interface ITenantService : IDependency {
|
public interface ITenantService : IDependency {
|
||||||
IEnumerable<ShellSettings> GetTenants();
|
IEnumerable<ShellSettings> GetTenants();
|
||||||
void CreateTenant(ShellSettings settings);
|
void CreateTenant(ShellSettings settings);
|
||||||
void UpdateTenant(ShellSettings settings);
|
void UpdateTenant(ShellSettings settings);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a list of all installed themes
|
||||||
|
/// </summary>
|
||||||
|
IEnumerable<ExtensionDescriptor> GetInstalledThemes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,19 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
|
using Orchard.Environment.Extensions.Models;
|
||||||
|
using Orchard.Environment.Extensions;
|
||||||
|
|
||||||
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 IExtensionManager _extensionManager;
|
||||||
|
|
||||||
public TenantService(IShellSettingsManager shellSettingsManager) {
|
public TenantService(
|
||||||
|
IShellSettingsManager shellSettingsManager,
|
||||||
|
IExtensionManager extensionManager) {
|
||||||
_shellSettingsManager = shellSettingsManager;
|
_shellSettingsManager = shellSettingsManager;
|
||||||
|
_extensionManager = extensionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<ShellSettings> GetTenants() {
|
public IEnumerable<ShellSettings> GetTenants() {
|
||||||
@@ -24,5 +30,29 @@ namespace Orchard.MultiTenancy.Services {
|
|||||||
_shellSettingsManager.SaveSettings(settings);
|
_shellSettingsManager.SaveSettings(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads only installed themes
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<ExtensionDescriptor> GetInstalledThemes() {
|
||||||
|
return GetThemes(_extensionManager.AvailableExtensions());
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<ExtensionDescriptor> GetThemes(IEnumerable<ExtensionDescriptor> extensions) {
|
||||||
|
var themes = new List<ExtensionDescriptor>();
|
||||||
|
foreach (var descriptor in extensions) {
|
||||||
|
|
||||||
|
if (!DefaultExtensionTypes.IsTheme(descriptor.ExtensionType)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExtensionDescriptor theme = descriptor;
|
||||||
|
|
||||||
|
if (!theme.Tags.Contains("hidden")) {
|
||||||
|
themes.Add(theme);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return themes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Orchard.MultiTenancy.Annotations;
|
using Orchard.MultiTenancy.Annotations;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Orchard.MultiTenancy.ViewModels {
|
namespace Orchard.MultiTenancy.ViewModels {
|
||||||
public class TenantAddViewModel {
|
public class TenantAddViewModel {
|
||||||
public TenantAddViewModel() {
|
public TenantAddViewModel() {
|
||||||
// define "Allow the tenant to set up the database" as default value
|
// define "Allow the tenant to set up the database" as default value
|
||||||
DataProvider = "";
|
DataProvider = "";
|
||||||
|
Themes = new List<ThemeEntry>();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
@@ -16,6 +18,8 @@ namespace Orchard.MultiTenancy.ViewModels {
|
|||||||
[SqlDatabaseConnectionString]
|
[SqlDatabaseConnectionString]
|
||||||
public string DatabaseConnectionString { get; set; }
|
public string DatabaseConnectionString { get; set; }
|
||||||
public string DatabaseTablePrefix { get; set; }
|
public string DatabaseTablePrefix { get; set; }
|
||||||
|
|
||||||
|
public List<ThemeEntry> Themes { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
using Orchard.MultiTenancy.Annotations;
|
using Orchard.MultiTenancy.Annotations;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Orchard.MultiTenancy.ViewModels {
|
namespace Orchard.MultiTenancy.ViewModels {
|
||||||
public class TenantEditViewModel {
|
public class TenantEditViewModel {
|
||||||
|
public TenantEditViewModel() {
|
||||||
|
Themes = new List<ThemeEntry>();
|
||||||
|
}
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string RequestUrlHost { get; set; }
|
public string RequestUrlHost { get; set; }
|
||||||
@@ -13,6 +18,8 @@ namespace Orchard.MultiTenancy.ViewModels {
|
|||||||
public string DatabaseConnectionString { get; set; }
|
public string DatabaseConnectionString { get; set; }
|
||||||
public string DatabaseTablePrefix { get; set; }
|
public string DatabaseTablePrefix { get; set; }
|
||||||
public TenantState State { get; set; }
|
public TenantState State { get; set; }
|
||||||
|
|
||||||
|
public List<ThemeEntry> Themes { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
|
||||||
|
namespace Orchard.MultiTenancy.ViewModels {
|
||||||
|
public class ThemeEntry {
|
||||||
|
public bool Checked { get; set; }
|
||||||
|
public string ThemeName { get; set; }
|
||||||
|
public string ThemeId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<label for="@Html.FieldIdFor(m => m.Name)">@T("Name")</label>
|
<label for="@Html.FieldIdFor(m => m.Name)">@T("Name")</label>
|
||||||
@Html.TextBoxFor(m => m.Name, new { @class = "text" })
|
@Html.TextBoxFor(m => m.Name, new { @class = "text" })
|
||||||
|
<span class="hint">@T("The name of the tenant as it will be displayed in the admin.")</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="@Html.FieldIdFor(m => m.RequestUrlHost)">@T("Host")</label>
|
<label for="@Html.FieldIdFor(m => m.RequestUrlHost)">@T("Host")</label>
|
||||||
@@ -41,6 +42,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<div>
|
||||||
|
<label for="@Html.FieldIdFor(m => m.Themes)">@T("Available Themes")</label>
|
||||||
|
|
||||||
|
@for (var i=0 ;i<Model.Themes.Count; i++) {
|
||||||
|
var theme = Model.Themes[i];
|
||||||
|
@Html.CheckBox(Html.FieldNameFor(m => m.Themes[i].Checked), Model.Themes[i].Checked, new { id = Html.FieldIdFor(x => x.Themes[i]) })
|
||||||
|
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.Themes[i])">@Model.Themes[i].ThemeName</label>
|
||||||
|
@Html.HiddenFor(m => m.Themes[i].ThemeId)
|
||||||
|
@Html.HiddenFor(m => m.Themes[i].ThemeName)
|
||||||
|
}
|
||||||
|
|
||||||
|
<span class="hint">@T("Select the Themes which should be available for this tenant. If none is selected, they will all be available.")</span>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<button class="primaryAction" type="submit">@T("Save")</button>
|
<button class="primaryAction" type="submit">@T("Save")</button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="@Html.FieldIdFor(m => m.RequestUrlHost)">@T("Host")</label>
|
<label for="@Html.FieldIdFor(m => m.RequestUrlHost)">@T("Host")</label>
|
||||||
@Html.TextBoxFor(m => m.RequestUrlHost, new {@class = "textMedium"})
|
@Html.TextBoxFor(m => m.RequestUrlHost, new { @class = "textMedium" })
|
||||||
<span class="hint">@T("Example: If host is \"orchardproject.net\", the tenant site URL is \"http://orchardproject.net/\"")</span>
|
<span class="hint">@T("Example: If host is \"orchardproject.net\", the tenant site URL is \"http://orchardproject.net/\"")</span>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
@@ -19,7 +19,8 @@
|
|||||||
<legend>@T("Database Setup")</legend>
|
<legend>@T("Database Setup")</legend>
|
||||||
@if (Model.State.CurrentState != TenantState.State.Uninitialized) {
|
@if (Model.State.CurrentState != TenantState.State.Uninitialized) {
|
||||||
<div class="warning message">@T("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>
|
<div class="warning message">@T("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 {
|
}
|
||||||
|
else {
|
||||||
<div>
|
<div>
|
||||||
@Html.RadioButtonFor(svm => svm.DataProvider, "", new { id = "tenantDatabaseOption" })
|
@Html.RadioButtonFor(svm => svm.DataProvider, "", new { id = "tenantDatabaseOption" })
|
||||||
<label for="tenantDatabaseOption" class="forcheckbox">@T("Allow the tenant to set up the database")</label>
|
<label for="tenantDatabaseOption" class="forcheckbox">@T("Allow the tenant to set up the database")</label>
|
||||||
@@ -34,7 +35,7 @@
|
|||||||
<label for="sqlDatabaseOption" class="forcheckbox">@T("Use an existing SQL Server (or SQL Express) database")</label>
|
<label for="sqlDatabaseOption" class="forcheckbox">@T("Use an existing SQL Server (or SQL Express) database")</label>
|
||||||
<span data-controllerid="sqlDatabaseOption">
|
<span data-controllerid="sqlDatabaseOption">
|
||||||
<label for="DatabaseConnectionString">@T("Connection string")</label>
|
<label for="DatabaseConnectionString">@T("Connection string")</label>
|
||||||
@Html.TextBoxFor(svm => svm.DatabaseConnectionString, new {@class = "large text"})
|
@Html.TextBoxFor(svm => svm.DatabaseConnectionString, new { @class = "large text" })
|
||||||
<span class="hint">@T("Example:")<br />@T("Data Source=sqlServerName;Initial Catalog=dbName;Persist Security Info=True;User ID=userName;Password=password")</span>
|
<span class="hint">@T("Example:")<br />@T("Data Source=sqlServerName;Initial Catalog=dbName;Persist Security Info=True;User ID=userName;Password=password")</span>
|
||||||
</span>
|
</span>
|
||||||
<span data-controllerid="sqlDatabaseOption">
|
<span data-controllerid="sqlDatabaseOption">
|
||||||
@@ -43,6 +44,23 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<div>
|
||||||
|
<label for="@Html.FieldIdFor(m => m.Themes)">@T("Available Themes")</label>
|
||||||
|
|
||||||
|
@for (var i = 0; i < Model.Themes.Count; i++) {
|
||||||
|
var theme = Model.Themes[i];
|
||||||
|
@Html.CheckBox(Html.FieldNameFor(m => m.Themes[i].Checked), Model.Themes[i].Checked, new { id = Html.FieldIdFor(x => x.Themes[i]) })
|
||||||
|
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.Themes[i])">@Model.Themes[i].ThemeName</label>
|
||||||
|
@Html.HiddenFor(m => m.Themes[i].ThemeId)
|
||||||
|
@Html.HiddenFor(m => m.Themes[i].ThemeName)
|
||||||
|
}
|
||||||
|
|
||||||
|
<span class="hint">@T("Select the Themes which should be available for this tenant. If none is selected, they will all be available.")</span>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<button class="primaryAction" type="submit">@T("Save")</button>
|
<button class="primaryAction" type="submit">@T("Save")</button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ using Orchard.Themes.Services;
|
|||||||
using Orchard.Themes.ViewModels;
|
using Orchard.Themes.ViewModels;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
using Orchard.Utility.Extensions;
|
using Orchard.Utility.Extensions;
|
||||||
|
using Orchard.Environment.Configuration;
|
||||||
|
|
||||||
namespace Orchard.Themes.Controllers {
|
namespace Orchard.Themes.Controllers {
|
||||||
[ValidateInput(false)]
|
[ValidateInput(false)]
|
||||||
@@ -33,6 +34,7 @@ namespace Orchard.Themes.Controllers {
|
|||||||
private readonly IPreviewTheme _previewTheme;
|
private readonly IPreviewTheme _previewTheme;
|
||||||
private readonly IThemeService _themeService;
|
private readonly IThemeService _themeService;
|
||||||
private readonly IReportsCoordinator _reportsCoordinator;
|
private readonly IReportsCoordinator _reportsCoordinator;
|
||||||
|
private readonly ShellSettings _shellSettings;
|
||||||
|
|
||||||
public AdminController(
|
public AdminController(
|
||||||
IEnumerable<IExtensionDisplayEventHandler> extensionDisplayEventHandlers,
|
IEnumerable<IExtensionDisplayEventHandler> extensionDisplayEventHandlers,
|
||||||
@@ -44,7 +46,8 @@ namespace Orchard.Themes.Controllers {
|
|||||||
ShellDescriptor shellDescriptor,
|
ShellDescriptor shellDescriptor,
|
||||||
IPreviewTheme previewTheme,
|
IPreviewTheme previewTheme,
|
||||||
IThemeService themeService,
|
IThemeService themeService,
|
||||||
IReportsCoordinator reportsCoordinator) {
|
IReportsCoordinator reportsCoordinator,
|
||||||
|
ShellSettings shellSettings) {
|
||||||
Services = services;
|
Services = services;
|
||||||
|
|
||||||
_extensionDisplayEventHandler = extensionDisplayEventHandlers.FirstOrDefault();
|
_extensionDisplayEventHandler = extensionDisplayEventHandlers.FirstOrDefault();
|
||||||
@@ -56,6 +59,7 @@ namespace Orchard.Themes.Controllers {
|
|||||||
_previewTheme = previewTheme;
|
_previewTheme = previewTheme;
|
||||||
_themeService = themeService;
|
_themeService = themeService;
|
||||||
_reportsCoordinator = reportsCoordinator;
|
_reportsCoordinator = reportsCoordinator;
|
||||||
|
_shellSettings = shellSettings;
|
||||||
|
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
@@ -84,7 +88,10 @@ namespace Orchard.Themes.Controllers {
|
|||||||
hidden = tags.Split(',').Any(t => t.Trim().Equals("hidden", StringComparison.OrdinalIgnoreCase));
|
hidden = tags.Split(',').Any(t => t.Trim().Equals("hidden", StringComparison.OrdinalIgnoreCase));
|
||||||
}
|
}
|
||||||
|
|
||||||
return !hidden &&
|
// is the theme allowed for this tenant ?
|
||||||
|
bool allowed = _shellSettings.Themes.Length == 0 || _shellSettings.Themes.Contains(extensionDescriptor.Id);
|
||||||
|
|
||||||
|
return !hidden && allowed &&
|
||||||
DefaultExtensionTypes.IsTheme(extensionDescriptor.ExtensionType) &&
|
DefaultExtensionTypes.IsTheme(extensionDescriptor.ExtensionType) &&
|
||||||
(currentTheme == null ||
|
(currentTheme == null ||
|
||||||
!currentTheme.Descriptor.Id.Equals(extensionDescriptor.Id));
|
!currentTheme.Descriptor.Id.Equals(extensionDescriptor.Id));
|
||||||
@@ -200,7 +207,11 @@ namespace Orchard.Themes.Controllers {
|
|||||||
.FirstOrDefault(extension => DefaultExtensionTypes.IsTheme(extension.ExtensionType) && extension.Id.Equals(themeId)) == null) {
|
.FirstOrDefault(extension => DefaultExtensionTypes.IsTheme(extension.ExtensionType) && extension.Id.Equals(themeId)) == null) {
|
||||||
|
|
||||||
Services.Notifier.Error(T("Theme {0} was not found", themeId));
|
Services.Notifier.Error(T("Theme {0} was not found", themeId));
|
||||||
} else {
|
}
|
||||||
|
else if (_shellSettings.Themes.Any() && !_shellSettings.Themes.Contains(themeId)) {
|
||||||
|
return new HttpUnauthorizedResult();
|
||||||
|
}
|
||||||
|
else {
|
||||||
_themeService.EnableThemeFeatures(themeId);
|
_themeService.EnableThemeFeatures(themeId);
|
||||||
_siteThemeService.SetSiteTheme(themeId);
|
_siteThemeService.SetSiteTheme(themeId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
public ShellSettings() {
|
public ShellSettings() {
|
||||||
State = new TenantState("Invalid");
|
State = new TenantState("Invalid");
|
||||||
|
Themes = new string[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShellSettings(ShellSettings settings) {
|
public ShellSettings(ShellSettings settings) {
|
||||||
@@ -23,23 +24,64 @@
|
|||||||
HashAlgorithm = settings.HashAlgorithm;
|
HashAlgorithm = settings.HashAlgorithm;
|
||||||
HashKey = settings.HashKey;
|
HashKey = settings.HashKey;
|
||||||
State = settings.State;
|
State = settings.State;
|
||||||
|
Themes = settings.Themes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The name pf the tenant
|
||||||
|
/// </summary>
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The database provider
|
||||||
|
/// </summary>
|
||||||
public string DataProvider { get; set; }
|
public string DataProvider { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The database connection string
|
||||||
|
/// </summary>
|
||||||
public string DataConnectionString { get; set; }
|
public string DataConnectionString { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The data table prefix added to table names for this tenant
|
||||||
|
/// </summary>
|
||||||
public string DataTablePrefix { get; set; }
|
public string DataTablePrefix { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The host name of the tenant
|
||||||
|
/// </summary>
|
||||||
public string RequestUrlHost { get; set; }
|
public string RequestUrlHost { get; set; }
|
||||||
|
|
||||||
public string RequestUrlPrefix { get; set; }
|
public string RequestUrlPrefix { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The encryption algorithm used for encryption services
|
||||||
|
/// </summary>
|
||||||
public string EncryptionAlgorithm { get; set; }
|
public string EncryptionAlgorithm { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The encryption key used for encryption services
|
||||||
|
/// </summary>
|
||||||
public string EncryptionKey { get; set; }
|
public string EncryptionKey { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The hash algorithm used for encryption services
|
||||||
|
/// </summary>
|
||||||
public string HashAlgorithm { get; set; }
|
public string HashAlgorithm { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The hash key used for encryption services
|
||||||
|
/// </summary>
|
||||||
public string HashKey { get; set; }
|
public string HashKey { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List of available themes for this tenant
|
||||||
|
/// </summary>
|
||||||
|
public string[] Themes { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The state is which the tenant is
|
||||||
|
/// </summary>
|
||||||
public TenantState State { get; set; }
|
public TenantState State { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,8 +9,6 @@ namespace Orchard.Environment.Configuration {
|
|||||||
public class ShellSettingsManager : IShellSettingsManager {
|
public class ShellSettingsManager : IShellSettingsManager {
|
||||||
private readonly IAppDataFolder _appDataFolder;
|
private readonly IAppDataFolder _appDataFolder;
|
||||||
private readonly IShellSettingsManagerEventHandler _events;
|
private readonly IShellSettingsManagerEventHandler _events;
|
||||||
public const char Separator = ':';
|
|
||||||
public const string EmptyValue = "null";
|
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
@@ -34,7 +32,7 @@ namespace Orchard.Environment.Configuration {
|
|||||||
throw new ArgumentException(T("Settings \"Name\" is not set.").ToString());
|
throw new ArgumentException(T("Settings \"Name\" is not set.").ToString());
|
||||||
|
|
||||||
var filePath = Path.Combine(Path.Combine("Sites", settings.Name), "Settings.txt");
|
var filePath = Path.Combine(Path.Combine("Sites", settings.Name), "Settings.txt");
|
||||||
_appDataFolder.CreateFile(filePath, ComposeSettings(settings));
|
_appDataFolder.CreateFile(filePath, ShellSettingsSerializer.ComposeSettings(settings));
|
||||||
_events.Saved(settings);
|
_events.Saved(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,89 +43,8 @@ namespace Orchard.Environment.Configuration {
|
|||||||
.Where(path => string.Equals(Path.GetFileName(path), "Settings.txt", StringComparison.OrdinalIgnoreCase));
|
.Where(path => string.Equals(Path.GetFileName(path), "Settings.txt", StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
foreach (var filePath in filePaths) {
|
foreach (var filePath in filePaths) {
|
||||||
yield return ParseSettings(_appDataFolder.ReadFile(filePath));
|
yield return ShellSettingsSerializer.ParseSettings(_appDataFolder.ReadFile(filePath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ShellSettings ParseSettings(string text) {
|
|
||||||
var shellSettings = new ShellSettings();
|
|
||||||
if (String.IsNullOrEmpty(text))
|
|
||||||
return shellSettings;
|
|
||||||
|
|
||||||
var settings = new StringReader(text);
|
|
||||||
string setting;
|
|
||||||
while ((setting = settings.ReadLine()) != null)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(setting)) continue; ;
|
|
||||||
var separatorIndex = setting.IndexOf(Separator);
|
|
||||||
if (separatorIndex == -1)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
string key = setting.Substring(0, separatorIndex).Trim();
|
|
||||||
string value = setting.Substring(separatorIndex + 1).Trim();
|
|
||||||
|
|
||||||
if (value != EmptyValue)
|
|
||||||
{
|
|
||||||
switch (key)
|
|
||||||
{
|
|
||||||
case "Name":
|
|
||||||
shellSettings.Name = value;
|
|
||||||
break;
|
|
||||||
case "DataProvider":
|
|
||||||
shellSettings.DataProvider = value;
|
|
||||||
break;
|
|
||||||
case "State":
|
|
||||||
shellSettings.State = new TenantState(value);
|
|
||||||
break;
|
|
||||||
case "DataConnectionString":
|
|
||||||
shellSettings.DataConnectionString = value;
|
|
||||||
break;
|
|
||||||
case "DataPrefix":
|
|
||||||
shellSettings.DataTablePrefix = value;
|
|
||||||
break;
|
|
||||||
case "RequestUrlHost":
|
|
||||||
shellSettings.RequestUrlHost = value;
|
|
||||||
break;
|
|
||||||
case "RequestUrlPrefix":
|
|
||||||
shellSettings.RequestUrlPrefix = value;
|
|
||||||
break;
|
|
||||||
case "EncryptionAlgorithm":
|
|
||||||
shellSettings.EncryptionAlgorithm = value;
|
|
||||||
break;
|
|
||||||
case "EncryptionKey":
|
|
||||||
shellSettings.EncryptionKey = value;
|
|
||||||
break;
|
|
||||||
case "HashAlgorithm":
|
|
||||||
shellSettings.HashAlgorithm = value;
|
|
||||||
break;
|
|
||||||
case "HashKey":
|
|
||||||
shellSettings.HashKey = value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return shellSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
static string ComposeSettings(ShellSettings settings) {
|
|
||||||
if (settings == null)
|
|
||||||
return "";
|
|
||||||
|
|
||||||
return string.Format("Name: {0}\r\nDataProvider: {1}\r\nDataConnectionString: {2}\r\nDataPrefix: {3}\r\nRequestUrlHost: {4}\r\nRequestUrlPrefix: {5}\r\nState: {6}\r\nEncryptionAlgorithm: {7}\r\nEncryptionKey: {8}\r\nHashAlgorithm: {9}\r\nHashKey: {10}\r\n",
|
|
||||||
settings.Name,
|
|
||||||
settings.DataProvider,
|
|
||||||
settings.DataConnectionString ?? EmptyValue,
|
|
||||||
settings.DataTablePrefix ?? EmptyValue,
|
|
||||||
settings.RequestUrlHost ?? EmptyValue,
|
|
||||||
settings.RequestUrlPrefix ?? EmptyValue,
|
|
||||||
settings.State != null ? settings.State.ToString() : String.Empty,
|
|
||||||
settings.EncryptionAlgorithm ?? EmptyValue,
|
|
||||||
settings.EncryptionKey ?? EmptyValue,
|
|
||||||
settings.HashAlgorithm ?? EmptyValue,
|
|
||||||
settings.HashKey ?? EmptyValue
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Orchard.Environment.Configuration {
|
||||||
|
public class ShellSettingsSerializer {
|
||||||
|
public const char Separator = ':';
|
||||||
|
public const string EmptyValue = "null";
|
||||||
|
public const char ThemesSeparator = ';';
|
||||||
|
|
||||||
|
public static ShellSettings ParseSettings(string text) {
|
||||||
|
var shellSettings = new ShellSettings();
|
||||||
|
if (String.IsNullOrEmpty(text))
|
||||||
|
return shellSettings;
|
||||||
|
|
||||||
|
var settings = new StringReader(text);
|
||||||
|
string setting;
|
||||||
|
while ((setting = settings.ReadLine()) != null) {
|
||||||
|
if (string.IsNullOrWhiteSpace(setting)) continue; ;
|
||||||
|
var separatorIndex = setting.IndexOf(Separator);
|
||||||
|
if (separatorIndex == -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
string key = setting.Substring(0, separatorIndex).Trim();
|
||||||
|
string value = setting.Substring(separatorIndex + 1).Trim();
|
||||||
|
|
||||||
|
if (value != EmptyValue) {
|
||||||
|
switch (key) {
|
||||||
|
case "Name":
|
||||||
|
shellSettings.Name = value;
|
||||||
|
break;
|
||||||
|
case "DataProvider":
|
||||||
|
shellSettings.DataProvider = value;
|
||||||
|
break;
|
||||||
|
case "State":
|
||||||
|
shellSettings.State = new TenantState(value);
|
||||||
|
break;
|
||||||
|
case "DataConnectionString":
|
||||||
|
shellSettings.DataConnectionString = value;
|
||||||
|
break;
|
||||||
|
case "DataPrefix":
|
||||||
|
shellSettings.DataTablePrefix = value;
|
||||||
|
break;
|
||||||
|
case "RequestUrlHost":
|
||||||
|
shellSettings.RequestUrlHost = value;
|
||||||
|
break;
|
||||||
|
case "RequestUrlPrefix":
|
||||||
|
shellSettings.RequestUrlPrefix = value;
|
||||||
|
break;
|
||||||
|
case "EncryptionAlgorithm":
|
||||||
|
shellSettings.EncryptionAlgorithm = value;
|
||||||
|
break;
|
||||||
|
case "EncryptionKey":
|
||||||
|
shellSettings.EncryptionKey = value;
|
||||||
|
break;
|
||||||
|
case "HashAlgorithm":
|
||||||
|
shellSettings.HashAlgorithm = value;
|
||||||
|
break;
|
||||||
|
case "HashKey":
|
||||||
|
shellSettings.HashKey = value;
|
||||||
|
break;
|
||||||
|
case "Themes":
|
||||||
|
shellSettings.Themes = value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return shellSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ComposeSettings(ShellSettings settings) {
|
||||||
|
if (settings == null)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
return string.Format("Name: {0}\r\nDataProvider: {1}\r\nDataConnectionString: {2}\r\nDataPrefix: {3}\r\nRequestUrlHost: {4}\r\nRequestUrlPrefix: {5}\r\nState: {6}\r\nEncryptionAlgorithm: {7}\r\nEncryptionKey: {8}\r\nHashAlgorithm: {9}\r\nHashKey: {10}\r\nThemes: {11}\r\n",
|
||||||
|
settings.Name,
|
||||||
|
settings.DataProvider,
|
||||||
|
settings.DataConnectionString ?? EmptyValue,
|
||||||
|
settings.DataTablePrefix ?? EmptyValue,
|
||||||
|
settings.RequestUrlHost ?? EmptyValue,
|
||||||
|
settings.RequestUrlPrefix ?? EmptyValue,
|
||||||
|
settings.State != null ? settings.State.ToString() : String.Empty,
|
||||||
|
settings.EncryptionAlgorithm ?? EmptyValue,
|
||||||
|
settings.EncryptionKey ?? EmptyValue,
|
||||||
|
settings.HashAlgorithm ?? EmptyValue,
|
||||||
|
settings.HashKey ?? EmptyValue,
|
||||||
|
String.Join(";", settings.Themes ?? new string[0])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -232,7 +232,10 @@ namespace Orchard.Environment {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void IShellSettingsManagerEventHandler.Saved(ShellSettings settings) {
|
void IShellSettingsManagerEventHandler.Saved(ShellSettings settings) {
|
||||||
lock (_syncLock) {
|
lock (_syncLock) {
|
||||||
_tenantsToRestart = _tenantsToRestart.Where(x => x.Name != settings.Name).Union(new[] { settings });
|
// if a tenant has been altered, and is not uninitialized, reload it
|
||||||
|
if (settings.State.CurrentState != TenantState.State.Uninitialized) {
|
||||||
|
_tenantsToRestart = _tenantsToRestart.Where(x => x.Name != settings.Name).Union(new[] { settings });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -205,6 +205,7 @@
|
|||||||
<Compile Include="DisplayManagement\Shapes\ITagBuilderFactory.cs" />
|
<Compile Include="DisplayManagement\Shapes\ITagBuilderFactory.cs" />
|
||||||
<Compile Include="Environment\CollectionOrderModule.cs" />
|
<Compile Include="Environment\CollectionOrderModule.cs" />
|
||||||
<Compile Include="Caching\DefaultAsyncTokenProvider.cs" />
|
<Compile Include="Caching\DefaultAsyncTokenProvider.cs" />
|
||||||
|
<Compile Include="Environment\Configuration\ShellSettingsSerializer.cs" />
|
||||||
<Compile Include="Environment\Extensions\ExtensionMonitoringCoordinator.cs" />
|
<Compile Include="Environment\Extensions\ExtensionMonitoringCoordinator.cs" />
|
||||||
<Compile Include="Caching\IAsyncTokenProvider.cs" />
|
<Compile Include="Caching\IAsyncTokenProvider.cs" />
|
||||||
<Compile Include="Environment\Extensions\Folders\CoreModuleFolders.cs" />
|
<Compile Include="Environment\Extensions\Folders\CoreModuleFolders.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user