From cbb0fd41e2c77b336b822ffddf8a9017af6eb485 Mon Sep 17 00:00:00 2001 From: Miguel Serrano Date: Wed, 30 Jun 2021 13:03:29 +0200 Subject: [PATCH] Merge pull request #4273 from overleaf/msm-update-publish-modal-permissions User 'write' permission to display the publish button GitOrigin-RevId: f73ccf05b165ef1ef9e57e3aea4c04d177aba6d4 --- .../editor-navigation-toolbar-root.js | 19 ++++--------------- .../components/toolbar-header.js | 6 +++--- .../components/toolbar-header.test.js | 5 +++-- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/services/web/frontend/js/features/editor-navigation-toolbar/components/editor-navigation-toolbar-root.js b/services/web/frontend/js/features/editor-navigation-toolbar/components/editor-navigation-toolbar-root.js index fb33ddbf29..8afb9e5e0a 100644 --- a/services/web/frontend/js/features/editor-navigation-toolbar/components/editor-navigation-toolbar-root.js +++ b/services/web/frontend/js/features/editor-navigation-toolbar/components/editor-navigation-toolbar-root.js @@ -4,13 +4,8 @@ import ToolbarHeader from './toolbar-header' import { useEditorContext } from '../../../shared/context/editor-context' import { useChatContext } from '../../chat/context/chat-context' import { useLayoutContext } from '../../../shared/context/layout-context' -import { useUserContext } from '../../../shared/context/user-context' import { useProjectContext } from '../../../shared/context/project-context' -const userContextPropTypes = { - id: PropTypes.string, -} - const projectContextPropTypes = { name: PropTypes.string.isRequired, } @@ -46,8 +41,6 @@ const EditorNavigationToolbarRoot = React.memo( openDoc, openShareProjectModal, }) { - const user = useUserContext(userContextPropTypes) - const { name: projectName } = useProjectContext(projectContextPropTypes) const { @@ -112,12 +105,6 @@ const EditorNavigationToolbarRoot = React.memo( [openDoc] ) - // the existing angular implementation prevents collaborators from updating a - // project's name, but the backend allows that with the following logic: - // `const hasRenamePermissions = permissionsLevel === 'owner' || permissionsLevel === 'readAndWrite'` - // See https://github.com/overleaf/issues/issues/4492 - const hasRenamePermissions = permissionsLevel === 'owner' - // using {display: 'none'} as 1:1 migration from Angular's ng-hide. Using // `loading ? null : ` causes UI glitches return ( @@ -135,10 +122,12 @@ const EditorNavigationToolbarRoot = React.memo( onlineUsers={onlineUsersArray} goToUser={goToUser} isRestrictedTokenMember={isRestrictedTokenMember} - isAnonymousUser={user == null} + hasPublishPermissions={ + permissionsLevel === 'owner' || permissionsLevel === 'readAndWrite' + } projectName={projectName} renameProject={renameProject} - hasRenamePermissions={hasRenamePermissions} + hasRenamePermissions={permissionsLevel === 'owner'} openShareModal={openShareModal} pdfViewIsOpen={view === 'pdf'} pdfButtonIsVisible={pdfLayout === 'flat'} diff --git a/services/web/frontend/js/features/editor-navigation-toolbar/components/toolbar-header.js b/services/web/frontend/js/features/editor-navigation-toolbar/components/toolbar-header.js index fc6f45c453..5d4074b528 100644 --- a/services/web/frontend/js/features/editor-navigation-toolbar/components/toolbar-header.js +++ b/services/web/frontend/js/features/editor-navigation-toolbar/components/toolbar-header.js @@ -28,7 +28,7 @@ const ToolbarHeader = React.memo(function ToolbarHeader({ onlineUsers, goToUser, isRestrictedTokenMember, - isAnonymousUser, + hasPublishPermissions, projectName, renameProject, hasRenamePermissions, @@ -37,7 +37,7 @@ const ToolbarHeader = React.memo(function ToolbarHeader({ pdfButtonIsVisible, togglePdfView, }) { - const shouldDisplayPublishButton = !isAnonymousUser && PublishButton + const shouldDisplayPublishButton = hasPublishPermissions && PublishButton return (
@@ -106,7 +106,7 @@ ToolbarHeader.propTypes = { onlineUsers: PropTypes.array.isRequired, goToUser: PropTypes.func.isRequired, isRestrictedTokenMember: PropTypes.bool, - isAnonymousUser: PropTypes.bool, + hasPublishPermissions: PropTypes.bool, projectName: PropTypes.string.isRequired, renameProject: PropTypes.func.isRequired, hasRenamePermissions: PropTypes.bool, diff --git a/services/web/test/frontend/features/editor-navigation-toolbar/components/toolbar-header.test.js b/services/web/test/frontend/features/editor-navigation-toolbar/components/toolbar-header.test.js index 81ab925d42..413936d812 100644 --- a/services/web/test/frontend/features/editor-navigation-toolbar/components/toolbar-header.test.js +++ b/services/web/test/frontend/features/editor-navigation-toolbar/components/toolbar-header.test.js @@ -16,6 +16,7 @@ describe('', function () { renameProject: () => {}, openShareModal: () => {}, togglePdfView: () => {}, + hasPublishPermissions: true, } describe('cobranding logo', function () { @@ -109,10 +110,10 @@ describe('', function () { screen.getByText('Submit') }) - it('is not displayed for anonymous users', function () { + it('is not displayed for users with no publish permissions', function () { const props = { ...defaultProps, - isAnonymousUser: true, + hasPublishPermissions: false, } render() expect(screen.queryByText('Submit')).to.not.exist