From 190fcce1266ec7db0c1c0b60999b0b5234348032 Mon Sep 17 00:00:00 2001 From: Pallavi Mishra Date: Wed, 19 Jun 2024 16:59:10 +0530 Subject: [PATCH 1/2] Check entity create permission in selector component while creating a new entity --- studio/src/components/Selector/index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/studio/src/components/Selector/index.js b/studio/src/components/Selector/index.js index c2e34feb..3964c9ec 100644 --- a/studio/src/components/Selector/index.js +++ b/studio/src/components/Selector/index.js @@ -2,7 +2,7 @@ import React, { useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { Select, Empty, Button } from 'antd'; import deepEqual from 'deep-equal'; - +import getUserPermission from '../../utils/getUserPermission'; function Selector({ invalidOptions = [], setLoading = true, @@ -16,6 +16,9 @@ function Selector({ style, }) { const entity = action.toLowerCase(); + const spaces = useSelector(({ spaces }) => spaces); + const actions = getUserPermission({ resources: ['categories', 'tags'], action: 'create', spaces }); + const selectorType = require(`../../actions/${entity}`); const [entityCreatedFlag, setEntityCreatedFlag] = React.useState(false); const [query, setQuery] = React.useState({ @@ -133,7 +136,7 @@ function Selector({ } }} notFoundContent={ - query.q?.trim() && createEntity ? ( + actions.includes('admin') || actions.includes('create') ? ( - ) : createEntity ? ( + ) : ( - ) : null + ) } getPopupContainer={(trigger) => trigger.parentNode} autoClearSearchValue={true} From a854e1017a3109135ee7cefe2d5e4357300b8e81 Mon Sep 17 00:00:00 2001 From: Pallavi Mishra Date: Thu, 20 Jun 2024 16:05:16 +0530 Subject: [PATCH 2/2] checking permissions --- studio/src/components/Selector/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/studio/src/components/Selector/index.js b/studio/src/components/Selector/index.js index 3964c9ec..274b041a 100644 --- a/studio/src/components/Selector/index.js +++ b/studio/src/components/Selector/index.js @@ -17,7 +17,7 @@ function Selector({ }) { const entity = action.toLowerCase(); const spaces = useSelector(({ spaces }) => spaces); - const actions = getUserPermission({ resources: ['categories', 'tags'], action: 'create', spaces }); + const actions = getUserPermission({ resource: createEntity, action: 'create', spaces }); const selectorType = require(`../../actions/${entity}`); const [entityCreatedFlag, setEntityCreatedFlag] = React.useState(false);