Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordartcafe <github@dartcafe.de>2020-04-10 16:22:59 +0300
committerdartcafe <github@dartcafe.de>2020-04-10 16:22:59 +0300
commit4fca38bd4d2612da9db8c7cd0413d22b2314d8e3 (patch)
treef7c6fcf3da5e860b54c67c5d668dfea44f1ddf7a /lib
parent8611ef7f10052e94c6bd77be53511db0944c0812 (diff)
hide results
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/VoteController.php4
-rw-r--r--lib/Db/VoteMapper.php21
-rw-r--r--lib/Model/Acl.php18
3 files changed, 42 insertions, 1 deletions
diff --git a/lib/Controller/VoteController.php b/lib/Controller/VoteController.php
index 1ab4f464..7d5ba3ab 100644
--- a/lib/Controller/VoteController.php
+++ b/lib/Controller/VoteController.php
@@ -111,7 +111,9 @@ class VoteController extends Controller {
$this->acl->setPollId($pollId);
}
- if (!$this->acl->getAllowSeeUsernames()) {
+ if (!$this->acl->getAllowSeeResults()) {
+ return new DataResponse((array) $this->mapper->findByPollAndUser($pollId, $this->userId), Http::STATUS_OK);
+ } elseif (!$this->acl->getAllowSeeUsernames()) {
$this->anonymizer->set($pollId, $this->acl->getUserId());
return new DataResponse((array) $this->anonymizer->getVotes(), Http::STATUS_OK);
} else {
diff --git a/lib/Db/VoteMapper.php b/lib/Db/VoteMapper.php
index 244eaf26..c38d9e4b 100644
--- a/lib/Db/VoteMapper.php
+++ b/lib/Db/VoteMapper.php
@@ -59,6 +59,27 @@ class VoteMapper extends QBMapper {
/**
* @param int $pollId
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
+ * @return array
+ */
+
+ public function findByPollAndUser($pollId, $userId) {
+ $qb = $this->db->getQueryBuilder();
+
+ $qb->select('*')
+ ->from($this->getTableName())
+ ->where(
+ $qb->expr()->eq('poll_id', $qb->createNamedParameter($pollId, IQueryBuilder::PARAM_INT))
+ )
+ ->andWhere(
+ $qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
+ );
+
+ return $this->findEntities($qb);
+ }
+
+ /**
+ * @param int $pollId
+ * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @return Vote
*/
diff --git a/lib/Model/Acl.php b/lib/Model/Acl.php
index c0f07cb7..cd572865 100644
--- a/lib/Model/Acl.php
+++ b/lib/Model/Acl.php
@@ -320,6 +320,23 @@ class Acl implements JsonSerializable {
* @NoAdminRequired
* @return bool
*/
+ public function getAllowSeeResults(): bool {
+ if ($this->poll->getShowResults() === 'always' || $this->getIsOwner()) {
+ // if ($this->poll->getShowResults() === 'always') {
+ return true;
+ } elseif ($this->poll->getShowResults() === 'never') {
+ return false;
+ } elseif ($this->poll->getShowResults() === 'expired') {
+ return $this->getExpired();
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * @NoAdminRequired
+ * @return bool
+ */
public function getAllowSeeUsernames(): bool {
return !($this->poll->getAnonymous() && !$this->getIsOwner()); ;
}
@@ -404,6 +421,7 @@ class Acl implements JsonSerializable {
'allowVote' => $this->getAllowVote(),
'allowComment' => $this->getAllowComment(),
'allowEdit' => $this->getAllowEdit(),
+ 'allowSeeResults' => $this->getAllowSeeResults(),
'allowSeeUsernames' => $this->getAllowSeeUsernames(),
'allowSeeAllVotes' => $this->getAllowSeeAllVotes(),
'userHasVoted' => $this->getUserHasVoted(),