Skip to content

Commit

Permalink
added roles endpoint from core
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhaeger committed Dec 16, 2024
1 parent 2d5ab15 commit 19fb7f9
Showing 1 changed file with 59 additions and 0 deletions.
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);
}
}
}

0 comments on commit 19fb7f9

Please sign in to comment.