Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added roles endpoint from core #131

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/Controllers/Authorization/RolesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

using Altinn.Platform.Authorization.Services.Interface;
using Altinn.Platform.Storage.Helpers;
using Authorization.Interface.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Altinn.Platform.Authorization.Controllers
{
/// <summary>
/// Contains all actions related to the roles model
/// </summary>
[Route("authorization/api/v1/roles")]
[ApiController]
public class RolesController : ControllerBase
{
private readonly IRoles _rolesWrapper;

/// <summary>
/// Initializes a new instance of the <see cref="RolesController"/> class
/// </summary>
public RolesController(IRoles rolesWrapper)
{
_rolesWrapper = rolesWrapper;
}

/// <summary>
/// Get the decision point roles for the loggedin user for a selected party
/// </summary>
/// <param name="coveredByUserId">the logged in user id</param>
/// <param name="offeredByPartyId">the partyid of the person/org the logged in user is representing</param>
/// <returns></returns>
[HttpGet]
[Authorize]
public async Task<ActionResult> Get(int coveredByUserId, int offeredByPartyId)
{
int? authnUserId = User.GetUserIdAsInt();

if (coveredByUserId != authnUserId)
{
return Forbid();
}

if (coveredByUserId == 0 || offeredByPartyId == 0)
{
return BadRequest();
}

List<Role> roleList = await _rolesWrapper.GetDecisionPointRolesForUser(coveredByUserId, offeredByPartyId);

if (roleList == null || roleList.Count == 0)
{
return NotFound();
}

return Ok(roleList);
}
}
}
Loading