From 4cea990eb39786870787fb191e21e05e84606c35 Mon Sep 17 00:00:00 2001 From: WonderAliceUwU Date: Tue, 17 Nov 2026 15:24:45 +0100 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20feat:=20choose=20the=20sec?= =?UTF-8?q?tions=20each=20profile=20sees=20and=20review=20its=20Jellyfin?= =?UTF-8?q?=20libraries=20from=20the=20admin=20menu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/index.ts | 40 +++++-- server/lib/services.ts | 61 +++++++++- shared/contracts.ts | 35 +++++- src/App.tsx | 211 ++++++++++++++++++++++++++-------- src/api.ts | 2 + src/index.css | 249 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 532 insertions(+), 66 deletions(-) diff --git a/server/index.ts b/server/index.ts index fd2a0e9..1005eb0 100644 --- a/server/index.ts +++ b/server/index.ts @@ -4,6 +4,7 @@ import { BlockList, isIP } from 'node:net'; import { resolve } from 'node:path'; import { defaultConfig, + HIDEABLE_SECTIONS, type AppConfig, type AuthPayload, type BackupFile, @@ -14,6 +15,7 @@ import { type SeriesEpisodeRequestPayload, type EpisodeWatchStateRequest, type DiskSpaceStatus, + type HideableSection, type HubPageResponse, type JellyfinLoginPayload, type MovieDeletePayload, @@ -58,6 +60,7 @@ import { setEpisodeWatchState, sanitizeConfig, getDownloadsResponse, + getProfileLibraryAccess, dismissCompletedDownload, dismissAllCompletedDownloads } from './lib/services.js'; @@ -274,6 +277,23 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse): return; } + if (url.pathname === '/api/admin/profile-access' && method === 'GET') { + const config = await readConfig(session!.encryptionKey); + sendJson(response, 200, { profiles: await getProfileLibraryAccess(config) }); + return; + } + + // Sections the administrator switched off for this profile are closed on the + // server too, not only hidden from the menu. + const section = session?.role === 'user' && session.userId ? getSectionOfRoute(url.pathname) : null; + if (section) { + const config = await readConfig(session!.encryptionKey); + if ((config.preferences.hiddenSections[session!.userId!] ?? []).includes(section)) { + sendJson(response, 403, { error: 'This section is not available for your profile.' }); + return; + } + } + if (url.pathname === '/api/admin/backup' && method === 'GET') { const backup: BackupFile = { app: 'omniarr', @@ -394,14 +414,6 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse): return; } - if (url.pathname.startsWith('/api/downloads')) { - const config = await readConfig(session!.encryptionKey); - if (!canViewDownloads(session!, config)) { - sendJson(response, 403, { error: 'You do not have access to downloads.' }); - return; - } - } - if (url.pathname === '/api/downloads' && method === 'GET') { const config = await readConfig(session!.encryptionKey); sendJson(response, 200, await getDownloadsResponse(config)); @@ -719,10 +731,14 @@ function mergeStoredConfig(stored: Partial): AppConfig { // Profiles keep their own wishlist; the administrator has no Jellyfin profile // and shares a single one. -// Profiles the administrator listed cannot open the Downloads page; the admin -// session always can. -function canViewDownloads(session: SessionRecord, config: AppConfig): boolean { - return session.role === 'admin' || !session.userId || !config.preferences.downloadsRestrictedUserIds.includes(session.userId); +// The section of the app an API route serves, if the administrator can switch it off. +function getSectionOfRoute(pathname: string): HideableSection | null { + const section = pathname.startsWith('/api/downloads') ? 'downloads' + : pathname.startsWith('/api/calendar') ? 'calendar' + : pathname.startsWith('/api/search') ? 'search' + : pathname.startsWith('/api/hubs/') ? decodeURIComponent(pathname.replace('/api/hubs/', '')) + : ''; + return HIDEABLE_SECTIONS.find((candidate) => candidate.id === section)?.id ?? null; } function getWishlistOwner(session: SessionRecord): string { diff --git a/server/lib/services.ts b/server/lib/services.ts index 9420584..1fb4a9c 100644 --- a/server/lib/services.ts +++ b/server/lib/services.ts @@ -11,10 +11,12 @@ import type { EpisodeRequestPayload, EpisodeWatchStateRequest, HubPageResponse, + HideableSection, HubSection, MediaCard, MovieDeletePayload, ProcessingItem, + ProfileLibraryAccess, SeasonDeletePayload, SeasonRequestPayload, SeriesEpisodeRequestPayload, @@ -26,6 +28,7 @@ import type { TitleDetailsSeason, TitleDetailsCastMember } from '../../shared/contracts.js'; +import { HIDEABLE_SECTIONS } from '../../shared/contracts.js'; const TMDB_IMAGE = 'https://image.tmdb.org/t/p'; const TMDB_ARTWORK_TTL_MS = 6 * 60 * 60 * 1000; @@ -373,6 +376,24 @@ let tvdbTokenCache: { token: string; expiresAt: number } | null = null; const tmdbArtworkCache = new Map }>(); const tvdbTranslationCache = new Map }>(); +const HIDEABLE_SECTION_IDS = new Set(HIDEABLE_SECTIONS.map((section) => section.id)); + +function sanitizeHiddenSections(input: unknown): Record { + const hidden: Record = {}; + if (!input || typeof input !== 'object') { + return hidden; + } + for (const [userId, sections] of Object.entries(input)) { + const valid = Array.isArray(sections) + ? [...new Set(sections.map(String))].filter((section): section is HideableSection => HIDEABLE_SECTION_IDS.has(section)) + : []; + if (userId && valid.length) { + hidden[userId] = valid; + } + } + return hidden; +} + export function sanitizeConfig(input: AppConfig): AppConfig { return { preferences: { @@ -386,9 +407,8 @@ export function sanitizeConfig(input: AppConfig): AppConfig { radarrDownloadQualityProfileIds: Array.isArray(input.preferences.radarrDownloadQualityProfileIds) ? input.preferences.radarrDownloadQualityProfileIds.map(String) : [], - downloadsRestrictedUserIds: Array.isArray(input.preferences.downloadsRestrictedUserIds) - ? input.preferences.downloadsRestrictedUserIds.map(String) - : [] + hiddenSections: sanitizeHiddenSections(input.preferences.hiddenSections), + filterUpcomingByLibrary: Boolean(input.preferences.filterUpcomingByLibrary) }, jellyfin: { baseUrl: normalizeBaseUrl(input.jellyfin.baseUrl), @@ -754,8 +774,8 @@ export async function getCalendar(config: AppConfig, start: Date, end: Date): Pr // tell which episodes are already in the library. const library = await getLibrarySnapshot(config).catch(() => null); - // A profile only sees upcoming releases that belong to the libraries it can open. - const hidden = await getHiddenLibraryScope(config, library?.allItems ?? []); + // With the setting on, a profile only sees upcoming releases from the libraries it can open. + const hidden = config.preferences.filterUpcomingByLibrary ? await getHiddenLibraryScope(config, library?.allItems ?? []) : null; const sonarrItems = sonarrResult.status === 'fulfilled' ? sonarrResult.value .filter((item) => !hidden?.hides('series', Number(item.series?.tmdbId) || undefined, item.series?.path)) @@ -869,6 +889,37 @@ async function getHiddenLibraryScope(config: AppConfig, visibleItems: JellyfinIt } } +// What Jellyfin lets each profile open, for the administrator to review; the +// permissions themselves are managed in Jellyfin. +export async function getProfileLibraryAccess(config: AppConfig): Promise { + if (!config.jellyfin.baseUrl || !config.jellyfin.apiKey) { + return []; + } + + const [users, folders] = await Promise.all([ + jellyfinFetch>(config, '/Users'), + jellyfinFetch>(config, '/Library/VirtualFolders') + ]); + const libraries = folders.filter((folder) => folder.ItemId && folder.Name); + + return users + .filter((user) => user.Id) + .map((user) => { + const allLibraries = user.Policy?.EnableAllFolders !== false; + const enabled = new Set((user.Policy?.EnabledFolders ?? []).map(normalizeLibraryId)); + return { + userId: String(user.Id), + label: user.Name || 'User', + allLibraries, + libraries: libraries.map((folder) => ({ + id: String(folder.ItemId), + name: String(folder.Name), + access: allLibraries || enabled.has(normalizeLibraryId(folder.ItemId)) + })) + }; + }); +} + export async function searchTitles( config: AppConfig, rawQuery: string diff --git a/shared/contracts.ts b/shared/contracts.ts index 1f82d7a..89b445e 100644 --- a/shared/contracts.ts +++ b/shared/contracts.ts @@ -15,6 +15,24 @@ export type AppRoute = | 'wishlist' | 'settings'; +// Sections of the app the administrator can switch off for a profile. +export const HIDEABLE_SECTIONS = [ + { id: 'search', label: 'Search' }, + { id: 'calendar', label: 'Upcoming' }, + { id: 'downloads', label: 'Downloads' }, + { id: 'wishlist', label: 'Wishlist' }, + { id: 'dorama', label: 'K-Drama' }, + { id: 'anime', label: 'Anime' }, + { id: 'library', label: 'Library' }, + { id: 'netflix', label: 'Netflix' }, + { id: 'primevideo', label: 'Prime Video' }, + { id: 'hbo', label: 'HBO' }, + { id: 'viki', label: 'Viki' }, + { id: 'disney', label: 'Disney+' } +] as const; + +export type HideableSection = (typeof HIDEABLE_SECTIONS)[number]['id']; + export interface ServiceConfig { baseUrl: string; } @@ -56,8 +74,18 @@ export interface AppPreferences { animationLevel: 'smooth' | 'reduced'; sonarrDownloadQualityProfileIds: string[]; radarrDownloadQualityProfileIds: string[]; - /** Jellyfin profiles that cannot open the Downloads page; empty lets everyone in. */ - downloadsRestrictedUserIds: string[]; + /** Sections switched off for each Jellyfin profile, by user id; a profile that is not listed sees everything. */ + hiddenSections: Record; + /** Upcoming leaves out releases from Jellyfin libraries the signed-in profile cannot open. */ + filterUpcomingByLibrary: boolean; +} + +export interface ProfileLibraryAccess { + userId: string; + label: string; + /** Jellyfin lets this profile open every library, including ones added later. */ + allLibraries: boolean; + libraries: Array<{ id: string; name: string; access: boolean }>; } export interface AppConfig { @@ -394,7 +422,8 @@ export const defaultConfig: AppConfig = { animationLevel: 'smooth', sonarrDownloadQualityProfileIds: [], radarrDownloadQualityProfileIds: [], - downloadsRestrictedUserIds: [] + hiddenSections: {}, + filterUpcomingByLibrary: false }, jellyfin: { baseUrl: '', diff --git a/src/App.tsx b/src/App.tsx index 161ecef..d07d821 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -22,9 +22,11 @@ import { type CompletedDownloadItem, type DownloadItem, type DiskSpaceStatus, + type HideableSection, type HubPageResponse, type MediaCard, type ProcessingItem, + type ProfileLibraryAccess, type SearchResponse, type SelectOption, type ServiceOptionsResponse, @@ -33,6 +35,7 @@ import { type TitleDetailsResponse, type WishlistEntry, } from '../shared/contracts' +import { HIDEABLE_SECTIONS } from '../shared/contracts' type AuthState = 'loading' | 'setup' | 'login' | 'profiles' | 'admin' | 'app' type EntryStage = 'onboarding' | 'profiles' | 'dashboard' @@ -125,8 +128,10 @@ function App() { const [downloadDeleteId, setDownloadDeleteId] = useState('') const [wishlist, setWishlist] = useState([]) const [entryTransitionState, setEntryTransitionState] = useState('idle') - // The administrator can keep some profiles away from Downloads. - const canViewDownloads = sessionRole !== 'user' || !config.preferences.downloadsRestrictedUserIds.includes(config.jellyfin.userId) + // The administrator can switch sections off for each profile; admin sessions see them all. + const hiddenSections: string[] = sessionRole === 'user' ? (config.preferences.hiddenSections[config.jellyfin.userId] ?? []) : [] + const isSectionHidden = (sectionRoute: AppRoute) => hiddenSections.includes(sectionRoute) + const routeHidden = isSectionHidden(route) async function transitionEntryStage(nextStage: EntryStage) { if (nextStage === entryStage) { @@ -239,15 +244,16 @@ function App() { return } + if (routeHidden) { + setRoute('home') + return + } + if (route === 'settings' || route === 'calendar' || route === 'search' || route === 'wishlist') { return } if (route === 'downloads') { - if (!canViewDownloads) { - setRoute('home') - return - } void refreshDownloads() const interval = window.setInterval(() => { void refreshDownloads() @@ -276,7 +282,7 @@ function App() { return () => { cancelled = true } - }, [authState, canViewDownloads, entryStage, route]) + }, [authState, entryStage, route, routeHidden]) @@ -672,11 +678,11 @@ function App() { const currentHub = isHubRoute(route) ? hubPages[route as HubPageResponse['page']] : undefined return ( - +
) : null} - {route === 'calendar' && isRouteAvailable(route, connections) ? setSelectedCard({ card, originRect: originRect ?? null })} /> : null} - {route === 'downloads' && canViewDownloads && isRouteAvailable(route, connections) ? setSelectedCard({ card, originRect: originRect ?? null })} processingItems={processingItems} /> : null} + {route === 'calendar' && !routeHidden && isRouteAvailable(route, connections) ? setSelectedCard({ card, originRect: originRect ?? null })} /> : null} + {route === 'downloads' && isRouteAvailable(route, connections) ? setSelectedCard({ card, originRect: originRect ?? null })} processingItems={processingItems} /> : null} {route === 'search' ? ( boolean onExitProfile: () => void }) { const [menuOpen, setMenuOpen] = useState(false) @@ -843,7 +849,7 @@ function Sidebar(props: {
- {topSidebarItems.filter((item) => isRouteAvailable(item.route, props.connections) && (item.route !== 'downloads' || props.canViewDownloads)).map((item) => ( + {topSidebarItems.filter((item) => isRouteAvailable(item.route, props.connections) && !props.isSectionHidden(item.route)).map((item) => ( + {open ? ( +
+
+

Sections

+
+ {HIDEABLE_SECTIONS.map((section) => ( + + ))} +
+
+
+

Libraries

+ {profileAccess ? ( + <> + {profileAccess.allLibraries ?

Can open every library.

: null} +
    + {profileAccess.libraries.map((library) => ( +
  • + + {library.name} + {library.access ? 'has access' : 'no access'} +
  • + ))} +
+ + ) : ( +

{accessError || 'Loading libraries…'}

+ )} +
+
+ ) : null} + + ) + })} + +
+ ) +} + +function ToggleSwitch(props: { checked: boolean; label: string; onChange: (checked: boolean) => void }) { + return ( + + props.onChange(event.target.checked)} + type="checkbox" + /> + ) } diff --git a/src/api.ts b/src/api.ts index 7af35fe..ff340d5 100644 --- a/src/api.ts +++ b/src/api.ts @@ -12,6 +12,7 @@ import type { JellyfinLoginPayload, MediaCard, MovieDeletePayload, + ProfileLibraryAccess, SearchResponse, ServiceOptionsResponse, SessionResponse, @@ -103,6 +104,7 @@ export const api = { body: JSON.stringify(payload), }), exportBackup: () => request('/api/admin/backup'), + getProfileAccess: () => request<{ profiles: ProfileLibraryAccess[] }>('/api/admin/profile-access'), importBackup: (backup: unknown) => request<{ config: AppConfig; connections: ConnectionStatus[] }>('/api/admin/backup', { method: 'POST', diff --git a/src/index.css b/src/index.css index b4a2142..3b5576a 100644 --- a/src/index.css +++ b/src/index.css @@ -6073,3 +6073,252 @@ img { max-width: 76rem; margin: 0 auto 1rem; } + +/* Profiles: who sees which sections, and which libraries Jellyfin gives them. */ +.settings-card.is-wide { + grid-column: 1 / -1; +} + +.visually-hidden { + position: absolute; + width: 1px; + height: 1px; + margin: -1px; + padding: 0; + overflow: hidden; + clip: rect(0, 0, 0, 0); + white-space: nowrap; + border: 0; +} + +.profiles-access { + display: grid; + gap: 0.9rem; +} + +.profiles-access-note { + margin: 0; + color: #9ba9c2; + font-size: 0.86rem; +} + +.profiles-access-option { + display: flex; + align-items: center; + justify-content: space-between; + gap: 1rem; + padding: 0.85rem 0.95rem; + border: 1px solid rgba(255, 255, 255, 0.06); + border-radius: 1rem; + background: rgba(255, 255, 255, 0.03); +} + +.profiles-access-option > span:first-child { + display: grid; + gap: 0.2rem; + min-width: 0; + color: #e8efff; + font-size: 0.92rem; +} + +.profiles-access-option small { + color: #9ba9c2; + font-size: 0.8rem; +} + +.profiles-access-list { + display: grid; + gap: 0.6rem; + margin: 0; + padding: 0; + list-style: none; +} + +.profiles-access-item { + border: 1px solid rgba(255, 255, 255, 0.08); + border-radius: 1rem; + background: rgba(255, 255, 255, 0.025); + overflow: hidden; +} + +.profiles-access-item.is-open { + border-color: rgba(255, 255, 255, 0.18); +} + +.profiles-access-summary { + display: flex; + align-items: center; + gap: 0.85rem; + width: 100%; + padding: 0.7rem 0.95rem; + border: 0; + background: transparent; + color: #f4f7ff; + text-align: left; + cursor: pointer; +} + +.profiles-access-summary:hover, +.profiles-access-summary:focus-visible { + background: rgba(255, 255, 255, 0.04); +} + +.profiles-access-summary .profile-avatar { + flex: none; + width: 2.4rem; + height: 2.4rem; + border-radius: 50%; + font-size: 1rem; + overflow: hidden; +} + +.profiles-access-summary .profile-avatar img { + width: 100%; + height: 100%; + object-fit: cover; +} + +.profiles-access-name { + flex: 1; + min-width: 0; + font-weight: 600; +} + +.profiles-access-meta { + color: #9ba9c2; + font-size: 0.82rem; +} + +.profiles-access-chevron { + width: 0.55rem; + height: 0.55rem; + border-right: 2px solid #9ba9c2; + border-bottom: 2px solid #9ba9c2; + transform: rotate(45deg); + transition: transform 160ms ease; +} + +.profiles-access-item.is-open .profiles-access-chevron { + transform: rotate(225deg); +} + +.profiles-access-detail { + display: grid; + grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); + gap: 1.4rem; + padding: 0.4rem 0.95rem 1.1rem; + border-top: 1px solid rgba(255, 255, 255, 0.06); +} + +.profiles-access-detail h3 { + margin: 0.8rem 0 0.6rem; + color: #e8efff; + font-size: 0.84rem; + font-weight: 700; + letter-spacing: 0.08em; + text-transform: uppercase; +} + +.profiles-access-sections { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); + gap: 0.5rem 1rem; +} + +.profiles-access-section { + display: flex; + align-items: center; + justify-content: space-between; + gap: 0.75rem; + color: #dfe7f7; + font-size: 0.9rem; +} + +.profiles-access-libraries { + display: grid; + gap: 0.4rem; + margin: 0; + padding: 0; + list-style: none; +} + +.profiles-access-libraries li { + display: flex; + align-items: center; + gap: 0.55rem; + font-size: 0.9rem; +} + +.profiles-access-libraries li.has-access { + color: #dfe7f7; +} + +.profiles-access-libraries li.has-access > span:first-child { + color: #68d391; +} + +.profiles-access-libraries li.no-access { + color: #7d89a1; +} + +.profiles-access-libraries li.no-access > span:first-child { + color: #ff6b81; +} + +.toggle-switch { + position: relative; + display: inline-flex; + flex: none; + width: 2.5rem; + height: 1.4rem; +} + +.toggle-switch input { + position: absolute; + inset: 0; + z-index: 1; + width: 100%; + height: 100%; + margin: 0; + opacity: 0; + cursor: pointer; +} + +.toggle-switch-track { + position: absolute; + inset: 0; + border-radius: 999px; + background: rgba(255, 255, 255, 0.16); + transition: background 160ms ease; +} + +.toggle-switch-track::after { + content: ''; + position: absolute; + top: 0.2rem; + left: 0.2rem; + width: 1rem; + height: 1rem; + border-radius: 50%; + background: #f4f7ff; + transition: transform 160ms ease; +} + +.toggle-switch input:checked + .toggle-switch-track { + background: #68d391; +} + +.toggle-switch input:checked + .toggle-switch-track::after { + transform: translateX(1.1rem); +} + +.toggle-switch input:focus-visible + .toggle-switch-track { + outline: 2px solid #dfe7f7; + outline-offset: 2px; +} + +@media (max-width: 760px) { + .profiles-access-detail { + grid-template-columns: minmax(0, 1fr); + } +}