Skip to content

Commit 6190648

Browse files
Udpdate permissions and getstate api calling logic in webapp
1 parent 9da8aca commit 6190648

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed
Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,57 @@
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;
211

312
namespace ApiIntegrationMvc.Areas.Admin.Controllers
413
{
514
[Area("Admin")]
615
public class RolesController : Controller
716
{
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)]
822
public IActionResult Index()
923
{
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);
1255
}
1356
}
1457
}

0 commit comments

Comments
 (0)