diff --git a/appinfo/info.xml b/appinfo/info.xml index 7d2b6726c..6c26a037a 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -4,7 +4,7 @@ Polls A polls app, similar to Doodle/Dudle with the possibility to restrict access. A polls app, similar to Doodle/Dudle with the possibility to restrict access (members, certain groups/users, hidden and public). - 6.0.0 + 6.0.1 agpl Vinzenz Rosenkranz René Gieling diff --git a/lib/Db/EntityWithUser.php b/lib/Db/EntityWithUser.php index baddbf3fb..a9a86a315 100644 --- a/lib/Db/EntityWithUser.php +++ b/lib/Db/EntityWithUser.php @@ -33,14 +33,14 @@ /** * @method int getPollId() - * @method string getUserId() - * @method string getDisplayName() - * @method string getEmailAdress() - * @method string getUserType() + * @method ?string getUserId() + * @method ?string getDisplayName() + * @method ?string getEmailAdress() + * @method ?string getUserType() */ abstract class EntityWithUser extends Entity { - protected string $publicUserId = ''; + protected ?string $publicUserId = ''; protected ?string $displayName = ''; protected ?string $emailAddress = ''; protected ?string $userType = ''; @@ -57,6 +57,10 @@ public function getIsNoUser(): bool { * - otherwise assume a deleted user **/ public function getDisplayName(): ?string { + if (!$this->getUserId()) { + return null; + } + return Container::queryClass(IUserManager::class)->get($this->getUserId())?->getDisplayName() ?? $this->displayName ?? 'Deleted User'; @@ -68,12 +72,21 @@ public function getDisplayName(): ?string { * - first tries to get type from joined share * - then try to verify an internal user and set type user * - otherwise assume a deleted user - **/ - public function getUserType(): ?string { - return $this->userType - ?? Container::queryClass(IUserManager::class)->get($this->getUserId()) - ? User::TYPE_USER - : User::TYPE_GHOST; + * + * @return null|string + */ + public function getUserType(): string|null { + if (!$this->getUserId()) { + return null; + } + + if ($this->userType) { + return $this->userType; + } + + return Container::queryClass(IUserManager::class)->get($this->getUserId()) + ? User::TYPE_USER + : User::TYPE_GHOST; } /** @@ -83,6 +96,9 @@ public function getUserType(): ?string { * - then get it from joined share **/ public function getEmailAddress(): ?string { + if (!$this->getUserId()) { + return null; + } return Container::queryClass(IUserManager::class)->get($this->getUserId())?->getEmailAddress() ?? $this->emailAddress; } @@ -92,9 +108,9 @@ public function getEmailAddress(): ?string { * * Avoids leaking internal userIds by replacing the actual userId by another string in public access **/ - private function getPublicUserId(): string { + private function getPublicUserId(): ?string { if (!$this->getUserId()) { - return ''; + return null; } if ($this->publicUserId) { @@ -105,6 +121,10 @@ private function getPublicUserId(): string { } public function generateHashedUserId(): void { + if (!$this->getUserId()) { + $this->publicUserId = null; + } + $this->publicUserId = hash('md5', $this->getUserId()); } diff --git a/lib/Db/VoteMapper.php b/lib/Db/VoteMapper.php index a97af27d6..14c3cd992 100644 --- a/lib/Db/VoteMapper.php +++ b/lib/Db/VoteMapper.php @@ -40,14 +40,16 @@ public function __construct(IDBConnection $db) { parent::__construct($db, self::TABLE, Vote::class); } - public function update(Entity $entity): Entity { + public function update(Entity $entity): Vote { $entity->setVoteOptionHash(hash('md5', $entity->getPollId() . $entity->getUserId() . $entity->getVoteOptionText())); - return parent::update($entity); + $entity = parent::update($entity); + return $this->find($entity->getId()); } - - public function insert(Entity $entity): Entity { + + public function insert(Entity $entity): Vote { $entity->setVoteOptionHash(hash('md5', $entity->getPollId() . $entity->getUserId() . $entity->getVoteOptionText())); - return parent::insert($entity); + $entity = parent::insert($entity); + return $this->find($entity->getId()); } /** @@ -187,6 +189,12 @@ public function fixVoteOptionText(int $pollId, int $optionId, string $searchOpti /** * Build the enhanced query with joined tables */ + protected function find(int $id): Vote { + $qb = $this->buildQuery(); + $qb->where($qb->expr()->eq(self::TABLE . '.id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); + return $this->findEntity($qb); + } + protected function buildQuery(): IQueryBuilder { $qb = $this->db->getQueryBuilder(); diff --git a/lib/Event/BaseEvent.php b/lib/Event/BaseEvent.php index 1f9ac1c66..665a7d978 100644 --- a/lib/Event/BaseEvent.php +++ b/lib/Event/BaseEvent.php @@ -70,7 +70,7 @@ public function getPollOwner(): string { return $this->poll->getOwner(); } - public function getActor(): string { + public function getActor(): ?string { return $this->userSession->getUser()?->getUID() ?? $this->eventObject->getUserId(); } diff --git a/lib/Model/Acl.php b/lib/Model/Acl.php index e13152c5d..0f30d4bff 100644 --- a/lib/Model/Acl.php +++ b/lib/Model/Acl.php @@ -181,10 +181,17 @@ public function setPoll(Poll $poll, string $permission = self::PERMISSION_POLL_V /** * Property getters */ - public function getPoll(): Poll|null { + public function getPoll(): ?Poll { return $this->poll; } + /** + * Property getters + */ + public function getShare(): ?Share { + return $this->share; + } + public function getPollId(): int { return $this->poll->getId(); } diff --git a/lib/Service/PollService.php b/lib/Service/PollService.php index d3597ed4d..c5cc5f2ad 100644 --- a/lib/Service/PollService.php +++ b/lib/Service/PollService.php @@ -403,9 +403,6 @@ public function clone(int $pollId): Poll { /** * Collect email addresses from particitipants * - * @return string[][] - * - * @psalm-return list */ public function getParticipantsEmailAddresses(int $pollId): array { $this->acl->setPollId($pollId, Acl::PERMISSION_POLL_EDIT); diff --git a/lib/Service/VoteService.php b/lib/Service/VoteService.php index d33b09ae0..ca0d19e5c 100644 --- a/lib/Service/VoteService.php +++ b/lib/Service/VoteService.php @@ -104,12 +104,12 @@ public function set(int $optionId, string $setTo, ?Acl $acl = null): ?Vote { $option = $this->optionMapper->find($optionId); if ($acl) { - $this->acl = $acl; // ->setToken($token, Acl::PERMISSION_VOTE_EDIT, $option->getPollId()); - // $this->acl->setToken($token, Acl::PERMISSION_VOTE_EDIT, $option->getPollId()); + $this->acl = $acl; + $this->acl->request(Acl::PERMISSION_VOTE_EDIT); } else { $this->acl->setPollId($option->getPollId(), Acl::PERMISSION_VOTE_EDIT); } - + if ($setTo === Vote::VOTE_YES) { $this->checkLimits($option, $this->acl->getUserId()); } @@ -122,7 +122,7 @@ public function set(int $optionId, string $setTo, ?Acl $acl = null): ?Vote { $this->voteMapper->delete($this->vote); } else { $this->vote->setVoteAnswer($setTo); - $this->voteMapper->update($this->vote); + $this->vote = $this->voteMapper->update($this->vote); } } catch (DoesNotExistException $e) { // Vote does not exist, insert as new Vote @@ -133,7 +133,7 @@ public function set(int $optionId, string $setTo, ?Acl $acl = null): ?Vote { $this->vote->setVoteOptionText($option->getPollOptionText()); $this->vote->setVoteOptionId($option->getId()); $this->vote->setVoteAnswer($setTo); - $this->voteMapper->insert($this->vote); + $this->vote = $this->voteMapper->insert($this->vote); } $this->eventDispatcher->dispatchTyped(new VoteSetEvent($this->vote)); diff --git a/package-lock.json b/package-lock.json index 3f4e5de32..ed7d171f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "polls", - "version": "6.0.0", + "version": "6.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "polls", - "version": "6.0.0", + "version": "6.0.1", "license": "AGPL-3.0", "dependencies": { "@nextcloud/auth": "^2.2.1", diff --git a/package.json b/package.json index bd3c42a6c..c262ca8aa 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "polls", "description": "Polls app for nextcloud", - "version": "6.0.0", + "version": "6.0.1", "authors": [ { "name": "Vinzenz Rosenkranz", diff --git a/src/js/components/Shares/ShareItem.vue b/src/js/components/Shares/ShareItem.vue index dff2b6992..ca55bd064 100644 --- a/src/js/components/Shares/ShareItem.vue +++ b/src/js/components/Shares/ShareItem.vue @@ -24,6 +24,7 @@