diff --git a/Directory.Build.props b/Directory.Build.props index 2c6528d..67655cb 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 1.0.0.8 - 1.0.0.8 - 1.0.0.8 + 1.0.0.9 + 1.0.0.9 + 1.0.0.9 diff --git a/Jellyfin.Plugin.Request/Api/RequestController.cs b/Jellyfin.Plugin.Request/Api/RequestController.cs index 918c855..94b38ed 100644 --- a/Jellyfin.Plugin.Request/Api/RequestController.cs +++ b/Jellyfin.Plugin.Request/Api/RequestController.cs @@ -61,11 +61,14 @@ public sealed class RequestController : ControllerBase public ActionResult 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) diff --git a/Jellyfin.Plugin.Request/Hosting/WebNavInjector.cs b/Jellyfin.Plugin.Request/Hosting/WebNavInjector.cs index 1f7aa2f..56f63fb 100644 --- a/Jellyfin.Plugin.Request/Hosting/WebNavInjector.cs +++ b/Jellyfin.Plugin.Request/Hosting/WebNavInjector.cs @@ -21,7 +21,7 @@ public sealed class WebNavInjector : IHostedService /// /// Script URL injected into jellyfin-web index.html. /// - 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 = ""; private const string MarkerEnd = ""; diff --git a/Jellyfin.Plugin.Request/Web/request.js b/Jellyfin.Plugin.Request/Web/request.js index 4e00dda..090846e 100644 --- a/Jellyfin.Plugin.Request/Web/request.js +++ b/Jellyfin.Plugin.Request/Web/request.js @@ -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,19 +277,31 @@ async function loadCurrentUser() { try { - const response = await fetch("/Users/Me", { - cache: "no-store", - headers: authHeader() - }); - if (!response.ok) { - return; + 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() + }); + if (!response.ok) { + return; + } + + me = await response.json(); } - const me = await response.json(); - state.isAdmin = !!me?.Policy?.IsAdministrator; - els.adminTab.classList.toggle("req-hidden", !state.isAdmin); + 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 = `

No requests yet.

`; return; @@ -498,15 +530,17 @@ ? `Seasons ${item.seasons.join(", ")}` : ""; const status = statusName(item.status); - const actions = adminMode - ? ` - - - - ` - : (status === "Pending" - ? `` - : ""); + const requestId = String(item.id || ""); + let actions = ""; + if (showAdminActions && requestId) { + actions = ` + + + + `; + } else if (!showAdminActions && status === "Pending" && requestId) { + actions = ``; + } return `
@@ -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(); } }; } diff --git a/build.yaml b/build.yaml index b3ec91c..b5a9727 100644 --- a/build.yaml +++ b/build.yaml @@ -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" diff --git a/manifest.json b/manifest.json index 87d0576..93a4f53 100644 --- a/manifest.json +++ b/manifest.json @@ -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": [] } ] diff --git a/release/Jellyfin.Plugin.Request_1.0.0.9.zip b/release/Jellyfin.Plugin.Request_1.0.0.9.zip new file mode 100644 index 0000000..328e0fb Binary files /dev/null and b/release/Jellyfin.Plugin.Request_1.0.0.9.zip differ diff --git a/scripts/package-release.ps1 b/scripts/package-release.ps1 index b6f0cb8..bada36b 100644 --- a/scripts/package-release.ps1 +++ b/scripts/package-release.ps1 @@ -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