diff --git a/frontend/cypress/support/config.ts b/frontend/cypress/support/config.ts index 8f6aaefd0..f3a0c70ec 100644 --- a/frontend/cypress/support/config.ts +++ b/frontend/cypress/support/config.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -8,8 +8,8 @@ import { HttpMethod } from '../../src/handler-utils/respond-to-matching-request' declare namespace Cypress { interface Chainable { - loadConfig(additionalConfig?: Partial): Chainable, - logIn: Chainable, + loadConfig(additionalConfig?: Partial): Chainable + logIn: Chainable logOut: Chainable } } @@ -61,8 +61,8 @@ export const authProviders = [ ] export const config = { - allowAnonymous: true, allowRegister: true, + guestAccess: 'write', authProviders: authProviders, branding: branding, useImageProxy: false, diff --git a/frontend/src/api/config/types.ts b/frontend/src/api/config/types.ts index e8f06a6aa..1866073e7 100644 --- a/frontend/src/api/config/types.ts +++ b/frontend/src/api/config/types.ts @@ -5,10 +5,10 @@ */ export interface FrontendConfig { - allowAnonymous: boolean allowRegister: boolean authProviders: AuthProvider[] branding: BrandingConfig + guestAccess: GuestAccessLevel useImageProxy: boolean specialUrls: SpecialUrls version: BackendVersion @@ -16,6 +16,13 @@ export interface FrontendConfig { maxDocumentLength: number } +export enum GuestAccessLevel { + DENY = 'deny', + READ = 'read', + WRITE = 'write', + CREATE = 'create' +} + export enum AuthProviderType { DROPBOX = 'dropbox', FACEBOOK = 'facebook', diff --git a/frontend/src/components/login-page/guest/guest-card.tsx b/frontend/src/components/login-page/guest/guest-card.tsx index c40c3008d..4c6644985 100644 --- a/frontend/src/components/login-page/guest/guest-card.tsx +++ b/frontend/src/components/login-page/guest/guest-card.tsx @@ -10,16 +10,17 @@ import { NewNoteButton } from '../../common/new-note-button/new-note-button' import { HistoryButton } from '../../layout/app-bar/app-bar-elements/help-dropdown/history-button' import { useFrontendConfig } from '../../common/frontend-config-context/use-frontend-config' import { Trans, useTranslation } from 'react-i18next' +import { GuestAccessLevel } from '../../../api/config/types' /** * Renders the card with the options for not logged-in users. */ export const GuestCard: React.FC = () => { - const allowAnonymous = useFrontendConfig().allowAnonymous + const guestAccessLevel = useFrontendConfig().guestAccess useTranslation() - if (!allowAnonymous) { + if (guestAccessLevel === GuestAccessLevel.DENY) { return null } diff --git a/frontend/src/pages/api/private/config.ts b/frontend/src/pages/api/private/config.ts index 9f186ba91..783452063 100644 --- a/frontend/src/pages/api/private/config.ts +++ b/frontend/src/pages/api/private/config.ts @@ -4,7 +4,7 @@ * SPDX-License-Identifier: AGPL-3.0-only */ import type { FrontendConfig } from '../../../api/config/types' -import { AuthProviderType } from '../../../api/config/types' +import { AuthProviderType, GuestAccessLevel } from '../../../api/config/types' import { HttpMethod, respondToMatchingRequest, @@ -14,12 +14,12 @@ import { isTestMode } from '../../../utils/test-modes' import type { NextApiRequest, NextApiResponse } from 'next' const initialConfig: FrontendConfig = { - allowAnonymous: true, allowRegister: true, branding: { name: 'DEMO Corp', logo: '/public/img/demo.png' }, + guestAccess: GuestAccessLevel.WRITE, useImageProxy: false, specialUrls: { privacy: 'https://example.com/privacy',