From b4f51cb5af7c2eb274773a303a8525968a3f9e39 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Wed, 13 Dec 2023 23:05:02 +0530 Subject: [PATCH] chore: cycle and module sidebar permission validation (#3095) --- web/components/cycles/sidebar.tsx | 19 +++++++--- web/components/modules/sidebar.tsx | 59 ++++++++++++++++++++---------- 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/web/components/cycles/sidebar.tsx b/web/components/cycles/sidebar.tsx index 4ae5c9d8b..c99ad9519 100644 --- a/web/components/cycles/sidebar.tsx +++ b/web/components/cycles/sidebar.tsx @@ -30,6 +30,8 @@ import { } from "helpers/date-time.helper"; // types import { ICycle } from "types"; +// constants +import { EUserWorkspaceRoles } from "constants/workspace"; // fetch-keys import { CYCLE_STATUS } from "constants/cycle"; @@ -53,6 +55,7 @@ export const CycleDetailsSidebar: React.FC = observer((props) => { const { cycle: cycleDetailsStore, trackEvent: { setTrackElement }, + user: { currentProjectRole }, } = useMobxStore(); const cycleDetails = cycleDetailsStore.cycle_details[cycleId] ?? undefined; @@ -286,6 +289,8 @@ export const CycleDetailsSidebar: React.FC = observer((props) => { : `${cycleDetails.total_issues}` : `${cycleDetails.completed_issues}/${cycleDetails.total_issues}`; + const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserWorkspaceRoles.MEMBER; + return ( <> {cycleDetails && workspaceSlug && projectId && ( @@ -312,7 +317,7 @@ export const CycleDetailsSidebar: React.FC = observer((props) => { - {!isCompleted && ( + {!isCompleted && isEditingAllowed && ( { @@ -349,8 +354,10 @@ export const CycleDetailsSidebar: React.FC = observer((props) => {
{areYearsEqual ? renderShortDate(startDate, "_ _") : renderShortMonthDate(startDate, "_ _")} @@ -385,8 +392,10 @@ export const CycleDetailsSidebar: React.FC = observer((props) => { <> {areYearsEqual ? renderShortDate(endDate, "_ _") : renderShortMonthDate(endDate, "_ _")} diff --git a/web/components/modules/sidebar.tsx b/web/components/modules/sidebar.tsx index 85e542434..ea7acfbaa 100644 --- a/web/components/modules/sidebar.tsx +++ b/web/components/modules/sidebar.tsx @@ -261,6 +261,8 @@ export const ModuleDetailsSidebar: React.FC = observer((props) => { : `${moduleDetails.total_issues}` : `${moduleDetails.completed_issues}/${moduleDetails.total_issues}`; + const isEditingAllowed = !!userRole && userRole >= EUserWorkspaceRoles.MEMBER; + return ( <> = observer((props) => { - - setModuleDeleteModal(true)}> - - - Delete module - - - + {isEditingAllowed && ( + + setModuleDeleteModal(true)}> + + + Delete module + + + + )}
@@ -311,7 +315,9 @@ export const ModuleDetailsSidebar: React.FC = observer((props) => { = observer((props) => { onChange={(value: any) => { submitChanges({ status: value }); }} + disabled={!isEditingAllowed} > {MODULE_STATUS.map((status) => ( @@ -339,7 +346,12 @@ export const ModuleDetailsSidebar: React.FC = observer((props) => {
- + {areYearsEqual ? renderShortDate(startDate, "_ _") : renderShortMonthDate(startDate, "_ _")} @@ -371,7 +383,12 @@ export const ModuleDetailsSidebar: React.FC = observer((props) => { <> - + {areYearsEqual ? renderShortDate(endDate, "_ _") : renderShortMonthDate(endDate, "_ _")} @@ -553,15 +570,17 @@ export const ModuleDetailsSidebar: React.FC = observer((props) => {
{userRole && moduleDetails.link_module && moduleDetails.link_module.length > 0 ? ( <> -
- -
+ {isEditingAllowed && ( +
+ +
+ )}