feat: admin users can view all downloads with user badges

- Admin users (Emby IsAdministrator) see a 'Show all users' toggle
- When toggled, all tagged downloads are shown regardless of user
- Each download card shows the tagged user's name as a badge
- Non-admin users see only their own downloads (unchanged behavior)
- Backend accepts ?showAll=true query param (admin-only)
This commit is contained in:
2026-05-15 20:46:56 +01:00
parent 6463c6b3d1
commit 0957f83411
5 changed files with 89 additions and 16 deletions

View File

@@ -37,9 +37,11 @@ router.post('/login', async (req, res) => {
console.log(`[Auth] Login successful for user: ${user.Name}`);
// Set authentication cookie
const isAdmin = !!(user.Policy && user.Policy.IsAdministrator);
res.cookie('emby_user', JSON.stringify({
id: user.Id,
name: user.Name,
isAdmin: isAdmin,
token: authData.AccessToken
}), {
httpOnly: true,
@@ -50,7 +52,8 @@ router.post('/login', async (req, res) => {
success: true,
user: {
id: user.Id,
name: user.Name
name: user.Name,
isAdmin: isAdmin
}
});
} catch (error) {
@@ -76,7 +79,8 @@ router.get('/me', (req, res) => {
authenticated: true,
user: {
id: user.id,
name: user.name
name: user.name,
isAdmin: !!user.isAdmin
}
});
} catch (error) {

View File

@@ -53,7 +53,9 @@ router.get('/user-downloads', async (req, res) => {
const user = JSON.parse(userCookie);
const username = user.name.toLowerCase();
console.log(`[Dashboard] Fetching downloads for authenticated user: ${user.name} (${username})`);
const isAdmin = !!user.isAdmin;
const showAll = isAdmin && req.query.showAll === 'true';
console.log(`[Dashboard] Fetching downloads for authenticated user: ${user.name} (${username}), isAdmin: ${isAdmin}, showAll: ${showAll}`);
// Get all service instances
const sabInstances = getSABnzbdInstances();
@@ -301,7 +303,7 @@ router.get('/user-downloads', async (req, res) => {
const series = seriesMap.get(sonarrMatch.seriesId) || sonarrMatch.series;
if (series) {
const userTag = extractUserTag(series.tags, sonarrTagMap);
if (userTag && userTag.toLowerCase() === username) {
if (userTag && (showAll || userTag.toLowerCase() === username)) {
userDownloads.push({
type: 'series',
title: nzbName,
@@ -314,7 +316,8 @@ router.get('/user-downloads', async (req, res) => {
speed: slotState.speed,
eta: slot.timeleft,
seriesName: series.title,
episodeInfo: sonarrMatch
episodeInfo: sonarrMatch,
userTag: userTag
});
}
}
@@ -330,7 +333,7 @@ router.get('/user-downloads', async (req, res) => {
const movie = moviesMap.get(radarrMatch.movieId) || radarrMatch.movie;
if (movie) {
const userTag = extractUserTag(movie.tags, radarrTagMap);
if (userTag && userTag.toLowerCase() === username) {
if (userTag && (showAll || userTag.toLowerCase() === username)) {
userDownloads.push({
type: 'movie',
title: nzbName,
@@ -343,7 +346,8 @@ router.get('/user-downloads', async (req, res) => {
speed: slotState.speed,
eta: slot.timeleft,
movieName: movie.title,
movieInfo: radarrMatch
movieInfo: radarrMatch,
userTag: userTag
});
}
}
@@ -376,7 +380,7 @@ router.get('/user-downloads', async (req, res) => {
const series = seriesMap.get(sonarrMatch.seriesId) || sonarrMatch.series;
if (series) {
const userTag = extractUserTag(series.tags, sonarrTagMap);
if (userTag && userTag.toLowerCase() === username) {
if (userTag && (showAll || userTag.toLowerCase() === username)) {
userDownloads.push({
type: 'series',
title: nzbName,
@@ -385,7 +389,8 @@ router.get('/user-downloads', async (req, res) => {
size: slot.size,
completedAt: slot.completed_time,
seriesName: series.title,
episodeInfo: sonarrMatch
episodeInfo: sonarrMatch,
userTag: userTag
});
}
}
@@ -401,7 +406,7 @@ router.get('/user-downloads', async (req, res) => {
const movie = moviesMap.get(radarrMatch.movieId) || radarrMatch.movie;
if (movie) {
const userTag = extractUserTag(movie.tags, radarrTagMap);
if (userTag && userTag.toLowerCase() === username) {
if (userTag && (showAll || userTag.toLowerCase() === username)) {
userDownloads.push({
type: 'movie',
title: nzbName,
@@ -410,7 +415,8 @@ router.get('/user-downloads', async (req, res) => {
size: slot.size,
completedAt: slot.completed_time,
movieName: movie.title,
movieInfo: radarrMatch
movieInfo: radarrMatch,
userTag: userTag
});
}
}
@@ -462,7 +468,7 @@ router.get('/user-downloads', async (req, res) => {
const series = seriesMap.get(sonarrMatch.seriesId) || sonarrMatch.series;
if (series) {
const userTag = extractUserTag(series.tags, sonarrTagMap);
if (userTag && userTag.toLowerCase() === username) {
if (userTag && (showAll || userTag.toLowerCase() === username)) {
console.log(`[Dashboard] Matched torrent "${torrentName}" to Sonarr series "${series.title}"`);
const download = mapTorrentToDownload(torrent);
download.type = 'series';
@@ -486,7 +492,7 @@ router.get('/user-downloads', async (req, res) => {
const movie = moviesMap.get(radarrMatch.movieId) || radarrMatch.movie;
if (movie) {
const userTag = extractUserTag(movie.tags, radarrTagMap);
if (userTag && userTag.toLowerCase() === username) {
if (userTag && (showAll || userTag.toLowerCase() === username)) {
console.log(`[Dashboard] Matched torrent "${torrentName}" to Radarr movie "${movie.title}"`);
const download = mapTorrentToDownload(torrent);
download.type = 'movie';
@@ -510,7 +516,7 @@ router.get('/user-downloads', async (req, res) => {
const series = seriesMap.get(sonarrHistoryMatch.seriesId) || sonarrHistoryMatch.series;
if (series) {
const userTag = extractUserTag(series.tags, sonarrTagMap);
if (userTag && userTag.toLowerCase() === username) {
if (userTag && (showAll || userTag.toLowerCase() === username)) {
console.log(`[Dashboard] Matched torrent "${torrentName}" to Sonarr history "${series.title}"`);
const download = mapTorrentToDownload(torrent);
download.type = 'series';
@@ -534,7 +540,7 @@ router.get('/user-downloads', async (req, res) => {
const movie = moviesMap.get(radarrHistoryMatch.movieId) || radarrHistoryMatch.movie;
if (movie) {
const userTag = extractUserTag(movie.tags, radarrTagMap);
if (userTag && userTag.toLowerCase() === username) {
if (userTag && (showAll || userTag.toLowerCase() === username)) {
console.log(`[Dashboard] Matched torrent "${torrentName}" to Radarr history "${movie.title}"`);
const download = mapTorrentToDownload(torrent);
download.type = 'movie';
@@ -561,6 +567,7 @@ router.get('/user-downloads', async (req, res) => {
res.json({
user: user.name,
isAdmin: isAdmin,
downloads: userDownloads
});
} catch (error) {