Skip to content

Commit d5dafb9

Browse files
authored
Keybindings respect permissions (#2472)
1 parent ae808f5 commit d5dafb9

File tree

711 files changed

+25190
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

711 files changed

+25190
-23
lines changed

assets/js/src/core/modules/app/base-layout/main-nav/main-nav.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { ROLES_WIDGET, USERS_WIDGET } from '@Pimcore/modules/user'
3636
import { CUSTOM_REPORTS_WIDGET, REPORTS_WIDGET } from '@Pimcore/modules/reports'
3737
import { REDIRECTS_WIDGET } from '@Pimcore/modules/redirects'
3838
import { TAG_CONFIGURATION_WIDGET } from '@Pimcore/modules/tags'
39+
import { UserPermission } from '@Pimcore/modules/auth/enums/user-permission'
3940

4041
export const MainNav = (): React.JSX.Element => {
4142
const { t } = useTranslation()
@@ -213,24 +214,24 @@ export const MainNav = (): React.JSX.Element => {
213214
})
214215
}
215216

216-
useHandleKeyBindings(() => { handleOpen('data-object') }, 'openObject', true)
217-
useHandleKeyBindings(() => { handleOpen('document') }, 'openDocument', true)
218-
useHandleKeyBindings(() => { handleOpen('asset') }, 'openAsset', true)
217+
useHandleKeyBindings(() => { handleOpen('data-object') }, 'openObject', true, UserPermission.Objects)
218+
useHandleKeyBindings(() => { handleOpen('document') }, 'openDocument', true, UserPermission.Documents)
219+
useHandleKeyBindings(() => { handleOpen('asset') }, 'openAsset', true, UserPermission.Assets)
219220

220-
useHandleKeyBindings(() => { openMainWidget(TRANSLATIONS_WIDGET) }, 'sharedTranslations', true)
221-
useHandleKeyBindings(() => { openMainWidget(RECYCLE_BIN_WIDGET) }, 'recycleBin', true)
222-
useHandleKeyBindings(() => { openMainWidget(NOTES_AND_EVENTS_WIDGET) }, 'notesEvents', true)
221+
useHandleKeyBindings(() => { openMainWidget(TRANSLATIONS_WIDGET) }, 'sharedTranslations', true, UserPermission.Translations)
222+
useHandleKeyBindings(() => { openMainWidget(RECYCLE_BIN_WIDGET) }, 'recycleBin', true, UserPermission.RecycleBin)
223+
useHandleKeyBindings(() => { openMainWidget(NOTES_AND_EVENTS_WIDGET) }, 'notesEvents', true, UserPermission.NotesAndEvents)
223224

224-
useHandleKeyBindings(() => { openMainWidget(USERS_WIDGET) }, 'users', true)
225-
useHandleKeyBindings(() => { openMainWidget(ROLES_WIDGET) }, 'roles', true)
225+
useHandleKeyBindings(() => { openMainWidget(USERS_WIDGET) }, 'users', true, UserPermission.Users)
226+
useHandleKeyBindings(() => { openMainWidget(ROLES_WIDGET) }, 'roles', true, UserPermission.Users)
226227

227-
useHandleKeyBindings(() => { openMainWidget(REPORTS_WIDGET) }, 'reports', true)
228-
useHandleKeyBindings(() => { openMainWidget(CUSTOM_REPORTS_WIDGET) }, 'customReports', true)
228+
useHandleKeyBindings(() => { openMainWidget(REPORTS_WIDGET) }, 'reports', true, UserPermission.Reports)
229+
useHandleKeyBindings(() => { openMainWidget(CUSTOM_REPORTS_WIDGET) }, 'customReports', true, UserPermission.ReportsConfig)
229230

230-
useHandleKeyBindings(() => { openMainWidget(APPLICATION_LOGGER_WIDGET) }, 'applicationLogger', true)
231+
useHandleKeyBindings(() => { openMainWidget(APPLICATION_LOGGER_WIDGET) }, 'applicationLogger', true, UserPermission.ApplicationLogger)
231232

