Skip to content

Commit b9a745c

Browse files
authored
feat: add setting to allow reader to edit etherpad (#946)
1 parent 872d23a commit b9a745c

File tree

18 files changed

+393
-74
lines changed

18 files changed

+393
-74
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,110 @@
1-
import { PackedEtherpadItemFactory } from '@graasp/sdk';
1+
import {
2+
EtherpadPermission,
3+
PackedEtherpadItemFactory,
4+
PackedFolderItemFactory,
5+
} from '@graasp/sdk';
26

3-
import { buildItemsGridMoreButtonSelector } from '../../../../../src/config/selectors';
4-
import { EDIT_ITEM_PAUSE } from '../../../../support/constants';
5-
import { editItem } from '../../../../support/editUtils';
6-
import { HOME_PATH } from '../../utils';
7+
import {
8+
EDIT_ITEM_BUTTON_CLASS,
9+
ETHERPAD_ALLOW_READER_TO_WRITE_SETTING_ID,
10+
ITEM_FORM_CONFIRM_BUTTON_ID,
11+
ITEM_FORM_NAME_INPUT_ID,
12+
buildItemsGridMoreButtonSelector,
13+
} from '../../../../../src/config/selectors';
14+
import { HOME_PATH, buildItemPath } from '../../utils';
715

8-
const EDITED_FIELDS = {
9-
name: 'new name',
10-
};
16+
const editEtherpad = (
17+
{
18+
name,
19+
toggleAllowReadersToWrite,
20+
}: {
21+
name?: string;
22+
toggleAllowReadersToWrite?: boolean;
23+
},
24+
{ confirm = true }: { confirm?: boolean } = {},
25+
) => {
26+
cy.get(`.${EDIT_ITEM_BUTTON_CLASS}`).click();
1127

12-
const GRAASP_ETHERPAD_ITEM = PackedEtherpadItemFactory();
28+
if (name) {
29+
cy.get(`#${ITEM_FORM_NAME_INPUT_ID}`).type(`{selectall}{backspace}${name}`);
30+
}
1331

14-
describe('Edit Etherpad', () => {
15-
beforeEach(() => {
16-
cy.setUpApi({ items: [GRAASP_ETHERPAD_ITEM] });
17-
});
32+
if (toggleAllowReadersToWrite) {
33+
cy.get(`#${ETHERPAD_ALLOW_READER_TO_WRITE_SETTING_ID}`).click();
34+
}
35+
36+
if (confirm) {
37+
cy.get(`#${ITEM_FORM_CONFIRM_BUTTON_ID}`).click();
38+
}
39+
};
1840

41+
describe('Edit Etherpad', () => {
1942
it('edit etherpad on Home', () => {
43+
const itemToEdit = PackedEtherpadItemFactory({
44+
extra: {
45+
etherpad: {
46+
padID: 'padId',
47+
groupID: 'groupId',
48+
readerPermission: EtherpadPermission.Read,
49+
},
50+
},
51+
});
52+
cy.setUpApi({ items: [itemToEdit] });
2053
cy.visit(HOME_PATH);
2154

22-
const itemToEdit = GRAASP_ETHERPAD_ITEM;
55+
cy.intercept(`/items/etherpad/${itemToEdit.id}`, (request) => {
56+
request.reply(itemToEdit);
57+
}).as('editEtherpad');
2358

2459
// edit
2560
cy.get(buildItemsGridMoreButtonSelector(itemToEdit.id)).click();
26-
editItem({
27-
...itemToEdit,
28-
...EDITED_FIELDS,
61+
editEtherpad({
62+
name: 'newName',
63+
toggleAllowReadersToWrite: true,
2964
});
3065

31-
cy.wait('@editItem').then(
66+
cy.wait('@editEtherpad').then(
3267
({
33-
response: {
34-
body: { id, name },
68+
request: {
69+
body: { name, readerPermission },
3570
},
3671
}) => {
37-
// check item is edited and updated
38-
cy.wait(EDIT_ITEM_PAUSE);
72+
// check item is edited
3973
cy.get('@getAccessibleItems');
40-
expect(id).to.equal(itemToEdit.id);
41-
expect(name).to.equal(EDITED_FIELDS.name);
74+
expect(name).to.equal('newName');
75+
expect(readerPermission).to.eq('write');
4276
},
4377
);
4478
});
79+
80+
it('edit reader permission of etherpad', () => {
81+
const parentItem = PackedFolderItemFactory();
82+
const itemToEdit = PackedEtherpadItemFactory({
83+
parentItem,
84+
extra: {
85+
etherpad: {
86+
padID: 'padId',
87+
groupID: 'groupId',
88+
readerPermission: EtherpadPermission.Read,
89+
},
90+
},
91+
});
92+
cy.setUpApi({ items: [parentItem, itemToEdit] });
93+
cy.intercept(`/items/etherpad/${itemToEdit.id}`, (request) => {
94+
request.reply(itemToEdit);
95+
}).as('editEtherpad');
96+
97+
// go in child item
98+
cy.visit(buildItemPath(itemToEdit.id));
99+
100+
// edit reader permission
101+
// cy.get(buildItemsGridMoreButtonSelector(itemToEdit.id)).click();
102+
editEtherpad({ toggleAllowReadersToWrite: true });
103+
104+
cy.wait('@editEtherpad').then(({ request: { body } }) => {
105+
// check item is edited
106+
cy.get('@getAccessibleItems');
107+
expect(body.readerPermission).to.equal('write');
108+
});
109+
});
45110
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { EtherpadPermission, PackedEtherpadItemFactory } from '@graasp/sdk';
2+
3+
import { buildItemPath } from '../../utils';
4+
5+
describe('Etherpad', () => {
6+
it('view etherpad with readerPermission=read', () => {
7+
const itemToEdit = PackedEtherpadItemFactory({
8+
extra: {
9+
etherpad: {
10+
padID: 'padId',
11+
groupID: 'groupId',
12+
readerPermission: EtherpadPermission.Read,
13+
},
14+
},
15+
});
16+
cy.setUpApi({ items: [itemToEdit] });
17+
18+
cy.intercept(`/items/etherpad/view/${itemToEdit.id}?mode=write`).as(
19+
'viewEtherpad',
20+
);
21+
22+
const { id } = itemToEdit;
23+
cy.visit(buildItemPath(id));
24+
25+
cy.wait('@viewEtherpad');
26+
});
27+
28+
it('view etherpad with readerPermission=write', () => {
29+
const itemToEdit = PackedEtherpadItemFactory({
30+
extra: {
31+
etherpad: {
32+
padID: 'padId',
33+
groupID: 'groupId',
34+
readerPermission: EtherpadPermission.Write,
35+
},
36+
},
37+
});
38+
cy.setUpApi({ items: [itemToEdit] });
39+
40+
cy.intercept(`/items/etherpad/view/${itemToEdit.id}?mode=write`).as(
41+
'viewEtherpad',
42+
);
43+
44+
const { id } = itemToEdit;
45+
cy.visit(buildItemPath(id));
46+
47+
cy.wait('@viewEtherpad');
48+
});
49+
});

cypress/e2e/player/etherpad.cy.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { PackedEtherpadItemFactory } from '@graasp/sdk';
2+
3+
import { buildContentPagePath } from './utils';
4+
5+
describe('Etherpad', () => {
6+
it('view etherpad', () => {
7+
const itemToEdit = PackedEtherpadItemFactory({
8+
extra: {
9+
etherpad: {
10+
padID: 'padId',
11+
groupID: 'groupId',
12+
},
13+
},
14+
});
15+
cy.setUpApi({ items: [itemToEdit] });
16+
17+
cy.intercept(`/items/etherpad/view/${itemToEdit.id}?mode=write`).as(
18+
'viewEtherpad',
19+
);
20+
21+
const { id } = itemToEdit;
22+
cy.visit(buildContentPagePath({ rootId: id, itemId: id }));
23+
24+
cy.wait('@viewEtherpad');
25+
});
26+
});

cypress/support/viewUtils.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ import {
1717
buildSettingsButtonId,
1818
buildShareButtonId,
1919
} from '../../src/config/selectors';
20-
import { ITEM_TYPES_WITH_CAPTIONS } from '../../src/modules/builder/constants';
2120
import { getHighestPermissionForMemberFromMemberships } from '../../src/modules/builder/utils/item';
2221
import { CURRENT_MEMBER } from '../fixtures/members';
2322
import { ItemForTest, MemberForTest } from './types';
2423

2524
const BR_REGEX = /<br(?:\s*\/?)>/g;
2625

2726
export const expectItemHeaderLayout = ({
28-
item: { id, type, memberships, path },
27+
item: { id, memberships, path },
2928
currentMember,
3029
}: {
3130
item: ItemForTest;
@@ -45,9 +44,7 @@ export const expectItemHeaderLayout = ({
4544
: false;
4645

4746
if (canEditSettings) {
48-
if (ITEM_TYPES_WITH_CAPTIONS.includes(type)) {
49-
header.get(`#${buildEditButtonId(id)}`).should('exist');
50-
}
47+
header.get(`#${buildEditButtonId(id)}`).should('exist');
5148
header.get(`#${buildSettingsButtonId(id)}`).should('exist');
5249
}
5350
};

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
"@emotion/react": "11.14.0",
2020
"@emotion/styled": "11.14.0",
2121
"@fontsource-variable/nunito": "5.1.1",
22-
"@graasp/sdk": "5.9.1",
22+
"@graasp/sdk": "5.10.1",
2323
"@graasp/stylis-plugin-rtl": "2.2.0",
24-
"@mui/icons-material": "6.4.4",
2524
"@hey-api/client-fetch": "0.7.2",
25+
"@mui/icons-material": "6.4.4",
2626
"@mui/lab": "6.0.0-beta.27",
2727
"@mui/material": "6.4.4",
2828
"@sentry/react": "9.1.0",
@@ -130,8 +130,8 @@
130130
"@eslint/compat": "1.2.6",
131131
"@eslint/eslintrc": "3.2.0",
132132
"@eslint/js": "9.20.0",
133-
"@storybook/addon-a11y": "8.5.6",
134133
"@hey-api/openapi-ts": "0.63.0",
134+
"@storybook/addon-a11y": "8.5.6",
135135
"@storybook/addon-coverage": "1.0.5",
136136
"@storybook/addon-essentials": "8.5.6",
137137
"@storybook/addon-links": "8.5.6",

pnpm-lock.yaml

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config/selectors.ts

+2
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ export const CREATE_ITEM_ZIP_ID = 'createItemZip';
294294
export const CREATE_ITEM_H5P_ID = 'createItemH5P';
295295
export const CREATE_ITEM_ETHERPAD_ID = 'createItemEtherpad';
296296
export const ITEM_FORM_ETHERPAD_NAME_INPUT_ID = 'itemFormEtherpadNameInputId';
297+
export const ETHERPAD_ALLOW_READER_TO_WRITE_SETTING_ID =
298+
'etherpadAllowReaderToWriteSetting';
297299
export const ITEM_FORM_APP_URL_ID = 'itemFormAppUrl';
298300
export const buildItemFormAppOptionId = (id?: string): string =>
299301
`app-option-${id}`;

src/locales/en/builder.json

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"CREATE_NEW_ITEM_ETHERPAD_INFORMATIONS": "Etherpad is a collaborative real-time text editor",
4343
"CREATE_NEW_ITEM_ETHERPAD_LABEL": "Name",
4444
"CREATE_NEW_ITEM_ETHERPAD_TITLE": "Add an Etherpad",
45+
"ETHERPAG_ALLOW_READER_TO_WRITE_SETTING": "Allow readers to edit etherpad",
4546
"CREATE_NEW_ITEM_NAME_LABEL": "Name",
4647
"CREATE_SHORTCUT_BUTTON": "Create shortcut",
4748
"CREATE_SHORTCUT_BUTTON_zero": "Create shortcut",

src/modules/builder/components/item/edit/EditModal.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { EDIT_MODAL_ID } from '@/config/selectors';
1212
import { BUILDER } from '../../../langs';
1313
import BaseItemForm from '../form/BaseItemForm';
1414
import { DocumentEditForm } from '../form/document/DocumentEditForm';
15+
import { EtherpadEditForm } from '../form/etherpad/EtherpadEditForm';
1516
import { FileForm } from '../form/file/FileForm';
1617
import { FolderEditForm } from '../form/folder/FolderEditForm';
1718
import { LinkEditForm } from '../form/link/LinkEditForm';
@@ -56,14 +57,13 @@ export function EditModal({
5657
if (item.type === ItemType.DOCUMENT) {
5758
return <DocumentEditForm onClose={onClose} item={item} />;
5859
}
60+
if (item.type === ItemType.ETHERPAD) {
61+
return <EtherpadEditForm onClose={onClose} item={item} />;
62+
}
5963
if (item.type === ItemType.LINK) {
6064
return <LinkEditForm onClose={onClose} item={item} />;
6165
}
62-
if (
63-
item.type === ItemType.ETHERPAD ||
64-
item.type === ItemType.APP ||
65-
item.type === ItemType.H5P
66-
) {
66+
if (item.type === ItemType.APP || item.type === ItemType.H5P) {
6767
return <BaseItemForm onClose={onClose} item={item} />;
6868
}
6969

0 commit comments

Comments
 (0)