commit
fc7000394f
|
@ -1,5 +1,5 @@
|
||||||
@namespace Oqtane.Modules.Controls
|
@namespace Oqtane.Modules.Controls
|
||||||
@inherits ModuleControlBase
|
@inherits LocalizableComponent
|
||||||
@inject IUserService UserService
|
@inject IUserService UserService
|
||||||
|
|
||||||
@if (_authorized)
|
@if (_authorized)
|
||||||
|
@ -56,6 +56,8 @@
|
||||||
|
|
||||||
protected override void OnParametersSet()
|
protected override void OnParametersSet()
|
||||||
{
|
{
|
||||||
|
base.OnParametersSet();
|
||||||
|
|
||||||
_text = Action;
|
_text = Action;
|
||||||
if (!string.IsNullOrEmpty(Text))
|
if (!string.IsNullOrEmpty(Text))
|
||||||
{
|
{
|
||||||
|
@ -93,6 +95,7 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_text = Localize(nameof(Text));
|
||||||
_url = EditUrl(Action, _parameters);
|
_url = EditUrl(Action, _parameters);
|
||||||
_authorized = IsAuthorized();
|
_authorized = IsAuthorized();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
@namespace Oqtane.Modules.Controls
|
@namespace Oqtane.Modules.Controls
|
||||||
@inherits ModuleControlBase
|
@inherits LocalizableComponent
|
||||||
@using Microsoft.Extensions.Localization
|
|
||||||
|
|
||||||
@if (!string.IsNullOrEmpty(HelpText))
|
@if (!string.IsNullOrEmpty(HelpText))
|
||||||
{
|
{
|
||||||
|
@ -27,11 +26,10 @@ else
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public string HelpText { get; set; } // optional - tooltip for this label
|
public string HelpText { get; set; } // optional - tooltip for this label
|
||||||
|
|
||||||
[Parameter]
|
|
||||||
public string ResourceKey { get; set; }
|
|
||||||
|
|
||||||
protected override void OnParametersSet()
|
protected override void OnParametersSet()
|
||||||
{
|
{
|
||||||
|
base.OnParametersSet();
|
||||||
|
|
||||||
_openLabel = "<label";
|
_openLabel = "<label";
|
||||||
if (!string.IsNullOrEmpty(For))
|
if (!string.IsNullOrEmpty(For))
|
||||||
{
|
{
|
||||||
|
@ -45,23 +43,10 @@ else
|
||||||
|
|
||||||
_openLabel += ">";
|
_openLabel += ">";
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(ResourceKey))
|
if (IsLocalizable)
|
||||||
{
|
{
|
||||||
if (ModuleState?.ModuleType != null)
|
ChildContent =@<text>@Localize("Text")</text>;
|
||||||
{
|
HelpText = Localize(nameof(HelpText));
|
||||||
var moduleType = Type.GetType(ModuleState.ModuleType);
|
|
||||||
var localizerTypeName = $"Microsoft.Extensions.Localization.IStringLocalizer`1[[{moduleType.AssemblyQualifiedName}]], Microsoft.Extensions.Localization.Abstractions";
|
|
||||||
var localizerType = Type.GetType(localizerTypeName);
|
|
||||||
|
|
||||||
// HACK: Use ServiceActivator instead of injecting IHttpContextAccessor, because HttpContext throws NRE in WebAssembly runtime
|
|
||||||
using (var scope = ServiceActivator.GetScope())
|
|
||||||
{
|
|
||||||
var localizer = (IStringLocalizer)scope.ServiceProvider.GetService(localizerType);
|
|
||||||
|
|
||||||
ChildContent = @<text>@localizer[$"{ResourceKey}.Text"]</text>;
|
|
||||||
HelpText = localizer[$"{ResourceKey}.{nameof(HelpText)}"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
54
Oqtane.Client/Modules/Controls/LocalizableComponent.cs
Normal file
54
Oqtane.Client/Modules/Controls/LocalizableComponent.cs
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
using System;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using Microsoft.Extensions.Localization;
|
||||||
|
using Oqtane.Shared;
|
||||||
|
|
||||||
|
namespace Oqtane.Modules.Controls
|
||||||
|
{
|
||||||
|
public class LocalizableComponent : ModuleControlBase
|
||||||
|
{
|
||||||
|
private IStringLocalizer _localizer;
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public string ResourceKey { get; set; }
|
||||||
|
|
||||||
|
protected bool IsLocalizable { get; private set; }
|
||||||
|
|
||||||
|
protected string Localize(string name)
|
||||||
|
{
|
||||||
|
if (!IsLocalizable)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var key = $"{ResourceKey}.{name}";
|
||||||
|
|
||||||
|
return _localizer?[key] ?? key;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnParametersSet()
|
||||||
|
{
|
||||||
|
if (!String.IsNullOrEmpty(ResourceKey))
|
||||||
|
{
|
||||||
|
if (ModuleState?.ModuleType != null)
|
||||||
|
{
|
||||||
|
var moduleType = Type.GetType(ModuleState.ModuleType);
|
||||||
|
var localizerTypeName = $"Microsoft.Extensions.Localization.IStringLocalizer`1[[{moduleType.AssemblyQualifiedName}]], Microsoft.Extensions.Localization.Abstractions";
|
||||||
|
var localizerType = Type.GetType(localizerTypeName);
|
||||||
|
|
||||||
|
// HACK: Use ServiceActivator instead of injecting IHttpContextAccessor, because HttpContext throws NRE in WebAssembly runtime
|
||||||
|
using (var scope = ServiceActivator.GetScope())
|
||||||
|
{
|
||||||
|
_localizer = (IStringLocalizer)scope.ServiceProvider.GetService(localizerType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IsLocalizable = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IsLocalizable = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,6 @@
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<LangVersion>7.3</LangVersion>
|
|
||||||
<RazorLangVersion>3.0</RazorLangVersion>
|
<RazorLangVersion>3.0</RazorLangVersion>
|
||||||
<Configurations>Debug;Release</Configurations>
|
<Configurations>Debug;Release</Configurations>
|
||||||
<Version>1.0.4</Version>
|
<Version>1.0.4</Version>
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace Oqtane
|
||||||
_supportedCultures = localizationManager.GetSupportedCultures();
|
_supportedCultures = localizationManager.GetSupportedCultures();
|
||||||
|
|
||||||
_runtime = (Configuration.GetSection("Runtime").Value == "WebAssembly") ? Runtime.WebAssembly : Runtime.Server;
|
_runtime = (Configuration.GetSection("Runtime").Value == "WebAssembly") ? Runtime.WebAssembly : Runtime.Server;
|
||||||
|
|
||||||
//add possibility to switch off swagger on production.
|
//add possibility to switch off swagger on production.
|
||||||
_useSwagger = Configuration.GetSection("UseSwagger").Value != "false";
|
_useSwagger = Configuration.GetSection("UseSwagger").Value != "false";
|
||||||
|
|
||||||
|
@ -92,13 +92,13 @@ namespace Oqtane
|
||||||
// register custom authorization policies
|
// register custom authorization policies
|
||||||
services.AddAuthorizationCore(options =>
|
services.AddAuthorizationCore(options =>
|
||||||
{
|
{
|
||||||
options.AddPolicy("ViewPage", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Page, PermissionNames.View)));
|
options.AddPolicy(PolicyNames.ViewPage, policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Page, PermissionNames.View)));
|
||||||
options.AddPolicy("EditPage", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Page, PermissionNames.Edit)));
|
options.AddPolicy(PolicyNames.EditPage, policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Page, PermissionNames.Edit)));
|
||||||
options.AddPolicy("ViewModule", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Module, PermissionNames.View)));
|
options.AddPolicy(PolicyNames.ViewModule, policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Module, PermissionNames.View)));
|
||||||
options.AddPolicy("EditModule", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Module, PermissionNames.Edit)));
|
options.AddPolicy(PolicyNames.EditModule, policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Module, PermissionNames.Edit)));
|
||||||
options.AddPolicy("ViewFolder", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Folder, PermissionNames.View)));
|
options.AddPolicy(PolicyNames.ViewFolder, policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Folder, PermissionNames.View)));
|
||||||
options.AddPolicy("EditFolder", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Folder, PermissionNames.Edit)));
|
options.AddPolicy(PolicyNames.EditFolder, policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Folder, PermissionNames.Edit)));
|
||||||
options.AddPolicy("ListFolder", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Folder, PermissionNames.Browse)));
|
options.AddPolicy(PolicyNames.ListFolder, policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Folder, PermissionNames.Browse)));
|
||||||
});
|
});
|
||||||
|
|
||||||
// register scoped core services
|
// register scoped core services
|
||||||
|
@ -133,7 +133,7 @@ namespace Oqtane
|
||||||
|
|
||||||
services.AddDbContext<MasterDBContext>(options =>
|
services.AddDbContext<MasterDBContext>(options =>
|
||||||
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")
|
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")
|
||||||
.Replace("|DataDirectory|", AppDomain.CurrentDomain.GetData("DataDirectory")?.ToString())
|
.Replace("|DataDirectory|", AppContext.GetData("DataDirectory")?.ToString())
|
||||||
));
|
));
|
||||||
services.AddDbContext<TenantDBContext>(options => { });
|
services.AddDbContext<TenantDBContext>(options => { });
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ using [Owner].[Module].Repository;
|
||||||
|
|
||||||
namespace [Owner].[Module].Controllers
|
namespace [Owner].[Module].Controllers
|
||||||
{
|
{
|
||||||
[Route("{alias}/api/[controller]")]
|
[Route(ControllerRoutes.Default)]
|
||||||
public class [Module]Controller : Controller
|
public class [Module]Controller : Controller
|
||||||
{
|
{
|
||||||
private readonly I[Module]Repository _[Module]Repository;
|
private readonly I[Module]Repository _[Module]Repository;
|
||||||
|
@ -30,7 +30,7 @@ namespace [Owner].[Module].Controllers
|
||||||
|
|
||||||
// GET: api/<controller>?moduleid=x
|
// GET: api/<controller>?moduleid=x
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Authorize(Policy = "ViewModule")]
|
[Authorize(Policy = PolicyNames.ViewModule)]
|
||||||
public IEnumerable<Models.[Module]> Get(string moduleid)
|
public IEnumerable<Models.[Module]> Get(string moduleid)
|
||||||
{
|
{
|
||||||
return _[Module]Repository.Get[Module]s(int.Parse(moduleid));
|
return _[Module]Repository.Get[Module]s(int.Parse(moduleid));
|
||||||
|
@ -38,7 +38,7 @@ namespace [Owner].[Module].Controllers
|
||||||
|
|
||||||
// GET api/<controller>/5
|
// GET api/<controller>/5
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Authorize(Policy = "ViewModule")]
|
[Authorize(Policy = PolicyNames.ViewModule)]
|
||||||
public Models.[Module] Get(int id)
|
public Models.[Module] Get(int id)
|
||||||
{
|
{
|
||||||
Models.[Module] [Module] = _[Module]Repository.Get[Module](id);
|
Models.[Module] [Module] = _[Module]Repository.Get[Module](id);
|
||||||
|
@ -51,7 +51,7 @@ namespace [Owner].[Module].Controllers
|
||||||
|
|
||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(Policy = "EditModule")]
|
[Authorize(Policy = PolicyNames.EditModule)]
|
||||||
public Models.[Module] Post([FromBody] Models.[Module] [Module])
|
public Models.[Module] Post([FromBody] Models.[Module] [Module])
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid && [Module].ModuleId == _entityId)
|
if (ModelState.IsValid && [Module].ModuleId == _entityId)
|
||||||
|
@ -64,7 +64,7 @@ namespace [Owner].[Module].Controllers
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Policy = "EditModule")]
|
[Authorize(Policy = PolicyNames.EditModule)]
|
||||||
public Models.[Module] Put(int id, [FromBody] Models.[Module] [Module])
|
public Models.[Module] Put(int id, [FromBody] Models.[Module] [Module])
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid && [Module].ModuleId == _entityId)
|
if (ModelState.IsValid && [Module].ModuleId == _entityId)
|
||||||
|
@ -77,7 +77,7 @@ namespace [Owner].[Module].Controllers
|
||||||
|
|
||||||
// DELETE api/<controller>/5
|
// DELETE api/<controller>/5
|
||||||
[HttpDelete("{id}")]
|
[HttpDelete("{id}")]
|
||||||
[Authorize(Policy = "EditModule")]
|
[Authorize(Policy = PolicyNames.EditModule)]
|
||||||
public void Delete(int id)
|
public void Delete(int id)
|
||||||
{
|
{
|
||||||
Models.[Module] [Module] = _[Module]Repository.Get[Module](id);
|
Models.[Module] [Module] = _[Module]Repository.Get[Module](id);
|
||||||
|
|
|
@ -20,7 +20,7 @@ GO
|
||||||
/*
|
/*
|
||||||
Create foreign key relationships
|
Create foreign key relationships
|
||||||
*/
|
*/
|
||||||
ALTER TABLE [dbo].[[Owner][Module]] WITH CHECK ADD CONSTRAINT [FK_[Owner][Module]_Module] FOREIGN KEY([ModuleId])
|
ALTER TABLE [dbo].[[Owner][Module]] WITH CHECK ADD CONSTRAINT [FK_[Owner][Module]_Module] FOREIGN KEY([ModuleId])
|
||||||
REFERENCES [dbo].Module ([ModuleId])
|
REFERENCES [dbo].Module ([ModuleId])
|
||||||
ON DELETE CASCADE
|
ON DELETE CASCADE
|
||||||
GO
|
GO
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.1</TargetFramework>
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
<LangVersion>7.3</LangVersion>
|
|
||||||
<Version>1.0.0</Version>
|
<Version>1.0.0</Version>
|
||||||
<Product>[Owner].[Module]</Product>
|
<Product>[Owner].[Module]</Product>
|
||||||
<Authors>[Owner]</Authors>
|
<Authors>[Owner]</Authors>
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<LangVersion>7.3</LangVersion>
|
|
||||||
<Configurations>Debug;Release</Configurations>
|
<Configurations>Debug;Release</Configurations>
|
||||||
<Version>1.0.4</Version>
|
<Version>1.0.4</Version>
|
||||||
<Product>Oqtane</Product>
|
<Product>Oqtane</Product>
|
||||||
|
|
|
@ -1,10 +1,19 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Oqtane.Shared {
|
namespace Oqtane.Shared
|
||||||
public class PolicyNames {
|
{
|
||||||
|
public class PolicyNames
|
||||||
|
{
|
||||||
|
public const string ViewPage = "ViewPage";
|
||||||
|
public const string EditPage = "EditPage";
|
||||||
|
|
||||||
public const string ViewModule = "ViewModule";
|
public const string ViewModule = "ViewModule";
|
||||||
public const string EditModule = "EditModule";
|
public const string EditModule = "EditModule";
|
||||||
|
|
||||||
|
public const string ViewFolder = "ViewFolder";
|
||||||
|
public const string EditFolder = "EditFolder";
|
||||||
|
public const string ListFolder = "ListFolder";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<LangVersion>7.3</LangVersion>
|
|
||||||
<Configurations>Debug;Release</Configurations>
|
<Configurations>Debug;Release</Configurations>
|
||||||
<Version>1.0.4</Version>
|
<Version>1.0.4</Version>
|
||||||
<Product>Oqtane</Product>
|
<Product>Oqtane</Product>
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<LangVersion>7.3</LangVersion>
|
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<Version>1.0.4</Version>
|
<Version>1.0.4</Version>
|
||||||
<Product>Oqtane</Product>
|
<Product>Oqtane</Product>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user