diff options
author | dartcafe <github@dartcafe.de> | 2020-08-07 23:47:10 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2020-08-07 23:47:10 +0300 |
commit | dad6b97a38348f620d20e5d20108a628269645ee (patch) | |
tree | c93f41df133cf0e6ac9f67557e05b065fe57f46e /lib/Service | |
parent | db579c72b6315944e6e6b2170acc17f973f8e7f8 (diff) |
public subscription for shares with mail address
Diffstat (limited to 'lib/Service')
-rw-r--r-- | lib/Service/CommentService.php | 6 | ||||
-rw-r--r-- | lib/Service/OptionService.php | 19 | ||||
-rw-r--r-- | lib/Service/PollService.php | 36 | ||||
-rw-r--r-- | lib/Service/ShareService.php | 12 | ||||
-rw-r--r-- | lib/Service/SubscriptionService.php | 34 | ||||
-rw-r--r-- | lib/Service/VoteService.php | 6 |
6 files changed, 53 insertions, 60 deletions
diff --git a/lib/Service/CommentService.php b/lib/Service/CommentService.php index 6c5f89b6..cdb2616a 100644 --- a/lib/Service/CommentService.php +++ b/lib/Service/CommentService.php @@ -78,7 +78,7 @@ class CommentService { */ public function list($pollId = 0, $token = '') { - if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowView()) { + if (!$this->acl->set($pollId, $token)->getAllowView()) { throw new NotAuthorizedException; } @@ -101,7 +101,7 @@ class CommentService { */ public function add($pollId = 0, $message, $token = '') { - if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowComment()) { + if (!$this->acl->set($pollId, $token)->getAllowComment()) { throw new NotAuthorizedException; } @@ -136,7 +136,7 @@ class CommentService { public function delete($commentId, $token = '') { $this->comment = $this->commentMapper->find($commentId); - if ($this->acl->setPollIdOrToken($this->comment->getPollId(), $token)->getUserId() !== $this->acl->getUserId()) { + if ($this->acl->set($this->comment->getPollId(), $token)->getUserId() !== $this->acl->getUserId()) { throw new NotAuthorizedException; } diff --git a/lib/Service/OptionService.php b/lib/Service/OptionService.php index 3cabc5ae..c598073e 100644 --- a/lib/Service/OptionService.php +++ b/lib/Service/OptionService.php @@ -90,13 +90,14 @@ class OptionService { * @throws NotAuthorizedException */ public function list($pollId = 0, $token = '') { + $acl = $this->acl->set($pollId, $token); - if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowView()) { + if (!$acl->getAllowView()) { throw new NotAuthorizedException; } try { - return $this->optionMapper->findByPoll($pollId); + return $this->optionMapper->findByPoll($acl->getPollId()); } catch (DoesNotExistException $e) { return []; } @@ -115,7 +116,7 @@ class OptionService { public function add($pollId, $timestamp = 0, $pollOptionText = '') { $this->poll = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } @@ -141,7 +142,7 @@ class OptionService { $this->option = $this->optionMapper->find($optionId); $this->poll = $this->pollMapper->find($this->option->getPollId()); - if (!$this->acl->setPollId($this->option->getPollId())->getAllowEdit()) { + if (!$this->acl->set($this->option->getPollId())->getAllowEdit()) { throw new NotAuthorizedException; } @@ -160,7 +161,7 @@ class OptionService { public function delete($optionId) { $this->option = $this->optionMapper->find($optionId); - if (!$this->acl->setPollId($this->option->getPollId())->getAllowEdit()) { + if (!$this->acl->set($this->option->getPollId())->getAllowEdit()) { throw new NotAuthorizedException; } @@ -179,7 +180,7 @@ class OptionService { public function confirm($optionId) { $this->option = $this->optionMapper->find($optionId); - if (!$this->acl->setPollId($this->option->getPollId())->getAllowEdit()) { + if (!$this->acl->set($this->option->getPollId())->getAllowEdit()) { throw new NotAuthorizedException; } @@ -202,7 +203,7 @@ class OptionService { */ public function clone($fromPollId, $toPollId) { - if (!$this->acl->setPollId($fromPollId)->getAllowView()) { + if (!$this->acl->set($fromPollId)->getAllowView()) { throw new NotAuthorizedException; } @@ -232,7 +233,7 @@ class OptionService { $this->poll = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } @@ -267,7 +268,7 @@ class OptionService { $pollId = $this->option->getPollId(); $this->poll = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } diff --git a/lib/Service/PollService.php b/lib/Service/PollService.php index 73b2044c..b9fdbdef 100644 --- a/lib/Service/PollService.php +++ b/lib/Service/PollService.php @@ -111,7 +111,7 @@ class PollService { // TODO: Not the elegant way. Improvement neccessary foreach ($polls as $poll) { $combinedPoll = (object) array_merge( - (array) json_decode(json_encode($poll)), (array) json_decode(json_encode($this->acl->setPollId($poll->getId())))); + (array) json_decode(json_encode($poll)), (array) json_decode(json_encode($this->acl->set($poll->getId())))); if ($combinedPoll->allowView) { $pollList[] = $combinedPoll; } @@ -127,30 +127,14 @@ class PollService { * @return Poll * @throws NotAuthorizedException */ - public function get($pollId) { + public function get($pollId, $token) { + $acl = $this->acl->set($pollId, $token); - if (!$this->acl->setPollId($pollId)->getAllowView()) { + if (!$acl->getAllowView()) { throw new NotAuthorizedException; } - return $this->pollMapper->find($pollId); - - } - - /** - * get poll configuration by token - * @NoAdminRequired - * @param int $pollId - * @return Poll - * @throws NotAuthorizedException - */ - public function getByToken($token) { - - if (!$this->acl->setToken($token)->getAllowView()) { - throw new NotAuthorizedException; - } - - return $this->pollMapper->find($this->acl->getPollId()); + return $this->pollMapper->find($acl->getPollId()); } @@ -219,7 +203,7 @@ class PollService { $this->poll = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($this->poll->getId())->getAllowEdit()) { + if (!$this->acl->set($this->poll->getId())->getAllowEdit()) { throw new NotAuthorizedException; } @@ -255,7 +239,7 @@ class PollService { public function delete($pollId) { $this->poll = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } @@ -282,7 +266,7 @@ class PollService { public function deletePermanently($pollId) { $this->poll = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($pollId)->getAllowEdit() || !$this->poll->getDeleted()) { + if (!$this->acl->set($pollId)->getAllowEdit() || !$this->poll->getDeleted()) { throw new NotAuthorizedException; } @@ -299,7 +283,7 @@ class PollService { public function clone($pollId) { $origin = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($origin->getId())->getAllowView()) { + if (!$this->acl->set($origin->getId())->getAllowView()) { throw new NotAuthorizedException; } @@ -334,7 +318,7 @@ class PollService { public function getParticipantsEmailAddresses($pollId) { $this->poll = $this->pollMapper->find($pollId); - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + if (!$this->acl->set($pollId)->getAllowEdit()) { return []; } diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index aaddefb8..70881cf9 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -82,8 +82,12 @@ class ShareService { * @return array array of Share * @throws NotAuthorizedException */ - public function list($pollId) { - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + public function list($pollId, $token) { + if ($token) { + return array($this->get($token)); + } + + if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } @@ -112,7 +116,7 @@ class ShareService { */ public function add($pollId, $type, $userId, $userEmail = '') { - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } @@ -213,7 +217,7 @@ class ShareService { public function delete($token) { $this->share = $this->shareMapper->findByToken($token); - if (!$this->acl->setPollId($this->share->getPollId())->getAllowEdit()) { + if (!$this->acl->set($this->share->getPollId())->getAllowEdit()) { throw new NotAuthorizedException; } diff --git a/lib/Service/SubscriptionService.php b/lib/Service/SubscriptionService.php index 0f7d82a7..8678817e 100644 --- a/lib/Service/SubscriptionService.php +++ b/lib/Service/SubscriptionService.php @@ -59,16 +59,16 @@ class SubscriptionService { * @param int $pollId * @return array */ - public function get($pollId) { - if (!$this->acl->setPollId($pollId)->getAllowView()) { + public function get($pollId, $token) { + if (!$this->acl->set($pollId, $token)->getAllowView()) { throw new NotAuthorizedException; } try { - return $this->subscriptionMapper->findByUserAndPoll($pollId, $this->acl->getUserId()); + return $this->subscriptionMapper->findByUserAndPoll($this->acl->getPollId(), $this->acl->getUserId()); } catch (MultipleObjectsReturnedException $e) { // subscription should be unique. If duplicates are found resubscribe // duplicates are removed in $this->set() - return $this->set($pollId, true); + return $this->set($pollId, $token, true); } } @@ -76,51 +76,55 @@ class SubscriptionService { /** * @NoAdminRequired * @param int $pollId + * @param string $token + * @param bool $subscribed * @return array */ - public function set($pollId, $subscribed) { - if (!$this->acl->setPollId($pollId)->getAllowView()) { + 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 { - $subscription = $this->subscriptionMapper->findByUserAndPoll($pollId, $this->acl->getUserId()); + $subscription = $this->subscriptionMapper->findByUserAndPoll($this->acl->getPollId(), $this->acl->getUserId()); if (!$subscribed) { $this->subscriptionMapper->delete($subscription); - return ['status' => 'Unsubscribed from poll ' . $pollId]; + return ['status' => 'Unsubscribed from poll ' . $this->acl->getPollId()]; } else { // subscription already exists, just return the existing subscription - return ['status' => 'Subscribed to poll ' . $pollId]; + return ['status' => 'Subscribed to poll ' . $this->acl->getPollId()]; } } catch (DoesNotExistException $e) { if ($subscribed) { $subscription = new Subscription(); - $subscription->setPollId($pollId); + $subscription->setPollId($this->acl->getPollId()); $subscription->setUserId($this->acl->getUserId()); $this->subscriptionMapper->insert($subscription); - return ['status' => 'Subscribed to poll ' . $pollId]; + return ['status' => 'Subscribed to poll ' . $this->acl->getPollId()]; } else { // subscription is not found, just approve the unsubscription - return ['status' => 'Unsubscribed from poll ' . $pollId]; + return ['status' => 'Unsubscribed from poll ' . $this->acl->getPollId()]; } } catch (MultipleObjectsReturnedException $e) { // Duplicates should not exist but if found, fix it // unsubscribe from all and resubscribe, if requested \OC::$server->getLogger()->debug('Multiple subscription (dulpicates) found'); - $this->subscriptionMapper->unsubscribe($pollId, $this->acl->getUserId()); + $this->subscriptionMapper->unsubscribe($this->acl->getPollId(), $this->acl->getUserId()); \OC::$server->getLogger()->debug('Unsubscribed all for user ' . $this->acl->getUserId() . 'in poll' . $pollId); if ($subscribed) { $subscription = new Subscription(); - $subscription->setPollId($pollId); + $subscription->setPollId($this->acl->getPollId()); $subscription->setUserId($this->acl->getUserId()); $this->subscriptionMapper->insert($subscription); \OC::$server->getLogger()->debug('Added new subscription'); return $subscription; } else { - return ['status' => 'Unsubscribed from poll ' . $pollId]; + return ['status' => 'Unsubscribed from poll ' . $this->acl->getPollId()]; } } diff --git a/lib/Service/VoteService.php b/lib/Service/VoteService.php index 32076289..cbedb1ad 100644 --- a/lib/Service/VoteService.php +++ b/lib/Service/VoteService.php @@ -88,7 +88,7 @@ class VoteService { * @throws NotAuthorizedException */ public function list($pollId = 0, $token = '') { - if (!$this->acl->setPollIdOrToken($pollId, $token)->getAllowView()) { + if (!$this->acl->set($pollId, $token)->getAllowView()) { throw new NotAuthorizedException; } @@ -115,7 +115,7 @@ class VoteService { $option = $this->optionMapper->find($optionId); - if (!$this->acl->setPollIdOrToken($option->getPollId(), $token)->getAllowVote()) { + if (!$this->acl->set($option->getPollId(), $token)->getAllowVote()) { throw new NotAuthorizedException; } @@ -156,7 +156,7 @@ class VoteService { */ public function delete($pollId, $userId) { - if (!$this->acl->setPollId($pollId)->getAllowEdit()) { + if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } |