summaryrefslogtreecommitdiffstats
path: root/lib/Controller/PollController.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-05-06 16:13:27 +0200
committerJoas Schilling <coding@schilljs.com>2022-06-13 12:52:58 +0200
commitaeb1bd528871ec286ae4dc60997bc17259ffcbe2 (patch)
treeab98a0c7295a998492f9e7e54a4ab812e7f9cdc3 /lib/Controller/PollController.php
parentbce64c3fbf65fc2032e6a59748329035ab707518 (diff)
Allow to see the poll data and close it
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Controller/PollController.php')
-rw-r--r--lib/Controller/PollController.php56
1 files changed, 52 insertions, 4 deletions
diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php
index 7babba223..def2d5cf0 100644
--- a/lib/Controller/PollController.php
+++ b/lib/Controller/PollController.php
@@ -1,11 +1,10 @@
<?php
declare(strict_types=1);
+
/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ * @copyright Copyright (c) 2022 Joas Schilling <coding@schilljs.com>
*
- * @author Lukas Reschke <lukas@statuscode.ch>
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
@@ -28,11 +27,13 @@ declare(strict_types=1);
namespace OCA\Talk\Controller;
use OCA\Talk\Chat\ChatManager;
+use OCA\Talk\Exceptions\WrongPermissionsException;
+use OCA\Talk\Model\Poll;
use OCA\Talk\Service\PollService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\Comments\MessageTooLongException;
+use OCP\DB\Exception;
use OCP\IRequest;
use Psr\Log\LoggerInterface;
@@ -105,4 +106,51 @@ class PollController extends AEnvironmentAwareController {
return new DataResponse($poll->asArray());
}
+
+ /**
+ * @PublicPage
+ * @RequireParticipant
+ * @RequireModeratorOrNoLobby
+ *
+ * @param int $pollId
+ * @return DataResponse
+ */
+ public function showPoll(int $pollId): DataResponse {
+ try {
+ $poll = $this->pollService->getPoll($this->room->getId(), $pollId);
+ } catch (\Exception $e) {
+ return new DataResponse([], Http::STATUS_NOT_FOUND);
+ }
+
+ return new DataResponse($poll->asArray());
+ }
+
+ /**
+ * @PublicPage
+ * @RequireParticipant
+ * @RequireModeratorOrNoLobby
+ *
+ * @param int $pollId
+ * @return DataResponse
+ */
+ public function closePoll(int $pollId): DataResponse {
+ try {
+ $poll = $this->pollService->getPoll($this->room->getId(), $pollId);
+ } catch (\Exception $e) {
+ return new DataResponse([], Http::STATUS_NOT_FOUND);
+ }
+
+ $poll->setStatus(Poll::STATUS_CLOSED);
+
+ try {
+ $this->pollService->updatePoll($this->participant, $poll);
+ } catch (WrongPermissionsException $e) {
+ return new DataResponse([], Http::STATUS_FORBIDDEN);
+ } catch (Exception $e) {
+ $this->logger->error($e->getMessage(), ['exception' => $e]);
+ return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
+ }
+
+ return new DataResponse($poll->asArray());
+ }
}