Fix share page permissions
This commit is contained in:
1 parent
f41c0221c4
commit
9d477b25b4
7 files changed
+47
-29
No files matched your search
@@ -1,10 +1,10 @@
|
||||
'use client';
|
||||
import { Loading } from '@umami/react-zen';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import { createContext, type ReactNode, useEffect } from 'react';
|
||||
import { useShareTokenQuery } from '@/components/hooks';
|
||||
import { ENTITY_TYPE } from '@/lib/constants';
|
||||
import type { WhiteLabel } from '@/lib/types';
|
||||
import { Loading } from '@umami/react-zen';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import { createContext, type ReactNode, useEffect } from 'react';
|
||||
|
||||
export interface ShareData {
|
||||
shareId: string;
|
||||
@@ -56,14 +56,15 @@ export function ShareProvider({ slug, children }: { slug: string; children: Reac
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const path = getSharePath(pathname);
|
||||
const isBoardShare = share?.shareType === ENTITY_TYPE.board;
|
||||
const isWebsiteShare = share?.shareType === ENTITY_TYPE.website;
|
||||
|
||||
const allowedSections = isWebsiteShare && share?.parameters
|
||||
? ALL_SECTION_IDS.filter(id => share.parameters[id] === true)
|
||||
: [];
|
||||
const allowedSections =
|
||||
isWebsiteShare && share?.parameters
|
||||
? ALL_SECTION_IDS.filter(id => share.parameters[id] === true)
|
||||
: [];
|
||||
|
||||
const shouldRedirect = isWebsiteShare &&
|
||||
const shouldRedirect =
|
||||
isWebsiteShare &&
|
||||
allowedSections.length === 1 &&
|
||||
allowedSections[0] !== 'overview' &&
|
||||
(path === undefined || path === '' || path === 'overview');
|
||||
|
||||
@@ -83,6 +83,10 @@ export function SharePage() {
|
||||
}
|
||||
}, [setTheme]);
|
||||
|
||||
// Check if the requested path is allowed
|
||||
const pageKey = path || '';
|
||||
const isAllowed = pageKey === '' || parameters[pageKey] === true;
|
||||
|
||||
const entityPage =
|
||||
shareType === ENTITY_TYPE.board && boardId ? (
|
||||
<BoardViewPage boardId={boardId} showActions={false} />
|
||||
@@ -92,6 +96,12 @@ export function SharePage() {
|
||||
<LinkPage linkId={linkId} showHeaderActions={false} />
|
||||
) : null;
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAllowed) {
|
||||
router.replace(`/share/${slug}`);
|
||||
}
|
||||
}, [isAllowed, slug, router]);
|
||||
|
||||
if (entityPage) {
|
||||
return (
|
||||
<Column>
|
||||
@@ -101,12 +111,7 @@ export function SharePage() {
|
||||
);
|
||||
}
|
||||
|
||||
// Check if the requested path is allowed
|
||||
const pageKey = path || '';
|
||||
const isAllowed = pageKey === '' || parameters[pageKey] === true;
|
||||
|
||||
if (!isAllowed) {
|
||||
router.replace(`/share/${slug}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user