diff options
Diffstat (limited to 'lib/Controller')
-rw-r--r-- | lib/Controller/AclController.php | 80 | ||||
-rw-r--r-- | lib/Controller/CommentApiController.php | 16 | ||||
-rw-r--r-- | lib/Controller/CommentController.php | 28 | ||||
-rw-r--r-- | lib/Controller/OptionApiController.php | 74 | ||||
-rw-r--r-- | lib/Controller/OptionController.php | 68 | ||||
-rw-r--r-- | lib/Controller/PageController.php | 1 | ||||
-rw-r--r-- | lib/Controller/PollApiController.php | 52 | ||||
-rw-r--r-- | lib/Controller/PollController.php | 126 | ||||
-rw-r--r-- | lib/Controller/ShareApiController.php | 58 | ||||
-rw-r--r-- | lib/Controller/ShareController.php | 69 | ||||
-rw-r--r-- | lib/Controller/SubscriptionApiController.php | 31 | ||||
-rw-r--r-- | lib/Controller/SubscriptionController.php | 26 | ||||
-rw-r--r-- | lib/Controller/SystemController.php | 37 | ||||
-rw-r--r-- | lib/Controller/VoteApiController.php | 31 | ||||
-rw-r--r-- | lib/Controller/VoteController.php | 41 |
15 files changed, 321 insertions, 417 deletions
diff --git a/lib/Controller/AclController.php b/lib/Controller/AclController.php deleted file mode 100644 index 2bb1561f..00000000 --- a/lib/Controller/AclController.php +++ /dev/null @@ -1,80 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com> - * - * @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\Controller; - -use OCP\AppFramework\Controller; -use OCP\AppFramework\Http; -use OCP\AppFramework\Http\DataResponse; - -use OCP\IRequest; - -use OCA\Polls\Model\Acl; - - -class AclController extends Controller { - - private $acl; - - /** - * PageController constructor. - * @param string $appName - * @param IRequest $request - * @param Acl $acl - */ - public function __construct( - $appName, - IRequest $request, - Acl $acl - ) { - parent::__construct($appName, $request); - $this->acl = $acl; - } - - /** - * Read acl with poll id for current user - * @NoAdminRequired - * @param integer $pollId - * @return array - */ - public function get($id) { - $acl = $this->acl->setPollId($id); - // $acl = $this->acl->setUserId('dartcafe'); - return new DataResponse($acl, Http::STATUS_OK); - } - - /** - * Read acl with share token - * @NoAdminRequired - * @PublicPage - * @NoCSRFRequired - * @param integer $pollId - * @return array - */ - public function getByToken($token) { - $acl = $this->acl->setToken($token); - return new DataResponse($acl, Http::STATUS_OK); - - } - -} diff --git a/lib/Controller/CommentApiController.php b/lib/Controller/CommentApiController.php index 6cc56bba..16d3b66a 100644 --- a/lib/Controller/CommentApiController.php +++ b/lib/Controller/CommentApiController.php @@ -25,24 +25,25 @@ namespace OCA\Polls\Controller; use Exception; use OCP\AppFramework\Db\DoesNotExistException; +use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; -use \OCP\IURLGenerator; +use OCP\IURLGenerator; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; -use OCA\Polls\Exceptions\NotAuthorizedException; - use OCA\Polls\Service\CommentService; class CommentApiController extends ApiController { + /** @var CommentService */ private $commentService; + /** - * CommentApiController constructor. + * CommentApiController constructor * @param string $appName * @param IRequest $request * @param CommentService $commentService @@ -62,12 +63,11 @@ class CommentApiController extends ApiController { } /** - * get * Read all comments of a poll based on the poll id and return list as array * @NoAdminRequired * @CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse */ public function list($pollId) { @@ -81,7 +81,7 @@ class CommentApiController extends ApiController { } /** - * Write a new comment to the db and returns the new comment as array + * Add comment * @NoAdminRequired * @CORS * @NoCSRFRequired @@ -100,7 +100,7 @@ class CommentApiController extends ApiController { } /** - * Delete Comment + * Delete comment * @NoAdminRequired * @CORS * @NoCSRFRequired diff --git a/lib/Controller/CommentController.php b/lib/Controller/CommentController.php index 6f240f05..d68d875e 100644 --- a/lib/Controller/CommentController.php +++ b/lib/Controller/CommentController.php @@ -25,25 +25,24 @@ namespace OCA\Polls\Controller; use Exception; use OCP\AppFramework\Db\DoesNotExistException; +use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; -use OCP\ILogger; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; -use OCA\Polls\Exceptions\NotAuthorizedException; - use OCA\Polls\Service\CommentService; class CommentController extends Controller { + /** @var CommentService */ private $commentService; /** - * CommentController constructor. + * CommentController constructor * @param string $appName * @param IRequest $request * @param CommentService $commentService @@ -58,28 +57,15 @@ class CommentController extends Controller { $this->commentService = $commentService; } - /** - * get - * Read all comments of a poll based on the poll id and return list as array - * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId - * @return DataResponse - */ - public function list($pollId) { - return new DataResponse($this->commentService->list($pollId), Http::STATUS_OK); - } - // /** - // * Read all comments of a poll based on a share token and return list as array + // * Read all comments of a poll based on the poll id and return list as array // * @NoAdminRequired - // * @NoCSRFRequired - // * @PublicPage + // * @param int $pollId // * @param string $token // * @return DataResponse // */ - // public function getByToken($token) { - // return new DataResponse($this->commentService->get(0, $token), Http::STATUS_OK); + // public function list($pollId) { + // return new DataResponse($this->commentService->list($pollId), Http::STATUS_OK); // } // /** diff --git a/lib/Controller/OptionApiController.php b/lib/Controller/OptionApiController.php index e3396a3e..5c3e6f3c 100644 --- a/lib/Controller/OptionApiController.php +++ b/lib/Controller/OptionApiController.php @@ -23,21 +23,21 @@ namespace OCA\Polls\Controller; -use Exception; -use Doctrine\DBAL\Exception\UniqueConstraintViolationException; +use \Exception; +use \Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OCP\AppFramework\Db\DoesNotExistException; use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; + use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; - - use OCA\Polls\Service\OptionService; class OptionApiController extends ApiController { + /** @var OptionService */ private $optionService; /** @@ -65,14 +65,14 @@ class OptionApiController extends ApiController { * @NoAdminRequired * @CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse */ public function list($pollId) { try { return new DataResponse(['options' => $this->optionService->list($pollId)], Http::STATUS_OK); } catch (DoesNotExistException $e) { - return new DataResponse(['error' => 'Poll with id ' . $pollId . ' not found'], Http::STATUS_NOT_FOUND); + return new DataResponse([], Http::STATUS_NOT_FOUND); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } @@ -80,26 +80,18 @@ class OptionApiController extends ApiController { /** - * Add a new Option to poll + * Add a new option * @NoAdminRequired * @CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @param string $pollOptionText - * @param integer $timestamp + * @param int $timestamp * @return DataResponse */ - public function add($pollId, $pollOptionText = '', $timestamp = 0) { - $option = [ - 'pollId' => $pollId, - 'pollOptionText' => $pollOptionText, - 'timestamp' => $timestamp - ]; - + public function add($pollId, $timestamp = 0, $pollOptionText = '') { try { - return new DataResponse(['option' => $this->optionService->add($option)], Http::STATUS_CREATED); - } catch (DoesNotExistException $e) { - return new DataResponse(['error' => 'Poll with id ' . $pollId . ' not found'], Http::STATUS_NOT_FOUND); + return new DataResponse(['option' => $this->optionService->add($pollId, $timestamp, $pollOptionText)], Http::STATUS_CREATED); } catch (UniqueConstraintViolationException $e) { return new DataResponse(['error' => 'Option exists'], Http::STATUS_CONFLICT); } catch (NotAuthorizedException $e) { @@ -109,27 +101,27 @@ class OptionApiController extends ApiController { /** - * Update poll option + * Update option * @NoAdminRequired * @CORS * @NoCSRFRequired * @param array $option * @return DataResponse */ - public function update($option) { + public function update($optionId, $timestamp = 0, $pollOptionText = '') { try { - return new DataResponse(['option' => $this->optionService->update($option)], Http::STATUS_OK); + return new DataResponse(['option' => $this->optionService->update($optionId, $timestamp, $pollOptionText)], Http::STATUS_OK); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } } /** - * Remove a single option + * Delete option * @NoAdminRequired * @CORS * @NoCSRFRequired - * @param integer $optionId + * @param int $optionId * @return DataResponse */ public function delete($optionId) { @@ -141,4 +133,38 @@ class OptionApiController extends ApiController { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } } + + /** + * Switch option confirmation + * @NoAdminRequired + * @CORS + * @NoCSRFRequired + * @param int $optionId + * @return DataResponse + */ + public function confirm($optionId) { + try { + return new DataResponse(['option' => $this->optionService->confirm($optionId)], Http::STATUS_OK); + } catch (DoesNotExistException $e) { + return new DataResponse(['error' => 'Option does not exist'], Http::STATUS_NOT_FOUND); + } catch (NotAuthorizedException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } + } + + /** + * Set order position for option + * @NoAdminRequired + * @CORS + * @NoCSRFRequired + * @param array $option + * @return DataResponse + */ + public function setOrder($optionId, $order) { + try { + return new DataResponse(['option' => $this->optionService->setOrder($optionId, $order)], Http::STATUS_OK); + } catch (NotAuthorizedException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } + } } diff --git a/lib/Controller/OptionController.php b/lib/Controller/OptionController.php index 0ec24092..9fc74889 100644 --- a/lib/Controller/OptionController.php +++ b/lib/Controller/OptionController.php @@ -26,16 +26,15 @@ namespace OCA\Polls\Controller; use Exception; use OCP\IRequest; + use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; - -use OCA\Polls\Exceptions\NotAuthorizedException; - use OCA\Polls\Service\OptionService; class OptionController extends Controller { + /** @var OptionService */ private $optionService; /** @@ -57,70 +56,77 @@ class OptionController extends Controller { /** * Get all options of given poll * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse */ public function list($pollId) { - return new DataResponse($this->optionService->list($pollId), Http::STATUS_OK); + return new DataResponse(['options' => $this->optionService->list($pollId)], Http::STATUS_OK); } + // + // /** + // * Get all options specified by token + // * Read all options of a poll based on a share token and return list as array + // * @NoAdminRequired + // * @PublicPage + // * @param string $token + // * @return DataResponse + // */ + // public function listByToken($token) { + // return new DataResponse($this->optionService->list(0, $token), Http::STATUS_OK); + // } + + + /** - * getByToken - * Read all options of a poll based on a share token and return list as array + * Add a new option * @NoAdminRequired - * @PublicPage - * @NoCSRFRequired - * @param string $token + * @param array $option * @return DataResponse */ - public function getByToken($token) { - return new DataResponse($this->optionService->list(0, $token), Http::STATUS_OK); + public function add($pollId, $timestamp = 0, $pollOptionText = '') { + return new DataResponse(['option' => $this->optionService->add($pollId, $timestamp, $pollOptionText)], Http::STATUS_OK); } /** - * Add a new Option to poll + * Update option * @NoAdminRequired - * @NoCSRFRequired * @param array $option * @return DataResponse */ - public function add($option) { - return new DataResponse($this->optionService->add($option), Http::STATUS_OK); + public function update($optionId, $timestamp, $pollOptionText) { + return new DataResponse(['option' => $this->optionService->update($optionId, $timestamp, $pollOptionText)], Http::STATUS_OK); } /** - * Update poll option + * Delete option * @NoAdminRequired - * @NoCSRFRequired - * @param array $option + * @param Option $option * @return DataResponse */ - public function update($option) { - return new DataResponse($this->optionService->update($option), Http::STATUS_OK); + public function delete($optionId) { + return new DataResponse(['option' => $this->optionService->delete($optionId)], Http::STATUS_OK); } /** - * Remove a single option + * Switch option confirmation * @NoAdminRequired - * @NoCSRFRequired - * @param Option $option + * @param int $optionId * @return DataResponse */ - public function remove($option) { - return new DataResponse($this->optionService->delete($option['id']), Http::STATUS_OK); + public function confirm($optionId) { + return new DataResponse(['option' => $this->optionService->confirm($optionId)], Http::STATUS_OK); } /** - * Set order by order of the given array + * Reorder options * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @param Array $options * @return DataResponse */ public function reorder($pollId, $options) { - return new DataResponse($this->optionService->reorder($pollId, $options), Http::STATUS_OK); + return new DataResponse(['options' => $this->optionService->reorder($pollId, $options)], Http::STATUS_OK); } } diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 71e0a7cd..587a4184 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -37,6 +37,7 @@ use OCP\IURLGenerator; class PageController extends Controller { + /** @var IURLGenerator */ private $urlGenerator; /** diff --git a/lib/Controller/PollApiController.php b/lib/Controller/PollApiController.php index 3c8acc9d..20eb2ea0 100644 --- a/lib/Controller/PollApiController.php +++ b/lib/Controller/PollApiController.php @@ -32,7 +32,6 @@ use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; - use OCP\ILogger; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; @@ -41,35 +40,32 @@ class PollApiController extends ApiController { - private $logger; + + /** @var PollService */ private $pollService; /** - * PollController constructor. + * PollApiController constructor * @param string $appName - * @param $userId * @param IRequest $request - * @param ILogger $logger * @param PollService $pollService */ public function __construct( string $appName, IRequest $request, - ILogger $logger, PollService $pollService ) { parent::__construct($appName, $request); - $this->logger = $logger; $this->pollService = $pollService; } /** - * list + * Get list of polls * @NoAdminRequired - * @NoCSRFRequired * @CORS + * @NoCSRFRequired * @return DataResponse */ @@ -85,11 +81,12 @@ /** - * get + * get poll configuration * @NoAdminRequired + * @CORS * @NoCSRFRequired - * @param integer $pollId - * @return array + * @param int $pollId + * @return DataResponse */ public function get($pollId) { try { @@ -102,9 +99,10 @@ } /** - * write + * Add poll * @NoAdminRequired * @NoCSRFRequired + * @CORS * @param Array $poll * @return DataResponse */ @@ -122,10 +120,12 @@ } /** - * write + * Update poll configuration * @NoAdminRequired + * @CORS * @NoCSRFRequired - * @param Array $poll + * @param int $pollId + * @param array $poll * @return DataResponse */ @@ -146,14 +146,15 @@ } /** - * delete + * Switch deleted status (move to deleted polls) * @NoAdminRequired + * @CORS * @NoCSRFRequired - * @param Array $poll + * @param int $pollId * @return DataResponse */ - public function delete($pollId) { + public function trash($pollId) { try { return new DataResponse(['poll' => $this->pollService->delete($pollId)], Http::STATUS_OK); } catch (DoesNotExistException $e) { @@ -164,14 +165,15 @@ } /** - * deletePermanently + * Delete poll * @NoAdminRequired + * @CORS * @NoCSRFRequired - * @param Array $poll + * @param int $pollId * @return DataResponse */ - public function deletePermanently($pollId) { + public function delete($pollId) { try { return new DataResponse(['poll' => $this->pollService->deletePermanently($pollId)], Http::STATUS_OK); } catch (DoesNotExistException $e) { @@ -183,10 +185,11 @@ } /** - * clone + * Clone poll * @NoAdminRequired + * @CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse */ public function clone($pollId) { @@ -200,8 +203,9 @@ } /** - * enum + * Get valid values for configuration options * @NoAdminRequired + * @CORS * @NoCSRFRequired * @param Array $poll * @return DataResponse diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php index 27f9c4be..d1b4945b 100644 --- a/lib/Controller/PollController.php +++ b/lib/Controller/PollController.php @@ -21,7 +21,7 @@ * */ - namespace OCA\Polls\Controller; +namespace OCA\Polls\Controller; use Exception; use OCP\AppFramework\Db\DoesNotExistException; @@ -32,7 +32,6 @@ use OCA\Polls\Exceptions\InvalidPollTypeException; use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; -use OCP\ILogger; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; @@ -46,31 +45,39 @@ use OCA\Polls\Model\Acl; class PollController extends Controller { - private $logger; + /** @var PollService */ private $pollService; + + /** @var CommentService */ private $commentService; + + /** @var OptionService */ private $optionService; + + /** @var ShareService */ private $shareService; + + /** @var VoteService */ private $voteService; + + /** @var Acl */ private $acl; /** * PollController constructor. * @param string $appName * @param IRequest $request - * @param ILogger $logger * @param PollService $pollService - * @param CommentService $commentService - * @param OptionService $optionService - * @param ShareService $shareService - * @param VoteService $voteService - * @param Acl $acl - */ + * @param CommentService $commentService + * @param OptionService $optionService + * @param ShareService $shareService + * @param VoteService $voteService + * @param Acl $acl + */ public function __construct( string $appName, IRequest $request, - ILogger $logger, PollService $pollService, CommentService $commentService, OptionService $optionService, @@ -79,7 +86,6 @@ class PollController extends Controller { Acl $acl ) { parent::__construct($appName, $request); - $this->logger = $logger; $this->pollService = $pollService; $this->commentService = $commentService; $this->optionService = $optionService; @@ -90,9 +96,8 @@ class PollController extends Controller { /** - * list + * Get list of polls * @NoAdminRequired - * @NoCSRFRequired * @return DataResponse */ @@ -108,12 +113,12 @@ class PollController extends Controller { /** - * get + * get complete poll * @NoAdminRequired - * @NoCSRFRequired * @PublicPage - * @param integer $pollId - * @return array + * @param int $pollId + * @param string $token + * @return DataResponse */ public function get($pollId, $token) { try { @@ -125,8 +130,6 @@ class PollController extends Controller { $acl = $this->acl->setPollId($pollId); } - // $this->poll = $this->pollService->get($pollId, $token); - // return new DataResponse($this->pollService->get($pollId, $token), Http::STATUS_OK); } catch (DoesNotExistException $e) { return new DataResponse(['error' => 'Not found'], Http::STATUS_NOT_FOUND); } catch (NotAuthorizedException $e) { @@ -134,25 +137,25 @@ class PollController extends Controller { } try { - $comments = $this->commentService->list($this->acl->getPollId(), $token); + $comments = $this->commentService->list($poll->getId(), $token); } catch (Exception $e) { $comments = []; } try { - $options = $this->optionService->list($this->acl->getPollId(), $token); + $options = $this->optionService->list($poll->getId(), $token); } catch (Exception $e) { $options = []; } try { - $votes = $this->voteService->list($this->acl->getPollId(), $token); + $votes = $this->voteService->list($poll->getId(), $token); } catch (Exception $e) { $votes = []; } try { - $shares = $this->shareService->list($this->acl->getPollId()); + $shares = $this->shareService->list($poll->getId()); } catch (Exception $e) { $shares = []; } @@ -168,98 +171,95 @@ class PollController extends Controller { } /** - * delete + * Add poll * @NoAdminRequired - * @NoCSRFRequired - * @param Array $poll + * @param string $type + * @param string $title * @return DataResponse */ - public function delete($pollId) { + public function add($type, $title) { try { - return new DataResponse($this->pollService->delete($pollId), Http::STATUS_OK); - } catch (DoesNotExistException $e) { - return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND); + return new DataResponse($this->pollService->add($type, $title), Http::STATUS_OK); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (InvalidPollTypeException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (EmptyTitleException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } } /** - * deletePermanently + * Update poll configuration * @NoAdminRequired - * @NoCSRFRequired - * @param Array $poll + * @param int $pollId + * @param array $poll * @return DataResponse */ - public function deletePermanently($pollId) { + public function update($pollId, $poll) { try { - return new DataResponse($this->pollService->deletePermanently($pollId), Http::STATUS_OK); + return new DataResponse($this->pollService->update($pollId, $poll), Http::STATUS_OK); } catch (DoesNotExistException $e) { return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (InvalidAccessException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (InvalidShowResultsException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (EmptyTitleException $e) { + return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } } - /** - * add + * Switch deleted status (move to deleted polls) * @NoAdminRequired - * @NoCSRFRequired - * @param string $type - * @param string $title + * @param int $pollId * @return DataResponse */ - public function add($type, $title) { + public function delete($pollId) { try { - return new DataResponse($this->pollService->add($type, $title), Http::STATUS_OK); + return new DataResponse($this->pollService->delete($pollId), Http::STATUS_OK); + } catch (DoesNotExistException $e) { + return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); - } catch (InvalidPollTypeException $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); - } catch (EmptyTitleException $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } } /** - * write + * Delete poll * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId - * @param array $poll + * @param Array $poll * @return DataResponse */ - public function update($pollId, $poll) { + public function deletePermanently($pollId) { try { - return new DataResponse($this->pollService->update($pollId, $poll), Http::STATUS_OK); + return new DataResponse($this->pollService->deletePermanently($pollId), Http::STATUS_OK); } catch (DoesNotExistException $e) { return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); - } catch (InvalidAccessException $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); - } catch (InvalidShowResultsException $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); - } catch (EmptyTitleException $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } } /** - * clone + * Clone poll * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse */ public function clone($pollId) { try { - return new DataResponse($this->pollService->clone($pollId), Http::STATUS_OK); + $poll = $this->pollService->clone($pollId); + $this->optionService->clone($pollId, $poll->getId()); + + return new DataResponse($poll, Http::STATUS_OK); } catch (DoesNotExistException $e) { return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND); } catch (NotAuthorizedException $e) { diff --git a/lib/Controller/ShareApiController.php b/lib/Controller/ShareApiController.php index 3d7912da..57c65033 100644 --- a/lib/Controller/ShareApiController.php +++ b/lib/Controller/ShareApiController.php @@ -28,7 +28,6 @@ use OCP\AppFramework\Db\DoesNotExistException; use OCA\Polls\Exceptions\NotAuthorizedException; use OCA\Polls\Exceptions\InvalidUsername; - use OCP\IRequest; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; @@ -39,13 +38,15 @@ use OCA\Polls\Service\MailService; class ShareApiController extends ApiController { + /** @var ShareService */ private $shareService; + + /** @var MailService */ private $mailService; /** - * ShareController constructor. + * ShareApiController constructor * @param string $appName - * @param string $userId * @param IRequest $request * @param MailService $mailService * @param ShareService $shareService @@ -59,19 +60,18 @@ class ShareApiController extends ApiController { parent::__construct($appName, $request, 'POST, PUT, GET, DELETE', - 'Authorization, Content-Type, Accept', - 1728000); + 'Authorization, Content-Type, Accept', + 1728000); $this->shareService = $shareService; $this->mailService = $mailService; } /** - * list * Read all shares of a poll based on the poll id and return list as array * @NoAdminRequired * @CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse */ public function list($pollId) { @@ -85,14 +85,13 @@ class ShareApiController extends ApiController { } /** - * get share by token - * Get pollId by token - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * @param string $token - * @return DataResponse - */ + * Get share by token + * @NoAdminRequired + * @CORS + * @NoCSRFRequired + * @param string $token + * @return DataResponse + */ public function get($token) { try { return new DataResponse(['share' => $this->shareService->get($token)], Http::STATUS_OK); @@ -104,7 +103,7 @@ class ShareApiController extends ApiController { } /** - * Write a new share to the db and returns the new share as array + * Add share * @NoAdminRequired * @CORS * @NoCSRFRequired @@ -117,47 +116,46 @@ class ShareApiController extends ApiController { public function add($pollId, $type, $userId = '', $userEmail = '') { try { return new DataResponse(['share' => $this->shareService->add($pollId, $type, $userId, $userEmail)], Http::STATUS_CREATED); - } catch (\Exception $e) { - return new DataResponse(['error' => $e], Http::STATUS_CONFLICT); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (Exception $e) { + return new DataResponse(['error' => $e], Http::STATUS_CONFLICT); } } /** - * SendInvitation - * Sent invitation mails for a share + * Delete share * @NoAdminRequired * @CORS * @NoCSRFRequired * @param string $token * @return DataResponse */ - public function sendInvitation($token) { + + public function delete($token) { try { - return new DataResponse($this->mailService->sendInvitationMail($token), Http::STATUS_OK); - } catch (Exception $e) { + return new DataResponse(['share' => $this->shareService->delete($token)], Http::STATUS_OK); + } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (DoesNotExistException $e) { + return new DataResponse($e, Http::STATUS_NOT_FOUND); } } /** - * delete share + * Sent invitation mails for a share * @NoAdminRequired * @CORS * @NoCSRFRequired * @param string $token * @return DataResponse */ - - public function delete($token) { + public function sendInvitation($token) { try { - return new DataResponse(['share' => $this->shareService->remove($token)], Http::STATUS_OK); - } catch (NotAuthorizedException $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + return new DataResponse($this->mailService->sendInvitationMail($token), Http::STATUS_OK); } catch (Exception $e) { - return new DataResponse($e, Http::STATUS_NOT_FOUND); + return new DataResponse(['error' => $e], Http::STATUS_CONFLICT); } } } diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php index bd3dd187..4810ed23 100644 --- a/lib/Controller/ShareController.php +++ b/lib/Controller/ShareController.php @@ -30,54 +30,47 @@ use OCA\Polls\Exceptions\InvalidUsername; use OCP\IRequest; -use OCP\ILogger; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; - - -use OCA\Polls\Model\Acl; use OCA\Polls\Service\ShareService; use OCA\Polls\Service\MailService; class ShareController extends Controller { - private $logger; + /** @var ShareService */ private $shareService; + + /** @var MailService */ private $mailService; - private $userId; /** * ShareController constructor. * @param string $appName - * @param string $userId * @param IRequest $request - * @param ILogger $logger * @param MailService $mailService * @param ShareService $shareService */ public function __construct( string $appName, - $userId, IRequest $request, - ILogger $logger, MailService $mailService, ShareService $shareService ) { parent::__construct($appName, $request); - $this->logger = $logger; - $this->userId = $userId; $this->shareService = $shareService; $this->mailService = $mailService; } /** - * Write a new share to the db and returns the new share as array + * Add share * @NoAdminRequired - * @NoCSRFRequired * @param int $pollId - * @param Array $share + * @param int $pollId + * @param string $type + * @param string $userId + * @param string $userEmail * @return DataResponse */ public function add($pollId, $type, $userId = '', $userEmail = '') { @@ -91,19 +84,18 @@ class ShareController extends Controller { } /** - * createPersonalShare - * Write a new share to the db and returns the new share as array + * Create a personal share from a public share + * or update an email share with the username * @NoAdminRequired * @PublicPage - * @NoCSRFRequired * @param string $token * @param string $userName * @return DataResponse */ - public function createPersonalShare($token, $userName) { + public function personal($token, $userName) { try { - return new DataResponse($this->shareService->createPersonalShare($token, $userName), Http::STATUS_CREATED); + return new DataResponse($this->shareService->personal($token, $userName), Http::STATUS_CREATED); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } catch (InvalidUsername $e) { @@ -115,43 +107,36 @@ class ShareController extends Controller { } /** - * SendInvitation - * Sent invitation mails for a share + * Delete share * @NoAdminRequired - * @PublicPage - * @NoCSRFRequired * @param string $token * @return DataResponse */ - public function sendInvitation($token) { + + public function delete($token) { try { - $sentResult = $this->mailService->sendInvitationMail($token); - $share = $this->shareService->get($token); - return new DataResponse(['share' => $share, 'sentResult' => $sentResult], Http::STATUS_OK); - } catch (Exception $e) { + return new DataResponse($this->shareService->delete($token), Http::STATUS_OK); + } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + } catch (Exception $e) { + return new DataResponse($e, Http::STATUS_NOT_FOUND); } } /** - * remove - * remove share + * Sent invitation mails for a share * @NoAdminRequired - * @NoCSRFRequired - * @param Share $share + * @PublicPage + * @param string $token * @return DataResponse */ - - public function delete($share) { + public function sendInvitation($token) { try { - return new DataResponse(array( - 'action' => 'deleted', - 'shareId' => $this->shareService->remove($share['token'])->getId() - ), Http::STATUS_OK); - } catch (NotAuthorizedException $e) { - return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); + $sentResult = $this->mailService->sendInvitationMail($token); + $share = $this->shareService->get($token); + return new DataResponse(['share' => $share, 'sentResult' => $sentResult], Http::STATUS_OK); } catch (Exception $e) { - return new DataResponse($e, Http::STATUS_NOT_FOUND); + return new DataResponse(['error' => $e], Http::STATUS_CONFLICT); } } } diff --git a/lib/Controller/SubscriptionApiController.php b/lib/Controller/SubscriptionApiController.php index 3a23d403..b8a87d16 100644 --- a/lib/Controller/SubscriptionApiController.php +++ b/lib/Controller/SubscriptionApiController.php @@ -28,7 +28,6 @@ use OCP\AppFramework\Db\DoesNotExistException; use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; -use OCP\ILogger; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; @@ -38,43 +37,39 @@ use OCA\Polls\Service\SubscriptionService; class SubscriptionApiController extends ApiController { - private $userId; + /** @var SubscriptionService */ private $subscriptionService; - private $logger; /** - * SubscriptionController constructor. + * SubscriptionApiController constructor * @param string $appName - * @param $UserId * @param SubscriptionService $subscriptionService * @param IRequest $request - * @param ILogger $logger */ public function __construct( string $appName, - $userId, SubscriptionService $subscriptionService, - IRequest $request, - ILogger $logger + IRequest $request ) { parent::__construct($appName, $request, 'PUT, GET, DELETE', - 'Authorization, Content-Type, Accept', - 1728000); - $this->userId = $userId; + 'Authorization, Content-Type, Accept', + 1728000); $this->subscriptionService = $subscriptionService; - $this->logger = $logger; } /** + * Get subscription status * @NoAdminRequired * CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse + * @throws DoesNotExistException + * @throws NotAuthorizedException */ public function get($pollId) { try { @@ -88,10 +83,12 @@ class SubscriptionApiController extends ApiController { } /** + * Subscribe to poll * @NoAdminRequired * @CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId + * @throws NotAuthorizedException */ public function subscribe($pollId) { try { @@ -102,10 +99,12 @@ class SubscriptionApiController extends ApiController { } } /** + * Unsubscribe from poll * @NoAdminRequired * @CORS * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId + * @throws NotAuthorizedException */ public function unsubscribe($pollId) { try { diff --git a/lib/Controller/SubscriptionController.php b/lib/Controller/SubscriptionController.php index e90f4a66..f2517237 100644 --- a/lib/Controller/SubscriptionController.php +++ b/lib/Controller/SubscriptionController.php @@ -28,7 +28,6 @@ use OCP\AppFramework\Db\DoesNotExistException; use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; -use OCP\ILogger; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; @@ -37,38 +36,32 @@ use OCA\Polls\Service\SubscriptionService; class SubscriptionController extends Controller { - private $userId; + /** @var SubscriptionService */ private $subscriptionService; - private $logger; /** * SubscriptionController constructor. * @param string $appName - * @param $UserId * @param SubscriptionService $subscriptionService * @param IRequest $request - * @param ILogger $logger */ public function __construct( string $appName, - $userId, SubscriptionService $subscriptionService, - IRequest $request, - ILogger $logger - + IRequest $request ) { parent::__construct($appName, $request); - $this->userId = $userId; $this->subscriptionService = $subscriptionService; - $this->logger = $logger; } /** + * Get subscription status * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse + * @throws DoesNotExistException + * @throws NotAuthorizedException */ public function get($pollId) { try { @@ -81,9 +74,12 @@ class SubscriptionController extends Controller { } /** + * Switch subscription status * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId + * @param int $subscribed + * @return DataResponse + * @throws NotAuthorizedException */ public function set($pollId, $subscribed) { try { diff --git a/lib/Controller/SystemController.php b/lib/Controller/SystemController.php index d4c15963..67b9bbc2 100644 --- a/lib/Controller/SystemController.php +++ b/lib/Controller/SystemController.php @@ -36,16 +36,25 @@ use OCA\Polls\Db\Share; use OCA\Polls\Db\ShareMapper; use OCA\Polls\Db\Vote; use OCA\Polls\Db\VoteMapper; -use OCP\ILogger; class SystemController extends Controller { + /** @var string */ private $userId; - private $logger; + + /** @var IConfig */ private $systemConfig; + + /** @var IGroupManager */ private $groupManager; + + /** @var IUserManager */ private $userManager; + + /** @var VoteMapper */ private $voteMapper; + + /** @var ShareMapper */ private $shareMapper; /** @@ -53,7 +62,6 @@ class SystemController extends Controller { * @param string $appName * @param $userId * @param IRequest $request - * @param ILogger $logger * @param IConfig $systemConfig * @param IGroupManager $groupManager * @param IUserManager $userManager @@ -64,7 +72,6 @@ class SystemController extends Controller { string $appName, $userId, IRequest $request, - ILogger $logger, IConfig $systemConfig, IGroupManager $groupManager, IUserManager $userManager, @@ -74,7 +81,6 @@ class SystemController extends Controller { parent::__construct($appName, $request); $this->voteMapper = $voteMapper; $this->shareMapper = $shareMapper; - $this->logger = $logger; $this->userId = $userId; $this->systemConfig = $systemConfig; $this->groupManager = $groupManager; @@ -85,7 +91,7 @@ class SystemController extends Controller { * Validate string as email address * @NoAdminRequired * @param string $query - * @return Boolean + * @return bool */ private function isValidEmail($email) { return (!preg_match('/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/', $email)) ? false : true; @@ -202,7 +208,6 @@ class SystemController extends Controller { } } - } return new DataResponse([ @@ -298,13 +303,13 @@ class SystemController extends Controller { ], Http::STATUS_OK); } - public function getDisplayName() { - $this->userManager = \OC::$server->getUserManager(); - - if (\OC::$server->getUserManager()->get($this->userId) instanceof IUser) { - return \OC::$server->getUserManager()->get($this->userId)->getDisplayName(); - } else { - return $this->userId; - } - } + // public function getDisplayName() { + // $this->userManager = \OC::$server->getUserManager(); + // + // if (\OC::$server->getUserManager()->get($this->userId) instanceof IUser) { + // return \OC::$server->getUserManager()->get($this->userId)->getDisplayName(); + // } else { + // return $this->userId; + // } + // } } diff --git a/lib/Controller/VoteApiController.php b/lib/Controller/VoteApiController.php index 21d7762d..28b1eded 100644 --- a/lib/Controller/VoteApiController.php +++ b/lib/Controller/VoteApiController.php @@ -28,7 +28,6 @@ use OCP\AppFramework\Db\DoesNotExistException; use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\IRequest; -use OCP\ILogger; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; @@ -37,38 +36,34 @@ use OCA\Polls\Service\VoteService; class VoteApiController extends ApiController { - private $logger; + /** @var VoteService */ private $voteService; /** - * VoteController constructor. + * VoteAPIController constructor * @param string $appName * @param IRequest $request - * @param ILogger $logger * @param VoteService $voteService */ public function __construct( string $appName, IRequest $request, - ILogger $logger, VoteService $voteService ) { parent::__construct($appName, $request, 'PUT, GET, DELETE', - 'Authorization, Content-Type, Accept', - 1728000); + 'Authorization, Content-Type, Accept', + 1728000); $this->voteService = $voteService; - $this->logger = $logger; } /** - * Get all votes of given poll * Read all votes of a poll based on the poll id and return list as array * @NoAdminRequired - * @NoCSRFRequired * @CORS - * @param integer $pollId + * @NoCSRFRequired + * @param int $pollId * @return DataResponse */ public function list($pollId) { @@ -82,21 +77,19 @@ class VoteApiController extends ApiController { } /** - * set + * Set vote answer * @NoAdminRequired - * @NoCSRFRequired * @CORS - * @param integer $pollId - * @param Array $option - * @param string $userId + * @NoCSRFRequired + * @param int $optionId * @param string $setTo * @return DataResponse */ - public function set($pollId, $pollOptionText, $setTo) { + public function set($optionId, $setTo) { try { - return new DataResponse(['vote' => $this->voteService->set($pollId, $pollOptionText, $setTo)], Http::STATUS_OK); + return new DataResponse(['vote' => $this->voteService->set($optionId, $setTo)], Http::STATUS_OK); } catch (DoesNotExistException $e) { - return new DataResponse(['error' => 'Option not found'], Http::STATUS_NOT_FOUND); + return new DataResponse(['error' => 'Option or poll not found'], Http::STATUS_NOT_FOUND); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } diff --git a/lib/Controller/VoteController.php b/lib/Controller/VoteController.php index f666c004..32fc89a2 100644 --- a/lib/Controller/VoteController.php +++ b/lib/Controller/VoteController.php @@ -27,7 +27,6 @@ namespace OCA\Polls\Controller; use OCP\AppFramework\Db\DoesNotExistException; use OCA\Polls\Exceptions\NotAuthorizedException; -use OCP\ILogger; use OCP\IRequest; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; @@ -38,34 +37,28 @@ use OCA\Polls\Service\VoteService; class VoteController extends Controller { + /** @var VoteService */ private $voteService; - private $logger; /** - * VoteController constructor. + * VoteController constructor * @param string $appName * @param IRequest $request - * @param ILogger $logger * @param VoteService $voteService - */ public function __construct( string $appName, - ILogger $logger, IRequest $request, VoteService $voteService ) { parent::__construct($appName, $request); - $this->logger = $logger; $this->voteService = $voteService; } /** - * Get all votes of given poll * Read all votes of a poll based on the poll id and return list as array * @NoAdminRequired - * @NoCSRFRequired - * @param integer $pollId + * @param int $pollId * @return DataResponse */ public function get($pollId) { @@ -82,33 +75,28 @@ class VoteController extends Controller { * set * @NoAdminRequired * @NoCSRFRequired - * @param integer $pollId - * @param Array $option - * @param string $userId + * @param int $optionId * @param string $setTo * @return DataResponse */ - public function set($pollId, $option, $setTo) { + public function set($optionId, $setTo) { try { - return new DataResponse($this->voteService->set($pollId, $option['pollOptionText'], $setTo), Http::STATUS_OK); + return new DataResponse($this->voteService->set($optionId, $setTo), Http::STATUS_OK); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } catch (DoesNotExistException $e) { - return new DataResponse(['error' => 'Option not found'], Http::STATUS_NOT_FOUND); + return new DataResponse(['error' => 'Option or poll not found'], Http::STATUS_NOT_FOUND); } } - /** - * delete + * Remove user from poll * @NoAdminRequired - * @NoCSRFRequired - * @param integer $voteId * @param string $userId - * @param integer $pollId + * @param int $pollId * @return DataResponse */ - public function delete($userId, $pollId) { + public function delete($pollId, $userId) { try { return new DataResponse($this->voteService->delete($pollId, $userId), Http::STATUS_OK); } catch (NotAuthorizedException $e) { @@ -123,18 +111,17 @@ class VoteController extends Controller { */ /** - * setByToken + * Set vote with token * @NoAdminRequired * @PublicPage - * @NoCSRFRequired * @param Array $option * @param string $setTo * @param string $token * @return DataResponse */ - public function setByToken($option, $setTo, $token) { + public function setByToken($optionId, $setTo, $token) { try { - return new DataResponse($this->voteService->set(0, $option['pollOptionText'], $setTo, $token), Http::STATUS_OK); + return new DataResponse($this->voteService->set($optionId, $setTo, $token), Http::STATUS_OK); } catch (NotAuthorizedException $e) { return new DataResponse(['error' => $e->getMessage()], $e->getStatus()); } catch (DoesNotExistException $e) { @@ -144,11 +131,9 @@ class VoteController extends Controller { } /** - * getByToken * Read all votes of a poll based on a share token and return list as array * @NoAdminRequired * @PublicPage - * @NoCSRFRequired * @param string $token * @return DataResponse */ |