#18040: Adding a list of available themes per tenant

Work Item: 18040

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-12-14 16:49:01 -08:00
parent 1b4a46f053
commit b6fbe4bd63
16 changed files with 279 additions and 176 deletions

View File

@@ -20,6 +20,7 @@ using Orchard.Themes.Services;
using Orchard.Themes.ViewModels;
using Orchard.UI.Notify;
using Orchard.Utility.Extensions;
using Orchard.Environment.Configuration;
namespace Orchard.Themes.Controllers {
[ValidateInput(false)]
@@ -33,6 +34,7 @@ namespace Orchard.Themes.Controllers {
private readonly IPreviewTheme _previewTheme;
private readonly IThemeService _themeService;
private readonly IReportsCoordinator _reportsCoordinator;
private readonly ShellSettings _shellSettings;
public AdminController(
IEnumerable<IExtensionDisplayEventHandler> extensionDisplayEventHandlers,
@@ -44,7 +46,8 @@ namespace Orchard.Themes.Controllers {
ShellDescriptor shellDescriptor,
IPreviewTheme previewTheme,
IThemeService themeService,
IReportsCoordinator reportsCoordinator) {
IReportsCoordinator reportsCoordinator,
ShellSettings shellSettings) {
Services = services;
_extensionDisplayEventHandler = extensionDisplayEventHandlers.FirstOrDefault();
@@ -56,7 +59,8 @@ namespace Orchard.Themes.Controllers {
_previewTheme = previewTheme;
_themeService = themeService;
_reportsCoordinator = reportsCoordinator;
_shellSettings = shellSettings;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance;
}
@@ -84,7 +88,10 @@ namespace Orchard.Themes.Controllers {
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) &&
(currentTheme == null ||
!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) {
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);
_siteThemeService.SetSiteTheme(themeId);
}