From 3e8414b4e0227a2cc8ea219ac549ea15e388fa85 Mon Sep 17 00:00:00 2001 From: Sangeeth Sivan <74818788+berzerkeer@users.noreply.github.com> Date: Fri, 2 Dec 2022 02:56:21 +0530 Subject: [PATCH] fix: page list item icons aren't permission driven on first load (#18586) * fix: page list ctas permission driven fix * fix: page list and page context menu , datasource action pane create permission driven * fix: check manage permission on page aswell for cloning * fix: duplicate & fork app permission driven * fix: onclick triggers on disabled icons --- .../pages/Applications/ApplicationCard.tsx | 8 ++++++- app/client/src/pages/Applications/index.tsx | 3 +++ .../Editor/Explorer/Pages/PageContextMenu.tsx | 20 ++++++++++++---- .../src/pages/Editor/Explorer/Pages/index.tsx | 8 ++----- .../pages/Editor/PagesEditor/ContextMenu.tsx | 23 +++++++++++++++---- .../pages/Editor/PagesEditor/PageListItem.tsx | 19 +++++++++++---- .../Editor/QueryEditor/EditorJSONtoForm.tsx | 20 ++++++++++++---- 7 files changed, 76 insertions(+), 25 deletions(-) diff --git a/app/client/src/pages/Applications/ApplicationCard.tsx b/app/client/src/pages/Applications/ApplicationCard.tsx index df92080e6e..08673a87fc 100644 --- a/app/client/src/pages/Applications/ApplicationCard.tsx +++ b/app/client/src/pages/Applications/ApplicationCard.tsx @@ -310,6 +310,7 @@ type ApplicationCardProps = { update?: (id: string, data: UpdateApplicationPayload) => void; enableImportExport?: boolean; isMobile?: boolean; + hasCreateNewApplicationPermission?: boolean; }; const EditButton = styled(Button)` @@ -469,7 +470,11 @@ export function ApplicationCard(props: ApplicationCardProps) { cypressSelector: "t--share", }); } - if (props.duplicate && hasEditPermission) { + if ( + props.duplicate && + props.hasCreateNewApplicationPermission && + hasEditPermission + ) { moreActionItems.push({ onSelect: duplicateApp, text: "Duplicate", @@ -516,6 +521,7 @@ export function ApplicationCard(props: ApplicationCardProps) { const hasDeletePermission = hasDeleteApplicationPermission( props.application?.userPermissions, ); + const updateColor = (color: string) => { setSelectedColor(color); props.update && diff --git a/app/client/src/pages/Applications/index.tsx b/app/client/src/pages/Applications/index.tsx index 6c027bf827..1b5964e11f 100644 --- a/app/client/src/pages/Applications/index.tsx +++ b/app/client/src/pages/Applications/index.tsx @@ -922,6 +922,9 @@ function ApplicationsSection(props: any) { delete={deleteApplication} duplicate={duplicateApplicationDispatch} enableImportExport={enableImportExport} + hasCreateNewApplicationPermission={ + hasCreateNewApplicationPermission + } isMobile={isMobile} key={application.id} update={updateApplicationDispatch} diff --git a/app/client/src/pages/Editor/Explorer/Pages/PageContextMenu.tsx b/app/client/src/pages/Editor/Explorer/Pages/PageContextMenu.tsx index 6dd61cbe09..8a7ed03d2e 100644 --- a/app/client/src/pages/Editor/Explorer/Pages/PageContextMenu.tsx +++ b/app/client/src/pages/Editor/Explorer/Pages/PageContextMenu.tsx @@ -25,10 +25,13 @@ import { createMessage, } from "@appsmith/constants/messages"; import { + hasCreatePagePermission, hasDeletePagePermission, hasManagePagePermission, } from "@appsmith/utils/permissionHelpers"; import { getPageById } from "selectors/editorSelectors"; +import { getCurrentApplication } from "selectors/applicationSelectors"; +import { AppState } from "@appsmith/reducers"; const CustomLabel = styled.div` display: flex; @@ -101,6 +104,12 @@ export function PageContextMenu(props: { const pagePermissions = useSelector(getPageById(props.pageId))?.userPermissions || []; + const userAppPermissions = useSelector( + (state: AppState) => getCurrentApplication(state)?.userPermissions ?? [], + ); + + const canCreatePages = hasCreatePagePermission(userAppPermissions); + const canManagePages = hasManagePagePermission(pagePermissions); const canDeletePages = hasDeletePagePermission(pagePermissions); @@ -111,11 +120,12 @@ export function PageContextMenu(props: { onSelect: editPageName, label: createMessage(CONTEXT_EDIT_NAME), }, - canManagePages && { - value: "clone", - onSelect: clonePage, - label: createMessage(CONTEXT_CLONE), - }, + canCreatePages && + canManagePages && { + value: "clone", + onSelect: clonePage, + label: createMessage(CONTEXT_CLONE), + }, canManagePages && { value: "visibility", onSelect: setHiddenField, diff --git a/app/client/src/pages/Editor/Explorer/Pages/index.tsx b/app/client/src/pages/Editor/Explorer/Pages/index.tsx index 366485c6d9..a1c2ad95e1 100644 --- a/app/client/src/pages/Editor/Explorer/Pages/index.tsx +++ b/app/client/src/pages/Editor/Explorer/Pages/index.tsx @@ -10,7 +10,6 @@ import { getCurrentApplication, getCurrentApplicationId, getCurrentPageId, - getPagePermissions, } from "selectors/editorSelectors"; import Entity, { EntityClassNames } from "../Entity"; import history from "utils/history"; @@ -192,18 +191,16 @@ function Pages() { (state: AppState) => getCurrentApplication(state)?.userPermissions ?? [], ); - const pagePermissions = useSelector(getPagePermissions); - const canCreatePages = hasCreatePagePermission(userAppPermissions); - const canManagePages = hasManagePagePermission(pagePermissions); - const pageElements = useMemo( () => pages.map((page) => { const icon = page.isDefault ? defaultPageIcon : pageIcon; const rightIcon = !!page.isHidden ? hiddenPageIcon : null; const isCurrentPage = currentPageId === page.pageId; + const pagePermissions = page.userPermissions; + const canManagePages = hasManagePagePermission(pagePermissions); const contextMenu = ( { - setIsOpen(isOpen); + (canManagePages || canDeletePages) && setIsOpen(isOpen); }, []); - const pagePermissions = useSelector(getPagePermissions); + const pagePermissions = + useSelector(getPageById(page.pageId))?.userPermissions || []; + + const userAppPermissions = useSelector( + (state: AppState) => getCurrentApplication(state)?.userPermissions ?? [], + ); + + const canCreatePages = hasCreatePagePermission(userAppPermissions); const canManagePages = hasManagePagePermission(pagePermissions); const canDeletePages = hasDeletePagePermission(pagePermissions); + const canClonePages = canCreatePages && canManagePages; + return ( onCopy(page.pageId)} + onClick={!canClonePages ? noop : () => onCopy(page.pageId)} width={16} /> @@ -239,6 +251,7 @@ function ContextMenu(props: Props) { getCurrentApplication(state)?.userPermissions ?? [], + ); + + const canCreatePages = hasCreatePagePermission(userAppPermissions); const canManagePages = hasManagePagePermission(pagePermissions); const canDeletePages = hasDeletePagePermission(pagePermissions); + const canClonePages = canCreatePages && canManagePages; + return ( @@ -212,9 +223,9 @@ function PageListItem(props: PageListItemProps) { diff --git a/app/client/src/pages/Editor/QueryEditor/EditorJSONtoForm.tsx b/app/client/src/pages/Editor/QueryEditor/EditorJSONtoForm.tsx index 544fcd9238..e36b37ea70 100644 --- a/app/client/src/pages/Editor/QueryEditor/EditorJSONtoForm.tsx +++ b/app/client/src/pages/Editor/QueryEditor/EditorJSONtoForm.tsx @@ -109,6 +109,7 @@ import { import LoadingOverlayScreen from "components/editorComponents/LoadingOverlayScreen"; import { EditorTheme } from "components/editorComponents/CodeEditor/EditorConfig"; import { + hasCreateDatasourcePermission, hasDeleteActionPermission, hasExecuteActionPermission, hasManageActionPermission, @@ -125,6 +126,7 @@ import { setQueryPaneResponseSelectedTab, } from "actions/queryPaneActions"; import { ActionExecutionResizerHeight } from "pages/Editor/APIEditor/constants"; +import { getCurrentAppWorkspace } from "@appsmith/selectors/workspaceSelectors"; const QueryFormContainer = styled.form` flex: 1; @@ -522,6 +524,14 @@ export function EditorJSONtoForm(props: Props) { currentActionConfig?.userPermissions, ); + const userWorkspacePermissions = useSelector( + (state: AppState) => getCurrentAppWorkspace(state).userPermissions ?? [], + ); + + const canCreateDatasource = hasCreateDatasourcePermission( + userWorkspacePermissions, + ); + // Query is executed even once during the session, show the response data. if (executedQueryData) { if (!executedQueryData.isExecutionSuccess) { @@ -555,10 +565,12 @@ export function EditorJSONtoForm(props: Props) { return ( <> {props.children} - onCreateDatasourceClick()}> - - {createMessage(CREATE_NEW_DATASOURCE)} - + {canCreateDatasource ? ( + onCreateDatasourceClick()}> + + {createMessage(CREATE_NEW_DATASOURCE)} + + ) : null} ); }