diff options
author | dartcafe <github@dartcafe.de> | 2020-09-03 09:32:46 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2020-09-03 09:32:46 +0300 |
commit | 3018352517c723ab753528872d7408a1f8940c63 (patch) | |
tree | ad209871212a70d22847b72f9954088394c69714 /lib/Service | |
parent | fa30cc5f307e06eda3f54f5be188761753d0e9c1 (diff) |
php-cs fix
Diffstat (limited to 'lib/Service')
-rw-r--r-- | lib/Service/AnonymizeService.php | 6 | ||||
-rw-r--r-- | lib/Service/CalendarService.php | 6 | ||||
-rw-r--r-- | lib/Service/CommentService.php | 9 | ||||
-rw-r--r-- | lib/Service/LogService.php | 2 | ||||
-rw-r--r-- | lib/Service/MailService.php | 71 | ||||
-rw-r--r-- | lib/Service/OptionService.php | 19 | ||||
-rw-r--r-- | lib/Service/PollService.php | 65 | ||||
-rw-r--r-- | lib/Service/ShareService.php | 9 | ||||
-rw-r--r-- | lib/Service/SubscriptionService.php | 7 | ||||
-rw-r--r-- | lib/Service/SystemService.php | 124 | ||||
-rw-r--r-- | lib/Service/VoteService.php | 8 |
11 files changed, 116 insertions, 210 deletions
diff --git a/lib/Service/AnonymizeService.php b/lib/Service/AnonymizeService.php index 27fbdc9b..fcc5988b 100644 --- a/lib/Service/AnonymizeService.php +++ b/lib/Service/AnonymizeService.php @@ -3,7 +3,7 @@ * @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 @@ -38,7 +38,7 @@ class AnonymizeService { private $commentMapper; /** @var array */ - private $anonList = array(); + private $anonList = []; /** @var string */ private $userId; @@ -126,6 +126,4 @@ class AnonymizeService { public function getVotes() { return $this->anonymize($this->voteMapper->findByPoll($this->pollId)); } - - } diff --git a/lib/Service/CalendarService.php b/lib/Service/CalendarService.php index f9bd0892..cb9bd29e 100644 --- a/lib/Service/CalendarService.php +++ b/lib/Service/CalendarService.php @@ -3,7 +3,7 @@ * @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 @@ -26,10 +26,8 @@ namespace OCA\Polls\Service; use DateTime; use OCP\Calendar\IManager as CalendarManager; -use OCP\Calendar\ICalendar; class CalendarService { - private $calendarManager; private $calendars; @@ -82,6 +80,4 @@ class CalendarService { public function getCalendars() { return $this->calendars; } - - } diff --git a/lib/Service/CommentService.php b/lib/Service/CommentService.php index cdb2616a..eeff8a06 100644 --- a/lib/Service/CommentService.php +++ b/lib/Service/CommentService.php @@ -29,9 +29,6 @@ use OCA\Polls\Exceptions\NotAuthorizedException; use OCA\Polls\Db\Comment; use OCA\Polls\Db\CommentMapper; use OCA\Polls\Model\Acl; -use OCA\Polls\Service\AnonymizeService; - - class CommentService { @@ -77,7 +74,6 @@ class CommentService { * @throws NotAuthorizedException */ public function list($pollId = 0, $token = '') { - if (!$this->acl->set($pollId, $token)->getAllowView()) { throw new NotAuthorizedException; } @@ -100,7 +96,6 @@ class CommentService { * @throws NotAuthorizedException */ public function add($pollId = 0, $message, $token = '') { - if (!$this->acl->set($pollId, $token)->getAllowComment()) { throw new NotAuthorizedException; } @@ -117,12 +112,10 @@ class CommentService { } else { throw new NotAuthorizedException; } - } catch (Exception $e) { \OC::$server->getLogger()->alert('Error writing comment for pollId ' . $pollId . ': ' . $e); throw new NotAuthorizedException($e); } - } /** @@ -142,7 +135,5 @@ class CommentService { $this->commentMapper->delete($this->comment); return $this->comment; - } - } diff --git a/lib/Service/LogService.php b/lib/Service/LogService.php index 950abf44..9c0db75c 100644 --- a/lib/Service/LogService.php +++ b/lib/Service/LogService.php @@ -23,7 +23,6 @@ namespace OCA\Polls\Service; -use Exception; use OCP\AppFramework\Db\DoesNotExistException; use OCA\Polls\Db\Log; @@ -98,5 +97,4 @@ class LogService { return $this->logMapper->insert($this->log); } } - } diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php index 3c0b835d..43077414 100644 --- a/lib/Service/MailService.php +++ b/lib/Service/MailService.php @@ -36,9 +36,7 @@ use OCP\Mail\IMailer; use OCP\Mail\IEMailTemplate; use OCA\Polls\Db\SubscriptionMapper; -use OCA\Polls\Db\Subscription; use OCA\Polls\Db\PollMapper; -use OCA\Polls\Db\Poll; use OCA\Polls\Db\ShareMapper; use OCA\Polls\Db\Share; use OCA\Polls\Db\LogMapper; @@ -131,14 +129,13 @@ class MailService { */ private function sendMail($emailTemplate, $userId = '', $emailAddress = '', $displayName = '') { - if ($this->userManager->get($userId) instanceof IUser) { $emailAddress = \OC::$server->getConfig()->getUserValue($userId, 'settings', 'email'); $displayName = $this->userManager->get($userId)->getDisplayName(); } if (!$emailAddress || !filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) { - throw new Exception('Invalid email address (' . $emailAddress . ')'); + throw new Exception('Invalid email address (' . $emailAddress . ')'); } try { @@ -148,12 +145,10 @@ class MailService { $this->mailer->send($message); return null; - } catch (\Exception $e) { \OC::$server->getLogger()->logException($e, ['app' => 'polls']); throw $e; } - } @@ -163,7 +158,6 @@ class MailService { * @return string */ public function resolveEmailAddress($pollId, $userId) { - if ($this->userManager->get($userId) instanceof IUser) { return \OC::$server->getConfig()->getUserValue($userId, 'settings', 'email'); } @@ -192,8 +186,7 @@ class MailService { $contactsManager = \OC::$server->getContactsManager(); if ($share->getType() === 'user') { - - $recipients[] = array( + $recipients[] = [ 'userId' => $share->getUserId(), 'eMailAddress' => \OC::$server->getConfig()->getUserValue($share->getUserId(), 'settings', 'email'), 'displayName' => $this->userManager->get($share->getUserId())->getDisplayName(), @@ -204,13 +197,12 @@ class MailService { 'link' => $this->urlGenerator->getAbsoluteURL( $this->urlGenerator->linkToRoute( 'polls.page.indexvote', - array('id' => $share->getPollId()) + ['id' => $share->getPollId()] ) ) - ); - + ]; } elseif ($share->getType() === 'email') { - $recipients[] = array( + $recipients[] = [ 'userId' => $share->getUserEmail(), 'eMailAddress' => $share->getUserEmail(), 'displayName' => $share->getUserEmail(), @@ -218,17 +210,16 @@ class MailService { 'link' => $this->urlGenerator->getAbsoluteURL( $this->urlGenerator->linkToRoute( 'polls.page.vote_publicpublic', - array('token' => $share->getToken()) + ['token' => $share->getToken()] ) ) - ); - + ]; } elseif ($share->getType() === 'contact') { - $contacts = $contactsManager->search($share->getUserId(), array('FN')); + $contacts = $contactsManager->search($share->getUserId(), ['FN']); if (is_array($contacts)) { $contact = $contacts[0]; - $recipients[] = array( + $recipients[] = [ 'userId' => $share->getUserId(), 'eMailAddress' => $share->getUserEmail(), 'displayName' => $share->getUserId(), @@ -236,16 +227,15 @@ class MailService { 'link' => $this->urlGenerator->getAbsoluteURL( $this->urlGenerator->linkToRoute( 'polls.page.vote_publicpublic', - array('token' => $share->getToken()) + ['token' => $share->getToken()] ) ) - ); + ]; } else { return; } - } elseif ($share->getType() === 'external') { - $recipients[] = array( + $recipients[] = [ 'userId' => $share->getUserId(), 'eMailAddress' => $share->getUserEmail(), 'displayName' => $share->getUserId(), @@ -253,13 +243,11 @@ class MailService { 'link' => $this->urlGenerator->getAbsoluteURL( $this->urlGenerator->linkToRoute( 'polls.page.vote_publicpublic', - array('token' => $share->getToken()) + ['token' => $share->getToken()] ) ) - ); - + ]; } elseif ($share->getType() === 'group') { - $groupMembers = array_keys($this->groupManager->displayNamesInGroup($share->getUserId())); foreach ($groupMembers as $member) { @@ -267,7 +255,7 @@ class MailService { continue; } - $recipients[] = array( + $recipients[] = [ 'userId' => $member, 'eMailAddress' => \OC::$server->getConfig()->getUserValue($member, 'settings', 'email'), 'displayName' => $this->userManager->get($member)->getDisplayName(), @@ -277,8 +265,7 @@ class MailService { 'polls.page.indexvote', ['id' => $share->getPollId()] ) ) - ); - + ]; } } return $recipients; @@ -288,7 +275,6 @@ class MailService { * @param string $token */ public function sendInvitationMail($token) { - $share = $this->shareMapper->findByToken($token); $poll = $this->pollMapper->find($share->getPollId()); $owner = $this->userManager->get($poll->getOwner()); @@ -376,7 +362,6 @@ class MailService { } catch (\Exception $e) { continue; } - } $trans = $this->transFactory->get('polls', $lang); @@ -384,7 +369,7 @@ class MailService { $url = $this->urlGenerator->getAbsoluteURL( $this->urlGenerator->linkToRoute( 'polls.page.indexvote', - array('id' => $subscription->getPollId()) + ['id' => $subscription->getPollId()] ) ); @@ -413,49 +398,41 @@ class MailService { if ($logItem->getMessage()) { $emailTemplate->addBodyText($logItem->getMessage()); - } elseif ($logItem->getMessageId() === 'setVote') { $emailTemplate->addBodyText($trans->t( '- %s voted.', - array($displayUser) + [$displayUser] )); - } elseif ($logItem->getMessageId() === 'updatePoll') { $emailTemplate->addBodyText($trans->t( '- %s updated the poll configuration. Please check your votes.', - array($displayUser) + [$displayUser] )); - } elseif ($logItem->getMessageId() === 'deletePoll') { $emailTemplate->addBodyText($trans->t( '- %s deleted the poll.', - array($displayUser) + [$displayUser] )); - } elseif ($logItem->getMessageId() === 'restorePoll') { $emailTemplate->addBodyText($trans->t( '- %s restored the poll.', - array($displayUser) + [$displayUser] )); - } elseif ($logItem->getMessageId() === 'expirePoll') { $emailTemplate->addBodyText($trans->t( '- The poll expired.', - array($displayUser) + [$displayUser] )); - } elseif ($logItem->getMessageId() === 'addOption') { $emailTemplate->addBodyText($trans->t( '- %s added a vote option.', - array($displayUser) + [$displayUser] )); - } elseif ($logItem->getMessageId() === 'deleteOption') { $emailTemplate->addBodyText($trans->t( '- %s removed a vote option.', - array($displayUser) + [$displayUser] )); - } else { $emailTemplate->addBodyText( $logItem->getMessageId() . " (" . $displayUser . ")" diff --git a/lib/Service/OptionService.php b/lib/Service/OptionService.php index 90014612..298fb863 100644 --- a/lib/Service/OptionService.php +++ b/lib/Service/OptionService.php @@ -24,7 +24,6 @@ namespace OCA\Polls\Service; use DateTime; -use Exception; use OCP\AppFramework\Db\DoesNotExistException; use OCA\Polls\Exceptions\NotAuthorizedException; use OCA\Polls\Exceptions\BadRequestException; @@ -35,7 +34,6 @@ use OCA\Polls\Db\OptionMapper; use OCA\Polls\Db\Option; use OCA\Polls\Db\PollMapper; use OCA\Polls\Db\Poll; -use OCA\Polls\Service\LogService; use OCA\Polls\Model\Acl; class OptionService { @@ -72,7 +70,7 @@ class OptionService { OptionMapper $optionMapper, Option $option, PollMapper $pollMapper, - Poll $poll, + Poll $poll, LogService $logService, Acl $acl ) { @@ -114,7 +112,6 @@ class OptionService { * @throws NotAuthorizedException */ public function get($optionId) { - if (!$this->acl->set($this->optionMapper->find($optionId)->getPollId())->getAllowView()) { throw new NotAuthorizedException; } @@ -133,7 +130,6 @@ class OptionService { * @throws NotAuthorizedException */ public function add($pollId, $timestamp = 0, $pollOptionText = '') { - $this->poll = $this->pollMapper->find($pollId); if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; @@ -148,7 +144,6 @@ class OptionService { } catch (UniqueConstraintViolationException $e) { throw new DuplicateEntryException('This option already exists'); } - } /** @@ -162,7 +157,6 @@ class OptionService { * @throws NotAuthorizedException */ public function update($optionId, $timestamp = 0, $pollOptionText = '', $order = 0) { - $this->option = $this->optionMapper->find($optionId); $this->poll = $this->pollMapper->find($this->option->getPollId()); @@ -228,7 +222,6 @@ class OptionService { * @throws NotAuthorizedException */ public function sequence($optionId, $step, $unit, $amount) { - $baseDate = new DateTime; $origin = $this->optionMapper->find($optionId); @@ -243,7 +236,6 @@ class OptionService { $baseDate->setTimestamp($origin->getTimestamp()); for ($i = 0; $i < $amount; $i++) { - $this->option = new Option(); $this->option->setPollId($origin->getPollId()); $this->option->setConfirmed(0); @@ -268,7 +260,6 @@ class OptionService { * @throws NotAuthorizedException */ public function clone($fromPollId, $toPollId) { - if (!$this->acl->set($fromPollId)->getAllowView()) { throw new NotAuthorizedException; } @@ -296,7 +287,6 @@ class OptionService { * @throws BadRequestException */ public function reorder($pollId, $options) { - $this->poll = $this->pollMapper->find($pollId); if (!$this->acl->set($pollId)->getAllowEdit()) { @@ -329,7 +319,6 @@ class OptionService { * @throws BadRequestException */ public function setOrder($optionId, $newOrder) { - $this->option = $this->optionMapper->find($optionId); $pollId = $this->option->getPollId(); $this->poll = $this->pollMapper->find($pollId); @@ -353,23 +342,17 @@ class OptionService { foreach ($this->optionMapper->findByPoll($pollId) as $option) { $currentOrder = $option->getOrder(); if ($currentOrder > $oldOrder && $currentOrder <= $newOrder) { - $option->setOrder($currentOrder - 1); $this->optionMapper->update($option); - } elseif ( ($currentOrder < $oldOrder && $currentOrder >= $newOrder) || ($currentOrder < $oldOrder && $currentOrder = $newOrder) ) { - $option->setOrder($currentOrder + 1); $this->optionMapper->update($option); - } elseif ($currentOrder === $oldOrder) { - $option->setOrder($newOrder); $this->optionMapper->update($option); - } else { continue; } diff --git a/lib/Service/PollService.php b/lib/Service/PollService.php index 5f365cdb..02e50d97 100644 --- a/lib/Service/PollService.php +++ b/lib/Service/PollService.php @@ -23,8 +23,6 @@ namespace OCA\Polls\Service; -use Exception; -use OCP\AppFramework\Db\DoesNotExistException; use OCA\Polls\Exceptions\EmptyTitleException; use OCA\Polls\Exceptions\InvalidAccessException; use OCA\Polls\Exceptions\InvalidShowResultsException; @@ -36,8 +34,6 @@ use OCA\Polls\Db\PollMapper; use OCA\Polls\Db\Poll; use OCA\Polls\Db\VoteMapper; use OCA\Polls\Db\Vote; -use OCA\Polls\Service\LogService; -use OCA\Polls\Service\MailService; use OCA\Polls\Model\Acl; class PollService { @@ -46,7 +42,7 @@ class PollService { private $pollMapper; /** @var Poll */ - private $poll; + private $poll; /** @var VoteMapper */ private $voteMapper; @@ -55,42 +51,42 @@ class PollService { private $vote; /** @var LogService */ - private $logService; + private $logService; /** @var MailService */ - private $mailService; + private $mailService; /** @var Acl */ - private $acl; - - /** - * PollController constructor. - * @param PollMapper $pollMapper - * @param Poll $poll - * @param VoteMapper $voteMapper - * @param Vote $vote - * @param LogService $logService - * @param MailService $mailService - * @param Acl $acl - */ - - public function __construct( - PollMapper $pollMapper, - Poll $poll, + private $acl; + + /** + * PollController constructor. + * @param PollMapper $pollMapper + * @param Poll $poll + * @param VoteMapper $voteMapper + * @param Vote $vote + * @param LogService $logService + * @param MailService $mailService + * @param Acl $acl + */ + + public function __construct( + PollMapper $pollMapper, + Poll $poll, VoteMapper $voteMapper, - Vote $vote, + Vote $vote, LogService $logService, MailService $mailService, - Acl $acl - ) { - $this->pollMapper = $pollMapper; - $this->poll = $poll; + Acl $acl + ) { + $this->pollMapper = $pollMapper; + $this->poll = $poll; $this->voteMapper = $voteMapper; - $this->vote = $vote; + $this->vote = $vote; $this->logService = $logService; $this->mailService = $mailService; - $this->acl = $acl; - } + $this->acl = $acl; + } /** @@ -127,7 +123,7 @@ class PollService { * @return Poll * @throws NotAuthorizedException */ - public function get($pollId, $token) { + public function get($pollId, $token) { $acl = $this->acl->set($pollId, $token); if (!$acl->getAllowView()) { @@ -135,8 +131,7 @@ class PollService { } return $this->pollMapper->find($acl->getPollId()); - - } + } /** * Add poll @@ -200,7 +195,6 @@ class PollService { */ public function update($pollId, $poll) { - $this->poll = $this->pollMapper->find($pollId); if (!$this->acl->set($this->poll->getId())->getAllowEdit()) { @@ -281,7 +275,6 @@ class PollService { * @throws NotAuthorizedException */ public function clone($pollId) { - $origin = $this->pollMapper->find($pollId); if (!$this->acl->set($origin->getId())->getAllowView()) { throw new NotAuthorizedException; diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 83b20dda..ae14935a 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -23,7 +23,6 @@ namespace OCA\Polls\Service; -use Exception; use OCA\Polls\Exceptions\NotAuthorizedException; use OCA\Polls\Exceptions\InvalidUsername; use OCA\Polls\Exceptions\InvalidShareType; @@ -33,7 +32,6 @@ use OCP\Security\ISecureRandom; use OCA\Polls\Controller\SystemController; use OCA\Polls\Db\ShareMapper; use OCA\Polls\Db\Share; -use OCA\Polls\Service\MailService; use OCA\Polls\Model\Acl; class ShareService { @@ -84,7 +82,7 @@ class ShareService { */ public function list($pollId, $token) { if ($token) { - return array($this->get($token)); + return [$this->get($token)]; } if (!$this->acl->set($pollId)->getAllowEdit()) { @@ -147,7 +145,6 @@ class ShareService { * @throws NotAuthorizedException */ public function setEmailAddress($token, $emailAddress) { - $this->share = $this->shareMapper->findByToken($token); if ($this->share->getType() === 'external') { // TODO: Simple validate email address @@ -181,7 +178,6 @@ class ShareService { } if ($this->share->getType() === 'public') { - $pollId = $this->share->getPollId(); $this->share = new Share(); $this->share->setToken(\OC::$server->getSecureRandom()->generate( @@ -198,14 +194,11 @@ class ShareService { $this->shareMapper->insert($this->share); $this->mailService->sendInvitationMail($this->share->getToken()); return $this->share; - } elseif ($this->share->getType() === 'email') { - $this->share->setType('external'); $this->share->setUserId($userName); $this->share->setUserEmail($emailAddress); return $this->shareMapper->update($this->share); - } else { throw new NotAuthorizedException; } diff --git a/lib/Service/SubscriptionService.php b/lib/Service/SubscriptionService.php index 9c3f1855..ec824b61 100644 --- a/lib/Service/SubscriptionService.php +++ b/lib/Service/SubscriptionService.php @@ -23,7 +23,6 @@ namespace OCA\Polls\Service; -use Exception; use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\AppFramework\Db\DoesNotExistException; @@ -70,7 +69,6 @@ class SubscriptionService { // duplicates are removed in $this->set() return $this->set($pollId, $token, true); } - } /** @@ -93,9 +91,7 @@ class SubscriptionService { // subscription already exists, just return the existing subscription return ['status' => 'Subscribed to poll ' . $this->acl->getPollId()]; } - } catch (DoesNotExistException $e) { - if ($subscribed) { $subscription = new Subscription(); $subscription->setPollId($this->acl->getPollId()); @@ -107,7 +103,6 @@ class SubscriptionService { // subscription is not found, just approve the unsubscription 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 @@ -124,8 +119,6 @@ class SubscriptionService { } else { return ['status' => 'Unsubscribed from poll ' . $this->acl->getPollId()]; } - } - } } diff --git a/lib/Service/SystemService.php b/lib/Service/SystemService.php index eb47cad6..7ac14284 100644 --- a/lib/Service/SystemService.php +++ b/lib/Service/SystemService.php @@ -23,18 +23,14 @@ namespace OCA\Polls\Service; -use Exception; use OCA\Polls\Exceptions\NotAuthorizedException; use OCA\Polls\Exceptions\TooShortException; use OCA\Polls\Exceptions\UsernameInvalidException; use OCP\IGroupManager; -use OCP\IUser; use OCP\IUserManager; -use OCP\IRequest; use OCA\Polls\Db\Share; use OCA\Polls\Db\ShareMapper; -use OCA\Polls\Db\Vote; use OCA\Polls\Db\VoteMapper; class SystemService { @@ -76,50 +72,50 @@ class SystemService { * @param string $query * @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; - } - - - /** - * Get a list of users - * @NoAdminRequired - * @param string $query - * @param array $skip - usernames to skip in return array - * @return Array - */ - public function getSiteUsers($query = '', $skip = array()) { - $users = array(); - foreach ($this->userManager->searchDisplayName($query) as $user) { - if (!in_array($user->getUID(), $skip) && $user->isEnabled()) { - $users[] = [ - 'id' => $user->getUID(), - 'user' => $user->getUID(), - 'displayName' => $user->getDisplayName(), - 'organisation' => '', - 'emailAddress' => $user->getEMailAddress(), - 'desc' => 'User', - 'type' => 'user', - 'icon' => 'icon-user', - 'avatarURL' => '', - 'avatar' => '', - 'lastLogin' => $user->getLastLogin(), - 'cloudId' => $user->getCloudId() - ]; - } - } - return $users; - } - - /** - * Get a list of user groups - * @NoAdminRequired - * @param string $query - * @param array $skip - group names to skip in return array - * @return Array - */ - public function getSiteGroups($query = '', $skip = array()) { - $groups = array(); + 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; + } + + + /** + * Get a list of users + * @NoAdminRequired + * @param string $query + * @param array $skip - usernames to skip in return array + * @return Array + */ + public function getSiteUsers($query = '', $skip = []) { + $users = []; + foreach ($this->userManager->searchDisplayName($query) as $user) { + if (!in_array($user->getUID(), $skip) && $user->isEnabled()) { + $users[] = [ + 'id' => $user->getUID(), + 'user' => $user->getUID(), + 'displayName' => $user->getDisplayName(), + 'organisation' => '', + 'emailAddress' => $user->getEMailAddress(), + 'desc' => 'User', + 'type' => 'user', + 'icon' => 'icon-user', + 'avatarURL' => '', + 'avatar' => '', + 'lastLogin' => $user->getLastLogin(), + 'cloudId' => $user->getCloudId() + ]; + } + } + return $users; + } + + /** + * Get a list of user groups + * @NoAdminRequired + * @param string $query + * @param array $skip - group names to skip in return array + * @return Array + */ + public function getSiteGroups($query = '', $skip = []) { + $groups = []; foreach ($this->groupManager->search($query) as $group) { if (!in_array($group->getGID(), $skip)) { try { @@ -157,17 +153,16 @@ class SystemService { * @return Array */ public function getContacts($query = '') { - $contacts = array(); - foreach (\OC::$server->getContactsManager()->search($query, array('FN', 'EMAIL', 'ORG', 'CATEGORIES')) as $contact) { + $contacts = []; + foreach (\OC::$server->getContactsManager()->search($query, ['FN', 'EMAIL', 'ORG', 'CATEGORIES']) as $contact) { if (!array_key_exists('isLocalSystemBook', $contact) && array_key_exists('EMAIL', $contact)) { - $emailAdresses = $contact['EMAIL']; if (!is_array($emailAdresses)) { - $emailAdresses = array($emailAdresses); + $emailAdresses = [$emailAdresses]; } else { // take the first eMail address for now - $emailAdresses = array($emailAdresses[0]); + $emailAdresses = [$emailAdresses[0]]; } foreach ($emailAdresses as $emailAddress) { @@ -186,7 +181,6 @@ class SystemService { 'cloudId' => '', ]; } - } } return $contacts; @@ -199,8 +193,8 @@ class SystemService { * @return Array */ public function getContactsGroupMembers($query = '') { - $contacts = array(); - foreach (\OC::$server->getContactsManager()->search($query, array('CATEGORIES')) as $contact) { + $contacts = []; + foreach (\OC::$server->getContactsManager()->search($query, ['CATEGORIES']) as $contact) { if ( !array_key_exists('isLocalSystemBook', $contact) && array_key_exists('EMAIL', $contact) @@ -209,10 +203,10 @@ class SystemService { $emailAdresses = $contact['EMAIL']; if (!is_array($emailAdresses)) { - $emailAdresses = array($emailAdresses); + $emailAdresses = [$emailAdresses]; } else { // take the first eMail address for now - $emailAdresses = array($emailAdresses[0]); + $emailAdresses = [$emailAdresses[0]]; } foreach ($emailAdresses as $emailAddress) { @@ -243,11 +237,10 @@ class SystemService { * @return Array */ public function getContactsGroups($query = '') { - $contactGroups = array(); + $contactGroups = []; $foundContacts = []; - foreach (\OC::$server->getContactsManager()->search($query, array('CATEGORIES')) as $contact) { - + foreach (\OC::$server->getContactsManager()->search($query, ['CATEGORIES']) as $contact) { foreach (explode(',', $contact['CATEGORIES']) as $contactGroup) { if (strpos($contactGroup, $query) === 0 && !in_array($contactGroup, $foundContacts)) { $foundContacts[] = $contactGroup; @@ -291,10 +284,10 @@ class SystemService { $getContacts = true, $getContactGroups = true, $getMail = false, - $skipGroups = array(), - $skipUsers = array() + $skipGroups = [], + $skipUsers = [] ) { - $list = array(); + $list = []; if ($getMail && $this->isValidEmail($query)) { $list[] = [ @@ -356,7 +349,7 @@ class SystemService { return new TooShortException('Username must have at least 3 characters'); } - $list = array(); + $list = []; // get all groups $groups = $this->groupManager->search(''); @@ -417,5 +410,4 @@ class SystemService { // return true, if username is allowed return true; } - } diff --git a/lib/Service/VoteService.php b/lib/Service/VoteService.php index 5fb0b5c7..f2558667 100644 --- a/lib/Service/VoteService.php +++ b/lib/Service/VoteService.php @@ -23,15 +23,12 @@ namespace OCA\Polls\Service; -use Exception; use OCP\AppFramework\Db\DoesNotExistException; use OCA\Polls\Exceptions\NotAuthorizedException; use OCA\Polls\Db\VoteMapper; use OCA\Polls\Db\Vote; use OCA\Polls\Db\OptionMapper; -use OCA\Polls\Service\AnonymizeService; -use OCA\Polls\Service\LogService; use OCA\Polls\Model\Acl; class VoteService { @@ -112,7 +109,6 @@ class VoteService { * @throws NotAuthorizedException */ public function set($optionId, $setTo, $token = '') { - $option = $this->optionMapper->find($optionId); if (!$this->acl->set($option->getPollId(), $token)->getAllowVote()) { @@ -127,7 +123,6 @@ class VoteService { $this->vote = $this->voteMapper->findSingleVote($this->acl->getPollId(), $option->getPollOptionText(), $this->acl->getUserId()); $this->vote->setVoteAnswer($setTo); $this->voteMapper->update($this->vote); - } catch (DoesNotExistException $e) { // Vote does not exist, insert as new Vote $this->vote = new Vote(); @@ -138,7 +133,6 @@ class VoteService { $this->vote->setVoteOptionId($option->getId()); $this->vote->setVoteAnswer($setTo); $this->voteMapper->insert($this->vote); - } finally { $this->logService->setLog($this->acl->getPollId(), 'setVote', $this->vote->getUserId()); return $this->vote; @@ -155,7 +149,6 @@ class VoteService { * @throws NotAuthorizedException */ public function delete($pollId, $userId) { - if (!$this->acl->set($pollId)->getAllowEdit()) { throw new NotAuthorizedException; } @@ -163,5 +156,4 @@ class VoteService { $this->voteMapper->deleteByPollAndUser($pollId, $userId); return $userId; } - } |