diff options
Diffstat (limited to 'lib/Service/SubscriptionService.php')
-rw-r--r-- | lib/Service/SubscriptionService.php | 34 |
1 files changed, 19 insertions, 15 deletions
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()]; } } |