diff --git a/.dockerignore b/.dockerignore index 9c6a50ec..8eaac594 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,3 +7,4 @@ README.md .git media .env* +db diff --git a/README.md b/README.md index ab63604f..78bd872f 100644 --- a/README.md +++ b/README.md @@ -50,18 +50,19 @@ This project uses environment variables to configure its behavior. The following environment variables are used: -| Variable | Description | Example Value | -| ------------------------- | --------------------------------------------------------------- | ---------------------------------------------------------------------- | -| DATABASE_URL | Database connection URL | `postgresql://postgres:postgres@localhost:5432/postgres?schema=public` | -| GAMMA_API_KEY_ID | Gamma info API key ID | `api-key-id-uuid-here` | -| GAMMA_API_KEY_TOKEN | Gamma info API token | `token` | -| GAMMA_CLIENT_ID | Gamma OAuth client ID | `id` | -| GAMMA_CLIENT_SECRET | Gamma OAuth client secret | `secret` | -| GAMMA_ROOT_URL | Gamma root URL | `https://auth.chalmers.it` | -| BASE_URL | URL that is used as a base for linking to news | `https://chalmers.it` | -| NEXTAUTH_SECRET | Secret used for signing cookies | `secret` | -| NEXTAUTH_URL | URL to the NextAuth API | `http://localhost:3000/api/auth` | -| MEDIA_PATH | Path to store media | `./media` | -| ACTIVE_GROUP_TYPES | Comma-separated list of group types that are considered active | `committee,society` | -| ADMIN_GROUPS | Comma-separated list of groups that are considered admin groups | `styrit` | -| CORPORATE_RELATIONS_GROUP | Group that is considered the corporate relations group | `armit` | +| Variable | Description | Example Value | +|---------------------------|----------------------------------------------------------------------------------------------|------------------------------------------------------------------------| +| DATABASE_URL | Database connection URL | `postgresql://postgres:postgres@localhost:5432/postgres?schema=public` | +| GAMMA_API_KEY_ID | Gamma info API key ID | `api-key-id-uuid-here` | +| GAMMA_API_KEY_TOKEN | Gamma info API token | `token` | +| GAMMA_CLIENT_ID | Gamma OAuth client ID | `id` | +| GAMMA_CLIENT_SECRET | Gamma OAuth client secret | `secret` | +| GAMMA_ROOT_URL | Gamma root URL | `https://auth.chalmers.it` | +| BASE_URL | URL that is used as a base for linking to news | `https://chalmers.it` | +| NEXTAUTH_SECRET | Secret used for signing cookies | `secret` | +| NEXTAUTH_URL | URL to the NextAuth API | `http://localhost:3000/api/auth` | +| MEDIA_PATH | Path to store media | `./media` | +| ACTIVE_GROUP_TYPES | Comma-separated list of group types that are considered active | `committee,society` | +| ADMIN_GROUPS | Comma-separated list of groups that are considered admin groups | `styrit,digit` | +| PAGE_EDITOR_GROUPS | Comma-separated list of groups that are allowed to edit division pages in addition to admins | 'snit,motespresidit' | +| CORPORATE_RELATIONS_GROUP | Group that is considered the corporate relations group | `armit` | diff --git a/src/actions/divisionPages.ts b/src/actions/divisionPages.ts index 11b1b310..7bae948d 100644 --- a/src/actions/divisionPages.ts +++ b/src/actions/divisionPages.ts @@ -17,9 +17,15 @@ export async function create( divisionGroupId?: number, parentId?: number ) { - if (!(await SessionService.isAdmin())) { + if ( + !( + (await SessionService.isPageEditor()) && + (divisionGroupId === null || divisionGroupId === undefined) + ) + ) { if ( divisionGroupId === undefined || + divisionGroupId === null || !(await SessionService.canEditGroupByInternalId(divisionGroupId)) ) { throw new Error('Unauthorized'); @@ -50,7 +56,12 @@ export async function create( export async function deletePage(id: number) { const divisionGroupId = (await DivisionPageService.getSingleById(id)) ?.divisionGroupId; - if (!(await SessionService.isAdmin())) { + if ( + !( + (await SessionService.isAdmin()) || + ((await SessionService.isPageEditor()) && divisionGroupId === null) + ) + ) { if ( divisionGroupId === undefined || divisionGroupId === null || @@ -79,11 +90,9 @@ export async function edit( throw new Error('Page not found'); } - for (const file of files.getAll('file') as unknown as File[]) { - await MediaService.save(file, Object.values(MediaType)); - } - - if (!(await SessionService.isAdmin())) { + if ( + !((await SessionService.isPageEditor()) && page.divisionGroupId === null) + ) { if ( page.divisionGroupId === null || !(await SessionService.canEditGroupByInternalId(page.divisionGroupId)) @@ -91,6 +100,11 @@ export async function edit( throw new Error('Unauthorized'); } } + + for (const file of files.getAll('file') as unknown as File[]) { + await MediaService.save(file, Object.values(MediaType)); + } + await DivisionPageService.edit( id, titleEn, diff --git a/src/app/[locale]/pages/page.tsx b/src/app/[locale]/pages/page.tsx index f4cc25f1..6953d33f 100644 --- a/src/app/[locale]/pages/page.tsx +++ b/src/app/[locale]/pages/page.tsx @@ -24,14 +24,17 @@ export default async function Groups({ } const Pages = async ({ locale }: { locale: string }) => { - const isAdmin = await SessionService.isAdmin(); + const isPageEditor = await SessionService.isPageEditor(); const l = i18nService.getLocale(locale); const en = locale === 'en'; + console.log(isPageEditor); return (

{l.pages.about}

- {isAdmin && {l.pages.create}} + {isPageEditor && ( + {l.pages.create} + )}