expand user permissions
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { getLibrary } from '@/lib/libraries'
|
||||
import { notFound, redirect } from 'next/navigation'
|
||||
import { getServerSession } from '@/lib/auth'
|
||||
import { getPermittedLibraryIds } from '@/lib/users'
|
||||
import { getLibraryAccessLevel } from '@/lib/users'
|
||||
import GamesView from '@/components/games/GamesView'
|
||||
import MixedView from '@/components/mixed/MixedView'
|
||||
import MoviesView from '@/components/movies/MoviesView'
|
||||
@@ -23,9 +23,11 @@ export default async function LibraryPage({ params, searchParams }: Props) {
|
||||
const library = getLibrary(id)
|
||||
if (!library) notFound()
|
||||
|
||||
let readOnly = false
|
||||
if (session.role !== 'admin') {
|
||||
const permitted = getPermittedLibraryIds(session.userId)
|
||||
if (!permitted.includes(id)) notFound()
|
||||
const accessLevel = getLibraryAccessLevel(session.userId, id)
|
||||
if (!accessLevel) notFound()
|
||||
readOnly = accessLevel === 'read'
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -52,10 +54,10 @@ export default async function LibraryPage({ params, searchParams }: Props) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{library.type === 'games' && <GamesView libraryId={id} />}
|
||||
{library.type === 'mixed' && <MixedView libraryId={id} libraryName={library.name} initialPath={subpath ?? ''} />}
|
||||
{library.type === 'movies' && <MoviesView libraryId={id} />}
|
||||
{library.type === 'tv' && <TvView libraryId={id} />}
|
||||
{library.type === 'games' && <GamesView libraryId={id} readOnly={readOnly} />}
|
||||
{library.type === 'mixed' && <MixedView libraryId={id} libraryName={library.name} initialPath={subpath ?? ''} readOnly={readOnly} />}
|
||||
{library.type === 'movies' && <MoviesView libraryId={id} readOnly={readOnly} />}
|
||||
{library.type === 'tv' && <TvView libraryId={id} readOnly={readOnly} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user