|
1 | | -using Microsoft.AspNetCore.Mvc; |
| 1 | +using CentralizedLogging.Sdk.Abstractions; |
| 2 | +using Microsoft.AspNetCore.Authorization; |
| 3 | +using Microsoft.AspNetCore.Mvc; |
| 4 | +using SharedLibrary; |
| 5 | +using SharedLibrary.Auth; |
| 6 | +using SharedLibrary.Cache; |
| 7 | +using StackExchange.Redis; |
| 8 | +using System.Security.Claims; |
| 9 | +using UserManagement.Contracts.DTO; |
| 10 | +using UserManagement.Sdk.Abstractions; |
2 | 11 |
|
3 | 12 | namespace ApiIntegrationMvc.Areas.Admin.Controllers |
4 | 13 | { |
5 | 14 | [Area("Admin")] |
6 | 15 | public class RolesController : Controller |
7 | 16 | { |
| 17 | + private readonly IUserManagementClient _IUserManagementClient; |
| 18 | + private readonly ICacheAccessProvider _cache; |
| 19 | + public RolesController(IUserManagementClient userManagementClient, ICacheAccessProvider cache) => (_IUserManagementClient, _cache) = (userManagementClient, cache); |
| 20 | + |
| 21 | + [Authorize(Policy = PolicyType.WEB_LEVEL)] |
8 | 22 | public IActionResult Index() |
9 | 23 | { |
10 | | - return RedirectToAction("Index", "Home", new { area = "Home" }); |
11 | | - //return View(); |
| 24 | + return RedirectToAction("Index", "Home", new { area = "Home" }); |
| 25 | + } |
| 26 | + |
| 27 | + [HttpPost] |
| 28 | + public async Task<IActionResult> UpdatePermissions([FromBody] UpdatePermissionsRequest operations, CancellationToken ct) |
| 29 | + { |
| 30 | + string token = await _cache.GetAccessTokenAsync(ct); |
| 31 | + |
| 32 | + try |
| 33 | + { |
| 34 | + UpdatePermissionsResponse resp = await _IUserManagementClient.UpdatePermissions(operations, ct); |
| 35 | + return Ok(resp); |
| 36 | + } |
| 37 | + catch (PermissionDeniedException ex) when (ex.StatusCode == 403) |
| 38 | + { |
| 39 | + TempData["Error"] = "You do not have permission to view system error logs."; |
| 40 | + return RedirectToAction("Index", "Home", new { area = "Home" }); |
| 41 | + } |
| 42 | + catch (HttpRequestException hx) |
| 43 | + { |
| 44 | + TempData["Error"] = "Internal exception has occurred."; |
| 45 | + return RedirectToAction("Index", "Home", new { area = "Home" }); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + [HttpGet] |
| 50 | + public async Task<IActionResult> GetState(CancellationToken ct) |
| 51 | + { |
| 52 | + var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; |
| 53 | + object result = await _IUserManagementClient.GetState(int.Parse(userId)); |
| 54 | + return Ok(result); |
12 | 55 | } |
13 | 56 | } |
14 | 57 | } |
0 commit comments