Refactored IModule and ITheme interfaces for future compatibility scenarios. Added Permissions property to IModule interface to allow for explicit ordering and custom module permissions.

This commit is contained in:
Shaun Walker 2019-08-30 22:27:49 -04:00
parent 838b48f91e
commit 8351ec2d71
12 changed files with 144 additions and 92 deletions

View File

@ -81,9 +81,7 @@
[Parameter] [Parameter]
public string Permissions { get; set; } public string Permissions { get; set; }
[Parameter] string permissionnames = "";
public string PermissionNames { get; set; } // optional - can be used to specify permissions order or add custom permissions
List<Role> roles; List<Role> roles;
List<PermissionString> permissions = new List<PermissionString>(); List<PermissionString> permissions = new List<PermissionString>();
List<User> users = new List<User>(); List<User> users = new List<User>();
@ -92,14 +90,15 @@
protected override async Task OnInitializedAsync() 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 = await RoleService.GetRolesAsync(ModuleState.SiteId);
roles.Insert(0, new Role { Name = Constants.AllUsersRole }); 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 = "" }); permissions.Add(new PermissionString { PermissionName = permissionname, Permissions = "" });
} }

View File

@ -1,16 +1,22 @@
using Oqtane.Modules; using Oqtane.Modules;
using System.Collections.Generic;
namespace Oqtane.Client.Modules.Counter namespace Oqtane.Client.Modules.Counter
{ {
public class Module : IModule public class Module : IModule
{ {
public string Name { get { return "Counter"; } } public Dictionary<string, string> Properties
public string Description { get { return "Increments a counter"; } } {
public string Version { get { return "1.0.0"; } } get
public string Owner { get { return ""; } } {
public string Url { get { return ""; } } Dictionary<string, string> properties = new Dictionary<string, string>
public string Contact { get { return ""; } } {
public string License { get { return ""; } } { "Name", "Counter" },
public string Dependencies { get { return ""; } } { "Description", "Increments a counter" },
{ "Version", "1.0.0" }
};
return properties;
}
}
} }
} }

View File

@ -1,16 +1,22 @@
using Oqtane.Modules; using Oqtane.Modules;
using System.Collections.Generic;
namespace Oqtane.Client.Modules.HtmlText namespace Oqtane.Client.Modules.HtmlText
{ {
public class Module : IModule public class Module : IModule
{ {
public string Name { get { return "HtmlText"; } } public Dictionary<string, string> Properties
public string Description { get { return "Renders HTML or Text"; } } {
public string Version { get { return "1.0.0"; } } get
public string Owner { get { return ""; } } {
public string Url { get { return ""; } } Dictionary<string, string> properties = new Dictionary<string, string>
public string Contact { get { return ""; } } {
public string License { get { return ""; } } { "Name", "HtmlText" },
public string Dependencies { get { return ""; } } { "Description", "Renders HTML or Text" },
{ "Version", "1.0.0" }
};
return properties;
}
}
} }
} }

View File

@ -1,14 +1,9 @@
namespace Oqtane.Modules using System.Collections.Generic;
namespace Oqtane.Modules
{ {
public interface IModule public interface IModule
{ {
string Name { get; } Dictionary<string, string> Properties { get; }
string Description { get; }
string Version { get; }
string Owner { get; }
string Url { get; }
string Contact { get; }
string License { get; }
string Dependencies { get; }
} }
} }

View File

@ -1,16 +1,22 @@
using Oqtane.Modules; using Oqtane.Modules;
using System.Collections.Generic;
namespace Oqtane.Client.Modules.Weather namespace Oqtane.Client.Modules.Weather
{ {
public class Module : IModule public class Module : IModule
{ {
public string Name { get { return "Weather"; } } public Dictionary<string, string> Properties
public string Description { get { return "Displays random weather using a service"; } } {
public string Version { get { return "1.0.0"; } } get
public string Owner { get { return ""; } } {
public string Url { get { return ""; } } Dictionary<string, string> properties = new Dictionary<string, string>
public string Contact { get { return ""; } } {
public string License { get { return ""; } } { "Name", "Weather" },
public string Dependencies { get { return ""; } } { "Description", "Displays random weather using a service" },
{ "Version", "1.0.0" }
};
return properties;
}
}
} }
} }

View File

