From cb574cdb0fb72987562947ef1114d6395629f340 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Wed, 18 May 2022 15:26:46 +0200 Subject: [PATCH] change access and parameter Signed-off-by: dartcafe --- lib/Service/AnonymizeService.php | 24 ++++++------------------ lib/Service/CommentService.php | 7 +++---- lib/Service/OptionService.php | 2 +- lib/Service/PollService.php | 8 ++------ lib/Service/VoteService.php | 8 +++----- 5 files changed, 15 insertions(+), 34 deletions(-) diff --git a/lib/Service/AnonymizeService.php b/lib/Service/AnonymizeService.php index 4a5c41792..d60379c5e 100644 --- a/lib/Service/AnonymizeService.php +++ b/lib/Service/AnonymizeService.php @@ -31,7 +31,6 @@ use OCA\Polls\Db\CommentMapper; use OCA\Polls\Db\Option; use OCA\Polls\Db\OptionMapper; use OCA\Polls\Db\Poll; -use OCA\Polls\Model\UserGroup\UserBase; class AnonymizeService { @@ -142,22 +141,11 @@ class AnonymizeService { /** * Replaces userIds with displayName to avoid exposing usernames in public polls - * - * @param (Comment|Option|Poll|Vote)[]|Comment|Option|Poll|Vote $arrayOrObject - * - * @return (Comment|Option|Poll|Vote)[]|Comment|Option|Poll|Vote - * - * @psalm-return Comment|Option|Poll|Vote|array */ - public static function replaceUserId($arrayOrObject, ?string $token = null) { - $shareUser = null; - if ($token) { - $shareUser = UserBase::getUserGroupChildFromShare($token); - } - + public static function replaceUserId(&$arrayOrObject, string $userId) : void { if (is_array($arrayOrObject)) { foreach ($arrayOrObject as $item) { - if ($shareUser && $shareUser->getId() === $item->getUserId()) { + if ($item->getUserId() === $userId) { continue; } if ($item instanceof Comment || $item instanceof Vote) { @@ -167,11 +155,11 @@ class AnonymizeService { $item->setOwner($item->getDisplayName()); } } - return $arrayOrObject; + return; } - if ($shareUser && $shareUser->getId() === $arrayOrObject->getUserId()) { - return $arrayOrObject; + if ($arrayOrObject->getUserId() === $userId) { + return; } if ($arrayOrObject instanceof Option || $arrayOrObject instanceof Poll) { @@ -182,6 +170,6 @@ class AnonymizeService { $arrayOrObject->setUserId($arrayOrObject->getDisplayName()); } - return $arrayOrObject; + return; } } diff --git a/lib/Service/CommentService.php b/lib/Service/CommentService.php index 566b13bb8..3616dbbc1 100644 --- a/lib/Service/CommentService.php +++ b/lib/Service/CommentService.php @@ -65,11 +65,10 @@ class CommentService { * Get comments * Read all comments of a poll based on the poll id and return list as array * - * @return (Comment|\OCA\Polls\Db\Option|\OCA\Polls\Db\Poll|\OCA\Polls\Db\Vote|mixed)[]|Comment|\OCA\Polls\Db\Option|\OCA\Polls\Db\Poll|\OCA\Polls\Db\Vote + * @return Comment[] * - * @psalm-return Comment|\OCA\Polls\Db\Option|\OCA\Polls\Db\Poll|\OCA\Polls\Db\Vote|array */ - public function listFlat(?int $pollId = 0, string $token = '') { + public function listFlat(?int $pollId = 0, string $token = '') : array { if ($token) { $this->acl->setToken($token); } else { @@ -81,7 +80,7 @@ class CommentService { if (!$this->acl->getIsLoggedIn()) { // if participant is not logged in avoid leaking user ids - $comments = $this->anonymizer->replaceUserId($comments, $token); + AnonymizeService::replaceUserId($comments, $this->acl->getUserId()); } return $comments; diff --git a/lib/Service/OptionService.php b/lib/Service/OptionService.php index 6f260f321..81652eefd 100644 --- a/lib/Service/OptionService.php +++ b/lib/Service/OptionService.php @@ -132,7 +132,7 @@ class OptionService { if (!$this->acl->getIsLoggedIn()) { // if participant is not logged in avoid leaking user ids - $this->options = $this->anonymizer->replaceUserId($this->options, $token); + AnonymizeService::replaceUserId($this->options, $this->acl->getUserId()); } diff --git a/lib/Service/PollService.php b/lib/Service/PollService.php index 274404c0d..ce54116e0 100644 --- a/lib/Service/PollService.php +++ b/lib/Service/PollService.php @@ -193,18 +193,14 @@ class PollService { /** * get poll configuration - * - * @return (Poll|Vote|\OCA\Polls\Db\Comment|\OCA\Polls\Db\Option)[]|Poll|Vote|\OCA\Polls\Db\Comment|\OCA\Polls\Db\Option - * - * @psalm-return Poll|Vote|\OCA\Polls\Db\Comment|\OCA\Polls\Db\Option|array */ - public function get(int $pollId) { + public function get(int $pollId) : Poll { $this->acl->setPollId($pollId); $this->poll = $this->pollMapper->find($pollId); if (!$this->acl->getIsLoggedIn()) { // if participant is not logged in avoid leaking user ids - return AnonymizeService::replaceUserId($this->poll); + AnonymizeService::replaceUserId($this->poll, $this->acl->getUserId()); } return $this->poll; } diff --git a/lib/Service/VoteService.php b/lib/Service/VoteService.php index 6fa66741f..4f849e214 100644 --- a/lib/Service/VoteService.php +++ b/lib/Service/VoteService.php @@ -74,11 +74,9 @@ class VoteService { /** * Read all votes of a poll based on the poll id and return list as array * - * @return (Option|Vote|\OCA\Polls\Db\Comment|\OCA\Polls\Db\Poll|mixed)[]|Option|Vote|\OCA\Polls\Db\Comment|\OCA\Polls\Db\Poll - * - * @psalm-return Option|Vote|\OCA\Polls\Db\Comment|\OCA\Polls\Db\Poll|array + * @return Vote[] */ - public function list(int $pollId = 0, string $token = '') { + public function list(int $pollId = 0, string $token = '') : array { if ($token) { $this->acl->setToken($token); } else { @@ -99,7 +97,7 @@ class VoteService { if (!$this->acl->getIsLoggedIn()) { // if participant is not logged in avoid leaking user ids - $votes = $this->anonymizer->replaceUserId($votes, $token); + AnonymizeService::replaceUserId($votes, $this->acl->getUserId()); } } catch (DoesNotExistException $e) { $votes = [];