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>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>1.0.0.8</Version>
|
<Version>1.0.0.9</Version>
|
||||||
<AssemblyVersion>1.0.0.8</AssemblyVersion>
|
<AssemblyVersion>1.0.0.9</AssemblyVersion>
|
||||||
<FileVersion>1.0.0.8</FileVersion>
|
<FileVersion>1.0.0.9</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -61,11 +61,14 @@ public sealed class RequestController : ControllerBase
|
|||||||
public ActionResult<object> Status()
|
public ActionResult<object> Status()
|
||||||
{
|
{
|
||||||
var config = GetConfig();
|
var config = GetConfig();
|
||||||
|
var userId = GetUserId();
|
||||||
return Ok(new
|
return Ok(new
|
||||||
{
|
{
|
||||||
isConfigured = !string.IsNullOrWhiteSpace(config.TmdbApiKey),
|
isConfigured = !string.IsNullOrWhiteSpace(config.TmdbApiKey),
|
||||||
requestSubmissionEnabled = config.EnableRequestSubmission,
|
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();
|
var userId = GetUserId();
|
||||||
if (userId == Guid.Empty)
|
if (userId == Guid.Empty)
|
||||||
{
|
{
|
||||||
return Unauthorized();
|
return Unauthorized(new { message = "You must be signed in." });
|
||||||
}
|
}
|
||||||
|
|
||||||
var existing = await _store.GetByIdAsync(id, cancellationToken).ConfigureAwait(false);
|
var existing = await _store.GetByIdAsync(id, cancellationToken).ConfigureAwait(false);
|
||||||
if (existing is null)
|
if (existing is null)
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound(new { message = "Request not found." });
|
||||||
}
|
}
|
||||||
|
|
||||||
var isAdmin = IsAdministrator(userId);
|
var isAdmin = IsAdministrator(userId);
|
||||||
if (!isAdmin && (existing.RequestedByUserId != userId || existing.Status != RequestStatus.Pending))
|
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);
|
await _store.DeleteAsync(id, cancellationToken).ConfigureAwait(false);
|
||||||
@@ -390,18 +393,18 @@ public sealed class RequestController : ControllerBase
|
|||||||
var userId = GetUserId();
|
var userId = GetUserId();
|
||||||
if (userId == Guid.Empty)
|
if (userId == Guid.Empty)
|
||||||
{
|
{
|
||||||
return Unauthorized();
|
return Unauthorized(new { message = "You must be signed in." });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsAdministrator(userId))
|
if (!IsAdministrator(userId))
|
||||||
{
|
{
|
||||||
return Forbid();
|
return StatusCode(StatusCodes.Status403Forbidden, new { message = "Administrator access is required." });
|
||||||
}
|
}
|
||||||
|
|
||||||
var existing = await _store.GetByIdAsync(id, cancellationToken).ConfigureAwait(false);
|
var existing = await _store.GetByIdAsync(id, cancellationToken).ConfigureAwait(false);
|
||||||
if (existing is null)
|
if (existing is null)
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound(new { message = "Request not found." });
|
||||||
}
|
}
|
||||||
|
|
||||||
existing.Status = status;
|
existing.Status = status;
|
||||||
@@ -463,10 +466,26 @@ public sealed class RequestController : ControllerBase
|
|||||||
|
|
||||||
private Guid GetUserId()
|
private Guid GetUserId()
|
||||||
{
|
{
|
||||||
var raw = User.FindFirstValue(ClaimTypes.NameIdentifier)
|
string?[] candidates =
|
||||||
?? User.FindFirstValue("sub")
|
[
|
||||||
?? User.FindFirstValue("Jellyfin-UserId");
|
User.FindFirstValue(ClaimTypes.NameIdentifier),
|
||||||
return Guid.TryParse(raw, out var userId) ? userId : Guid.Empty;
|
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)
|
private bool IsAdministrator(Guid userId)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public sealed class WebNavInjector : IHostedService
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Script URL injected into jellyfin-web index.html.
|
/// Script URL injected into jellyfin-web index.html.
|
||||||
/// </summary>
|
/// </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 MarkerStart = "<!-- jellyfin-plugin-request-nav-start -->";
|
||||||
private const string MarkerEnd = "<!-- jellyfin-plugin-request-nav-end -->";
|
private const string MarkerEnd = "<!-- jellyfin-plugin-request-nav-end -->";
|
||||||
|
|||||||
@@ -227,14 +227,28 @@
|
|||||||
els.globalMessage.classList.toggle("req-error", !!isError);
|
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) {
|
function setView(view) {
|
||||||
|
if (view === "admin" && !state.isAdmin) {
|
||||||
|
view = "mine";
|
||||||
|
}
|
||||||
|
|
||||||
root.querySelectorAll(".req-tab").forEach((tab) => {
|
root.querySelectorAll(".req-tab").forEach((tab) => {
|
||||||
tab.classList.toggle("active", tab.dataset.view === view);
|
tab.classList.toggle("active", tab.dataset.view === view);
|
||||||
});
|
});
|
||||||
els.searchView.classList.toggle("req-hidden", view !== "search");
|
els.searchView.classList.toggle("req-hidden", view !== "search");
|
||||||
els.mineView.classList.toggle("req-hidden", view !== "mine");
|
els.mineView.classList.toggle("req-hidden", view !== "mine");
|
||||||
els.adminView.classList.toggle("req-hidden", view !== "admin");
|
els.adminView.classList.toggle("req-hidden", view !== "admin");
|
||||||
if (view === "mine" || view === "admin") {
|
if (view === "mine" || (view === "admin" && state.isAdmin)) {
|
||||||
loadRequests();
|
loadRequests();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,10 +256,15 @@
|
|||||||
async function loadStatus() {
|
async function loadStatus() {
|
||||||
try {
|
try {
|
||||||
state.status = await api("/Status");
|
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.textContent = "TMDB is not configured. An administrator must set a TMDB API key in Dashboard → Plugins → Request.";
|
||||||
els.statusBanner.classList.remove("req-hidden");
|
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.textContent = "Search is available. Request submission is disabled by the administrator.";
|
||||||
els.statusBanner.classList.remove("req-hidden");
|
els.statusBanner.classList.remove("req-hidden");
|
||||||
} else {
|
} else {
|
||||||
@@ -258,7 +277,12 @@
|
|||||||
|
|
||||||
async function loadCurrentUser() {
|
async function loadCurrentUser() {
|
||||||
try {
|
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",
|
cache: "no-store",
|
||||||
headers: authHeader()
|
headers: authHeader()
|
||||||
});
|
});
|
||||||
@@ -266,11 +290,18 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const me = await response.json();
|
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 {
|
} catch {
|
||||||
// Non-fatal.
|
// Non-fatal; Status endpoint remains the source of truth.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -484,6 +515,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderRequestList(container, items, adminMode) {
|
function renderRequestList(container, items, adminMode) {
|
||||||
|
const showAdminActions = !!(adminMode && state.isAdmin);
|
||||||
if (!items.length) {
|
if (!items.length) {
|
||||||
container.innerHTML = `<p class="req-message">No requests yet.</p>`;
|
container.innerHTML = `<p class="req-message">No requests yet.</p>`;
|
||||||
return;
|
return;
|
||||||
@@ -498,15 +530,17 @@
|
|||||||
? `Seasons ${item.seasons.join(", ")}`
|
? `Seasons ${item.seasons.join(", ")}`
|
||||||
: "";
|
: "";
|
||||||
const status = statusName(item.status);
|
const status = statusName(item.status);
|
||||||
const actions = adminMode
|
const requestId = String(item.id || "");
|
||||||
? `
|
let actions = "";
|
||||||
<button type="button" class="req-btn" data-action="approve" data-id="${escapeHtml(item.id)}">Approve</button>
|
if (showAdminActions && requestId) {
|
||||||
<button type="button" class="req-btn" data-action="reject" data-id="${escapeHtml(item.id)}">Reject</button>
|
actions = `
|
||||||
<button type="button" class="req-btn" data-action="fulfill" data-id="${escapeHtml(item.id)}">Fulfilled</button>
|
<button type="button" class="req-btn" data-action="approve" data-id="${escapeHtml(requestId)}">Approve</button>
|
||||||
<button type="button" class="req-btn danger" data-action="delete" data-id="${escapeHtml(item.id)}">Delete</button>`
|
<button type="button" class="req-btn" data-action="reject" data-id="${escapeHtml(requestId)}">Reject</button>
|
||||||
: (status === "Pending"
|
<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(item.id)}">Cancel</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 `
|
return `
|
||||||
<article class="req-list-item">
|
<article class="req-list-item">
|
||||||
@@ -523,20 +557,49 @@
|
|||||||
}).join("");
|
}).join("");
|
||||||
|
|
||||||
container.querySelectorAll("[data-action]").forEach((button) => {
|
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 {
|
try {
|
||||||
if (action === "delete") {
|
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 {
|
} else {
|
||||||
await api(`/${id}/${action}`, { method: "POST", body: "{}" });
|
showMessage("Unknown action.", true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await loadRequests();
|
await loadRequests();
|
||||||
showMessage("Updated.");
|
showMessage(messages[action] || "Updated.");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showMessage(error.message, true);
|
showMessage(error.message, true);
|
||||||
}
|
}
|
||||||
@@ -561,8 +624,9 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
loadStatus();
|
Promise.all([loadStatus(), loadCurrentUser()]).then(() => {
|
||||||
loadCurrentUser();
|
applyAdminUi();
|
||||||
|
});
|
||||||
|
|
||||||
return { setView, reload: () => { loadStatus(); loadRequests(); } };
|
return { setView, reload: () => { loadStatus(); loadRequests(); } };
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
name: "Request"
|
name: "Request"
|
||||||
guid: "11c08950-c4bb-484d-89ff-205b3724416b"
|
guid: "11c08950-c4bb-484d-89ff-205b3724416b"
|
||||||
version: "1.0.0.8"
|
version: "1.0.0.9"
|
||||||
targetAbi: "10.11.11.0"
|
targetAbi: "10.11.11.0"
|
||||||
framework: "net9.0"
|
framework: "net9.0"
|
||||||
overview: "Request movies and TV shows from a local admin review queue"
|
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",
|
"repositoryUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies",
|
||||||
"versions": [
|
"versions": [
|
||||||
{
|
{
|
||||||
"version": "1.0.0.8",
|
"version": "1.0.0.9",
|
||||||
"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",
|
||||||
"targetAbi": "10.11.11.0",
|
"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",
|
"sourceUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main/release/Jellyfin.Plugin.Request_1.0.0.9.zip",
|
||||||
"checksum": "50A8114FF61E2E4C440C332E1AEF3D01",
|
"checksum": "0A263FF8AC56B02D9C8021607CD1B087",
|
||||||
"timestamp": "2026-08-02T21:38:10.7513883Z",
|
"timestamp": "2026-08-02T21:40:27.2325188Z",
|
||||||
"dependencies": []
|
"dependencies": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Binary file not shown.
@@ -1,5 +1,5 @@
|
|||||||
param(
|
param(
|
||||||
[string]$Version = "1.0.0.8",
|
[string]$Version = "1.0.0.9",
|
||||||
[string]$TargetAbi = "10.11.11.0",
|
[string]$TargetAbi = "10.11.11.0",
|
||||||
[string]$RepoRawBase = "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main"
|
[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
|
$zipPath = Join-Path $releaseDir $zipFileName
|
||||||
$manifestPath = Join-Path $root "manifest.json"
|
$manifestPath = Join-Path $root "manifest.json"
|
||||||
$timestamp = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ")
|
$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..."
|
Write-Host "Building plugin..."
|
||||||
dotnet build (Join-Path $root "Jellyfin.Plugin.Request.sln") -c Release
|
dotnet build (Join-Path $root "Jellyfin.Plugin.Request.sln") -c Release
|
||||||
|
|||||||
Reference in new issue
Block a user