232-
useHandleKeyBindings(() => { openMainWidget(REDIRECTS_WIDGET) }, 'redirects', true)
233-
useHandleKeyBindings(() => { openMainWidget(TAG_CONFIGURATION_WIDGET) }, 'tagConfiguration', true)
233+
useHandleKeyBindings(() => { openMainWidget(REDIRECTS_WIDGET) }, 'redirects', true, UserPermission.Redirects)
234+
useHandleKeyBindings(() => { openMainWidget(TAG_CONFIGURATION_WIDGET) }, 'tagConfiguration', true, UserPermission.TagsConfiguration)
234235

235236
return (
236237
<div ref={ elRef }>

assets/js/src/core/modules/app/hook/use-handle-keybindings.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import { useUserDraft } from '@Pimcore/modules/auth/hooks/use-user-draft'
1313
import { type KeyBindingForAUser } from '@Pimcore/modules/auth/user/user-api-slice.gen'
1414
import { useIsActiveMainWidget } from '@Pimcore/modules/widget-manager/hooks/use-is-active-main-widget'
1515
import { useMergedKeyBindings } from '@Pimcore/modules/user/hooks/use-merged-keybindings'
16+
import { isAllowed } from '@Pimcore/modules/auth/permission-helper'
17+
import type { UserPermission } from '@Pimcore/modules/auth/enums/user-permission'
1618
// import { useWidgetManager } from '@Pimcore/modules/widget-manager/hooks/use-widget-manager'
1719

18-
export const useHandleKeyBindings = (callback: (evt: KeyboardEvent) => void, actionName: string, alwaysActive = false): void => {
20+
export const useHandleKeyBindings = (callback: (evt: KeyboardEvent) => void, actionName: string, alwaysActive = false, permission?: UserPermission): void => {
1921
const isWidgetActive = useIsActiveMainWidget()
2022
const { user } = useUserDraft()
2123
const { mergedKeyBindings } = useMergedKeyBindings(user?.keyBindings)
@@ -36,10 +38,13 @@ export const useHandleKeyBindings = (callback: (evt: KeyboardEvent) => void, act
3638
const { keyCode, ctrlKey, altKey, shiftKey } = evt
3739

3840
if (config?.key !== undefined && config.key === keyCode && config.ctrl === ctrlKey && config.shift === shiftKey && config.alt === altKey) {
41+
if (permission !== undefined && !isAllowed(permission)) {
42+
return
43+
}
3944
evt.preventDefault()
4045
callback(evt)
4146
}
42-
}, [callback, actionName])
47+
}, [callback, actionName, permission])
4348

