fix(admin): gate queue actions and harden approve flow
Expose isAdmin from Status, show Admin queue controls only for administrators, and return clear 403/404 messages for approve/reject/fulfill/delete. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3957c6ac1d
commit
2eed62390b
8 files changed
+135
-52
No files matched your search
@@ -61,11 +61,14 @@ public sealed class RequestController : ControllerBase
|
||||
public ActionResult<object> Status()
|
||||
{
|
||||
var config = GetConfig();
|
||||
var userId = GetUserId();
|
||||
return Ok(new
|
||||
{
|
||||
isConfigured = !string.IsNullOrWhiteSpace(config.TmdbApiKey),
|
||||
requestSubmissionEnabled = config.EnableRequestSubmission,
|
||||
allowSeasonSelection = config.AllowSeasonSelection
|
||||
allowSeasonSelection = config.AllowSeasonSelection,
|
||||
isAuthenticated = userId != Guid.Empty,
|
||||
isAdmin = userId != Guid.Empty && IsAdministrator(userId)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -362,19 +365,19 @@ public sealed class RequestController : ControllerBase
|
||||
var userId = GetUserId();
|
||||
if (userId == Guid.Empty)
|
||||
{
|
||||
return Unauthorized();
|
||||
return Unauthorized(new { message = "You must be signed in." });
|
||||
}
|
||||
|
||||
var existing = await _store.GetByIdAsync(id, cancellationToken).ConfigureAwait(false);
|
||||
if (existing is null)
|
||||
{
|
||||
return NotFound();
|
||||
return NotFound(new { message = "Request not found." });
|
||||
}
|
||||
|
||||
var isAdmin = IsAdministrator(userId);
|
||||
if (!isAdmin && (existing.RequestedByUserId != userId || existing.Status != RequestStatus.Pending))
|
||||
{
|
||||
return Forbid();
|
||||
return StatusCode(StatusCodes.Status403Forbidden, new { message = "You can only cancel your own pending requests." });
|
||||
}
|
||||
|
||||
await _store.DeleteAsync(id, cancellationToken).ConfigureAwait(false);
|
||||
@@ -390,18 +393,18 @@ public sealed class RequestController : ControllerBase
|
||||
var userId = GetUserId();
|
||||
if (userId == Guid.Empty)
|
||||
{
|
||||
return Unauthorized();
|
||||
return Unauthorized(new { message = "You must be signed in." });
|
||||
}
|
||||
|
||||
if (!IsAdministrator(userId))
|
||||
{
|
||||
return Forbid();
|
||||
return StatusCode(StatusCodes.Status403Forbidden, new { message = "Administrator access is required." });
|
||||
}
|
||||
|
||||
var existing = await _store.GetByIdAsync(id, cancellationToken).ConfigureAwait(false);
|
||||
if (existing is null)
|
||||
{
|
||||
return NotFound();
|
||||
return NotFound(new { message = "Request not found." });
|
||||
}
|
||||
|
||||
existing.Status = status;
|
||||
@@ -463,10 +466,26 @@ public sealed class RequestController : ControllerBase
|
||||
|
||||
private Guid GetUserId()
|
||||
{
|
||||
var raw = User.FindFirstValue(ClaimTypes.NameIdentifier)
|
||||
?? User.FindFirstValue("sub")
|
||||
?? User.FindFirstValue("Jellyfin-UserId");
|
||||
return Guid.TryParse(raw, out var userId) ? userId : Guid.Empty;
|
||||
string?[] candidates =
|
||||
[
|
||||
User.FindFirstValue(ClaimTypes.NameIdentifier),
|
||||
User.FindFirstValue("sub"),
|
||||
User.FindFirstValue("Jellyfin-UserId"),
|
||||
User.FindFirstValue("http://jellyfin.media/claims/user-id"),
|
||||
User.Claims.FirstOrDefault(claim =>
|
||||
claim.Type.EndsWith("/nameidentifier", StringComparison.OrdinalIgnoreCase)
|
||||
|| claim.Type.Equals("userid", StringComparison.OrdinalIgnoreCase))?.Value
|
||||
];
|
||||
|
||||
foreach (var raw in candidates)
|
||||
{
|
||||
if (Guid.TryParse(raw, out var userId) && userId != Guid.Empty)
|
||||
{
|
||||
return userId;
|
||||
}
|
||||
}
|
||||
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
||||
private bool IsAdministrator(Guid userId)
|
||||
|
||||
Reference in new issue
Block a user