From 10dd7e438616bd935e166e769eddec92de263326 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Wed, 4 Oct 2023 13:56:15 +0300 Subject: [PATCH] refactor proposal removal ability check --- .../utils/checkIsRemoveDiscussionAllowed.ts | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/pages/common/components/DiscussionFeedCard/utils/checkIsRemoveDiscussionAllowed.ts b/src/pages/common/components/DiscussionFeedCard/utils/checkIsRemoveDiscussionAllowed.ts index 2edd051f8f..ed7356a441 100644 --- a/src/pages/common/components/DiscussionFeedCard/utils/checkIsRemoveDiscussionAllowed.ts +++ b/src/pages/common/components/DiscussionFeedCard/utils/checkIsRemoveDiscussionAllowed.ts @@ -1,24 +1,25 @@ import { GovernanceActions } from "@/shared/constants"; import { PredefinedTypes } from "@/shared/models"; -import { hasPermission } from "@/shared/utils"; +import { getCirclesWithHighestTier, hasPermission } from "@/shared/utils"; import { GetAllowedItemsOptions } from "../../FeedItem"; export function checkIsRemoveDiscussionAllowed( options: GetAllowedItemsOptions, ): boolean { + const { commonMember } = options; + if ( - !options.commonMember || + !commonMember || options.discussion?.predefinedType === PredefinedTypes.General ) { return false; } const circles = options.governanceCircles || {}; - const isDiscussionOwner = - options.commonMember.userId === options.discussion?.ownerId; + const isDiscussionOwner = commonMember.userId === options.discussion?.ownerId; const hasPermissionToRemoveDiscussion = hasPermission({ - commonMember: options.commonMember, + commonMember, governance: { circles }, key: GovernanceActions.HIDE_OR_UNHIDE_DISCUSSION, }) || isDiscussionOwner; @@ -27,11 +28,14 @@ export function checkIsRemoveDiscussionAllowed( return hasPermissionToRemoveDiscussion; } + const circlesWithHighestTier = getCirclesWithHighestTier( + Object.values(circles), + ); + return ( - hasPermission({ - commonMember: options.commonMember, - governance: { circles }, - key: GovernanceActions.HIDE_OR_UNHIDE_PROPOSAL, - }) || isDiscussionOwner + isDiscussionOwner || + circlesWithHighestTier.some((circle) => + commonMember.circleIds.includes(circle.id), + ) ); }