4449
useEffect(() => {
4550
document.removeEventListener('keydown', eventHandler)

assets/js/src/core/modules/element/editor/shared-tab-manager/tabs-container.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ import { useLocateInTree } from '@Pimcore/modules/element/actions/locate-in-tree
2727
import { type Element } from '@Pimcore/modules/element/element-helper'
2828
import { type DataObject } from '@Pimcore/modules/data-object/data-object-api-slice.gen'
2929
import { type Document } from '@Pimcore/modules/document/document-api-slice.gen'
30-
import { isNull } from 'lodash'
30+
import { has, isNull } from 'lodash'
3131
import { isWorkflowAvailable } from '@Pimcore/modules/element/utils/workflow-availability'
32+
import { checkElementPermission } from '@Pimcore/modules/element/permissions/permission-helper'
33+
import { TreePermission } from '@Pimcore/modules/perspectives/enums/tree-permission'
34+
import {
35+
useTreePermission
36+
} from '@Pimcore/components/element-tree/provider/tree-permission-provider/use-tree-permission'
3237

3338
export const TabsContainer = ({ elementEditorType }: { elementEditorType: ElementEditorType }): React.JSX.Element => {
3439
const { t } = useTranslation()
@@ -41,6 +46,7 @@ export const TabsContainer = ({ elementEditorType }: { elementEditorType: Elemen
4146
const { unpublishTreeNode } = useUnpublish(elementType)
4247
const { refreshElement } = useElementRefresh(elementType)
4348
const { locateInTree } = useLocateInTree(elementType)
49+
const { isTreeActionAllowed } = useTreePermission()
4450

4551
const preparedTabs = tabs.map((tab, index) => {
4652
const baseTab = {
@@ -57,9 +63,9 @@ export const TabsContainer = ({ elementEditorType }: { elementEditorType: Elemen
5763
return baseTab
5864
})
5965

60-
useHandleKeyBindings(() => { if (element != null) rename(element.id, getElementKey(element as unknown as Element, elementType)) }, 'rename')
61-
useHandleKeyBindings(() => { if (element != null) publishNode(element as unknown as Element) }, 'publish')
62-
useHandleKeyBindings(() => { if (element != null && !isNull(elementType) && elementType !== 'asset') unpublishTreeNode(element as unknown as DataObject | Document) }, 'unpublish')
66+
useHandleKeyBindings(() => { if (element != null && checkElementPermission(element.permissions, 'rename') && !(element as unknown as Element).isLocked) rename(element.id, getElementKey(element as unknown as Element, elementType)) }, 'rename')
67+
useHandleKeyBindings(() => { if (element != null && isTreeActionAllowed(TreePermission.Publish) && !(element as unknown as Element).isLocked && (has(element, 'published') && element.published === false)) publishNode(element as unknown as Element) }, 'publish')
68+
useHandleKeyBindings(() => { if (element != null && !isNull(elementType) && elementType !== 'asset' && checkElementPermission(element.permissions, 'unpublish') && !(element as unknown as Element).isLocked) unpublishTreeNode(element as unknown as DataObject | Document) }, 'unpublish')
6369
useHandleKeyBindings(() => { if (element != null) refreshElement(element.id) }, 'refresh')
6470
useHandleKeyBindings(() => { if (element != null) locateInTree(element.id) }, 'openInTree')
6571

assets/js/src/core/modules/search/triggers/button/search-button.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ import React from 'react'
1313
import { useSearch } from '../../provider/use-search'
1414
import { useHandleKeyBindings } from '@Pimcore/modules/app/hook/use-handle-keybindings'
1515
import { elementTypes } from '@Pimcore/types/enums/element/element-type'
16+
import { UserPermission } from '@Pimcore/modules/auth/enums/user-permission'
1617

1718
export const SearchButton = (): React.JSX.Element => {
1819
const { open } = useSearch()
1920

2021
useHandleKeyBindings(() => { open('all') }, 'quickSearch', true)
21-
useHandleKeyBindings(() => { open(elementTypes.asset) }, 'searchAsset', true)
22-
useHandleKeyBindings(() => { open(elementTypes.dataObject) }, 'searchObject', true)
23-
useHandleKeyBindings(() => { open(elementTypes.document) }, 'searchDocument', true)
22+
useHandleKeyBindings(() => { open(elementTypes.asset) }, 'searchAsset', true, UserPermission.Assets)
23+
useHandleKeyBindings(() => { open(elementTypes.dataObject) }, 'searchObject', true, UserPermission.Objects)
24+
useHandleKeyBindings(() => { open(elementTypes.document) }, 'searchDocument', true, UserPermission.Documents)
2425

2526
return (
2627
<IconButton

assets/js/src/core/modules/user/management/detail/tabs/key-bindings/key-bindings.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
GENERAL_FIELDS,
2424
NAVIGATION_FIELDS,
2525
SEARCH_FIELDS,
26+
SEO_FIELDS,
2627
SYSTEM_FIELDS
2728
} from '@Pimcore/modules/user/management/detail/tabs/key-bindings/constants'
2829

@@ -124,7 +125,7 @@ const KeyBindings = ({ values, modified, onChange, onResetKeyBindings, ...props
124125
getAccordionItem('navigation', NAVIGATION_FIELDS),
125126
getAccordionItem('search', SEARCH_FIELDS),
126127
getAccordionItem('system', SYSTEM_FIELDS),
127-
getAccordionItem('seo', SEARCH_FIELDS),
128+
getAccordionItem('seo', SEO_FIELDS),
128129
...(!isEmpty(bundleFields) ? [getAccordionItem(BUNDLES, bundleFields!)] : [])
129130
]
130131

public/build/3eef943c-f8c8-4ed5-9a60-7ed068a5b559/entrypoints.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/3eef943c-f8c8-4ed5-9a60-7ed068a5b559/exposeRemote.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/3eef943c-f8c8-4ed5-9a60-7ed068a5b559/index.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)