Skip to content

Commit 18d4c84

Browse files
authored
added roles endpoint from core (#131)
1 parent 2d5ab15 commit 18d4c84

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
using Altinn.Platform.Authorization.Services.Interface;
3+
using Altinn.Platform.Storage.Helpers;
4+
using Authorization.Interface.Models;
5+
using Microsoft.AspNetCore.Authorization;
6+
using Microsoft.AspNetCore.Mvc;
7+
8+
namespace Altinn.Platform.Authorization.Controllers
9+
{
10+
/// <summary>
11+
/// Contains all actions related to the roles model
12+
/// </summary>
13+
[Route("authorization/api/v1/roles")]
14+
[ApiController]
15+
public class RolesController : ControllerBase
16+
{
17+
private readonly IRoles _rolesWrapper;
18+
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="RolesController"/> class
21+
/// </summary>
22+
public RolesController(IRoles rolesWrapper)
23+
{
24+
_rolesWrapper = rolesWrapper;
25+
}
26+
27+
/// <summary>
28+
/// Get the decision point roles for the loggedin user for a selected party
29+
/// </summary>
30+
/// <param name="coveredByUserId">the logged in user id</param>
31+
/// <param name="offeredByPartyId">the partyid of the person/org the logged in user is representing</param>
32+
/// <returns></returns>
33+
[HttpGet]
34+
[Authorize]
35+
public async Task<ActionResult> Get(int coveredByUserId, int offeredByPartyId)
36+
{
37+
int? authnUserId = User.GetUserIdAsInt();
38+
39+
if (coveredByUserId != authnUserId)
40+
{
41+
return Forbid();
42+
}
43+
44+
if (coveredByUserId == 0 || offeredByPartyId == 0)
45+
{
46+
return BadRequest();
47+
}
48+
49+
List<Role> roleList = await _rolesWrapper.GetDecisionPointRolesForUser(coveredByUserId, offeredByPartyId);
50+
51+
if (roleList == null || roleList.Count == 0)
52+
{
53+
return NotFound();
54+
}
55+
56+
return Ok(roleList);
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)