Browse Source

Check voting options for validity

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/7306/head
Joas Schilling 4 years ago
parent
commit
171f37d403
No known key found for this signature in database GPG Key ID: 7076EA9751AACDDA
  1. 18
      lib/Controller/PollController.php
  2. 2
      tests/integration/features/chat/poll.feature

18
lib/Controller/PollController.php

@ -89,10 +89,10 @@ class PollController extends AEnvironmentAwareController {
$message = json_encode([
'message' => 'object_shared',
'parameters' => [
'objectType' => 'highlight', // FIXME 'talk-poll',
'objectType' => 'talk-poll',
'objectId' => $poll->getId(),
'metaData' => [
'type' => 'highlight', // FIXME 'talk-poll',
'type' => 'talk-poll',
'id' => $poll->getId(),
'name' => $question,
]
@ -105,7 +105,7 @@ class PollController extends AEnvironmentAwareController {
$this->logger->error($e->getMessage(), ['exception' => $e]);
}
return new DataResponse($this->renderPoll($poll, []));
return new DataResponse($this->renderPoll($poll, []), Http::STATUS_CREATED);
}
/**
@ -144,6 +144,18 @@ class PollController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if ($poll->getMaxVotes() !== Poll::MAX_VOTES_UNLIMITED
&& $poll->getMaxVotes() < count($optionIds)) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
$maxOptionId = max(array_keys(json_decode($poll->getOptions(), true, 512, JSON_THROW_ON_ERROR)));
$maxVotedId = max($optionIds);
$minVotedId = min($optionIds);
if ($minVotedId < 0 || $maxVotedId > $maxOptionId) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
$votes = $this->pollService->votePoll($this->participant, $poll, $optionIds);
return new DataResponse($this->renderPoll($poll, $votes));

2
tests/integration/features/chat/poll.feature

@ -6,7 +6,7 @@ Feature: chat/poll
Given user "participant1" creates room "room" (v4)
| roomType | 2 |
| roomName | room |
When user "participant1" creates a poll in room "room" with 200
When user "participant1" creates a poll in room "room" with 201
| question | What is the question? |
| options | ["Where are you?","How much is the fish?"] |
| resultMode | public |

Loading…
Cancel
Save