diff --git a/Oqtane.Server/Modules/HtmlText/Controllers/HtmlTextController.cs b/Oqtane.Server/Modules/HtmlText/Controllers/HtmlTextController.cs
index 85fe9f5b..fb8ef512 100644
--- a/Oqtane.Server/Modules/HtmlText/Controllers/HtmlTextController.cs
+++ b/Oqtane.Server/Modules/HtmlText/Controllers/HtmlTextController.cs
@@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
-using Oqtane.Modules.HtmlText.Repository;
using Microsoft.AspNetCore.Http;
using Oqtane.Shared;
using Oqtane.Enums;
@@ -9,7 +8,6 @@ using Oqtane.Controllers;
using System.Net;
using Oqtane.Documentation;
using System.Collections.Generic;
-using System.Linq;
using Oqtane.Modules.HtmlText.Services;
using System.Threading.Tasks;
@@ -84,9 +82,7 @@ namespace Oqtane.Modules.HtmlText.Controllers
{
if (ModelState.IsValid && IsAuthorizedEntityId(EntityNames.Module, htmlText.ModuleId))
{
- htmlText = await _htmlTextService.AddHtmlTextAsync(htmlText);
- _logger.Log(LogLevel.Information, this, LogFunction.Create, "Html/Text Added {HtmlText}", htmlText);
- return htmlText;
+ return await _htmlTextService.AddHtmlTextAsync(htmlText);
}
else
{
@@ -104,7 +100,6 @@ namespace Oqtane.Modules.HtmlText.Controllers
if (IsAuthorizedEntityId(EntityNames.Module, moduleId))
{
await _htmlTextService.DeleteHtmlTextAsync(id, moduleId);
- _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Html/Text Deleted {HtmlTextId}", id);
}
else
{
diff --git a/Oqtane.Server/Modules/HtmlText/Services/HtmlTextService.cs b/Oqtane.Server/Modules/HtmlText/Services/HtmlTextService.cs
index b3a15549..1b551d0a 100644
--- a/Oqtane.Server/Modules/HtmlText/Services/HtmlTextService.cs
+++ b/Oqtane.Server/Modules/HtmlText/Services/HtmlTextService.cs
@@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Http;
using Oqtane.Documentation;
using Oqtane.Enums;
using Oqtane.Infrastructure;
+using Oqtane.Models;
using Oqtane.Modules.HtmlText.Repository;
using Oqtane.Security;
using Oqtane.Shared;
@@ -16,17 +17,17 @@ namespace Oqtane.Modules.HtmlText.Services
{
private readonly IHtmlTextRepository _htmlText;
private readonly IUserPermissions _userPermissions;
- private readonly ITenantManager _tenantManager;
private readonly ILogManager _logger;
private readonly IHttpContextAccessor _accessor;
+ private readonly Alias _alias;
public ServerHtmlTextService(IHtmlTextRepository htmlText, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor)
{
_htmlText = htmlText;
_userPermissions = userPermissions;
- _tenantManager = tenantManager;
_logger = logger;
_accessor = accessor;
+ _alias = tenantManager.GetAlias();
}
public async Task> GetHtmlTextsAsync(int moduleId)
@@ -44,8 +45,7 @@ namespace Oqtane.Modules.HtmlText.Services
public async Task GetHtmlTextAsync(int moduleId)
{
- var alias = _tenantManager.GetAlias();
- if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, alias.SiteId, EntityNames.Module, moduleId, PermissionNames.View))
+ if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, moduleId, PermissionNames.View))
{
var htmltexts = await _htmlText.GetHtmlTextsAsync(moduleId);
if (htmltexts != null && htmltexts.Any())
@@ -66,8 +66,7 @@ namespace Oqtane.Modules.HtmlText.Services
public async Task GetHtmlTextAsync(int htmlTextId, int moduleId)
{
- var alias = _tenantManager.GetAlias();
- if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, alias.SiteId, EntityNames.Module, moduleId, PermissionNames.View))
+ if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, moduleId, PermissionNames.View))
{
return await _htmlText.GetHtmlTextAsync(htmlTextId);
}
@@ -80,24 +79,25 @@ namespace Oqtane.Modules.HtmlText.Services
public async Task AddHtmlTextAsync(Models.HtmlText htmlText)
{
- var alias = _tenantManager.GetAlias();
- if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, alias.SiteId, EntityNames.Module, htmlText.ModuleId, PermissionNames.Edit))
+ if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, htmlText.ModuleId, PermissionNames.Edit))
{
- return await _htmlText.AddHtmlTextAsync(htmlText);
+ htmlText = await _htmlText.AddHtmlTextAsync(htmlText);
+ _logger.Log(LogLevel.Information, this, LogFunction.Create, "Html/Text Added {HtmlText}", htmlText);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Html/Text Add Attempt {HtmlText}", htmlText);
- return null;
+ htmlText = null;
}
+ return htmlText;
}
public async Task DeleteHtmlTextAsync(int htmlTextId, int moduleId)
{
- var alias = _tenantManager.GetAlias();
- if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, alias.SiteId, EntityNames.Module, moduleId, PermissionNames.Edit))
+ if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, moduleId, PermissionNames.Edit))
{
await _htmlText.DeleteHtmlTextAsync(htmlTextId);
+ _logger.Log(LogLevel.Information, this, LogFunction.Delete, "Html/Text Deleted {HtmlTextId}", htmlTextId);
}
else
{