add ModuleControllerBase helper method for validating EntityId

This commit is contained in:
Shaun Walker
2022-12-05 14:21:12 -05:00
parent cb10dde97d
commit 28b58b9048
4 changed files with 16 additions and 11 deletions

View File

@ -29,7 +29,7 @@ namespace Oqtane.Modules.HtmlText.Controllers
[Authorize(Roles = RoleNames.Registered)]
public IEnumerable<Models.HtmlText> Get(string moduleId)
{
if (int.TryParse(moduleId, out int ModuleId) && AuthEntityId(EntityNames.Module) == ModuleId)
if (int.TryParse(moduleId, out int ModuleId) && IsAuthorizedEntityId(EntityNames.Module, ModuleId))
{
return _htmlText.GetHtmlTexts(ModuleId);
}
@ -46,7 +46,7 @@ namespace Oqtane.Modules.HtmlText.Controllers
[Authorize(Policy = PolicyNames.ViewModule)]
public Models.HtmlText Get(int moduleId)
{
if (AuthEntityId(EntityNames.Module) == moduleId)
if (IsAuthorizedEntityId(EntityNames.Module, moduleId))
{
var htmltexts = _htmlText.GetHtmlTexts(moduleId);
if (htmltexts != null && htmltexts.Any())
@ -71,7 +71,7 @@ namespace Oqtane.Modules.HtmlText.Controllers
[Authorize(Policy = PolicyNames.ViewModule)]
public Models.HtmlText Get(int id, int moduleId)
{
if (AuthEntityId(EntityNames.Module) == moduleId)
if (IsAuthorizedEntityId(EntityNames.Module, moduleId))
{
return _htmlText.GetHtmlText(id);
}
@ -88,7 +88,7 @@ namespace Oqtane.Modules.HtmlText.Controllers
[Authorize(Policy = PolicyNames.EditModule)]
public Models.HtmlText Post([FromBody] Models.HtmlText htmlText)
{
if (ModelState.IsValid && AuthEntityId(EntityNames.Module) == htmlText.ModuleId)
if (ModelState.IsValid && IsAuthorizedEntityId(EntityNames.Module, htmlText.ModuleId))
{
htmlText = _htmlText.AddHtmlText(htmlText);
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Html/Text Added {HtmlText}", htmlText);
@ -107,7 +107,7 @@ namespace Oqtane.Modules.HtmlText.Controllers
[Authorize(Policy = PolicyNames.EditModule)]
public void Delete(int id, int moduleId)
{
if (AuthEntityId(EntityNames.Module) == moduleId)
if (IsAuthorizedEntityId(EntityNames.Module, moduleId))
{
_htmlText.DeleteHtmlText(id);
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Html/Text Deleted {HtmlTextId}", id);