From 9d3dedf758a348ab50da203c4dacc26f4edfb7c2 Mon Sep 17 00:00:00 2001 From: Darya Plotnytska Date: Mon, 7 Oct 2024 13:25:07 +0200 Subject: [PATCH 1/3] console: Add feature checks to shortcut panel --- .../containers/shortcut-panel/index.js | 86 ++++++++++++------- 1 file changed, 55 insertions(+), 31 deletions(-) diff --git a/pkg/webui/console/containers/shortcut-panel/index.js b/pkg/webui/console/containers/shortcut-panel/index.js index b50b6edccf..b0161831b6 100644 --- a/pkg/webui/console/containers/shortcut-panel/index.js +++ b/pkg/webui/console/containers/shortcut-panel/index.js @@ -14,7 +14,7 @@ import React from 'react' import { defineMessages } from 'react-intl' -import { useDispatch } from 'react-redux' +import { useDispatch, useSelector } from 'react-redux' import { APPLICATION } from '@console/constants/entities' @@ -29,6 +29,14 @@ import { import sharedMessages from '@ttn-lw/lib/shared-messages' +import { + checkFromState, + mayCreateApplications, + mayCreateGateways, + mayCreateOrganizations, + mayViewOrEditUserApiKeys, +} from '@console/lib/feature-checks' + import { setSearchOpen, setSearchScope } from '@console/store/actions/search' import Panel from '../../../components/panel' @@ -50,39 +58,55 @@ const ShortcutPanel = () => { dispatch(setSearchOpen(true)) }, [dispatch]) + const showApplicationButton = useSelector(state => checkFromState(mayCreateApplications, state)) + const showEndDeviceButton = useSelector(state => checkFromState(mayProvisionDevice, state)) + const showOrganizationButton = useSelector(state => checkFromState(mayCreateOrganizations, state)) + const showUserApiKeys = useSelector(state => checkFromState(mayViewOrEditUserApiKeys, state)) + const showGatewaysButton = useSelector(state => checkFromState(mayCreateGateways, state)) + return (
- - - - - + {showApplicationButton && ( + + )} + {showEndDeviceButton && ( + + )} + {showGatewaysButton && ( + + )} + {showUserApiKeys && ( + + )} + {showOrganizationButton && ( + + )}
) From 2b7b2216063e769ea98a3d6afb4acbcd35cdc763 Mon Sep 17 00:00:00 2001 From: Darya Plotnytska Date: Wed, 9 Oct 2024 14:13:32 +0200 Subject: [PATCH 2/3] console: Change device feature check --- pkg/webui/console/containers/shortcut-panel/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/webui/console/containers/shortcut-panel/index.js b/pkg/webui/console/containers/shortcut-panel/index.js index b0161831b6..84c94e0d07 100644 --- a/pkg/webui/console/containers/shortcut-panel/index.js +++ b/pkg/webui/console/containers/shortcut-panel/index.js @@ -33,6 +33,7 @@ import { checkFromState, mayCreateApplications, mayCreateGateways, + mayCreateOrEditApplicationDevices, mayCreateOrganizations, mayViewOrEditUserApiKeys, } from '@console/lib/feature-checks' @@ -59,7 +60,9 @@ const ShortcutPanel = () => { }, [dispatch]) const showApplicationButton = useSelector(state => checkFromState(mayCreateApplications, state)) - const showEndDeviceButton = useSelector(state => checkFromState(mayProvisionDevice, state)) + const showEndDeviceButton = useSelector(state => + checkFromState(mayCreateOrEditApplicationDevices, state), + ) const showOrganizationButton = useSelector(state => checkFromState(mayCreateOrganizations, state)) const showUserApiKeys = useSelector(state => checkFromState(mayViewOrEditUserApiKeys, state)) const showGatewaysButton = useSelector(state => checkFromState(mayCreateGateways, state)) From 796fad3fb895e6ad031c4f0454bfba0a167e4488 Mon Sep 17 00:00:00 2001 From: Darya Plotnytska Date: Wed, 9 Oct 2024 16:34:27 +0200 Subject: [PATCH 3/3] console: Fix featurecheck --- pkg/webui/console/containers/shortcut-panel/index.js | 6 ++---- pkg/webui/console/lib/feature-checks.js | 5 +++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/webui/console/containers/shortcut-panel/index.js b/pkg/webui/console/containers/shortcut-panel/index.js index 84c94e0d07..1fd9d401d3 100644 --- a/pkg/webui/console/containers/shortcut-panel/index.js +++ b/pkg/webui/console/containers/shortcut-panel/index.js @@ -32,8 +32,8 @@ import sharedMessages from '@ttn-lw/lib/shared-messages' import { checkFromState, mayCreateApplications, + mayCreateDevices, mayCreateGateways, - mayCreateOrEditApplicationDevices, mayCreateOrganizations, mayViewOrEditUserApiKeys, } from '@console/lib/feature-checks' @@ -60,9 +60,7 @@ const ShortcutPanel = () => { }, [dispatch]) const showApplicationButton = useSelector(state => checkFromState(mayCreateApplications, state)) - const showEndDeviceButton = useSelector(state => - checkFromState(mayCreateOrEditApplicationDevices, state), - ) + const showEndDeviceButton = useSelector(state => checkFromState(mayCreateDevices, state)) const showOrganizationButton = useSelector(state => checkFromState(mayCreateOrganizations, state)) const showUserApiKeys = useSelector(state => checkFromState(mayViewOrEditUserApiKeys, state)) const showGatewaysButton = useSelector(state => checkFromState(mayCreateGateways, state)) diff --git a/pkg/webui/console/lib/feature-checks.js b/pkg/webui/console/lib/feature-checks.js index 163be25c40..61d6e772a9 100644 --- a/pkg/webui/console/lib/feature-checks.js +++ b/pkg/webui/console/lib/feature-checks.js @@ -92,6 +92,11 @@ export const mayViewOrEditUserApiKeys = { check: rights => rights.includes('RIGHT_USER_SETTINGS_API_KEYS'), } +export const mayCreateDevices = { + rightsSelector: selectUserRights, + check: rights => rights.includes('RIGHT_APPLICATION_DEVICES_WRITE'), +} + // Application related feature checks. export const mayViewApplicationInfo = { rightsSelector: selectApplicationRights,