diff --git a/src/pages/OldCommon/components/CommonDetailContainer/CommonMenu/CommonMenu.tsx b/src/pages/OldCommon/components/CommonDetailContainer/CommonMenu/CommonMenu.tsx index c2fccb8072..a6e47f33ec 100644 --- a/src/pages/OldCommon/components/CommonDetailContainer/CommonMenu/CommonMenu.tsx +++ b/src/pages/OldCommon/components/CommonDetailContainer/CommonMenu/CommonMenu.tsx @@ -186,7 +186,7 @@ const CommonMenu: FC = (props) => { hasPermission({ commonMember: currentCommonMember, governance, - key: GovernanceActions.CREATE_SUBCOMMON, + action: GovernanceActions.CREATE_SUBCOMMON, }) ) { items.push(MenuItem.CreateProject); diff --git a/src/pages/OldCommon/components/CommonDetailContainer/DiscussionsComponent/DiscussionsComponent.tsx b/src/pages/OldCommon/components/CommonDetailContainer/DiscussionsComponent/DiscussionsComponent.tsx index d5d8b25f94..40cf084ce1 100644 --- a/src/pages/OldCommon/components/CommonDetailContainer/DiscussionsComponent/DiscussionsComponent.tsx +++ b/src/pages/OldCommon/components/CommonDetailContainer/DiscussionsComponent/DiscussionsComponent.tsx @@ -34,7 +34,7 @@ export default function DiscussionsComponent({ hasPermission({ commonMember, governance, - key: GovernanceActions.CREATE_DISCUSSION, + action: GovernanceActions.CREATE_DISCUSSION, }); return ( diff --git a/src/pages/common/components/ChatComponent/ChatComponent.tsx b/src/pages/common/components/ChatComponent/ChatComponent.tsx index aeaf2b676c..ab0637ac8c 100644 --- a/src/pages/common/components/ChatComponent/ChatComponent.tsx +++ b/src/pages/common/components/ChatComponent/ChatComponent.tsx @@ -163,7 +163,7 @@ export default function ChatComponent({ governance: { circles: governanceCircles, }, - key: GovernanceActions.HIDE_OR_UNHIDE_MESSAGE, + action: GovernanceActions.HIDE_OR_UNHIDE_MESSAGE, }) : false; const { diff --git a/src/pages/common/components/CommonMenuButton/utils/getAllowedItems.ts b/src/pages/common/components/CommonMenuButton/utils/getAllowedItems.ts index a516339dd1..c5195bfed4 100644 --- a/src/pages/common/components/CommonMenuButton/utils/getAllowedItems.ts +++ b/src/pages/common/components/CommonMenuButton/utils/getAllowedItems.ts @@ -28,7 +28,7 @@ const MENU_ITEM_TO_CHECK_FUNCTION_MAP: Record< hasPermission({ commonMember, governance, - key: ProposalsTypes.DELETE_COMMON, + proposal: ProposalsTypes.DELETE_COMMON, }), ), [CommonMenuItem.DeleteCommonAction]: ({ commonMember, governance }) => @@ -37,7 +37,7 @@ const MENU_ITEM_TO_CHECK_FUNCTION_MAP: Record< hasPermission({ commonMember, governance, - key: GovernanceActions.DELETE_COMMON_ACTION, + action: GovernanceActions.DELETE_COMMON, }), ), }; diff --git a/src/pages/common/components/CommonTabPanels/components/AboutTab/components/CommonProjects/CommonProjects.tsx b/src/pages/common/components/CommonTabPanels/components/AboutTab/components/CommonProjects/CommonProjects.tsx index 02e78d8467..ed3cf91881 100644 --- a/src/pages/common/components/CommonTabPanels/components/AboutTab/components/CommonProjects/CommonProjects.tsx +++ b/src/pages/common/components/CommonTabPanels/components/AboutTab/components/CommonProjects/CommonProjects.tsx @@ -52,7 +52,7 @@ const CommonProjects: FC = (props) => { hasPermission({ commonMember, governance: { circles }, - key: GovernanceActions.CREATE_PROJECT, + action: GovernanceActions.CREATE_PROJECT, }), ); diff --git a/src/pages/common/components/CommonTabPanels/components/FeedTab/components/NewStreamButton/utils/getAllowedItems.ts b/src/pages/common/components/CommonTabPanels/components/FeedTab/components/NewStreamButton/utils/getAllowedItems.ts index eeccfde296..94f29e519e 100644 --- a/src/pages/common/components/CommonTabPanels/components/FeedTab/components/NewStreamButton/utils/getAllowedItems.ts +++ b/src/pages/common/components/CommonTabPanels/components/FeedTab/components/NewStreamButton/utils/getAllowedItems.ts @@ -28,7 +28,7 @@ const MENU_ITEM_TO_CHECK_FUNCTION_MAP: Record< hasPermission({ commonMember, governance, - key: ProposalsTypes.SURVEY, + proposal: ProposalsTypes.SURVEY, }), ), [CommonAction.NewDiscussion]: ({ commonMember, governance }) => @@ -37,7 +37,7 @@ const MENU_ITEM_TO_CHECK_FUNCTION_MAP: Record< hasPermission({ commonMember, governance, - key: GovernanceActions.CREATE_DISCUSSION, + action: GovernanceActions.CREATE_DISCUSSION, }), ), [CommonAction.NewContribution]: () => false, diff --git a/src/pages/common/components/DiscussionFeedCard/utils/checkIsLinkToAllowed.ts b/src/pages/common/components/DiscussionFeedCard/utils/checkIsLinkToAllowed.ts index 0c44a1540e..7bc6b04502 100644 --- a/src/pages/common/components/DiscussionFeedCard/utils/checkIsLinkToAllowed.ts +++ b/src/pages/common/components/DiscussionFeedCard/utils/checkIsLinkToAllowed.ts @@ -26,7 +26,7 @@ export const checkIsLinkToAllowed = ( governance: { circles: options.governanceCircles || {}, }, - key: GovernanceActions.LINK_FROM_HERE, + action: GovernanceActions.LINK_FROM_HERE, }) ); }; diff --git a/src/pages/common/components/DiscussionFeedCard/utils/checkIsPinUnpinAllowed.ts b/src/pages/common/components/DiscussionFeedCard/utils/checkIsPinUnpinAllowed.ts index 10121f1ade..ee5d572477 100644 --- a/src/pages/common/components/DiscussionFeedCard/utils/checkIsPinUnpinAllowed.ts +++ b/src/pages/common/components/DiscussionFeedCard/utils/checkIsPinUnpinAllowed.ts @@ -37,7 +37,7 @@ export function checkIsPinUnpinAllowed( governance: { circles: options.governanceCircles || {}, }, - key: GovernanceActions.PIN_OR_UNPIN_FEED_ITEMS, + action: GovernanceActions.PIN_OR_UNPIN_FEED_ITEMS, }); return isAllowed; diff --git a/src/pages/common/components/DiscussionFeedCard/utils/checkIsRemoveDiscussionAllowed.ts b/src/pages/common/components/DiscussionFeedCard/utils/checkIsRemoveDiscussionAllowed.ts index 33aa43ed66..4977af6973 100644 --- a/src/pages/common/components/DiscussionFeedCard/utils/checkIsRemoveDiscussionAllowed.ts +++ b/src/pages/common/components/DiscussionFeedCard/utils/checkIsRemoveDiscussionAllowed.ts @@ -21,7 +21,7 @@ export function checkIsRemoveDiscussionAllowed( hasPermission({ commonMember, governance: { circles }, - key: GovernanceActions.HIDE_OR_UNHIDE_DISCUSSION, + action: GovernanceActions.HIDE_OR_UNHIDE_DISCUSSION, }) || isDiscussionOwner; if (!options.discussion?.proposalId) { diff --git a/src/services/Common.ts b/src/services/Common.ts index c9020042bc..4e7aace5c9 100644 --- a/src/services/Common.ts +++ b/src/services/Common.ts @@ -535,7 +535,7 @@ class CommonService { public deleteCommon = async (commonId: string): Promise => { await Api.post(ApiEndpoint.CreateAction, { - type: GovernanceActions.DELETE_COMMON_ACTION, + type: GovernanceActions.DELETE_COMMON, args: { commonId }, }); }; diff --git a/src/shared/components/ElementDropdown/ElementDropdown.tsx b/src/shared/components/ElementDropdown/ElementDropdown.tsx index ce34c50ab9..1e5c09ef83 100644 --- a/src/shared/components/ElementDropdown/ElementDropdown.tsx +++ b/src/shared/components/ElementDropdown/ElementDropdown.tsx @@ -191,7 +191,7 @@ const ElementDropdown: FC = ({ governance: { circles: governanceCircles, }, - key: HideContentTypes[entityType], + action: HideContentTypes[entityType], }) && !isOwner && !isHiddenElement @@ -211,7 +211,7 @@ const ElementDropdown: FC = ({ governance: { circles: governanceCircles, }, - key: DeleteContentTypes[entityType], + action: DeleteContentTypes[entityType], })) && (isDiscussionMessage || isChatMessage) ) { diff --git a/src/shared/constants/governance/GovernanceActions.ts b/src/shared/constants/governance/GovernanceActions.ts index 86d146bb65..2a15dfd80e 100644 --- a/src/shared/constants/governance/GovernanceActions.ts +++ b/src/shared/constants/governance/GovernanceActions.ts @@ -42,7 +42,7 @@ export enum GovernanceActions { PIN_OR_UNPIN_FEED_ITEMS = "PIN_OR_UNPIN_FEED_ITEMS", - DELETE_COMMON_ACTION = "DELETE_COMMON_ACTION", + DELETE_COMMON = "DELETE_COMMON", MOVE_TO_HERE = "MOVE_TO_HERE", LINK_TO_HERE = "LINK_TO_HERE", diff --git a/src/shared/utils/hasPermission.ts b/src/shared/utils/hasPermission.ts index 9120625382..809a0d3f35 100644 --- a/src/shared/utils/hasPermission.ts +++ b/src/shared/utils/hasPermission.ts @@ -2,20 +2,23 @@ import { GovernanceActions, ProposalsTypes } from "@/shared/constants"; import { CommonMember, Governance } from "@/shared/models"; import { generateCirclesDataForCommonMember } from "./generateCircleDataForCommonMember"; -interface Query { +type Query = { commonMember: CommonMember; governance: Pick; - key: ProposalsTypes | GovernanceActions; -} +} & ( + | { + action: GovernanceActions; + } + | { + proposal: ProposalsTypes; + } +); /** * Doesnt check for nested permissions, i.e assign/remove circle - these are check on the proposal creation level */ -export const hasPermission = ({ - commonMember, - governance, - key, -}: Query): boolean => { +export const hasPermission = (query: Query): boolean => { + const { commonMember, governance } = query; if (!commonMember || !governance) { return false; } @@ -26,22 +29,24 @@ export const hasPermission = ({ commonMember.circleIds, ); - if (Object.values(ProposalsTypes).includes(key as ProposalsTypes)) { + if ( + "proposal" in query && + Object.values(ProposalsTypes).includes(query.proposal) + ) { if ( !circlesPermissions?.allowedActions[GovernanceActions.CREATE_PROPOSAL] ) { return false; } - return Boolean( - circlesPermissions?.allowedProposals[key as ProposalsTypes], - ); + return Boolean(circlesPermissions?.allowedProposals[query.proposal]); } - if (Object.values(GovernanceActions).includes(key as GovernanceActions)) { - return Boolean( - circlesPermissions?.allowedActions[key as GovernanceActions], - ); + if ( + "action" in query && + Object.values(GovernanceActions).includes(query.action) + ) { + return Boolean(circlesPermissions?.allowedActions[query.action]); } } catch (err) { return false;