feat(app): add site filtering by user access rights (issue #136)
- GetSitesQuery now accepts optional UserId parameter - GetSitesHandler filters sites by user's accessible site IDs via ICameraAccessService - SitesController.List passes current user ID for RBAC filtering - Non-admin users only see sites they have access to via UserCameraAccess/UserSite - Admin users see all sites (ICameraAccessService handles admin bypass) - Updated GetSitesHandlerTests with ICameraAccessService mock - All 1700+ tests pass
This commit is contained in:
1 parent
6e34c512b6
commit
e4586c8c1c
4 files changed
+49
-13
No files matched your search
@@ -55,7 +55,7 @@ public class SitesController : ControllerBase
|
||||
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
}
|
||||
|
||||
/// <summary>List all sites.</summary>
|
||||
/// <summary>List all sites (filtered by user access for non-admins).</summary>
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.SiteRead)]
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(PagedResult<SiteResponse>), StatusCodes.Status200OK)]
|
||||
@@ -63,7 +63,10 @@ public class SitesController : ControllerBase
|
||||
public async Task<IActionResult> List(
|
||||
[FromQuery] int page = 1, [FromQuery] int pageSize = 20, CancellationToken ct = default)
|
||||
{
|
||||
var result = await _mediator.Send(new GetSitesQuery(page, pageSize), ct);
|
||||
if (!this.TryGetUserId(out var userId))
|
||||
return Unauthorized(new { error = "Invalid user identity" });
|
||||
|
||||
var result = await _mediator.Send(new GetSitesQuery(page, pageSize, userId), ct);
|
||||
if (!result.IsSuccess)
|
||||
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
return Ok(result.Data);
|
||||
|
||||
Reference in new issue
Block a user