diff options
author | dartcafe <github@dartcafe.de> | 2020-06-21 19:55:23 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2020-06-21 19:55:23 +0300 |
commit | 0d632d59b202f55da389db28b870b8c64416c00f (patch) | |
tree | 36d282c7642fd6a3da1d9cbb445939e72aa10b56 /lib/Service | |
parent | 9f98851cf5fc5a1bc6811c9d432e8c0464b9763d (diff) |
fixes and some code polish
Diffstat (limited to 'lib/Service')
-rw-r--r-- | lib/Service/CommentService.php | 38 | ||||
-rw-r--r-- | lib/Service/OptionService.php | 49 | ||||
-rw-r--r-- | lib/Service/PollService.php | 216 | ||||
-rw-r--r-- | lib/Service/ShareService.php | 44 | ||||
-rw-r--r-- | lib/Service/VoteService.php | 47 |
5 files changed, 177 insertions, 217 deletions
diff --git a/lib/Service/CommentService.php b/lib/Service/CommentService.php index 6a2b6d1d..8ae7ef1e 100644 --- a/lib/Service/CommentService.php +++ b/lib/Service/CommentService.php @@ -24,16 +24,11 @@ namespace OCA\Polls\Service; use \Exception; - -use OCP\IGroupManager; use OCP\ILogger; use OCA\Polls\Exceptions\NotAuthorizedException; - use OCA\Polls\Db\Comment; use OCA\Polls\Db\CommentMapper; -use OCA\Polls\Db\Poll; -use OCA\Polls\Db\PollMapper; use OCA\Polls\Model\Acl; use OCA\Polls\Service\AnonymizeService; @@ -41,41 +36,30 @@ use OCA\Polls\Service\AnonymizeService; class CommentService { - private $userId; private $comment; private $commentMapper; private $logger; - private $groupManager; - private $pollMapper; private $anonymizer; private $acl; /** * CommentService constructor. - * @param string $appName - * @param $UserId + * @param ILogger $logger * @param CommentMapper $commentMapper - * @param IGroupManager $groupManager - * @param PollMapper $pollMapper + * @param Comment $comment * @param AnonymizeService $anonymizer * @param Acl $acl */ public function __construct( - string $appName, - $userId, ILogger $logger, CommentMapper $commentMapper, - IGroupManager $groupManager, - PollMapper $pollMapper, + Comment $comment, AnonymizeService $anonymizer, Acl $acl ) { - $this->userId = $userId; $this->commentMapper = $commentMapper; $this->logger = $logger; - $this->groupManager = $groupManager; - $this->pollMapper = $pollMapper; $this->anonymizer = $anonymizer; $this->acl = $acl; } @@ -89,9 +73,8 @@ class CommentService { * @return Array */ public function list($pollId = 0, $token = '') { - $this->logger->debug('call commentService->get(' . $pollId . ', '. $token . ')'); - if (!$this->acl->checkAuthorize($pollId, $token)) { + if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowView()) { throw new NotAuthorizedException; } @@ -101,8 +84,6 @@ class CommentService { } else { return $this->commentMapper->findByPoll($this->acl->getPollId()); } - - } /** @@ -114,9 +95,8 @@ class CommentService { * @return Comment */ public function add($pollId = 0, $message, $token = '') { - $this->logger->debug('call commentService->write("' . $message . '", ' .$pollId . ', "' .$token . '")'); - if (!$this->acl->checkAuthorize($pollId, $token)) { + if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowComment()) { throw new NotAuthorizedException; } @@ -137,6 +117,7 @@ class CommentService { $this->logger->alert('Error writing comment for pollId ' . $pollId . ': '. $e); throw new NotAuthorizedException($e); } + } /** @@ -148,14 +129,13 @@ class CommentService { * @return Comment */ public function delete($commentId, $token = '') { - - $this->logger->debug('call commentService->delete(' . $commentId . ', "' .$token . '")'); $this->comment = $this->commentMapper->find($commentId); - if (!$this->acl->checkAuthorize($this->comment->getPollId(), $token) || $this->comment->getUserId() !== $this->acl->getUserId()) { + + if ($this->acl->setPollIdOrToken($this->comment->getPollId(), $token)->getUserId() !== $this->acl->getUserId()) { throw new NotAuthorizedException; } - $this->commentMapper->delete($this->comment); + $this->commentMapper->delete($this->comment); return $this->comment; } diff --git a/lib/Service/OptionService.php b/lib/Service/OptionService.php index e7f485aa..139c8267 100644 --- a/lib/Service/OptionService.php +++ b/lib/Service/OptionService.php @@ -23,15 +23,9 @@ namespace OCA\Polls\Service; -use \Exception; - -use OCP\IGroupManager; -use OCP\ILogger; +use Exception; use OCA\Polls\Exceptions\NotAuthorizedException; - -use OCA\Polls\Db\Poll; -use OCA\Polls\Db\PollMapper; use OCA\Polls\Db\Option; use OCA\Polls\Db\OptionMapper; use OCA\Polls\Service\LogService; @@ -39,45 +33,28 @@ use OCA\Polls\Model\Acl; class OptionService { - private $userId; private $optionMapper; private $options; private $option; - private $groupManager; - private $pollMapper; - private $logger; private $logService; private $acl; /** * OptionController constructor. - * @param string $appName - * @param $userId - * @param ILogger $logger * @param OptionMapper $optionMapper - * @param IGroupManager $groupManager - * @param PollMapper $pollMapper + * @param Option $option * @param LogService $logService * @param Acl $acl */ public function __construct( - string $appName, - $userId, OptionMapper $optionMapper, Option $option, - IGroupManager $groupManager, - PollMapper $pollMapper, - ILogger $logger, LogService $logService, Acl $acl ) { - $this->userId = $userId; $this->optionMapper = $optionMapper; $this->option = $option; - $this->groupManager = $groupManager; - $this->pollMapper = $pollMapper; - $this->logger = $logger; $this->logService = $logService; $this->acl = $acl; } @@ -117,13 +94,13 @@ class OptionService { * @return array Array of Option objects */ public function list($pollId = 0, $token = '') { - $this->logger->debug('call optionService->list(' . $pollId . ', '. $token . ')'); - if (!$this->acl->checkAuthorize($pollId, $token)) { + if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowView()) { throw new NotAuthorizedException; } return $this->optionMapper->findByPoll($pollId); + } @@ -134,15 +111,16 @@ class OptionService { * @return Option */ public function add($option) { - $this->logger->debug('call optionService->add(' . json_encode($option) . ')'); if (!$this->acl->setPollId($option['pollId'])->getAllowEdit()) { throw new NotAuthorizedException; } + $this->option = new Option(); $this->set($option); $this->optionMapper->insert($this->option); $this->logService->setLog($option['pollId'], 'addOption'); + return $this->option; } @@ -153,9 +131,8 @@ class OptionService { * @return array Array of Option objects */ public function delete($optionId) { - $this->logger->debug('call optionService->delete(' . json_encode($optionId) . ')'); - $this->option = $this->optionMapper->find($optionId); + if (!$this->acl->setPollId($this->option->getPollId())->getAllowEdit()) { throw new NotAuthorizedException; } @@ -163,6 +140,7 @@ class OptionService { $this->optionMapper->delete($this->option); return $this->option; + } /** @@ -172,8 +150,6 @@ class OptionService { * @return Option */ public function update($option) { - $this->logger->debug('call optionService->update(' . json_encode($option) . ')'); - if (!$this->acl->setPollId($option['pollId'])->getAllowEdit()) { throw new NotAuthorizedException; } @@ -183,10 +159,12 @@ class OptionService { $this->set($option); $this->optionMapper->update($this->option); $this->logService->setLog($option['pollId'], 'updateOption'); + return $this->option; } catch (Exception $e) { return new DoesNotExistException($e); } + } /** @@ -196,7 +174,6 @@ class OptionService { * @return array Array of Option objects */ public function reorder($pollId, $options) { - $this->logger->debug('call optionService->reorder(' . $pollId . ', ' . json_encode($options) . ')'); if (!$this->acl->setPollId($pollId)->getAllowEdit()) { throw new NotAuthorizedException; @@ -211,7 +188,7 @@ class OptionService { } } - return $this->get($pollId); + return $this->optionMapper->findByPoll($pollId); } @@ -223,6 +200,10 @@ class OptionService { */ public function clone($fromPollId, $toPollId) { + if (!$this->acl->setPollId($fromPollId)->getAllowView()) { + throw new NotAuthorizedException; + } + foreach ($this->optionMapper->findByPoll($fromPollId) as $option) { $option->setPollId($toPollId); $this->optionMapper->insert($option); diff --git a/lib/Service/PollService.php b/lib/Service/PollService.php index ecf35b18..e747450d 100644 --- a/lib/Service/PollService.php +++ b/lib/Service/PollService.php @@ -125,20 +125,46 @@ * @return array */ public function get($pollId = 0, $token = '') { - $this->poll = $this->pollMapper->find($pollId); - if (!$this->acl->checkAuthorize($pollId, $token) && !$this->acl->getAllowView()) { + + if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowView()) { throw new NotAuthorizedException; } + $this->poll = $this->pollMapper->find($this->acl->getPollId()); + + try { + $comments = $this->commentService->list($this->poll->getId(), $token); + } catch (Exception $e) { + $comments = []; + } + + try { + $options = $this->optionService->list($this->poll->getId(), $token); + } catch (Exception $e) { + $options = []; + + } + + try { + $votes = $this->voteService->list($this->poll->getId(), $token); + } catch (Exception $e) { + $votes = []; + } + + try { + $shares = $this->shareService->list($this->poll->getId()); + } catch (Exception $e) { + $shares = []; + } + return [ 'acl' => $this->acl, 'poll' => $this->poll, - 'comments' => $this->commentService->list($pollId, $token), - 'options' => $this->optionService->list($pollId, $token), - 'shares' => $this->shareService->list($pollId, $token), - 'votes' => $this->voteService->list($pollId, $token) + 'comments' => $comments, + 'options' => $options, + 'shares' => $shares, + 'votes' => $votes ]; - } /** @@ -155,6 +181,7 @@ if (!$this->acl->setPollId($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } + if ($this->poll->getDeleted()) { $this->poll->setDeleted(0); } else { @@ -163,6 +190,7 @@ $this->poll = $this->pollMapper->update($this->poll); $this->logService->setLog($this->poll->getId(), 'deletePoll'); + return $this->poll; } @@ -180,8 +208,8 @@ if (!$this->acl->setPollId($pollId)->getAllowEdit() || !$this->poll->getDeleted()) { throw new NotAuthorizedException; } + return $this->pollMapper->delete($this->poll); - // return $this->poll; } /** @@ -196,8 +224,6 @@ if (!\OC::$server->getUserSession()->isLoggedIn()) { throw new NotAuthorizedException; } - $this->logger->alert(json_encode($type)); - $this->logger->alert(json_encode($title)); // Validate valuess if (!in_array($type, $this->getValidPollType())) { @@ -228,95 +254,94 @@ $this->poll = $this->pollMapper->insert($this->poll); $this->logService->setLog($this->poll->getId(), 'addPoll'); - $this->logger->alert(json_encode($this->poll)); return $this->poll; } - /** - * write - * @NoAdminRequired - * @NoCSRFRequired - * @depricated - * @param Array $poll - * @return DataResponse - */ - - public function write($poll, $pollId = null) { - - if (!$pollId) { - $pollId = $poll['id']; - } - - // Validate valuess - if (isset($poll['showResults']) && !in_array($poll['showResults'], $this->getValidShowResults())) { - throw new InvalidShowResultsException('Invalid value for prop showResults'); - } - - if (isset($poll['access']) && !in_array($poll['access'], $this->getValidShowResults())) { - throw new InvalidAccessException('Invalid value for prop access'); - } - - if (isset($poll['title']) && !$poll['title']) { - throw new EmptyTitleException('Title must not be empty'); - } - - try { - // find pollId - $this->poll = $this->pollMapper->find($pollId); - $this->logService->setLog($this->poll->getId(), 'updatePoll'); - - - } catch (DoesNotExistException $e) { - // if not found create a new poll - - // Validate valuess - if (!in_array($poll['type'], $this->getValidPollType())) { - throw new InvalidPollTypeException('Invalid poll type'); - } - - if (!$poll['title']) { - throw new EmptyTitleException('Title must not be empty'); - } - - - $this->poll = new Poll(); - $this->poll->setType($poll['type']); - $this->poll->setOwner($this->userId); - $this->poll->setTitle($poll['title']); - $this->poll->setCreated(time()); - $this->poll = $this->pollMapper->insert($this->poll); - - $this->logService->setLog($this->poll->getId(), 'addPoll'); - } - - if (!$this->acl->setPollId($this->poll->getId())->getAllowEdit()) { - throw new NotAuthorizedException; - } - - $this->poll->setTitle(isset($poll['title']) ? $poll['title'] : $this->poll->getTitle()); - $this->poll->setDescription(isset($poll['description']) ? $poll['description'] : $this->poll->getDescription()); - $this->poll->setAccess(isset($poll['access']) ? $poll['access'] : $this->poll->getAccess()); - $this->poll->setExpire(isset($poll['expire']) ? $poll['expire'] : $this->poll->getExpire()); - $this->poll->setAnonymous(isset($poll['anonymous']) ? $poll['anonymous'] : $this->poll->getAnonymous()); - $this->poll->setAllowMaybe(isset($poll['allowMaybe']) ? $poll['allowMaybe'] : $this->poll->getAllowMaybe()); - $this->poll->setVoteLimit(isset($poll['voteLimit']) ? $poll['voteLimit'] : $this->poll->getVoteLimit()); - $this->poll->setShowResults(isset($poll['showResults']) ? $poll['showResults'] : $this->poll->getShowResults()); - $this->poll->setDeleted(isset($poll['deleted']) ? $poll['deleted'] : $this->poll->getDeleted()); - $this->poll->setAdminAccess(isset($poll['adminAccess']) ? $poll['adminAccess'] : $this->poll->getAdminAccess()); - - $this->poll->setFullAnonymous(0); - $this->poll->setVoteLimit(0); - $this->poll->setSettings(''); - $this->poll->setOptions(''); - - $this->pollMapper->update($this->poll); - - return $this->poll; - } + // /** + // * write + // * @NoAdminRequired + // * @NoCSRFRequired + // * @depricated + // * @param Array $poll + // * @return DataResponse + // */ + // + // public function write($poll, $pollId = null) { + // + // if (!$pollId) { + // $pollId = $poll['id']; + // } + // + // // Validate valuess + // if (isset($poll['showResults']) && !in_array($poll['showResults'], $this->getValidShowResults())) { + // throw new InvalidShowResultsException('Invalid value for prop showResults'); + // } + // + // if (isset($poll['access']) && !in_array($poll['access'], $this->getValidShowResults())) { + // throw new InvalidAccessException('Invalid value for prop access'); + // } + // + // if (isset($poll['title']) && !$poll['title']) { + // throw new EmptyTitleException('Title must not be empty'); + // } + // + // try { + // // find pollId + // $this->poll = $this->pollMapper->find($pollId); + // $this->logService->setLog($this->poll->getId(), 'updatePoll'); + // + // + // } catch (DoesNotExistException $e) { + // // if not found create a new poll + // + // // Validate valuess + // if (!in_array($poll['type'], $this->getValidPollType())) { + // throw new InvalidPollTypeException('Invalid poll type'); + // } + // + // if (!$poll['title']) { + // throw new EmptyTitleException('Title must not be empty'); + // } + // + // + // $this->poll = new Poll(); + // $this->poll->setType($poll['type']); + // $this->poll->setOwner($this->userId); + // $this->poll->setTitle($poll['title']); + // $this->poll->setCreated(time()); + // $this->poll = $this->pollMapper->insert($this->poll); + // + // $this->logService->setLog($this->poll->getId(), 'addPoll'); + // } + // + // if (!$this->acl->setPollId($this->poll->getId())->getAllowEdit()) { + // throw new NotAuthorizedException; + // } + // + // $this->poll->setTitle(isset($poll['title']) ? $poll['title'] : $this->poll->getTitle()); + // $this->poll->setDescription(isset($poll['description']) ? $poll['description'] : $this->poll->getDescription()); + // $this->poll->setAccess(isset($poll['access']) ? $poll['access'] : $this->poll->getAccess()); + // $this->poll->setExpire(isset($poll['expire']) ? $poll['expire'] : $this->poll->getExpire()); + // $this->poll->setAnonymous(isset($poll['anonymous']) ? $poll['anonymous'] : $this->poll->getAnonymous()); + // $this->poll->setAllowMaybe(isset($poll['allowMaybe']) ? $poll['allowMaybe'] : $this->poll->getAllowMaybe()); + // $this->poll->setVoteLimit(isset($poll['voteLimit']) ? $poll['voteLimit'] : $this->poll->getVoteLimit()); + // $this->poll->setShowResults(isset($poll['showResults']) ? $poll['showResults'] : $this->poll->getShowResults()); + // $this->poll->setDeleted(isset($poll['deleted']) ? $poll['deleted'] : $this->poll->getDeleted()); + // $this->poll->setAdminAccess(isset($poll['adminAccess']) ? $poll['adminAccess'] : $this->poll->getAdminAccess()); + // + // $this->poll->setFullAnonymous(0); + // $this->poll->setVoteLimit(0); + // $this->poll->setSettings(''); + // $this->poll->setOptions(''); + // + // $this->pollMapper->update($this->poll); + // + // return $this->poll; + // } /** - * write + * update * @NoAdminRequired * @NoCSRFRequired * @param Array $poll @@ -369,6 +394,11 @@ * @return DataResponse */ public function clone($pollId) { + + if (!$this->acl->setPollId($this->poll->getId())->getAllowView()) { + throw new NotAuthorizedException; + } + $this->poll = $this->pollMapper->find($pollId); $this->poll->setCreated(time()); diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 0df25218..04a40269 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -25,7 +25,6 @@ namespace OCA\Polls\Service; use Exception; -use OCP\ILogger; use OCP\Security\ISecureRandom; use OCA\Polls\Exceptions\NotAuthorizedException; @@ -35,27 +34,18 @@ use OCA\Polls\Db\Share; use OCA\Polls\Db\ShareMapper; use OCA\Polls\Service\MailService; use OCA\Polls\Model\Acl; -// TODO: Change to Service use OCA\Polls\Controller\SystemController; class ShareService { - private $logger; - private $acl; private $shareMapper; private $share; - private $userId; - - private $pollMapper; private $systemController; private $mailService; + private $acl; /** * ShareController constructor. - * @param string $appName - * @param string $userId - * @param IRequest $request - * @param ILogger $logger * @param ShareMapper $shareMapper * @param Share $share * @param SystemController $systemController @@ -63,17 +53,12 @@ class ShareService { * @param Acl $acl */ public function __construct( - string $appName, - $userId, - ILogger $logger, ShareMapper $shareMapper, Share $share, SystemController $systemController, MailService $mailService, Acl $acl ) { - $this->logger = $logger; - $this->userId = $userId; $this->shareMapper = $shareMapper; $this->share = $share; $this->systemController = $systemController; @@ -89,11 +74,12 @@ class ShareService { * @return DataResponse */ public function list($pollId) { - if ($this->acl->setPollId($pollId)->getAllowEdit()) { - return $this->shareMapper->findByPoll($pollId); - } else { + if (!$this->acl->setPollId($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } + + return $this->shareMapper->findByPoll($pollId); + } /** @@ -118,8 +104,8 @@ class ShareService { */ // TODO: Replace with $this->add and separate sending invitations public function write($pollId, $type, $userId, $userEmail = '') { - $this->acl->setPollId($pollId); - if (!$this->acl->getAllowEdit()) { + + if (!$this->acl->setPollId($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } @@ -152,8 +138,8 @@ class ShareService { * @return Array */ public function add($pollId, $type, $userId, $userEmail = '') { - $this->acl->setPollId($pollId); - if (!$this->acl->getAllowEdit()) { + + if (!$this->acl->setPollId($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } @@ -182,7 +168,6 @@ class ShareService { * @return Share */ public function createPersonalShare($token, $userName) { - $publicShare = $this->shareMapper->findByToken($token); // Return of validatePublicUsername is a DataResponse @@ -195,6 +180,7 @@ class ShareService { if ($publicShare->getType() === 'public') { + $this->share = new Share(); $this->share->setToken(\OC::$server->getSecureRandom()->generate( 16, @@ -231,11 +217,13 @@ class ShareService { public function remove($token) { $this->share = $this->shareMapper->findByToken($token); - if ($this->acl->setPollId($this->share->getPollId())->getAllowEdit()) { - $this->shareMapper->delete($this->share); - return $this->share; - } else { + if (!$this->acl->setPollId($this->share->getPollId())->getAllowEdit()) { throw new NotAuthorizedException; } + + $this->shareMapper->delete($this->share); + + return $this->share; + } } diff --git a/lib/Service/VoteService.php b/lib/Service/VoteService.php index 7f096b83..739640f9 100644 --- a/lib/Service/VoteService.php +++ b/lib/Service/VoteService.php @@ -26,10 +26,6 @@ namespace OCA\Polls\Service; use Exception; use OCP\AppFramework\Db\DoesNotExistException; -use OCP\IGroupManager; -use OCP\ILogger; - - use OCA\Polls\Db\Vote; use OCA\Polls\Db\VoteMapper; use OCA\Polls\Db\OptionMapper; @@ -39,47 +35,33 @@ use OCA\Polls\Model\Acl; class VoteService { - private $userId; - private $logger; - private $vote; private $voteMapper; + private $vote; private $optionMapper; - private $groupManager; private $anonymizer; private $logService; private $acl; /** * VoteController constructor. - * @param string $appName - * @param $userId - * @param ILogger $logger - * @param Vote $vote * @param VoteMapper $voteMapper + * @param Vote $vote * @param OptionMapper $optionMapper - * @param IGroupManager $groupManager * @param AnonymizeService $anonymizer * @param LogService $logService * @param Acl $acl */ public function __construct( - string $appName, - $userId, - ILogger $logger, VoteMapper $voteMapper, - OptionMapper $optionMapper, Vote $vote, - IGroupManager $groupManager, + OptionMapper $optionMapper, AnonymizeService $anonymizer, LogService $logService, Acl $acl ) { - $this->userId = $userId; - $this->vote = $vote; $this->voteMapper = $voteMapper; + $this->vote = $vote; $this->optionMapper = $optionMapper; - $this->logger = $logger; - $this->groupManager = $groupManager; $this->anonymizer = $anonymizer; $this->logService = $logService; $this->acl = $acl; @@ -94,17 +76,17 @@ class VoteService { * @return DataResponse */ public function list($pollId = 0, $token = '') { - if (!$this->acl->checkAuthorize($pollId, $token) && !$this->acl->getAllowView()) { + if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowView()) { throw new NotAuthorizedException; } if (!$this->acl->getAllowSeeResults()) { - return $this->voteMapper->findByPollAndUser($pollId, $this->acl->getUserId()); + return $this->voteMapper->findByPollAndUser($this->acl->getpollId(), $this->acl->getUserId()); } elseif (!$this->acl->getAllowSeeUsernames()) { - $this->anonymizer->set($pollId, $this->acl->getUserId()); + $this->anonymizer->set($this->acl->getpollId(), $this->acl->getUserId()); return $this->anonymizer->getVotes(); } else { - return $this->voteMapper->findByPoll($pollId); + return $this->voteMapper->findByPoll($this->acl->getpollId()); } } @@ -119,14 +101,14 @@ class VoteService { */ public function set($pollId = 0, $pollOptionText, $setTo, $token = '') { - if (!$this->acl->checkAuthorize($pollId, $token) && !$this->acl->getAllowVote()) { + if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowVote()) { throw new NotAuthorizedException; } - - $option = $this->optionMapper->findByPollAndText($pollId, $pollOptionText); + + $option = $this->optionMapper->findByPollAndText($this->acl->getpollId(), $pollOptionText); try { - $this->vote = $this->voteMapper->findSingleVote($pollId, $option->getPollOptionText(), $this->acl->getUserId()); + $this->vote = $this->voteMapper->findSingleVote($this->acl->getpollId(), $option->getPollOptionText(), $this->acl->getUserId()); $this->vote->setVoteAnswer($setTo); $this->voteMapper->update($this->vote); @@ -134,7 +116,7 @@ class VoteService { // Vote does not exist, insert as new Vote $this->vote = new Vote(); - $this->vote->setPollId($pollId); + $this->vote->setPollId($this->acl->getpollId()); $this->vote->setUserId($this->acl->getUserId()); $this->vote->setVoteOptionText($option->getPollOptionText()); $this->vote->setVoteOptionId($option->getId()); @@ -158,12 +140,11 @@ class VoteService { */ public function delete($pollId, $userId) { - if (!$this->acl->checkAuthorize($pollId, $token) && !$this->acl->getAllowEdit()) { + if (!$this->acl->setPollId($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } $votes = $this->voteMapper->deleteByPollAndUser($pollId, $userId); - $this->logger->alert('Deleted votes from ' . $userId . ' in poll ' . $pollId); } } |