diff options
author | dartcafe <github@dartcafe.de> | 2020-07-12 23:01:19 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2020-07-12 23:01:19 +0300 |
commit | 5151f1fcff7dfc36a3ec5fba8ed423d5e46fdb07 (patch) | |
tree | 7960a1fdd6422bd2786b67275846445821eff328 /lib | |
parent | e11022004cf8c6e7daf9bd8d0cbc5c414587e99a (diff) |
Avoid avatar errors and tidy acl model
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Db/Comment.php | 9 | ||||
-rw-r--r-- | lib/Db/Share.php | 8 | ||||
-rw-r--r-- | lib/Db/Vote.php | 8 | ||||
-rw-r--r-- | lib/Model/Acl.php | 77 |
4 files changed, 34 insertions, 68 deletions
diff --git a/lib/Db/Comment.php b/lib/Db/Comment.php index 56514570..4165996f 100644 --- a/lib/Db/Comment.php +++ b/lib/Db/Comment.php @@ -78,16 +78,21 @@ class Comment extends Entity implements JsonSerializable { 'dt' => $this->dt, 'timestamp' => intval($timestamp), 'comment' => $this->comment, - 'displayName' => $this->getDisplayName() + 'displayName' => $this->getDisplayName(), + 'externalUser' => $this->externalUser() ]; } private function getDisplayName() { - if (\OC::$server->getUserManager()->get($this->userId) instanceof IUser) { return \OC::$server->getUserManager()->get($this->userId)->getDisplayName(); } else { return $this->userId; } } + + private function externalUser() { + return (!\OC::$server->getUserManager()->get($this->userId) instanceof IUser); + } + } diff --git a/lib/Db/Share.php b/lib/Db/Share.php index 04b77733..84ae4ea2 100644 --- a/lib/Db/Share.php +++ b/lib/Db/Share.php @@ -73,8 +73,9 @@ class Share extends Entity implements JsonSerializable { 'pollId' => intval($this->pollId), 'userId' => $this->userId, 'userEmail' => $this->userEmail, + 'invitationSent' => intval($this->invitationSent), 'displayName' => $this->getDisplayName(), - 'invitationSent' => intval($this->invitationSent) + 'externalUser' => $this->externalUser() ]; } @@ -86,4 +87,9 @@ class Share extends Entity implements JsonSerializable { return $this->userId; } } + + private function externalUser() { + return (!\OC::$server->getUserManager()->get($this->userId) instanceof IUser); + } + } diff --git a/lib/Db/Vote.php b/lib/Db/Vote.php index 839f154a..85b63c09 100644 --- a/lib/Db/Vote.php +++ b/lib/Db/Vote.php @@ -66,16 +66,20 @@ class Vote extends Entity implements JsonSerializable { 'voteOptionId' => intval($this->voteOptionId), 'voteOptionText' => $this->voteOptionText, 'voteAnswer' => $this->voteAnswer, - 'displayName' => $this->getDisplayName() + 'displayName' => $this->getDisplayName(), + 'externalUser' => $this->externalUser() ]; } private function getDisplayName() { - if (\OC::$server->getUserManager()->get($this->userId) instanceof IUser) { return \OC::$server->getUserManager()->get($this->userId)->getDisplayName(); } else { return $this->userId; } } + + private function externalUser() { + return (!\OC::$server->getUserManager()->get($this->userId) instanceof IUser); + } } diff --git a/lib/Model/Acl.php b/lib/Model/Acl.php index 71319436..10760008 100644 --- a/lib/Model/Acl.php +++ b/lib/Model/Acl.php @@ -53,9 +53,6 @@ class Acl implements JsonSerializable { /** @var string */ private $token = ''; - /** @var bool */ - private $foundByToken = false; - /** @var string */ private $userId; @@ -77,7 +74,6 @@ class Acl implements JsonSerializable { /** @var Poll */ private $poll; - /** * Acl constructor. * @param string $appName @@ -129,27 +125,20 @@ class Acl implements JsonSerializable { } } - /** * @NoAdminRequired - * @return bool + * @return string */ - public function setPollIdOrToken($pollId = 0, $token = '') { - - if ($token) { - $this->setToken($token); - } elseif ($pollId) { - $this->setPollId($pollId); - } - - return $this; + public function getIsExternalUser() { + return !($this->userManager->get($this->userId) instanceof IUser); } + /** * @NoAdminRequired * @return bool */ - public function checkAuthorize($pollId = 0, $token = '') { + public function setPollIdOrToken($pollId = 0, $token = '') { if ($token) { $this->setToken($token); @@ -157,7 +146,7 @@ class Acl implements JsonSerializable { $this->setPollId($pollId); } - return ($this->userId && $this->poll->getId()); + return $this; } /** @@ -309,17 +298,10 @@ class Acl implements JsonSerializable { * @return bool */ public function getAllowVote(): bool { - if ( - ($this->getAllowView() || $this->getFoundByToken()) + return ($this->getAllowView() || $this->getToken()) && !$this->getExpired() && !$this->poll->getDeleted() - && $this->userId - - ) { - return true; - } else { - return false; - } + && $this->userId; } /** @@ -343,15 +325,9 @@ class Acl implements JsonSerializable { * @return bool */ public function getAllowSeeResults(): bool { - if ($this->poll->getShowResults() === 'always' || $this->getIsOwner()) { - return true; - } elseif ($this->poll->getShowResults() === 'never') { - return false; - } elseif ($this->poll->getShowResults() === 'expired') { - return $this->getExpired(); - } else { - return false; - } + return $this->poll->getShowResults() === 'always' + || ($this->poll->getShowResults() === 'expired' && $this->getExpired()) + || $this->getIsOwner(); } /** @@ -359,28 +335,7 @@ class Acl implements JsonSerializable { * @return bool */ public function getAllowSeeUsernames(): bool { - return !($this->poll->getAnonymous() && !$this->getIsOwner()); ; - } - - /** - * @NoAdminRequired - * @return bool - */ - public function getAllowSeeAllVotes(): bool { - // TODO: preparation for polls without displaying other votes - if ($this->pollId) { - return true; - } else { - return false; - } - } - - /** - * @NoAdminRequired - * @return bool - */ - public function getFoundByToken(): bool { - return $this->foundByToken; + return !$this->poll->getAnonymous() || $this->getIsOwner(); } /** @@ -401,7 +356,6 @@ class Acl implements JsonSerializable { $this->token = $token; $share = $this->shareMapper->findByToken($token); - $this->foundByToken = true; $this->setPollId($share->getPollId()); \OC::$server->getLogger()->debug('Share PollId: ' . $share->getPollId()); @@ -410,7 +364,6 @@ class Acl implements JsonSerializable { $this->setPollId(0); $this->setUserId(null); $this->token = ''; - $this->foundByToken = false; } else if (($share->getType() === 'group' || $share->getType() === 'public') && \OC::$server->getUserSession()->isLoggedIn()) { // Use user name of authorized user shareType public and group if user is logged in $this->setUserId($this->userId); @@ -423,7 +376,6 @@ class Acl implements JsonSerializable { $this->setPollId(0); $this->setUserId(null); $this->token = ''; - $this->foundByToken = false; } return $this; } @@ -436,6 +388,7 @@ class Acl implements JsonSerializable { 'userId' => $this->getUserId(), 'displayName' => $this->getDisplayName(), 'loggedIn' => $this->getLoggedIn(), + 'externalUser' => $this->getIsExternalUser(), 'pollId' => $this->getPollId(), 'token' => $this->getToken(), 'isOwner' => $this->getIsOwner(), @@ -446,12 +399,10 @@ class Acl implements JsonSerializable { 'allowEdit' => $this->getAllowEdit(), 'allowSeeResults' => $this->getAllowSeeResults(), 'allowSeeUsernames' => $this->getAllowSeeUsernames(), - 'allowSeeAllVotes' => $this->getAllowSeeAllVotes(), 'userHasVoted' => $this->getUserHasVoted(), 'groupShare' => $this->getGroupShare(), 'personalShare' => $this->getPersonalShare(), - 'publicShare' => $this->getPublicShare(), - 'foundByToken' => $this->getFoundByToken() + 'publicShare' => $this->getPublicShare() ]; } } |