Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hide publish tab for reader and public #721

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cypress/e2e/item/publish/coEditorSettings.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ describe('Co-editor setting permissions', () => {
cy.visit(buildItemPath(item.id));

cy.get(`#${ITEM_HEADER_ID}`).should('be.visible');
openPublishItemTab(item.id);
cy.get(`#${CO_EDITOR_SETTINGS_RADIO_GROUP_ID}`).should('not.exist');
cy.get(`#${buildPublishButtonId(item.id)}`).should('not.exist');
});
});
32 changes: 32 additions & 0 deletions cypress/e2e/item/publish/publishedItem.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
SAMPLE_ITEMS,
SAMPLE_PUBLIC_ITEMS,
} from '../../../fixtures/items';
import { MEMBERS } from '../../../fixtures/members';
import { PAGE_LOAD_WAITING_PAUSE } from '../../../support/constants';

const openPublishItemTab = (id) => {
cy.get(`#${buildPublishButtonId(id)}`).click();
Expand All @@ -21,6 +23,36 @@ export const publishItem = (): void => {
cy.get(`#${ITEM_PUBLISH_BUTTON_ID}`).click();
};

describe('Public', ()=> {
it('Should not view publish tab', () => {
const item = SAMPLE_PUBLIC_ITEMS.items[0];
cy.setUpApi({
items: [item],
currentMember:null
});
cy.visit(buildItemPath(item.id));

// wait for page to fully load
cy.wait(PAGE_LOAD_WAITING_PAUSE)
cy.get(`#${buildPublishButtonId(item.id)}`).should('not.exist');
});
})

describe('Read', ()=> {
it('Should not view publish tab', () => {
const item = SAMPLE_ITEMS.items[1];
cy.setUpApi({
items: [item],
currentMember: MEMBERS.BOB
});
cy.visit(buildItemPath(item.id));

// wait for page to fully load
cy.wait(PAGE_LOAD_WAITING_PAUSE)
cy.get(`#${buildPublishButtonId(item.id)}`).should('not.exist');
});
})

describe('Public Item', () => {
it('Validate item', () => {
cy.setUpApi(SAMPLE_PUBLIC_ITEMS);
Expand Down
3 changes: 1 addition & 2 deletions cypress/e2e/item/publish/tags.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ describe('Tags permissions', () => {
cy.visit(buildItemPath(item.id));

cy.get(`#${ITEM_HEADER_ID}`).should('be.visible');
openPublishItemTab(item.id);
cy.get(`#${ITEM_TAGS_EDIT_INPUT_ID}`).should('not.exist');
cy.get(`#${buildPublishButtonId(item.id)}`).should('not.exist');
});
});
1 change: 1 addition & 0 deletions cypress/support/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export const mockGetCurrentMember = (
url: `${API_HOST}/${GET_CURRENT_MEMBER_ROUTE}`,
},
({ reply }) => {

if (shouldThrowError) {
return reply({
statusCode: StatusCodes.INTERNAL_SERVER_ERROR,
Expand Down
4 changes: 2 additions & 2 deletions src/components/item/header/ItemHeaderActions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Stack } from '@mui/material';

import { ItemType } from '@graasp/sdk';
import { ItemType, PermissionLevel } from '@graasp/sdk';
import { ItemRecord } from '@graasp/sdk/frontend';
import { BUILDER } from '@graasp/translations';
import { ChatboxButton } from '@graasp/ui';
Expand Down Expand Up @@ -51,7 +51,7 @@ const ItemHeaderActions = ({ item }: Props): JSX.Element => {
? getHighestPermissionForMemberFromMemberships({
memberships,
memberId: member?.id,
})
})?.permission === PermissionLevel.Admin
: false;

const onClickChatbox = () => {
Expand Down