From 9ddae531db6f80df958ff9a263e08ebf3a990bf0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 26 Aug 2022 16:30:41 +0200 Subject: Don't allow to close polls twice Signed-off-by: Joas Schilling --- docs/poll.md | 1 + lib/Controller/PollController.php | 4 ++++ tests/integration/features/chat/poll.feature | 1 + 3 files changed, 6 insertions(+) diff --git a/docs/poll.md b/docs/poll.md index ca87b413d..758377b0f 100644 --- a/docs/poll.md +++ b/docs/poll.md @@ -77,6 +77,7 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1` * Response: - Status code: + `200 OK` + + `400 Bad Request` When the poll is already closed + `403 Forbidden` When the participant is not the author of the poll or a moderator + `404 Not Found` When the conversation could not be found for the participant + `404 Not Found` When the poll id could not be found in the conversation diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php index 3d89ad5c9..5b0c183dc 100644 --- a/lib/Controller/PollController.php +++ b/lib/Controller/PollController.php @@ -202,6 +202,10 @@ class PollController extends AEnvironmentAwareController { return new DataResponse([], Http::STATUS_NOT_FOUND); } + if ($poll->getStatus() === Poll::STATUS_CLOSED) { + return new DataResponse([], Http::STATUS_BAD_REQUEST); + } + $poll->setStatus(Poll::STATUS_CLOSED); try { diff --git a/tests/integration/features/chat/poll.feature b/tests/integration/features/chat/poll.feature index 46a90eb3a..d7acc1692 100644 --- a/tests/integration/features/chat/poll.feature +++ b/tests/integration/features/chat/poll.feature @@ -382,6 +382,7 @@ Feature: chat/poll | actorDisplayName | participant1-displayname | | status | closed | | votedSelf | [0] | + Then user "participant1" closes poll "What is the question?" in room "room" with 400 Then user "participant1" sees the following system messages in room "room" with 200 (v1) | room | actorType | actorId | actorDisplayName | systemMessage | | room | users | participant1 | participant1-displayname | poll_closed | -- cgit v1.2.3