@ -1,15 +1,10 @@
using System; using System;
using System.Collections.Generic;
namespace Oqtane.Themes namespace Oqtane.Themes
{ {
public interface ITheme public interface ITheme
{ {
string Name { get; } Dictionary<string, string> Properties { get; }
string Version { get; }
string Owner { get; }
string Url { get; }
string Contact { get; }
string License { get; }
string Dependencies { get; }
} }
} }

View File

@ -1,13 +1,20 @@
namespace Oqtane.Themes.Theme1 using System.Collections.Generic;
namespace Oqtane.Themes.Theme1
{ {
public class Theme : ITheme public class Theme : ITheme
{ {
public string Name { get { return "Theme1"; } } public Dictionary<string, string> Properties
public string Version { get { return "1.0.0"; } } {
public string Owner { get { return ""; } } get
public string Url { get { return ""; } } {
public string Contact { get { return ""; } } Dictionary<string, string> properties = new Dictionary<string, string>
public string License { get { return ""; } } {
public string Dependencies { get { return ""; } } { "Name", "Theme1" },
{ "Version", "1.0.0" }
};
return properties;
}
}
} }
} }

View File

@ -1,13 +1,20 @@
namespace Oqtane.Themes.Theme2 using System.Collections.Generic;
namespace Oqtane.Themes.Theme2
{ {
public class Theme : ITheme public class Theme : ITheme
{ {
public string Name { get { return "Theme2"; } } public Dictionary<string, string> Properties
public string Version { get { return "1.0.0"; } } {
public string Owner { get { return ""; } } get
public string Url { get { return ""; } } {
public string Contact { get { return ""; } } Dictionary<string, string> properties = new Dictionary<string, string>
public string License { get { return ""; } } {
public string Dependencies { get { return ""; } } { "Name", "Theme2" },
{ "Version", "1.0.0" }
};
return properties;
}
}
} }
} }

View File

@ -1,13 +1,20 @@
namespace Oqtane.Themes.Theme3 using System.Collections.Generic;
namespace Oqtane.Themes.Theme3
{ {
public class Theme : ITheme public class Theme : ITheme
{ {
public string Name { get { return "Theme3"; } } public Dictionary<string, string> Properties
public string Version { get { return "1.0.0"; } } {
public string Owner { get { return ""; } } get
public string Url { get { return ""; } } {
public string Contact { get { return ""; } } Dictionary<string, string> properties = new Dictionary<string, string>
public string License { get { return ""; } } {
public string Dependencies { get { return ""; } } { "Name", "Theme3" },
{ "Version", "1.0.0" }
};
return properties;
}
}
} }
} }

View File

@ -51,24 +51,26 @@ namespace Oqtane.Repository
{ {
/// determine if this module implements IModule /// determine if this module implements IModule
Type moduletype = assembly.GetTypes() Type moduletype = assembly.GetTypes()
.Where(item => item.Namespace != null) .Where(item => item.Namespace != null)
.Where(item => item.Namespace.StartsWith(ModuleType)) .Where(item => item.Namespace.StartsWith(ModuleType))
.Where(item => item.GetInterfaces().Contains(typeof(IModule))) .Where(item => item.GetInterfaces().Contains(typeof(IModule)))
.FirstOrDefault(); .FirstOrDefault();
if (moduletype != null) if (moduletype != null)
{ {
var moduleobject = Activator.CreateInstance(moduletype); var moduleobject = Activator.CreateInstance(moduletype);
Dictionary<string, string> properties = (Dictionary<string, string>)moduletype.GetProperty("Properties").GetValue(moduleobject);
moduledefinition = new ModuleDefinition moduledefinition = new ModuleDefinition
{ {
ModuleDefinitionName = QualifiedModuleType, ModuleDefinitionName = QualifiedModuleType,
Name = (string)moduletype.GetProperty("Name").GetValue(moduleobject), Name = GetProperty(properties, "Name"),
Description = (string)moduletype.GetProperty("Description").GetValue(moduleobject), Description = GetProperty(properties, "Description"),
Version = (string)moduletype.GetProperty("Version").GetValue(moduleobject), Version = GetProperty(properties, "Version"),
Owner = (string)moduletype.GetProperty("Owner").GetValue(moduleobject), Owner = GetProperty(properties, "Owner"),
Url = (string)moduletype.GetProperty("Url").GetValue(moduleobject), Url = GetProperty(properties, "Url"),
Contact = (string)moduletype.GetProperty("Contact").GetValue(moduleobject), Contact = GetProperty(properties, "Contact"),
License = (string)moduletype.GetProperty("License").GetValue(moduleobject), License = GetProperty(properties, "License"),
Dependencies = (string)moduletype.GetProperty("Dependencies").GetValue(moduleobject), Dependencies = GetProperty(properties, "Dependencies"),
Permissions = GetProperty(properties, "Permissions"),
ControlTypeTemplate = ModuleType + ".{Control}" + ", " + typename[1], ControlTypeTemplate = ModuleType + ".{Control}" + ", " + typename[1],
ControlTypeRoutes = "", ControlTypeRoutes = "",
AssemblyName = assembly.FullName.Split(",")[0] AssemblyName = assembly.FullName.Split(",")[0]
@ -87,6 +89,7 @@ namespace Oqtane.Repository
Contact = "", Contact = "",
License = "", License = "",
Dependencies = "", Dependencies = "",
Permissions = "",
ControlTypeTemplate = ModuleType + ".{Control}" + ", " + typename[1], ControlTypeTemplate = ModuleType + ".{Control}" + ", " + typename[1],
ControlTypeRoutes = "", ControlTypeRoutes = "",
AssemblyName = assembly.FullName.Split(",")[0] AssemblyName = assembly.FullName.Split(",")[0]
@ -118,5 +121,14 @@ namespace Oqtane.Repository
return ModuleDefinitions; return ModuleDefinitions;
} }
private string GetProperty(Dictionary<string, string> Properties, string Key)
{
string Value = "";
if (Properties.ContainsKey(Key))
{
Value = Properties[Key];
}
return Value;
}
} }
} }

