diff --git a/Oqtane.Client/Modules/Controls/PermissionGrid.razor b/Oqtane.Client/Modules/Controls/PermissionGrid.razor index d330a9b6..eed771a4 100644 --- a/Oqtane.Client/Modules/Controls/PermissionGrid.razor +++ b/Oqtane.Client/Modules/Controls/PermissionGrid.razor @@ -81,9 +81,7 @@ [Parameter] public string Permissions { get; set; } - [Parameter] - public string PermissionNames { get; set; } // optional - can be used to specify permissions order or add custom permissions - + string permissionnames = ""; List roles; List permissions = new List(); List users = new List(); @@ -92,14 +90,15 @@ protected override async Task OnInitializedAsync() { - if (string.IsNullOrEmpty(PermissionNames)) + permissionnames = PageState.ModuleDefinitions.Find(item => item.ModuleDefinitionName == ModuleState.ModuleDefinitionName).Permissions; + if (string.IsNullOrEmpty(permissionnames)) { - PermissionNames = "View,Edit"; + permissionnames = "View,Edit"; } roles = await RoleService.GetRolesAsync(ModuleState.SiteId); roles.Insert(0, new Role { Name = Constants.AllUsersRole }); - foreach (string permissionname in PermissionNames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) + foreach (string permissionname in permissionnames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { permissions.Add(new PermissionString { PermissionName = permissionname, Permissions = "" }); } diff --git a/Oqtane.Client/Modules/Counter/Module.cs b/Oqtane.Client/Modules/Counter/Module.cs index 63973db1..c7c95897 100644 --- a/Oqtane.Client/Modules/Counter/Module.cs +++ b/Oqtane.Client/Modules/Counter/Module.cs @@ -1,16 +1,22 @@ using Oqtane.Modules; +using System.Collections.Generic; namespace Oqtane.Client.Modules.Counter { public class Module : IModule { - public string Name { get { return "Counter"; } } - public string Description { get { return "Increments a counter"; } } - public string Version { get { return "1.0.0"; } } - public string Owner { get { return ""; } } - public string Url { get { return ""; } } - public string Contact { get { return ""; } } - public string License { get { return ""; } } - public string Dependencies { get { return ""; } } + public Dictionary Properties + { + get + { + Dictionary properties = new Dictionary + { + { "Name", "Counter" }, + { "Description", "Increments a counter" }, + { "Version", "1.0.0" } + }; + return properties; + } + } } } diff --git a/Oqtane.Client/Modules/HtmlText/Module.cs b/Oqtane.Client/Modules/HtmlText/Module.cs index 5fff736d..c21d8023 100644 --- a/Oqtane.Client/Modules/HtmlText/Module.cs +++ b/Oqtane.Client/Modules/HtmlText/Module.cs @@ -1,16 +1,22 @@ using Oqtane.Modules; +using System.Collections.Generic; namespace Oqtane.Client.Modules.HtmlText { public class Module : IModule { - public string Name { get { return "HtmlText"; } } - public string Description { get { return "Renders HTML or Text"; } } - public string Version { get { return "1.0.0"; } } - public string Owner { get { return ""; } } - public string Url { get { return ""; } } - public string Contact { get { return ""; } } - public string License { get { return ""; } } - public string Dependencies { get { return ""; } } + public Dictionary Properties + { + get + { + Dictionary properties = new Dictionary + { + { "Name", "HtmlText" }, + { "Description", "Renders HTML or Text" }, + { "Version", "1.0.0" } + }; + return properties; + } + } } } diff --git a/Oqtane.Client/Modules/IModule.cs b/Oqtane.Client/Modules/IModule.cs index 510c36a3..675378b8 100644 --- a/Oqtane.Client/Modules/IModule.cs +++ b/Oqtane.Client/Modules/IModule.cs @@ -1,14 +1,9 @@ -namespace Oqtane.Modules +using System.Collections.Generic; + +namespace Oqtane.Modules { public interface IModule { - string Name { get; } - string Description { get; } - string Version { get; } - string Owner { get; } - string Url { get; } - string Contact { get; } - string License { get; } - string Dependencies { get; } + Dictionary Properties { get; } } } diff --git a/Oqtane.Client/Modules/Weather/Module.cs b/Oqtane.Client/Modules/Weather/Module.cs index d816244b..e4134815 100644 --- a/Oqtane.Client/Modules/Weather/Module.cs +++ b/Oqtane.Client/Modules/Weather/Module.cs @@ -1,16 +1,22 @@ using Oqtane.Modules; +using System.Collections.Generic; namespace Oqtane.Client.Modules.Weather { public class Module : IModule { - public string Name { get { return "Weather"; } } - public string Description { get { return "Displays random weather using a service"; } } - public string Version { get { return "1.0.0"; } } - public string Owner { get { return ""; } } - public string Url { get { return ""; } } - public string Contact { get { return ""; } } - public string License { get { return ""; } } - public string Dependencies { get { return ""; } } + public Dictionary Properties + { + get + { + Dictionary properties = new Dictionary + { + { "Name", "Weather" }, + { "Description", "Displays random weather using a service" }, + { "Version", "1.0.0" } + }; + return properties; + } + } } } diff --git a/Oqtane.Client/Themes/ITheme.cs b/Oqtane.Client/Themes/ITheme.cs index 4a8ab2ab..134ec3a2 100644 --- a/Oqtane.Client/Themes/ITheme.cs +++ b/Oqtane.Client/Themes/ITheme.cs @@ -1,15 +1,10 @@ using System; +using System.Collections.Generic; namespace Oqtane.Themes { public interface ITheme { - string Name { get; } - string Version { get; } - string Owner { get; } - string Url { get; } - string Contact { get; } - string License { get; } - string Dependencies { get; } + Dictionary Properties { get; } } } diff --git a/Oqtane.Client/Themes/Theme1/Theme.cs b/Oqtane.Client/Themes/Theme1/Theme.cs index 715f75e5..3c1db0ca 100644 --- a/Oqtane.Client/Themes/Theme1/Theme.cs +++ b/Oqtane.Client/Themes/Theme1/Theme.cs @@ -1,13 +1,20 @@ -namespace Oqtane.Themes.Theme1 +using System.Collections.Generic; + +namespace Oqtane.Themes.Theme1 { public class Theme : ITheme { - public string Name { get { return "Theme1"; } } - public string Version { get { return "1.0.0"; } } - public string Owner { get { return ""; } } - public string Url { get { return ""; } } - public string Contact { get { return ""; } } - public string License { get { return ""; } } - public string Dependencies { get { return ""; } } + public Dictionary Properties + { + get + { + Dictionary properties = new Dictionary + { + { "Name", "Theme1" }, + { "Version", "1.0.0" } + }; + return properties; + } + } } } diff --git a/Oqtane.Client/Themes/Theme2/Theme.cs b/Oqtane.Client/Themes/Theme2/Theme.cs index 8107c75d..377bb1ad 100644 --- a/Oqtane.Client/Themes/Theme2/Theme.cs +++ b/Oqtane.Client/Themes/Theme2/Theme.cs @@ -1,13 +1,20 @@ -namespace Oqtane.Themes.Theme2 +using System.Collections.Generic; + +namespace Oqtane.Themes.Theme2 { public class Theme : ITheme { - public string Name { get { return "Theme2"; } } - public string Version { get { return "1.0.0"; } } - public string Owner { get { return ""; } } - public string Url { get { return ""; } } - public string Contact { get { return ""; } } - public string License { get { return ""; } } - public string Dependencies { get { return ""; } } + public Dictionary Properties + { + get + { + Dictionary properties = new Dictionary + { + { "Name", "Theme2" }, + { "Version", "1.0.0" } + }; + return properties; + } + } } } diff --git a/Oqtane.Client/Themes/Theme3/Theme.cs b/Oqtane.Client/Themes/Theme3/Theme.cs index 7edfd0d5..53def728 100644 --- a/Oqtane.Client/Themes/Theme3/Theme.cs +++ b/Oqtane.Client/Themes/Theme3/Theme.cs @@ -1,13 +1,20 @@ -namespace Oqtane.Themes.Theme3 +using System.Collections.Generic; + +namespace Oqtane.Themes.Theme3 { public class Theme : ITheme { - public string Name { get { return "Theme3"; } } - public string Version { get { return "1.0.0"; } } - public string Owner { get { return ""; } } - public string Url { get { return ""; } } - public string Contact { get { return ""; } } - public string License { get { return ""; } } - public string Dependencies { get { return ""; } } + public Dictionary Properties + { + get + { + Dictionary properties = new Dictionary + { + { "Name", "Theme3" }, + { "Version", "1.0.0" } + }; + return properties; + } + } } } diff --git a/Oqtane.Server/Repository/ModuleDefinitionRepository.cs b/Oqtane.Server/Repository/ModuleDefinitionRepository.cs index d626ead3..b02bee82 100644 --- a/Oqtane.Server/Repository/ModuleDefinitionRepository.cs +++ b/Oqtane.Server/Repository/ModuleDefinitionRepository.cs @@ -51,24 +51,26 @@ namespace Oqtane.Repository { /// determine if this module implements IModule Type moduletype = assembly.GetTypes() - .Where(item => item.Namespace != null) - .Where(item => item.Namespace.StartsWith(ModuleType)) - .Where(item => item.GetInterfaces().Contains(typeof(IModule))) - .FirstOrDefault(); + .Where(item => item.Namespace != null) + .Where(item => item.Namespace.StartsWith(ModuleType)) + .Where(item => item.GetInterfaces().Contains(typeof(IModule))) + .FirstOrDefault(); if (moduletype != null) { var moduleobject = Activator.CreateInstance(moduletype); + Dictionary properties = (Dictionary)moduletype.GetProperty("Properties").GetValue(moduleobject); moduledefinition = new ModuleDefinition { ModuleDefinitionName = QualifiedModuleType, - Name = (string)moduletype.GetProperty("Name").GetValue(moduleobject), - Description = (string)moduletype.GetProperty("Description").GetValue(moduleobject), - Version = (string)moduletype.GetProperty("Version").GetValue(moduleobject), - Owner = (string)moduletype.GetProperty("Owner").GetValue(moduleobject), - Url = (string)moduletype.GetProperty("Url").GetValue(moduleobject), - Contact = (string)moduletype.GetProperty("Contact").GetValue(moduleobject), - License = (string)moduletype.GetProperty("License").GetValue(moduleobject), - Dependencies = (string)moduletype.GetProperty("Dependencies").GetValue(moduleobject), + Name = GetProperty(properties, "Name"), + Description = GetProperty(properties, "Description"), + Version = GetProperty(properties, "Version"), + Owner = GetProperty(properties, "Owner"), + Url = GetProperty(properties, "Url"), + Contact = GetProperty(properties, "Contact"), + License = GetProperty(properties, "License"), + Dependencies = GetProperty(properties, "Dependencies"), + Permissions = GetProperty(properties, "Permissions"), ControlTypeTemplate = ModuleType + ".{Control}" + ", " + typename[1], ControlTypeRoutes = "", AssemblyName = assembly.FullName.Split(",")[0] @@ -87,6 +89,7 @@ namespace Oqtane.Repository Contact = "", License = "", Dependencies = "", + Permissions = "", ControlTypeTemplate = ModuleType + ".{Control}" + ", " + typename[1], ControlTypeRoutes = "", AssemblyName = assembly.FullName.Split(",")[0] @@ -118,5 +121,14 @@ namespace Oqtane.Repository return ModuleDefinitions; } + private string GetProperty(Dictionary Properties, string Key) + { + string Value = ""; + if (Properties.ContainsKey(Key)) + { + Value = Properties[Key]; + } + return Value; + } } } diff --git a/Oqtane.Server/Repository/ThemeRepository.cs b/Oqtane.Server/Repository/ThemeRepository.cs index 1b7ead1e..5cac43fc 100644 --- a/Oqtane.Server/Repository/ThemeRepository.cs +++ b/Oqtane.Server/Repository/ThemeRepository.cs @@ -49,23 +49,24 @@ namespace Oqtane.Repository if (index == -1) { /// determine if this theme implements ITheme - Type themeType = assembly.GetTypes() + Type themetype = assembly.GetTypes() .Where(item => item.Namespace != null) .Where(item => item.Namespace.StartsWith(Namespace)) .Where(item => item.GetInterfaces().Contains(typeof(ITheme))).FirstOrDefault(); - if (themeType != null) + if (themetype != null) { - var themeObject = Activator.CreateInstance(themeType); + var themeobject = Activator.CreateInstance(themetype); + Dictionary properties = (Dictionary)themetype.GetProperty("Properties").GetValue(themeobject); theme = new Theme { ThemeName = Namespace, - Name = (string)themeType.GetProperty("Name").GetValue(themeObject), - Version = (string)themeType.GetProperty("Version").GetValue(themeObject), - Owner = (string)themeType.GetProperty("Owner").GetValue(themeObject), - Url = (string)themeType.GetProperty("Url").GetValue(themeObject), - Contact = (string)themeType.GetProperty("Contact").GetValue(themeObject), - License = (string)themeType.GetProperty("License").GetValue(themeObject), - Dependencies = (string)themeType.GetProperty("Dependencies").GetValue(themeObject), + Name = GetProperty(properties, "Name"), + Version = GetProperty(properties, "Version"), + Owner = GetProperty(properties, "Owner"), + Url = GetProperty(properties, "Url"), + Contact = GetProperty(properties, "Contact"), + License = GetProperty(properties, "License"), + Dependencies = GetProperty(properties, "Dependencies"), ThemeControls = "", PaneLayouts = "", ContainerControls = "", @@ -122,5 +123,15 @@ namespace Oqtane.Repository { return Themes; } + + private string GetProperty(Dictionary Properties, string Key) + { + string Value = ""; + if (Properties.ContainsKey(Key)) + { + Value = Properties[Key]; + } + return Value; + } } } diff --git a/Oqtane.Shared/Models/ModuleDefinition.cs b/Oqtane.Shared/Models/ModuleDefinition.cs index 75ba1902..86d3dc54 100644 --- a/Oqtane.Shared/Models/ModuleDefinition.cs +++ b/Oqtane.Shared/Models/ModuleDefinition.cs @@ -11,6 +11,7 @@ public string Contact { get; set; } public string License { get; set; } public string Dependencies { get; set; } + public string Permissions { get; set; } public string ControlTypeTemplate { get; set; } public string ControlTypeRoutes { get; set; } public string AssemblyName { get; set; }