-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...d/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI/Controllers/BaseController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Altinn.AccessManagement.UI.Controllers | ||
{ | ||
/// <summary> | ||
/// Base controller class providing common functionality for derived controllers. | ||
/// </summary> | ||
public abstract class BaseController : ControllerBase | ||
{ | ||
/// <summary> | ||
/// Validates the model state and returns a BadRequest result if the model state is invalid. | ||
/// </summary> | ||
/// <returns>A BadRequest result if the model state is invalid; otherwise, null.</returns> | ||
protected ActionResult ValidateModelState() | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return BadRequest(ModelState); | ||
} | ||
Check failure on line 19 in backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI/Controllers/BaseController.cs GitHub Actions / Continous Integration / Build
Check failure on line 19 in backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI/Controllers/BaseController.cs GitHub Actions / Continous Integration / Build
Check warning on line 19 in backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI/Controllers/BaseController.cs GitHub Actions / Continous Integration / Test
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,8 @@ namespace Altinn.AccessManagement.UI.Controllers | |
/// The <see cref="RoleController"/> provides the API endpoints related to roles. | ||
/// </summary> | ||
[Route("accessmanagement/api/v1/role")] | ||
public class RoleController : Controller | ||
public class RoleController : BaseController | ||
{ | ||
private readonly IAccessPackageService _accessPackageService; | ||
private readonly IHttpContextAccessor _httpContextAccessor; | ||
private readonly ILogger _logger; | ||
private readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; | ||
|
@@ -25,9 +24,8 @@ public class RoleController : Controller | |
/// <summary> | ||
/// Initializes a new instance of the <see cref="RoleController"/> class | ||
/// </summary> | ||
public RoleController(IAccessPackageService accessPackageService, IHttpContextAccessor httpContextAccessor, ILogger<RoleController> logger, IRoleService roleService) | ||
public RoleController(IHttpContextAccessor httpContextAccessor, ILogger<RoleController> logger, IRoleService roleService) | ||
{ | ||
_accessPackageService = accessPackageService; | ||
_httpContextAccessor = httpContextAccessor; | ||
_logger = logger; | ||
_roleService = roleService; | ||
|
@@ -43,16 +41,10 @@ public RoleController(IAccessPackageService accessPackageService, IHttpContextAc | |
[Route("assignments/{rightOwnerUuid}/{rightHolderUuid}")] | ||
public async Task<ActionResult<List<RoleAssignment>>> GetRolesForUser(Guid rightOwnerUuid, Guid rightHolderUuid) | ||
Check failure Code scanning / SonarCloud ModelState.IsValid should be called in controller actions High
ModelState.IsValid should be checked in controller actions. See more on SonarQube Cloud
|
||
{ | ||
var httpContext = _httpContextAccessor.HttpContext; | ||
if (httpContext == null) | ||
{ | ||
_logger.LogError("HttpContext is null"); | ||
return StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"); | ||
} | ||
|
||
var languageCode = LanguageHelper.GetSelectedLanguageCookieValueBackendStandard(httpContext); | ||
try | ||
{ | ||
var httpContext = _httpContextAccessor.HttpContext; | ||
var languageCode = LanguageHelper.GetSelectedLanguageCookieValueBackendStandard(httpContext); | ||
return await _roleService.GetRolesForUser(languageCode, rightOwnerUuid, rightHolderUuid); | ||
} | ||
catch (HttpStatusException ex) | ||
|