-
Notifications
You must be signed in to change notification settings - Fork 13
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
1 parent
2d5ab15
commit 19fb7f9
Showing
1 changed file
with
59 additions
and
0 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
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); | ||
} | ||
} | ||
} |