View File

@ -49,23 +49,24 @@ namespace Oqtane.Repository
if (index == -1) if (index == -1)
{ {
/// determine if this theme implements ITheme /// determine if this theme implements ITheme
Type themeType = assembly.GetTypes() Type themetype = assembly.GetTypes()
.Where(item => item.Namespace != null) .Where(item => item.Namespace != null)
.Where(item => item.Namespace.StartsWith(Namespace)) .Where(item => item.Namespace.StartsWith(Namespace))
.Where(item => item.GetInterfaces().Contains(typeof(ITheme))).FirstOrDefault(); .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<string, string> properties = (Dictionary<string, string>)themetype.GetProperty("Properties").GetValue(themeobject);
theme = new Theme theme = new Theme
{ {
ThemeName = Namespace, ThemeName = Namespace,
Name = (string)themeType.GetProperty("Name").GetValue(themeObject), Name = GetProperty(properties, "Name"),
Version = (string)themeType.GetProperty("Version").GetValue(themeObject), Version = GetProperty(properties, "Version"),
Owner = (string)themeType.GetProperty("Owner").GetValue(themeObject), Owner = GetProperty(properties, "Owner"),
Url = (string)themeType.GetProperty("Url").GetValue(themeObject), Url = GetProperty(properties, "Url"),
Contact = (string)themeType.GetProperty("Contact").GetValue(themeObject), Contact = GetProperty(properties, "Contact"),
License = (string)themeType.GetProperty("License").GetValue(themeObject), License = GetProperty(properties, "License"),
Dependencies = (string)themeType.GetProperty("Dependencies").GetValue(themeObject), Dependencies = GetProperty(properties, "Dependencies"),
ThemeControls = "", ThemeControls = "",
PaneLayouts = "", PaneLayouts = "",
ContainerControls = "", ContainerControls = "",
@ -122,5 +123,15 @@ namespace Oqtane.Repository
{ {
return Themes; return Themes;
} }
private string GetProperty(Dictionary<string, string> Properties, string Key)
{
string Value = "";
if (Properties.ContainsKey(Key))
{
Value = Properties[Key];
}
return Value;
}
} }
} }

View File

@ -11,6 +11,7 @@
public string Contact { get; set; } public string Contact { get; set; }
public string License { get; set; } public string License { get; set; }
public string Dependencies { get; set; } public string Dependencies { get; set; }
public string Permissions { get; set; }
public string ControlTypeTemplate { get; set; } public string ControlTypeTemplate { get; set; }
public string ControlTypeRoutes { get; set; } public string ControlTypeRoutes { get; set; }
public string AssemblyName { get; set; } public string AssemblyName { get; set; }