Refactor authorization folder structure
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Distribution.Infra.Authorization;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/authorization")]
|
||||
[Authorize]
|
||||
public class AuthorizationController(
|
||||
IPermissionService permissionService,
|
||||
IScopeAccessService scopeAccessService,
|
||||
ICurrentUserService currentUser) : ControllerBase
|
||||
{
|
||||
[HttpGet("permissions/{permissionCode}")]
|
||||
public async Task<IActionResult> CheckPermission(string permissionCode)
|
||||
{
|
||||
if (currentUser.RoleId is not { } roleId) return Unauthorized();
|
||||
var result = await permissionService.HasPermissionAsync(roleId, permissionCode);
|
||||
return Ok(new PermissionCheckResponse(result));
|
||||
}
|
||||
|
||||
[HttpGet("scopes/stores/{storeId:guid}")]
|
||||
public async Task<IActionResult> CheckStoreScope(Guid storeId)
|
||||
{
|
||||
if (currentUser.UserId is not { } userId) return Unauthorized();
|
||||
var result = await scopeAccessService.HasStoreScopeAsync(userId, storeId);
|
||||
return Ok(new StoreScopeCheckResponse(result));
|
||||
}
|
||||
|
||||
[HttpGet("scopes/routes/{routeId:guid}")]
|
||||
public async Task<IActionResult> CheckRouteScope(Guid routeId)
|
||||
{
|
||||
if (currentUser.UserId is not { } userId) return Unauthorized();
|
||||
var result = await scopeAccessService.HasRouteScopeAsync(userId, routeId);
|
||||
return Ok(new RouteScopeCheckResponse(result));
|
||||
}
|
||||
|
||||
[HttpGet("scopes/regions/{regionId:guid}")]
|
||||
public async Task<IActionResult> CheckRegionScope(Guid regionId)
|
||||
{
|
||||
if (currentUser.UserId is not { } userId) return Unauthorized();
|
||||
var result = await scopeAccessService.HasRegionScopeAsync(userId, regionId);
|
||||
return Ok(new RegionScopeCheckResponse(result));
|
||||
}
|
||||
|
||||
[HttpGet("scopes/stores")]
|
||||
public async Task<IActionResult> GetAccessibleStores()
|
||||
{
|
||||
if (currentUser.UserId is not { } userId) return Unauthorized();
|
||||
var result = await scopeAccessService.GetAccessibleStoreIdsAsync(userId);
|
||||
return Ok(new AccessibleStoresResponse(result));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user