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
+130
-47
No files matched your search
@@ -1,7 +1,7 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>1.0.0.8</Version>
|
||||
<AssemblyVersion>1.0.0.8</AssemblyVersion>
|
||||
<FileVersion>1.0.0.8</FileVersion>
|
||||
<Version>1.0.0.9</Version>
|
||||
<AssemblyVersion>1.0.0.9</AssemblyVersion>
|
||||
<FileVersion>1.0.0.9</FileVersion>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -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)
|
||||
|
||||
@@ -21,7 +21,7 @@ public sealed class WebNavInjector : IHostedService
|
||||
/// <summary>
|
||||
/// Script URL injected into jellyfin-web index.html.
|
||||
/// </summary>
|
||||
public const string LoaderSrc = "/Requests/Assets/nav-loader.js?v=1.0.0.8";
|
||||
public const string LoaderSrc = "/Requests/Assets/nav-loader.js?v=1.0.0.9";
|
||||
|
||||
private const string MarkerStart = "<!-- jellyfin-plugin-request-nav-start -->";
|
||||
private const string MarkerEnd = "<!-- jellyfin-plugin-request-nav-end -->";
|
||||
|
||||
@@ -227,14 +227,28 @@
|
||||
els.globalMessage.classList.toggle("req-error", !!isError);
|
||||
}
|
||||
|
||||
function applyAdminUi() {
|
||||
els.adminTab.classList.toggle("req-hidden", !state.isAdmin);
|
||||
if (!state.isAdmin) {
|
||||
els.adminList.innerHTML = "";
|
||||
if (!els.adminView.classList.contains("req-hidden")) {
|
||||
setView("mine");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setView(view) {
|
||||
if (view === "admin" && !state.isAdmin) {
|
||||
view = "mine";
|
||||
}
|
||||
|
||||
root.querySelectorAll(".req-tab").forEach((tab) => {
|
||||
tab.classList.toggle("active", tab.dataset.view === view);
|
||||
});
|
||||
els.searchView.classList.toggle("req-hidden", view !== "search");
|
||||
els.mineView.classList.toggle("req-hidden", view !== "mine");
|
||||
els.adminView.classList.toggle("req-hidden", view !== "admin");
|
||||
if (view === "mine" || view === "admin") {
|
||||
if (view === "mine" || (view === "admin" && state.isAdmin)) {
|
||||
loadRequests();
|
||||
}
|
||||
}
|
||||
@@ -242,10 +256,15 @@
|
||||
async function loadStatus() {
|
||||
try {
|
||||
state.status = await api("/Status");
|
||||
if (!state.status.isConfigured) {
|
||||
const configured = !!(state.status.isConfigured ?? state.status.IsConfigured);
|
||||
const submissionsEnabled = !!(state.status.requestSubmissionEnabled ?? state.status.RequestSubmissionEnabled);
|
||||
state.isAdmin = !!(state.status.isAdmin ?? state.status.IsAdmin);
|
||||
applyAdminUi();
|
||||
|
||||
if (!configured) {
|
||||
els.statusBanner.textContent = "TMDB is not configured. An administrator must set a TMDB API key in Dashboard → Plugins → Request.";
|
||||
els.statusBanner.classList.remove("req-hidden");
|
||||
} else if (!state.status.requestSubmissionEnabled) {
|
||||
} else if (!submissionsEnabled) {
|
||||
els.statusBanner.textContent = "Search is available. Request submission is disabled by the administrator.";
|
||||
els.statusBanner.classList.remove("req-hidden");
|
||||
} else {
|
||||
@@ -258,7 +277,12 @@
|
||||
|
||||
async function loadCurrentUser() {
|
||||
try {
|
||||
const response = await fetch("/Users/Me", {
|
||||
let me = null;
|
||||
if (typeof ApiClient !== "undefined" && typeof ApiClient.getCurrentUser === "function") {
|
||||
me = await ApiClient.getCurrentUser();
|
||||
} else {
|
||||
const base = apiRoot().replace(/\/Requests$/, "");
|
||||
const response = await fetch(`${base}/Users/Me`, {
|
||||
cache: "no-store",
|
||||
headers: authHeader()
|
||||
});
|
||||
@@ -266,11 +290,18 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const me = await response.json();
|
||||
state.isAdmin = !!me?.Policy?.IsAdministrator;
|
||||
els.adminTab.classList.toggle("req-hidden", !state.isAdmin);
|
||||
me = await response.json();
|
||||
}
|
||||
|
||||
const policy = me?.Policy || me?.policy || {};
|
||||
const fromUser = !!(policy.IsAdministrator ?? policy.isAdministrator);
|
||||
if (fromUser) {
|
||||
state.isAdmin = true;
|
||||
}
|
||||
|
||||
applyAdminUi();
|
||||
} catch {
|
||||
// Non-fatal.
|
||||
// Non-fatal; Status endpoint remains the source of truth.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,6 +515,7 @@
|
||||
}
|
||||
|
||||
function renderRequestList(container, items, adminMode) {
|
||||
const showAdminActions = !!(adminMode && state.isAdmin);
|
||||
if (!items.length) {
|
||||
container.innerHTML = `<p class="req-message">No requests yet.</p>`;
|
||||
return;
|
||||
@@ -498,15 +530,17 @@
|
||||
? `Seasons ${item.seasons.join(", ")}`
|
||||
: "";
|
||||
const status = statusName(item.status);
|
||||
const actions = adminMode
|
||||
? `
|
||||
<button type="button" class="req-btn" data-action="approve" data-id="${escapeHtml(item.id)}">Approve</button>
|
||||
<button type="button" class="req-btn" data-action="reject" data-id="${escapeHtml(item.id)}">Reject</button>
|
||||
<button type="button" class="req-btn" data-action="fulfill" data-id="${escapeHtml(item.id)}">Fulfilled</button>
|
||||
<button type="button" class="req-btn danger" data-action="delete" data-id="${escapeHtml(item.id)}">Delete</button>`
|
||||
: (status === "Pending"
|
||||
? `<button type="button" class="req-btn danger" data-action="delete" data-id="${escapeHtml(item.id)}">Cancel</button>`
|
||||
: "");
|
||||
const requestId = String(item.id || "");
|
||||
let actions = "";
|
||||
if (showAdminActions && requestId) {
|
||||
actions = `
|
||||
<button type="button" class="req-btn" data-action="approve" data-id="${escapeHtml(requestId)}">Approve</button>
|
||||
<button type="button" class="req-btn" data-action="reject" data-id="${escapeHtml(requestId)}">Reject</button>
|
||||
<button type="button" class="req-btn" data-action="fulfill" data-id="${escapeHtml(requestId)}">Fulfilled</button>
|
||||
<button type="button" class="req-btn danger" data-action="delete" data-id="${escapeHtml(requestId)}">Delete</button>`;
|
||||
} else if (!showAdminActions && status === "Pending" && requestId) {
|
||||
actions = `<button type="button" class="req-btn danger" data-action="delete" data-id="${escapeHtml(requestId)}">Cancel</button>`;
|
||||
}
|
||||
|
||||
return `
|
||||
<article class="req-list-item">
|
||||
@@ -523,20 +557,49 @@
|
||||
}).join("");
|
||||
|
||||
container.querySelectorAll("[data-action]").forEach((button) => {
|
||||
button.addEventListener("click", () => handleRequestAction(button.dataset.action, button.dataset.id));
|
||||
button.addEventListener("click", () => handleRequestAction(button.dataset.action, button.dataset.id, showAdminActions));
|
||||
});
|
||||
}
|
||||
|
||||
async function handleRequestAction(action, id) {
|
||||
async function handleRequestAction(action, id, fromAdminQueue) {
|
||||
const requestId = String(id || "").trim();
|
||||
if (!requestId) {
|
||||
showMessage("Missing request id.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
const adminActions = new Set(["approve", "reject", "fulfill"]);
|
||||
if ((adminActions.has(action) || (action === "delete" && fromAdminQueue)) && !state.isAdmin) {
|
||||
showMessage("Administrator access is required.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "delete" && !window.confirm(fromAdminQueue ? "Delete this request?" : "Cancel this request?")) {
|
||||
return;
|
||||
}
|
||||
|
||||
const messages = {
|
||||
approve: "Request approved.",
|
||||
reject: "Request rejected.",
|
||||
fulfill: "Request marked fulfilled.",
|
||||
delete: fromAdminQueue ? "Request deleted." : "Request canceled."
|
||||
};
|
||||
|
||||
try {
|
||||
if (action === "delete") {
|
||||
await api(`/${id}`, { method: "DELETE" });
|
||||
await api(`/${encodeURIComponent(requestId)}`, { method: "DELETE" });
|
||||
} else if (adminActions.has(action)) {
|
||||
await api(`/${encodeURIComponent(requestId)}/${action}`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ adminNote: null })
|
||||
});
|
||||
} else {
|
||||
await api(`/${id}/${action}`, { method: "POST", body: "{}" });
|
||||
showMessage("Unknown action.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
await loadRequests();
|
||||
showMessage("Updated.");
|
||||
showMessage(messages[action] || "Updated.");
|
||||
} catch (error) {
|
||||
showMessage(error.message, true);
|
||||
}
|
||||
@@ -561,8 +624,9 @@
|
||||
}
|
||||
});
|
||||
|
||||
loadStatus();
|
||||
loadCurrentUser();
|
||||
Promise.all([loadStatus(), loadCurrentUser()]).then(() => {
|
||||
applyAdminUi();
|
||||
});
|
||||
|
||||
return { setView, reload: () => { loadStatus(); loadRequests(); } };
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
---
|
||||
name: "Request"
|
||||
guid: "11c08950-c4bb-484d-89ff-205b3724416b"
|
||||
version: "1.0.0.8"
|
||||
version: "1.0.0.9"
|
||||
targetAbi: "10.11.11.0"
|
||||
framework: "net9.0"
|
||||
overview: "Request movies and TV shows from a local admin review queue"
|
||||
|
||||
+5
-5
@@ -9,12 +9,12 @@
|
||||
"repositoryUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies",
|
||||
"versions": [
|
||||
{
|
||||
"version": "1.0.0.8",
|
||||
"changelog": "Fix My requests/Admin queue showing Unknown status and Invalid Date",
|
||||
"version": "1.0.0.9",
|
||||
"changelog": "Admin queue approve/reject/fulfill/delete; admin tab and buttons only for admins",
|
||||
"targetAbi": "10.11.11.0",
|
||||
"sourceUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main/release/Jellyfin.Plugin.Request_1.0.0.8.zip",
|
||||
"checksum": "50A8114FF61E2E4C440C332E1AEF3D01",
|
||||
"timestamp": "2026-08-02T21:38:10.7513883Z",
|
||||
"sourceUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main/release/Jellyfin.Plugin.Request_1.0.0.9.zip",
|
||||
"checksum": "0A263FF8AC56B02D9C8021607CD1B087",
|
||||
"timestamp": "2026-08-02T21:40:27.2325188Z",
|
||||
"dependencies": []
|
||||
}
|
||||
]
|
||||
|
||||
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
param(
|
||||
[string]$Version = "1.0.0.8",
|
||||
[string]$Version = "1.0.0.9",
|
||||
[string]$TargetAbi = "10.11.11.0",
|
||||
[string]$RepoRawBase = "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main"
|
||||
)
|
||||
@@ -17,7 +17,7 @@ $dllPath = Join-Path $root "Jellyfin.Plugin.Request\bin\Release\net9.0\Jellyfin.
|
||||
$zipPath = Join-Path $releaseDir $zipFileName
|
||||
$manifestPath = Join-Path $root "manifest.json"
|
||||
$timestamp = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ")
|
||||
$changelog = "Fix My requests/Admin queue showing Unknown status and Invalid Date"
|
||||
$changelog = "Admin queue approve/reject/fulfill/delete; admin tab and buttons only for admins"
|
||||
|
||||
Write-Host "Building plugin..."
|
||||
dotnet build (Join-Path $root "Jellyfin.Plugin.Request.sln") -c Release
|
||||
|
||||
Reference in new issue
Block a user