Skip to content

Commit

Permalink
fix proposal removal ability check
Browse files Browse the repository at this point in the history
  • Loading branch information
andreymikhadyuk committed Sep 27, 2023
1 parent 5c9e468 commit ecbf87b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,39 @@ import { GetAllowedItemsOptions } from "../../FeedItem";

export function checkIsRemoveDiscussionAllowed(
options: GetAllowedItemsOptions,
) {
if (!options.commonMember) return false;
if (options.discussion?.predefinedType === PredefinedTypes.General)
): boolean {
if (
!options.commonMember ||
options.discussion?.predefinedType === PredefinedTypes.General
) {
return false;
}

const circles = options.governanceCircles || {};
const isDiscussionOwner =
options.commonMember.userId === options.discussion?.ownerId;
const hasPermissionToRemoveDiscussion =
hasPermission({
commonMember: options.commonMember,
governance: {
circles: options.governanceCircles || {},
},
governance: { circles },
key: GovernanceActions.HIDE_OR_UNHIDE_DISCUSSION,
}) || options.commonMember.userId === options.discussion?.ownerId;
}) || isDiscussionOwner;

let isAllowed = hasPermissionToRemoveDiscussion;
if (options.discussion?.proposalId && isAllowed) {
const { proposal } = options;
const hasPermissionToRemoveProposal =
hasPermission({
commonMember: options.commonMember,
governance: {
circles: options.governanceCircles || {},
},
key: GovernanceActions.HIDE_OR_UNHIDE_PROPOSAL,
}) || options.commonMember.userId === options.discussion?.ownerId;
isAllowed =
!!proposal &&
checkIsCountdownState({ state: proposal.state }) &&
hasPermissionToRemoveProposal;
if (!options.discussion?.proposalId) {
return hasPermissionToRemoveDiscussion;
}
return isAllowed;

const { proposalState } = options;
const hasPermissionToRemoveProposal =
hasPermission({
commonMember: options.commonMember,
governance: { circles },
key: GovernanceActions.HIDE_OR_UNHIDE_PROPOSAL,
}) || isDiscussionOwner;

return Boolean(
proposalState &&
checkIsCountdownState({ state: proposalState }) &&
hasPermissionToRemoveProposal,
);
}
4 changes: 2 additions & 2 deletions src/pages/common/components/FeedItem/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
CommonFeed,
CommonMember,
Discussion,
Proposal,
CommonFeedType,
CommonFeedObjectUserUnique,
ProposalState,
} from "@/shared/models";
import { FeedItemMenuItem } from "./constants";

Expand All @@ -22,7 +22,7 @@ export interface GetAllowedItemsOptions {
discussion?: Discussion | null;
governanceCircles?: Circles;
feedItem?: CommonFeed;
proposal?: Proposal;
proposalState?: ProposalState;
commonMember?: CommonMember | null;
feedItemFollow: FeedItemFollowState;
getNonAllowedItems?: GetNonAllowedItemsOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ const ProposalFeedCard = forwardRef<FeedItemRef, ProposalFeedCardProps>(
feedItem: item,
discussion,
governanceCircles,
proposalState: proposal?.state,
commonMember,
feedItemFollow,
getNonAllowedItems,
Expand Down

0 comments on commit ecbf87b

Please sign in to comment.