diff --git a/README.md b/README.md
index 697989e..6913c3f 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,7 @@ If OmniArr is useful to you, you can support its development on [Ko-fi](https://
- A download manager to see what's cooking.
+- Per-profile control of which sections each person sees (see [Profiles](#profiles)).
And many things more!
@@ -122,6 +123,48 @@ npm run lint
npm run build
```
+## Profiles
+
+Open **Administration → Profiles** to see every Jellyfin profile. Selecting one
+opens its settings:
+
+- **Sections** are on/off switches for Search, Upcoming, Downloads, Wishlist,
+ K-Drama, Anime, Library and each network. Everything is on by default and
+ Home is always available. A hidden section disappears from the menu and the
+ server refuses its requests for that profile. The administrator always sees
+ everything.
+- **Libraries** shows which Jellyfin libraries the profile can open. It is read
+ from Jellyfin and cannot be changed here; manage it in Jellyfin.
+
+Save with the check button of the Profiles card.
+
+### Upcoming and library access
+
+Upcoming comes from Sonarr and Radarr, which know nothing about Jellyfin
+permissions. To keep each profile's calendar to what it can open, OmniArr asks
+Jellyfin for the libraries a profile cannot open and leaves out the releases
+that are stored in them.
+
+Sonarr, Radarr and Jellyfin often mount the media folder under different paths
+(for example `/shared/Library/Anime` for Sonarr and `/library/Anime` for
+Jellyfin), so a release is matched to a library by the **name of the library
+folder** found in the series or movie path. Keep that folder name the same in
+all three apps. A release whose path does not contain the name of any library is
+shown to everyone, and if Jellyfin cannot be reached the calendar is not
+filtered.
+
+## Tests
+
+```bash
+npm test
+```
+
+The tests run against small stand-ins for Jellyfin, Sonarr and Radarr
+(`server/test/mock-services.ts`). To point a running OmniArr at them while
+developing, start them with `node dist-server/server/test/mock-services.js` after
+a build; it prints the three URLs, accepts any API key and offers a `full`
+profile and a `limited` one that cannot open Anime or Anime Movies.
+
## Data and security
OmniArr keeps critical state under `OMNIARR_DATA_DIR` (by default
diff --git a/package.json b/package.json
index 9f54eb1..decb84f 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,8 @@
"lint": "eslint .",
"preview": "vite preview",
"start": "node dist-server/server/index.js",
- "serve": "npm run build && npm run start"
+ "serve": "npm run build && npm run start",
+ "test": "tsc -p tsconfig.server.json && node --test dist-server/server/test/*.test.js"
},
"dependencies": {
"react": "^19.2.5",
diff --git a/server/lib/services.ts b/server/lib/services.ts
index 4cf8b58..aae0174 100644
--- a/server/lib/services.ts
+++ b/server/lib/services.ts
@@ -193,6 +193,7 @@ interface SonarrCalendarRecord {
series?: {
title?: string;
tmdbId?: number;
+ path?: string;
images?: Array<{ coverType?: string; remoteUrl?: string; url?: string }>;
year?: number;
status?: string;
@@ -243,6 +244,7 @@ interface RadarrCalendarRecord {
digitalRelease?: string;
monitored?: boolean;
hasFile?: boolean;
+ path?: string;
images?: Array<{ coverType?: string; remoteUrl?: string; url?: string }>;
}
@@ -405,8 +407,7 @@ export function sanitizeConfig(input: AppConfig): AppConfig {
radarrDownloadQualityProfileIds: Array.isArray(input.preferences.radarrDownloadQualityProfileIds)
? input.preferences.radarrDownloadQualityProfileIds.map(String)
: [],
- hiddenSections: sanitizeHiddenSections(input.preferences.hiddenSections),
- filterUpcomingByLibrary: Boolean(input.preferences.filterUpcomingByLibrary)
+ hiddenSections: sanitizeHiddenSections(input.preferences.hiddenSections)
},
jellyfin: {
baseUrl: normalizeBaseUrl(input.jellyfin.baseUrl),
@@ -772,19 +773,16 @@ 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);
- // With the setting on, a profile's calendar is the releases of the titles in the
- // libraries it can open: Jellyfin answers per user with exactly those titles.
- const ownTitles = config.preferences.filterUpcomingByLibrary && config.jellyfin.userId && library
- ? new Set(library.allItems.map(getTmdbTitleKey).filter(Boolean))
- : null;
+ // A profile does not see releases that will be stored in a library it cannot open.
+ const hiddenFolders = await getHiddenLibraryFolders(config);
const sonarrItems = sonarrResult.status === 'fulfilled'
? sonarrResult.value
- .filter((item) => !ownTitles || ownTitles.has(`series:${Number(item.series?.tmdbId)}`))
+ .filter((item) => !isInFolders(item.series?.path, hiddenFolders))
.map((item) => mapSonarrCalendarEntry(item))
: []
const radarrItems = radarrResult.status === 'fulfilled'
? radarrResult.value
- .filter((item) => !ownTitles || ownTitles.has(`movie:${Number(item.tmdbId)}`))
+ .filter((item) => !isInFolders(item.path, hiddenFolders))
.map((item) => mapRadarrCalendarEntry(item))
: []
const libraryProviderIds = new Map();
@@ -827,9 +825,51 @@ function normalizeLibraryId(id: string | undefined): string {
return String(id || '').replace(/-/g, '').toLowerCase();
}
-function getTmdbTitleKey(item: JellyfinItem): string {
- const tmdbId = Number(item.ProviderIds?.Tmdb);
- return tmdbId ? `${item.Type === 'Movie' ? 'movie' : 'series'}:${tmdbId}` : '';
+function getFolderNames(locations: string[] | undefined): string[] {
+ return (locations ?? [])
+ .map((location) => location.replace(/\\/g, '/').split('/').filter(Boolean).pop()?.toLowerCase() ?? '')
+ .filter(Boolean);
+}
+
+// Sonarr and Radarr rarely see a folder under the same path as Jellyfin (they
+// mount it differently), so a release is matched to a library by the folder
+// name: a series stored in /shared/Library/Shows/X belongs to the library whose
+// folder is called "Shows".
+export function isInFolders(path: string | undefined, folderNames: string[] | null): boolean {
+ if (!path || !folderNames?.length) {
+ return false;
+ }
+ // The last segment is the title's own folder, not a library.
+ const parents = path.replace(/\\/g, '/').split('/').filter(Boolean).slice(0, -1).map((segment) => segment.toLowerCase());
+ return parents.some((segment) => folderNames.includes(segment));
+}
+
+// The folder names of the libraries the signed-in profile cannot open, read
+// from Jellyfin (its libraries, and the ones in the profile's views). Admin
+// sessions have no profile and see everything.
+async function getHiddenLibraryFolders(config: AppConfig): Promise {
+ if (!config.jellyfin.userId || !config.jellyfin.baseUrl || !config.jellyfin.apiKey) {
+ return null;
+ }
+
+ try {
+ const [folders, views] = await Promise.all([
+ jellyfinFetch>(config, '/Library/VirtualFolders'),
+ jellyfinFetch(config, `/UserViews?userId=${encodeURIComponent(config.jellyfin.userId)}`)
+ ]);
+ const visibleLibraryIds = new Set(views.map((view) => normalizeLibraryId(view.Id)));
+ const visibleNames = new Set(folders.filter((folder) => visibleLibraryIds.has(normalizeLibraryId(folder.ItemId))).flatMap((folder) => getFolderNames(folder.Locations)));
+ // A name shared with a library the profile can open stays visible.
+ const hidden = folders
+ .filter((folder) => folder.ItemId && !visibleLibraryIds.has(normalizeLibraryId(folder.ItemId)))
+ .flatMap((folder) => getFolderNames(folder.Locations))
+ .filter((name) => !visibleNames.has(name));
+ return hidden.length ? [...new Set(hidden)] : null;
+ } catch (error) {
+ // Better to show the calendar than to break it when Jellyfin cannot be asked.
+ console.warn('Could not read the profile libraries; the calendar is not filtered.', error);
+ return null;
+ }
}
// What Jellyfin lets each profile open, for the administrator to review; the
diff --git a/server/test/calendar-library-filter.test.ts b/server/test/calendar-library-filter.test.ts
new file mode 100644
index 0000000..583ab9a
--- /dev/null
+++ b/server/test/calendar-library-filter.test.ts
@@ -0,0 +1,79 @@
+import assert from 'node:assert/strict';
+import { after, before, describe, it } from 'node:test';
+import { defaultConfig, type AppConfig } from '../../shared/contracts.js';
+import { getCalendar, getProfileLibraryAccess, isInFolders } from '../lib/services.js';
+import { startMockServices } from './mock-services.js';
+
+let mocks: Awaited>;
+
+function configFor(userId: string): AppConfig {
+ return {
+ ...defaultConfig,
+ jellyfin: { baseUrl: mocks.jellyfinUrl, apiKey: 'key', userId },
+ sonarr: { ...defaultConfig.sonarr, baseUrl: mocks.sonarrUrl, apiKey: 'key' },
+ radarr: { ...defaultConfig.radarr, baseUrl: mocks.radarrUrl, apiKey: 'key' }
+ };
+}
+
+async function calendarTitles(config: AppConfig): Promise {
+ const calendar = await getCalendar(config, new Date('2026-11-01'), new Date('2026-11-30'));
+ return calendar.items.map((item) => item.title).sort();
+}
+
+before(async () => {
+ mocks = await startMockServices();
+});
+
+after(async () => {
+ await mocks.close();
+});
+
+describe('upcoming calendar per profile', () => {
+ it('shows everything to the administrator, who has no Jellyfin profile', async () => {
+ assert.deepEqual(await calendarTitles(configFor('')), ['Anime', 'Better Call Saul', 'Dune', 'Frieren', 'Your Name']);
+ });
+
+ it('shows everything to a profile that opens every library', async () => {
+ assert.deepEqual(await calendarTitles(configFor('full')), ['Anime', 'Better Call Saul', 'Dune', 'Frieren', 'Your Name']);
+ });
+
+ it('leaves out releases stored in libraries the profile cannot open', async () => {
+ assert.deepEqual(await calendarTitles(configFor('limited')), ['Anime', 'Better Call Saul', 'Dune']);
+ });
+
+ it('does not calendar-filter when Jellyfin cannot be asked', async () => {
+ const config = configFor('limited');
+ config.jellyfin.baseUrl = 'http://127.0.0.1:9';
+ assert.deepEqual(await calendarTitles(config), ['Anime', 'Better Call Saul', 'Dune', 'Frieren', 'Your Name']);
+ });
+});
+
+describe('library folder matching', () => {
+ it('matches a title by the library folder it is stored in', () => {
+ assert.equal(isInFolders('/shared/Library/Anime/Frieren', ['anime']), true);
+ assert.equal(isInFolders('/shared/library/ANIME/Frieren', ['anime']), true);
+ assert.equal(isInFolders('/shared/Library/Shows/Frieren', ['anime']), false);
+ });
+
+ it('ignores the title\'s own folder and handles missing data', () => {
+ assert.equal(isInFolders('/shared/Library/Shows/Anime', ['anime']), false);
+ assert.equal(isInFolders(undefined, ['anime']), false);
+ assert.equal(isInFolders('/shared/Library/Anime/Frieren', null), false);
+ assert.equal(isInFolders('C:\\Media\\Anime\\Frieren', ['anime']), true);
+ });
+});
+
+describe('profile library access', () => {
+ it('reports which libraries each Jellyfin profile can open', async () => {
+ const profiles = await getProfileLibraryAccess(configFor(''));
+ const full = profiles.find((profile) => profile.userId === 'full');
+ const limited = profiles.find((profile) => profile.userId === 'limited');
+ assert.equal(full?.allLibraries, true);
+ assert.ok(full?.libraries.every((library) => library.access));
+ assert.equal(limited?.allLibraries, false);
+ assert.deepEqual(
+ limited?.libraries.filter((library) => library.access).map((library) => library.name),
+ ['Shows', 'Movies']
+ );
+ });
+});
diff --git a/server/test/mock-services.ts b/server/test/mock-services.ts
new file mode 100644
index 0000000..18069f9
--- /dev/null
+++ b/server/test/mock-services.ts
@@ -0,0 +1,86 @@
+import { createServer, type Server } from 'node:http';
+import type { AddressInfo } from 'node:net';
+
+// Stand-ins for Jellyfin, Sonarr and Radarr with two profiles: "full" opens
+// every library and "limited" cannot open Anime or Anime Movies. Sonarr and
+// Radarr see the media under /shared/Library while Jellyfin sees /library, the
+// way the Docker mounts differ in a real setup.
+export const MOCK_LIBRARIES = [
+ { Name: 'Shows', ItemId: 'aaaaaaaa-0000-0000-0000-000000000001', Locations: ['/library/Shows'] },
+ { Name: 'Movies', ItemId: 'aaaaaaaa-0000-0000-0000-000000000002', Locations: ['/library/Movies'] },
+ { Name: 'Anime', ItemId: 'aaaaaaaa-0000-0000-0000-000000000003', Locations: ['/library/Anime'] },
+ { Name: 'Anime Movies', ItemId: 'aaaaaaaa-0000-0000-0000-000000000004', Locations: ['/library/AnimeMovies'] }
+];
+
+export const MOCK_USERS = [
+ { Id: 'full', Name: 'Full', Policy: { EnableAllFolders: true, EnabledFolders: [] } },
+ {
+ Id: 'limited',
+ Name: 'Limited',
+ Policy: { EnableAllFolders: false, EnabledFolders: [MOCK_LIBRARIES[0].ItemId, MOCK_LIBRARIES[1].ItemId] }
+ }
+];
+
+const AIR_DATE = '2026-11-20T20:00:00Z';
+
+const SONARR_CALENDAR = [
+ { id: 1, title: 'Pilot', airDateUtc: AIR_DATE, seasonNumber: 1, episodeNumber: 1, series: { title: 'Better Call Saul', tmdbId: 60059, path: '/shared/Library/Shows/Better Call Saul' } },
+ { id: 2, title: 'Chapter 1', airDateUtc: AIR_DATE, seasonNumber: 1, episodeNumber: 1, series: { title: 'Frieren', tmdbId: 209867, path: '/shared/Library/Anime/Frieren' } },
+ // A series folder that happens to be called like a library is still a Shows title.
+ { id: 3, title: 'Episode 1', airDateUtc: AIR_DATE, seasonNumber: 1, episodeNumber: 1, series: { title: 'Anime', tmdbId: 1, path: '/shared/Library/Shows/Anime' } }
+];
+
+const RADARR_CALENDAR = [
+ { id: 10, title: 'Dune', tmdbId: 438631, digitalRelease: AIR_DATE, path: '/shared/Library/Movies/Dune' },
+ { id: 11, title: 'Your Name', tmdbId: 372058, digitalRelease: AIR_DATE, path: '/shared/Library/AnimeMovies/Your Name' }
+];
+
+function listen(server: Server): Promise {
+ return new Promise((resolve) => {
+ server.listen(0, '127.0.0.1', () => resolve(`http://127.0.0.1:${(server.address() as AddressInfo).port}`));
+ });
+}
+
+function jsonServer(handler: (path: string, query: URLSearchParams) => unknown): Server {
+ return createServer((request, response) => {
+ const url = new URL(request.url || '/', 'http://localhost');
+ response.writeHead(200, { 'Content-Type': 'application/json' });
+ response.end(JSON.stringify(handler(url.pathname, url.searchParams)));
+ });
+}
+
+export async function startMockServices() {
+ const jellyfin = jsonServer((path, query) => {
+ if (path === '/Library/VirtualFolders') {
+ return MOCK_LIBRARIES;
+ }
+ if (path === '/Users') {
+ return MOCK_USERS;
+ }
+ if (path === '/UserViews') {
+ const user = MOCK_USERS.find((candidate) => candidate.Id === query.get('userId'));
+ const visible = MOCK_LIBRARIES.filter((library) => user?.Policy.EnableAllFolders || user?.Policy.EnabledFolders.includes(library.ItemId));
+ return { Items: visible.map((library) => ({ Id: library.ItemId.replace(/-/g, ''), Name: library.Name })) };
+ }
+ return { Items: [] };
+ });
+ const sonarr = jsonServer(() => SONARR_CALENDAR);
+ const radarr = jsonServer(() => RADARR_CALENDAR);
+ const [jellyfinUrl, sonarrUrl, radarrUrl] = await Promise.all([listen(jellyfin), listen(sonarr), listen(radarr)]);
+
+ return {
+ jellyfinUrl,
+ sonarrUrl,
+ radarrUrl,
+ close: () => Promise.all([jellyfin, sonarr, radarr].map((server) => new Promise((resolve) => server.close(resolve))))
+ };
+}
+
+// `node dist-server/server/test/mock-services.js` keeps the mocks running so the
+// app can be pointed at them (Jellyfin API key and Sonarr/Radarr keys: anything).
+const isMain = process.argv[1] !== undefined && import.meta.url.endsWith(process.argv[1].split('/').slice(-3).join('/'));
+if (isMain) {
+ const mocks = await startMockServices();
+ console.log(`Jellyfin ${mocks.jellyfinUrl}\nSonarr ${mocks.sonarrUrl}\nRadarr ${mocks.radarrUrl}`);
+ console.log('Profiles: "full" opens every library, "limited" cannot open Anime or Anime Movies.');
+}
diff --git a/shared/contracts.ts b/shared/contracts.ts
index 65cdb20..70612cd 100644
--- a/shared/contracts.ts
+++ b/shared/contracts.ts
@@ -76,8 +76,6 @@ export interface AppPreferences {
radarrDownloadQualityProfileIds: string[];
/** Sections switched off for each Jellyfin profile, by user id; a profile that is not listed sees everything. */
hiddenSections: Record;
- /** Upcoming only lists releases for titles in the Jellyfin libraries the signed-in profile can open. */
- filterUpcomingByLibrary: boolean;
}
export interface ProfileLibraryAccess {
@@ -422,8 +420,7 @@ export const defaultConfig: AppConfig = {
animationLevel: 'smooth',
sonarrDownloadQualityProfileIds: [],
radarrDownloadQualityProfileIds: [],
- hiddenSections: {},
- filterUpcomingByLibrary: false
+ hiddenSections: {}
},
jellyfin: {
baseUrl: '',
diff --git a/src/App.tsx b/src/App.tsx
index 356cd83..185fca3 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -12,6 +12,7 @@ import {
useRef,
useState,
} from 'react'
+import { createPortal } from 'react-dom'
import { api } from './api'
import {
type CalendarEntry,
@@ -4463,6 +4464,7 @@ function ProfilesAccess(props: {
const [accessError, setAccessError] = useState('')
const [openUserId, setOpenUserId] = useState('')
const preferences = props.config.preferences
+ const openUser = props.users.find((user) => user.id === openUserId)
useEffect(() => {
if (!props.users.length) {
@@ -4484,6 +4486,17 @@ function ProfilesAccess(props: {
}
}, [props.users.length])
+ useEffect(() => {
+ if (!openUser) {
+ return
+ }
+ const closeOnEscape = (event: KeyboardEvent) => {
+ if (event.key === 'Escape') setOpenUserId('')
+ }
+ window.addEventListener('keydown', closeOnEscape)
+ return () => window.removeEventListener('keydown', closeOnEscape)
+ }, [openUser])
+
function setSectionVisible(userId: string, section: HideableSection, visible: boolean) {
const current = preferences.hiddenSections[userId] ?? []
const next = visible ? current.filter((id) => id !== section) : [...current.filter((id) => id !== section), section]
@@ -4503,32 +4516,15 @@ function ProfilesAccess(props: {
return (
- Pick a profile to choose which sections it sees. Libraries come from its Jellyfin permissions and are managed there.
+ Pick a profile to choose which sections it sees and review the libraries Jellyfin gives it.
+ Upcoming also leaves out releases stored in libraries a profile cannot open.