mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#17775: Checking if a theme exists before applying it.
--HG-- branch : 1.x
This commit is contained in:
@@ -66,7 +66,6 @@ namespace Orchard.Themes.Controllers {
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
try {
|
||||
bool installThemes = _featureManager.GetEnabledFeatures().FirstOrDefault(f => f.Id == "PackagingServices") != null;
|
||||
|
||||
var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();
|
||||
@@ -107,39 +106,37 @@ namespace Orchard.Themes.Controllers {
|
||||
InstallThemes = installThemes,
|
||||
Themes = themes
|
||||
});
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Listing themes failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
|
||||
return View(new ThemesIndexViewModel());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost, FormValueAbsent("submit.Apply"), FormValueAbsent("submit.Cancel")]
|
||||
public ActionResult Preview(string themeName, string returnUrl) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't preview the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
if (_extensionManager.AvailableExtensions()
|
||||
.FirstOrDefault(extension => DefaultExtensionTypes.IsTheme(extension.ExtensionType) && extension.Name.Equals(themeName)) == null) {
|
||||
|
||||
Services.Notifier.Error(T("Theme {0} was not found", themeName));
|
||||
} else {
|
||||
_themeService.EnableThemeFeatures(themeName);
|
||||
_previewTheme.SetPreviewTheme(themeName);
|
||||
}
|
||||
|
||||
return this.RedirectLocal(returnUrl, "~/");
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Previewing theme failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Preview"), FormValueRequired("submit.Apply")]
|
||||
public ActionResult ApplyPreview(string themeName, string returnUrl) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't preview the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
if (_extensionManager.AvailableExtensions()
|
||||
.FirstOrDefault(extension => DefaultExtensionTypes.IsTheme(extension.ExtensionType) && extension.Name.Equals(themeName)) == null) {
|
||||
|
||||
Services.Notifier.Error(T("Theme {0} was not found", themeName));
|
||||
} else {
|
||||
_previewTheme.SetPreviewTheme(null);
|
||||
_siteThemeService.SetSiteTheme(themeName);
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Previewing theme failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
}
|
||||
|
||||
return RedirectToAction("Index");
|
||||
@@ -147,53 +144,60 @@ namespace Orchard.Themes.Controllers {
|
||||
|
||||
[HttpPost, ActionName("Preview"), FormValueRequired("submit.Cancel")]
|
||||
public ActionResult CancelPreview(string returnUrl) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't preview the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
_previewTheme.SetPreviewTheme(null);
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Previewing theme failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
}
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Enable(string themeName) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't enable the theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
if (_extensionManager.AvailableExtensions()
|
||||
.FirstOrDefault(extension => DefaultExtensionTypes.IsTheme(extension.ExtensionType) && extension.Name.Equals(themeName)) == null) {
|
||||
|
||||
Services.Notifier.Error(T("Theme {0} was not found", themeName));
|
||||
} else {
|
||||
_themeService.EnableThemeFeatures(themeName);
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Enabling theme failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
}
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Disable(string themeName) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't disable the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
if (_extensionManager.AvailableExtensions()
|
||||
.FirstOrDefault(extension => DefaultExtensionTypes.IsTheme(extension.ExtensionType) && extension.Name.Equals(themeName)) == null) {
|
||||
|
||||
Services.Notifier.Error(T("Theme {0} was not found", themeName));
|
||||
} else {
|
||||
_themeService.DisableThemeFeatures(themeName);
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Disabling theme failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
}
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Activate(string themeName) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't set the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
if (_extensionManager.AvailableExtensions()
|
||||
.FirstOrDefault(extension => DefaultExtensionTypes.IsTheme(extension.ExtensionType) && extension.Name.Equals(themeName)) == null) {
|
||||
|
||||
Services.Notifier.Error(T("Theme {0} was not found", themeName));
|
||||
} else {
|
||||
_themeService.EnableThemeFeatures(themeName);
|
||||
_siteThemeService.SetSiteTheme(themeName);
|
||||
} catch (Exception exception) {
|
||||
this.Error(exception, T("Activating theme failed: {0}", exception.Message), Logger, Services.Notifier);
|
||||
}
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,9 @@ namespace Orchard.Themes.Models {
|
||||
/// <summary>
|
||||
/// Default constructor.
|
||||
/// </summary>
|
||||
public ThemeEntry() {}
|
||||
public ThemeEntry() {
|
||||
Notifications = new List<string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a theme based on an extension descriptor.
|
||||
|
Reference in New Issue
Block a user