Skip to content

Commit a14367e

Browse files
authored
fix: check cast-poll-vote permission to show "Suggest an option" poll action (#2835)
1 parent 270ead2 commit a14367e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/components/Poll/PollActions/PollActions.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export const PollActions = ({
8787
} = useStateStore(poll.state, pollStateSelector);
8888
const [modalOpen, setModalOpen] = useState<ModalName | undefined>();
8989

90+
const canCastVote = channelCapabilities['cast-poll-vote'] && !is_closed;
9091
const closeModal = useCallback(() => setModalOpen(undefined), []);
9192
const onUpdateAnswerClick = useCallback(() => setModalOpen('add-comment'), []);
9293

@@ -106,7 +107,7 @@ export const PollActions = ({
106107
</PollAction>
107108
)}
108109

109-
{!is_closed &&
110+
{canCastVote &&
110111
allow_user_suggested_options &&
111112
options.length < MAX_POLL_OPTIONS && (
112113
<PollAction

src/components/Poll/__tests__/PollActions.test.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const END_VOTE_ACTION_TEXT = 'End vote';
2828
const t = (v) => v;
2929

3030
const defaultChannelStateContext = {
31-
channelCapabilities: { 'query-poll-votes': true },
31+
channelCapabilities: { 'cast-poll-vote': true, 'query-poll-votes': true },
3232
};
3333

3434
const defaultMessageContext = {
@@ -87,7 +87,20 @@ describe('PollActions', () => {
8787
expect(screen.queryByText(SEE_ALL_OPTIONS_ACTION_TEXT)).not.toBeInTheDocument();
8888
});
8989

90-
it('shows "Suggest an option" action if poll is not closed and suggestions are allowed', async () => {
90+
it('does not show "Suggest an option" action if poll is not closed and suggestions are allowed but user does not have permission to cast vote', async () => {
91+
const pollData = generatePoll({
92+
allow_user_suggested_options: true,
93+
is_closed: false,
94+
});
95+
const poll = new Poll({ client: {}, poll: pollData });
96+
await renderComponent({
97+
channelStateContext: { channelCapabilities: { 'cast-poll-vote': false } },
98+
poll,
99+
});
100+
expect(screen.queryByText(SUGGEST_OPTION_ACTION_TEXT)).not.toBeInTheDocument();
101+
});
102+
103+
it('shows "Suggest an option" action if poll is not closed and suggestions are allowed and user has permission to cast votes', async () => {
91104
const pollData = generatePoll({
92105
allow_user_suggested_options: true,
93106
is_closed: false,

0 commit comments

Comments
 (0)