Skip to content

Commit 7abe1c9

Browse files
committed
🛂(frontend) button request access only on parent
The children reflect the parent access. So we can request access only on the parent document.
1 parent 95838e3 commit 7abe1c9

File tree

6 files changed

+153
-18
lines changed

6 files changed

+153
-18
lines changed

src/frontend/apps/e2e/__tests__/app-impress/doc-member-create.spec.ts

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
randomName,
88
verifyDocName,
99
} from './common';
10+
import { createRootSubPage } from './sub-pages-utils';
1011

1112
test.describe('Document create member', () => {
1213
test.beforeEach(async ({ page }) => {
@@ -272,7 +273,9 @@ test.describe('Document create member: Multiple login', () => {
272273

273274
await expect(
274275
page.getByRole('link', { name: 'Docs Logo Docs' }),
275-
).toBeVisible();
276+
).toBeVisible({
277+
timeout: 10000,
278+
});
276279

277280
await page.goto(urlDoc);
278281

@@ -294,4 +297,61 @@ test.describe('Document create member: Multiple login', () => {
294297
await expect(page.getByText('Share with 2 users')).toBeVisible();
295298
await expect(page.getByText(`E2E ${otherBrowser}`)).toBeVisible();
296299
});
300+
301+
test('It cannot request member access on child doc on a 403 page', async ({
302+
page,
303+
browserName,
304+
}) => {
305+
test.slow();
306+
307+
await page.goto('/');
308+
await keyCloakSignIn(page, browserName);
309+
310+
const [docParent] = await createDoc(
311+
page,
312+
'Block Member access request on child doc - parent',
313+
browserName,
314+
1,
315+
);
316+
317+
await verifyDocName(page, docParent);
318+
319+
await createRootSubPage(
320+
page,
321+
browserName,
322+
'Block Member access request on child doc - child',
323+
);
324+
325+
const urlDoc = page.url();
326+
327+
await page
328+
.getByRole('button', {
329+
name: 'Logout',
330+
})
331+
.click();
332+
333+
const otherBrowser = BROWSERS.find((b) => b !== browserName);
334+
335+
await keyCloakSignIn(page, otherBrowser!);
336+
337+
await expect(
338+
page.getByRole('link', { name: 'Docs Logo Docs' }),
339+
).toBeVisible({
340+
timeout: 10000,
341+
});
342+
343+
await page.goto(urlDoc);
344+
345+
await expect(
346+
page.getByText(
347+
"You're currently viewing a sub-document. To gain access, please request permission from the main document.",
348+
),
349+
).toBeVisible({
350+
timeout: 10000,
351+
});
352+
353+
await expect(
354+
page.getByRole('button', { name: 'Request access' }),
355+
).toBeHidden();
356+
});
297357
});

src/frontend/apps/e2e/__tests__/app-impress/doc-visibility.spec.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
keyCloakSignIn,
88
verifyDocName,
99
} from './common';
10+
import { createRootSubPage } from './sub-pages-utils';
1011

1112
test.describe('Doc Visibility', () => {
1213
test.beforeEach(async ({ page }) => {
@@ -271,7 +272,7 @@ test.describe('Doc Visibility: Public', () => {
271272
await page.getByRole('button', { name: 'Share' }).click();
272273
await expect(
273274
page.getByText(
274-
'You do not have permission to view users sharing this document or modify link settings.',
275+
'You can view this document but need additional access to see its members or modify settings.',
275276
),
276277
).toBeVisible();
277278

@@ -398,6 +399,8 @@ test.describe('Doc Visibility: Authenticated', () => {
398399
page,
399400
browserName,
400401
}) => {
402+
test.slow();
403+
401404
await page.goto('/');
402405
await keyCloakSignIn(page, browserName);
403406

@@ -435,6 +438,14 @@ test.describe('Doc Visibility: Authenticated', () => {
435438

436439
const urlDoc = page.url();
437440

441+
const { name: childTitle } = await createRootSubPage(
442+
page,
443+
browserName,
444+
'Authenticated read onlyc - child',
445+
);
446+
447+
const urlChildDoc = page.url();
448+
438449
await page
439450
.getByRole('button', {
440451
name: 'Logout',
@@ -446,7 +457,9 @@ test.describe('Doc Visibility: Authenticated', () => {
446457

447458
await expect(
448459
page.getByRole('link', { name: 'Docs Logo Docs' }),
449-
).toBeVisible();
460+
).toBeVisible({
461+
timeout: 10000,
462+
});
450463

451464
await page.goto(urlDoc);
452465

@@ -457,7 +470,7 @@ test.describe('Doc Visibility: Authenticated', () => {
457470

458471
await expect(
459472
page.getByText(
460-
'You do not have permission to view users sharing this document or modify link settings.',
473+
'You can view this document but need additional access to see its members or modify settings.',
461474
),
462475
).toBeVisible();
463476

@@ -466,6 +479,22 @@ test.describe('Doc Visibility: Authenticated', () => {
466479
await expect(
467480
page.getByRole('button', { name: 'Request access' }),
468481
).toBeDisabled();
482+
483+
await page.goto(urlChildDoc);
484+
485+
await expect(page.locator('h2').getByText(childTitle)).toBeVisible();
486+
487+
await page.getByRole('button', { name: 'Share' }).click();
488+
489+
await expect(
490+
page.getByText(
491+
'As this is a sub-document, please request access to the parent document to enable these features.',
492+
),
493+
).toBeVisible();
494+
495+
await expect(
496+
page.getByRole('button', { name: 'Request access' }),
497+
).toBeHidden();
469498
});
470499

471500
test('It checks a authenticated doc in editable mode', async ({

src/frontend/apps/impress/src/components/Loading.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Loader } from '@openfun/cunningham-react';
22
import { useTranslation } from 'react-i18next';
33

4-
import { Box } from './Box';
4+
import { Box, BoxProps } from './Box';
55
import { Icon } from './Icon';
66
import { Text } from './Text';
77

@@ -36,8 +36,8 @@ export const LoadMoreText = ({
3636
);
3737
};
3838

39-
export const Loading = () => (
40-
<Box $align="center" $justify="center" $height="100%">
39+
export const Loading = (props: BoxProps) => (
40+
<Box $align="center" $justify="center" $height="100%" {...props}>
4141
<Loader />
4242
</Box>
4343
);

src/frontend/apps/impress/src/features/docs/doc-share/components/DocShareAccessRequest.tsx

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ import { useMemo, useState } from 'react';
88
import { useTranslation } from 'react-i18next';
99
import { createGlobalStyle } from 'styled-components';
1010

11-
import { Box, BoxButton, Icon, LoadMoreText } from '@/components';
11+
import {
12+
Box,
13+
BoxButton,
14+
Icon,
15+
LoadMoreText,
16+
Loading,
17+
Text,
18+
} from '@/components';
1219
import { QuickSearchData, QuickSearchGroup } from '@/components/quick-search';
1320
import { useCunninghamTheme } from '@/cunningham';
1421
import { AccessRequest, Doc } from '@/docs/doc-management/';
@@ -161,7 +168,11 @@ export const ButtonAccessRequest = ({
161168
...buttonProps
162169
}: ButtonAccessRequestProps) => {
163170
const { authenticated } = useAuth();
164-
const { data: requests } = useDocAccessRequests({
171+
const {
172+
data: requests,
173+
error: docAccessError,
174+
isLoading,
175+
} = useDocAccessRequests({
165176
docId,
166177
page: 1,
167178
});
@@ -175,14 +186,28 @@ export const ButtonAccessRequest = ({
175186
},
176187
});
177188

178-
const hasRequested = !!(
179-
requests && requests?.results.find((request) => request.document === docId)
180-
);
181-
182189
if (!authenticated) {
183190
return null;
184191
}
185192

193+
if (docAccessError?.status === 404) {
194+
return (
195+
<Text $maxWidth="320px" $textAlign="center" $variation="600" $size="sm">
196+
{t(
197+
'As this is a sub-document, please request access to the parent document to enable these features.',
198+
)}
199+
</Text>
200+
);
201+
}
202+
203+
if (isLoading) {
204+
return <Loading $height="auto" />;
205+
}
206+
207+
const hasRequested = !!(
208+
requests && requests?.results.find((request) => request.document === docId)
209+
);
210+
186211
return (
187212
<Button
188213
onClick={() => createRequest({ docId })}

src/frontend/apps/impress/src/features/docs/doc-share/components/DocShareModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export const DocShareModal = ({ doc, onClose, isRootDoc = true }: Props) => {
179179
$size="sm"
180180
>
181181
{t(
182-
'You do not have permission to view users sharing this document or modify link settings.',
182+
'You can view this document but need additional access to see its members or modify settings.',
183183
)}
184184
</Text>
185185
<ButtonAccessRequest

src/frontend/apps/impress/src/pages/docs/[id]/403.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ interface DocProps {
4646

4747
const DocPage403 = ({ id }: DocProps) => {
4848
const { t } = useTranslation();
49-
const { data: requests, isLoading: isLoadingRequest } = useDocAccessRequests({
49+
const {
50+
data: requests,
51+
isLoading: isLoadingRequest,
52+
error: docAccessError,
53+
} = useDocAccessRequests({
5054
docId: id,
5155
page: 1,
5256
});
@@ -56,7 +60,7 @@ const DocPage403 = ({ id }: DocProps) => {
5660
(request) => request.document === id,
5761
);
5862

59-
const { error, isLoading: isLoadingDoc } = useDoc(
63+
const { error: docError, isLoading: isLoadingDoc } = useDoc(
6064
{ id },
6165
{
6266
staleTime: 0,
@@ -71,7 +75,7 @@ const DocPage403 = ({ id }: DocProps) => {
7175
},
7276
);
7377

74-
if (!isLoadingDoc && error?.status !== 403) {
78+
if (!isLoadingDoc && docError?.status !== 403) {
7579
void replace(`/docs/${id}`);
7680
return <Loading />;
7781
}
@@ -115,6 +119,21 @@ const DocPage403 = ({ id }: DocProps) => {
115119
: t('Insufficient access rights to view the document.')}
116120
</Text>
117121

122+
{docAccessError?.status === 404 && (
123+
<Text
124+
as="p"
125+
$maxWidth="320px"
126+
$textAlign="center"
127+
$variation="600"
128+
$size="sm"
129+
$margin={{ top: '0' }}
130+
>
131+
{t(
132+
"You're currently viewing a sub-document. To gain access, please request permission from the main document.",
133+
)}
134+
</Text>
135+
)}
136+
118137
<Box $direction="row" $gap="0.7rem">
119138
<StyledLink href="/">
120139
<StyledButton
@@ -124,7 +143,9 @@ const DocPage403 = ({ id }: DocProps) => {
124143
{t('Home')}
125144
</StyledButton>
126145
</StyledLink>
127-
<ButtonAccessRequest docId={id} />
146+
{docAccessError?.status !== 404 && (
147+
<ButtonAccessRequest docId={id} />
148+
)}
128149
</Box>
129150
</Box>
130151
</Box>

0 commit comments

Comments
 (0)