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

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRené Gieling <github@dartcafe.de>2020-08-23 08:59:02 +0300
committerGitHub <noreply@github.com>2020-08-23 08:59:02 +0300
commitbdece5963ba5a88a841ed0dd04050bb1958c2a0f (patch)
treec16490cd29c049b0a0efe9366dddc37af6681f50 /lib
parentf29310618551b688c2bab412cb127b37c64ea3f2 (diff)
parent6b73deac12a2dabc4d94b92ce91eebd04620e3bb (diff)
Merge branch 'dev-1.5' into checkCalendar
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/OptionController.php7
-rw-r--r--lib/Exceptions/DuplicateEntryException.php40
-rw-r--r--lib/Service/OptionService.php9
-rw-r--r--lib/Service/ShareService.php1
-rw-r--r--lib/Service/SubscriptionService.php2
5 files changed, 54 insertions, 5 deletions
diff --git a/lib/Controller/OptionController.php b/lib/Controller/OptionController.php
index 3416a399..d8801d69 100644
--- a/lib/Controller/OptionController.php
+++ b/lib/Controller/OptionController.php
@@ -26,6 +26,7 @@ namespace OCA\Polls\Controller;
use DateTime;
use DateInterval;
use Exception;
+use OCA\Polls\Exceptions\DuplicateEntryException;
use OCP\IRequest;
@@ -79,7 +80,11 @@ class OptionController extends Controller {
* @return DataResponse
*/
public function add($pollId, $timestamp = 0, $pollOptionText = '') {
- return new DataResponse(['option' => $this->optionService->add($pollId, $timestamp, $pollOptionText)], Http::STATUS_OK);
+ try {
+ return new DataResponse(['option' => $this->optionService->add($pollId, $timestamp, $pollOptionText)], Http::STATUS_OK);
+ } catch (DuplicateEntryException $e) {
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
+ }
}
/**
diff --git a/lib/Exceptions/DuplicateEntryException.php b/lib/Exceptions/DuplicateEntryException.php
new file mode 100644
index 00000000..d019414f
--- /dev/null
+++ b/lib/Exceptions/DuplicateEntryException.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * @copyright Copyright (c) 2020 René Gieling <github@dartcafe.de>
+ *
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Polls\Exceptions;
+
+use OCP\AppFramework\Http;
+
+class DuplicateEntryException extends \Exception {
+ /**
+ * DuplicateEntryException Constructor
+ * @param string $e exception message
+ */
+ public function __construct($e = 'Duplicate Entry') {
+ parent::__construct($e);
+ }
+ public function getStatus() {
+ return Http::STATUS_CONFLICT;
+ }
+
+}
diff --git a/lib/Service/OptionService.php b/lib/Service/OptionService.php
index 0e2dbb88..3b9f1f87 100644
--- a/lib/Service/OptionService.php
+++ b/lib/Service/OptionService.php
@@ -27,6 +27,8 @@ use Exception;
use OCP\AppFramework\Db\DoesNotExistException;
use OCA\Polls\Exceptions\NotAuthorizedException;
use OCA\Polls\Exceptions\BadRequestException;
+use OCA\Polls\Exceptions\DuplicateEntryException;
+use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCA\Polls\Db\OptionMapper;
use OCA\Polls\Db\Option;
@@ -140,7 +142,12 @@ class OptionService {
$this->option->setPollId($pollId);
$this->setOption($timestamp, $pollOptionText, 0);
- return $this->optionMapper->insert($this->option);
+ try {
+ return $this->optionMapper->insert($this->option);
+ } catch (UniqueConstraintViolationException $e) {
+ throw new DuplicateEntryException('This option already exists');
+ }
+
}
/**
diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php
index 095b0fc5..83b20dda 100644
--- a/lib/Service/ShareService.php
+++ b/lib/Service/ShareService.php
@@ -117,7 +117,6 @@ class ShareService {
* @throws NotAuthorizedException
*/
public function add($pollId, $type, $userId, $userEmail = '') {
-
if (!$this->acl->set($pollId)->getAllowEdit()) {
throw new NotAuthorizedException;
}
diff --git a/lib/Service/SubscriptionService.php b/lib/Service/SubscriptionService.php
index 8678817e..9c3f1855 100644
--- a/lib/Service/SubscriptionService.php
+++ b/lib/Service/SubscriptionService.php
@@ -82,8 +82,6 @@ class SubscriptionService {
*/
public function set($pollId, $token, $subscribed) {
if (!$this->acl->set($pollId, $token)->getAllowView()) {
- \OC::$server->getLogger()->alert('Share token: ' . $token);
- \OC::$server->getLogger()->alert('Share PollId: ' . $pollId);
throw new NotAuthorizedException;
}
try {