Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2022-07-21 17:25:02 +0300
committerGitHub <noreply@github.com>2022-07-21 17:25:02 +0300
commite5e6cd72bf604766c71cfa7e9177bbbb5a41b55c (patch)
tree9b5f57f35d92a27778ad0b881fcdc3c2e2129fe8
parentcce20f0880f6f0f5012b033ffff19e2adbfeaa63 (diff)
parent7d16c40596e90395081e4636ddc1e481314248cd (diff)
Merge pull request #7621 from nextcloud/bugfix/7620/error-getting-poll-without-votes
Fix error getting poll without votes
-rw-r--r--lib/Controller/PollController.php2
-rw-r--r--lib/Service/PollService.php21
-rw-r--r--tests/integration/features/chat/poll.feature50
3 files changed, 67 insertions, 6 deletions
diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php
index 840ec5ffc..3d89ad5c9 100644
--- a/lib/Controller/PollController.php
+++ b/lib/Controller/PollController.php
@@ -148,7 +148,7 @@ class PollController extends AEnvironmentAwareController {
* @param int[] $optionIds
* @return DataResponse
*/
- public function votePoll(int $pollId, array $optionIds): DataResponse {
+ public function votePoll(int $pollId, array $optionIds = []): DataResponse {
try {
$poll = $this->pollService->getPoll($this->room->getId(), $pollId);
} catch (\Exception $e) {
diff --git a/lib/Service/PollService.php b/lib/Service/PollService.php
index 7e7a94861..7fa665c19 100644
--- a/lib/Service/PollService.php
+++ b/lib/Service/PollService.php
@@ -138,11 +138,13 @@ class PollService {
throw new \OverflowException();
}
- $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) {
- throw new \RangeException();
+ if (!empty($optionIds)) {
+ $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) {
+ throw new \RangeException();
+ }
}
$votes = [];
@@ -251,6 +253,15 @@ class PollService {
$this->connection->beginTransaction();
try {
$update->executeStatement();
+
+ // Fix `null` being stored if the only voter revokes their vote
+ $updateFixNull = $this->connection->getQueryBuilder();
+ $updateFixNull->update('talk_polls')
+ ->set('votes', $updateFixNull->createNamedParameter('{}'))
+ ->where($updateFixNull->expr()->eq('id', $updateFixNull->createNamedParameter($pollId, IQueryBuilder::PARAM_INT)))
+ ->andWhere($updateFixNull->expr()->isNull('votes'));
+
+ $updateFixNull->executeStatement();
} catch (\Exception $e) {
$this->connection->rollBack();
throw $e;
diff --git a/tests/integration/features/chat/poll.feature b/tests/integration/features/chat/poll.feature
index f0fb63bc4..2b64180ce 100644
--- a/tests/integration/features/chat/poll.feature
+++ b/tests/integration/features/chat/poll.feature
@@ -523,3 +523,53 @@ Feature: chat/poll
| actorDisplayName | participant2-displayname |
| status | open |
| votedSelf | [1] |
+
+ Scenario: Remove all votes
+ Given user "participant1" creates room "room" (v4)
+ | roomType | 2 |
+ | roomName | room |
+ When user "participant1" adds user "participant2" to room "room" with 200 (v4)
+ 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 |
+ | maxVotes | unlimited |
+ Then user "participant1" votes for options "[0]" on poll "What is the question?" in room "room" with 200
+ | id | POLL_ID(What is the question?) |
+ | question | What is the question? |
+ | options | ["Where are you?","How much is the fish?"] |
+ | votes | {"option-0":1} |
+ | numVoters | 1 |
+ | resultMode | public |
+ | maxVotes | unlimited |
+ | actorType | users |
+ | actorId | participant1 |
+ | actorDisplayName | participant1-displayname |
+ | status | open |
+ | votedSelf | [0] |
+ Then user "participant1" votes for options "{}" on poll "What is the question?" in room "room" with 200
+ | id | POLL_ID(What is the question?) |
+ | question | What is the question? |
+ | options | ["Where are you?","How much is the fish?"] |
+ | votes | [] |
+ | numVoters | 0 |
+ | resultMode | public |
+ | maxVotes | unlimited |
+ | actorType | users |
+ | actorId | participant1 |
+ | actorDisplayName | participant1-displayname |
+ | status | open |
+ | votedSelf | [] |
+ Then user "participant1" sees poll "What is the question?" in room "room" with 200
+ | id | POLL_ID(What is the question?) |
+ | question | What is the question? |
+ | options | ["Where are you?","How much is the fish?"] |
+ | votes | [] |
+ | numVoters | 0 |
+ | resultMode | public |
+ | maxVotes | unlimited |
+ | actorType | users |
+ | actorId | participant1 |
+ | actorDisplayName | participant1-displayname |
+ | status | open |
+ | votedSelf | [] |