From 3403164aea64504e0ef3c7d4c777241575d1894b Mon Sep 17 00:00:00 2001 From: rfcdejong Date: Wed, 2 Feb 2011 11:57:14 +0100 Subject: [PATCH 1/5] Added theme command support, list and the ability to activate a theme --- .../Orchard.Themes/Commands/ThemeCommands.cs | 106 ++++++++++++++++++ .../Orchard.Themes/Orchard.Themes.csproj | 1 + 2 files changed, 107 insertions(+) create mode 100644 src/Orchard.Web/Modules/Orchard.Themes/Commands/ThemeCommands.cs diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Commands/ThemeCommands.cs b/src/Orchard.Web/Modules/Orchard.Themes/Commands/ThemeCommands.cs new file mode 100644 index 000000000..9d7dc8639 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Themes/Commands/ThemeCommands.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Orchard.Commands; +using Orchard.Data.Migration; +using Orchard.Environment.Descriptor.Models; +using Orchard.Environment.Extensions; +using Orchard.Environment.Extensions.Models; +using Orchard.Themes.Services; +using Orchard.Themes.ViewModels; + +namespace Orchard.Themes.Commands { + public class ThemeCommands : DefaultOrchardCommandHandler { + private readonly IDataMigrationManager _dataMigrationManager; + private readonly ISiteThemeService _siteThemeService; + private readonly IExtensionManager _extensionManager; + private readonly ShellDescriptor _shellDescriptor; + private readonly IThemeService _themeService; + + public ThemeCommands(IDataMigrationManager dataMigrationManager, + ISiteThemeService siteThemeService, + IExtensionManager extensionManager, + ShellDescriptor shellDescriptor, + IThemeService themeService) { + _dataMigrationManager = dataMigrationManager; + _siteThemeService = siteThemeService; + _extensionManager = extensionManager; + _shellDescriptor = shellDescriptor; + _themeService = themeService; + } + + [OrchardSwitch] + public bool Summary { get; set; } + + [CommandName("theme list")] + [CommandHelp("theme list [/Summary:true|false]" + "\r\n\tDisplay list of available themes")] + [OrchardSwitches("Summary")] + public void List() { + var currentTheme = _siteThemeService.GetSiteTheme(); + var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate(); + + var themes = _extensionManager.AvailableExtensions() + .Where(d => DefaultExtensionTypes.IsTheme(d.ExtensionType)) + .Where(d => d.Tags.Split(',').Any(t => t.Trim().Equals("hidden", StringComparison.OrdinalIgnoreCase)) == false) + .Select(d => new ThemeEntry { + Descriptor = d, + NeedsUpdate = featuresThatNeedUpdate.Contains(d.Id), + Enabled = _shellDescriptor.Features.Any(sf => sf.Name == d.Id) + }) + .ToArray(); + + if (Summary) { + foreach (var theme in themes) { + Context.Output.WriteLine(T("{0}", theme.Name)); + } + } + else { + Context.Output.WriteLine(T("Current theme")); + Context.Output.WriteLine(T("--------------------------")); + WriteThemeLines(new ThemeEntry() { + Descriptor = currentTheme, + NeedsUpdate = featuresThatNeedUpdate.Contains(currentTheme.Id), + Enabled = _shellDescriptor.Features.Any(sf => sf.Name == currentTheme.Id) + }); + + Context.Output.WriteLine(T("List of available themes")); + Context.Output.WriteLine(T("--------------------------")); + themes.Where(t => t.Name.Trim().Equals(currentTheme.Name.Trim(), StringComparison.OrdinalIgnoreCase) == false) + .ToList() + .ForEach(t => WriteThemeLines(t)); + } + } + + private void WriteThemeLines(ThemeEntry theme) { + Context.Output.WriteLine(T(" Name: {0}", theme.Name)); + Context.Output.WriteLine(T(" State: {0}", theme.Enabled ? T("Enabled") : T("Disabled"))); + Context.Output.WriteLine(T(" NeedsUpdate: {0}", theme.NeedsUpdate ? T("Yes") : T("No"))); + Context.Output.WriteLine(T(" Author: {0}", theme.Descriptor.Author)); + Context.Output.WriteLine(T(" Version: {0}", theme.Descriptor.Version)); + Context.Output.WriteLine(T(" Description: {0}", theme.Descriptor.Description)); + Context.Output.WriteLine(T(" Website: {0}", theme.Descriptor.WebSite)); + Context.Output.WriteLine(T(" Zones: {0}", string.Join(", ", theme.Descriptor.Zones))); + Context.Output.WriteLine(); + } + + [CommandName("theme activate")] + [CommandHelp("theme activate " + "\r\n\tEnable and activates a theme")] + public void Activate(string themeName) { + var theme = _extensionManager.AvailableExtensions().FirstOrDefault(x => x.Name.Trim().Equals(themeName, StringComparison.OrdinalIgnoreCase)); + if (theme == null) { + Context.Output.WriteLine(T("Could not find theme {0}", themeName)); + return; + } + + if (!_shellDescriptor.Features.Any(sf => sf.Name == theme.Id)) { + Context.Output.WriteLine(T("Enabling theme \"{0}\"...", themeName)); + _themeService.EnableThemeFeatures(themeName); + } + + Context.Output.WriteLine(T("Activating theme \"{0}\"...", themeName)); + _siteThemeService.SetSiteTheme(themeName); + + Context.Output.WriteLine(T("Theme \"{0}\" activated", themeName)); + } + } +} diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj b/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj index a504b7e20..5eb5b51c0 100644 --- a/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj +++ b/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj @@ -49,6 +49,7 @@ + From 4896cca88b6c06890a1109540eb8420b41cd810c Mon Sep 17 00:00:00 2001 From: rukshanperera Date: Wed, 2 Feb 2011 11:02:39 +0000 Subject: [PATCH 2/5] Fix issue: 17229 Submitting an empty tag creates a "New Tag Name" tag --- src/Orchard.Web/Core/Shapes/Scripts/base.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Orchard.Web/Core/Shapes/Scripts/base.js b/src/Orchard.Web/Core/Shapes/Scripts/base.js index 1ec08c2fb..b14fe4df0 100644 --- a/src/Orchard.Web/Core/Shapes/Scripts/base.js +++ b/src/Orchard.Web/Core/Shapes/Scripts/base.js @@ -126,6 +126,11 @@ } }); + //make sure the placeholder value is not taken as the input value when submitting forms + $("form").live("submit", function () { + $(":input[placeholder].placeholderd").val(""); + }); + return _this; }, toggleWhatYouControl: function () { From e47c5820010e909157bebfd5511e3aba38b507c2 Mon Sep 17 00:00:00 2001 From: Suha Can Date: Wed, 2 Feb 2011 10:46:22 -0800 Subject: [PATCH 3/5] Minor cleanup --- .../Modules/Orchard.Themes/Commands/ThemeCommands.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Commands/ThemeCommands.cs b/src/Orchard.Web/Modules/Orchard.Themes/Commands/ThemeCommands.cs index 9d7dc8639..f05c5b3d5 100644 --- a/src/Orchard.Web/Modules/Orchard.Themes/Commands/ThemeCommands.cs +++ b/src/Orchard.Web/Modules/Orchard.Themes/Commands/ThemeCommands.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using Orchard.Commands; using Orchard.Data.Migration; @@ -57,7 +56,7 @@ namespace Orchard.Themes.Commands { else { Context.Output.WriteLine(T("Current theme")); Context.Output.WriteLine(T("--------------------------")); - WriteThemeLines(new ThemeEntry() { + WriteThemeLines(new ThemeEntry { Descriptor = currentTheme, NeedsUpdate = featuresThatNeedUpdate.Contains(currentTheme.Id), Enabled = _shellDescriptor.Features.Any(sf => sf.Name == currentTheme.Id) From 86c11ada8e8a2325f60a9f4885da6284249f9e9d Mon Sep 17 00:00:00 2001 From: rukshanperera Date: Thu, 3 Feb 2011 13:28:44 +0000 Subject: [PATCH 4/5] Fix issue: 16313 - Administrator can create two same roles --- .../Orchard.Roles/Controllers/AdminController.cs | 9 +++++++++ .../Modules/Orchard.Roles/Services/IRoleService.cs | 8 ++++++++ .../Modules/Orchard.Roles/Services/RoleService.cs | 11 +++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs index 72b384f8b..8b61b84d4 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs @@ -77,6 +77,15 @@ namespace Orchard.Roles.Controllers { var viewModel = new RoleCreateViewModel(); try { UpdateModel(viewModel); + + //check if the role name already exists + if (!_roleService.VerifyRoleUnicity(viewModel.Name)) + { + Services.Notifier.Error(T("Creating Role failed: {0}", "Role with same name already exists")); + + return RedirectToAction("Create"); + } + _roleService.CreateRole(viewModel.Name); foreach (string key in Request.Form.Keys) { if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") { diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Services/IRoleService.cs b/src/Orchard.Web/Modules/Orchard.Roles/Services/IRoleService.cs index 732d5d53f..21638218c 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Services/IRoleService.cs +++ b/src/Orchard.Web/Modules/Orchard.Roles/Services/IRoleService.cs @@ -15,5 +15,13 @@ namespace Orchard.Roles.Services { IEnumerable GetPermissionsForRole(int id); IEnumerable GetPermissionsForRoleByName(string name); + + + /// + /// Verify if the role name is unique + /// + /// Role name + /// Returns false if a role with the given name already exits + bool VerifyRoleUnicity(string name); } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Services/RoleService.cs b/src/Orchard.Web/Modules/Orchard.Roles/Services/RoleService.cs index c38e8e83a..0853bdf17 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Services/RoleService.cs +++ b/src/Orchard.Web/Modules/Orchard.Roles/Services/RoleService.cs @@ -151,6 +151,17 @@ namespace Orchard.Roles.Services { }); } + /// + /// Verify if the role name is unique + /// + /// Role name + /// Returns false if a role with the given name already exits + public bool VerifyRoleUnicity(string name) + { + return _roleRepository.Get(x => x.Name == name) == null ? true : false; + } + + IEnumerable GetPermissionsForRoleByNameInner(string name) { var roleRecord = GetRoleByName(name); return roleRecord == null ? Enumerable.Empty() : GetPermissionsForRole(roleRecord.Id); From b14d95778b973192da2952290d42f8f628a687b2 Mon Sep 17 00:00:00 2001 From: Suha Can Date: Thu, 3 Feb 2011 11:01:45 -0800 Subject: [PATCH 5/5] Minor alteration to previous contribution --- .../Modules/Orchard.Roles/Controllers/AdminController.cs | 6 ++---- .../Modules/Orchard.Roles/Services/RoleService.cs | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs index 8b61b84d4..a64fb1d9a 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs @@ -79,10 +79,8 @@ namespace Orchard.Roles.Controllers { UpdateModel(viewModel); //check if the role name already exists - if (!_roleService.VerifyRoleUnicity(viewModel.Name)) - { - Services.Notifier.Error(T("Creating Role failed: {0}", "Role with same name already exists")); - + if (!_roleService.VerifyRoleUnicity(viewModel.Name)) { + Services.Notifier.Error(T("Creating Role {0} failed: Role with same name already exists", viewModel.Name)); return RedirectToAction("Create"); } diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Services/RoleService.cs b/src/Orchard.Web/Modules/Orchard.Roles/Services/RoleService.cs index 0853bdf17..a1b971050 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Services/RoleService.cs +++ b/src/Orchard.Web/Modules/Orchard.Roles/Services/RoleService.cs @@ -156,9 +156,8 @@ namespace Orchard.Roles.Services { /// /// Role name /// Returns false if a role with the given name already exits - public bool VerifyRoleUnicity(string name) - { - return _roleRepository.Get(x => x.Name == name) == null ? true : false; + public bool VerifyRoleUnicity(string name) { + return (_roleRepository.Get(x => x.Name == name) == null); }