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-07-26 20:35:11 +0300
committerdartcafe <github@dartcafe.de>2020-07-26 20:35:11 +0300
commite857f1450b8e916b675a907fe75f236ad5cd9c99 (patch)
treeab557dae7d3ce0a0a7643b043b13d35b47d6ceaf /lib
parent7dd22d2073fd7eef0be8f52c5979817add6cc1df (diff)
copy participants addresses to clipboard
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/PollApiController.php19
-rw-r--r--lib/Controller/PollController.php17
-rw-r--r--lib/Db/ShareMapper.php22
-rw-r--r--lib/Db/Vote.php2
-rw-r--r--lib/Service/MailService.php29
-rw-r--r--lib/Service/PollService.php72
6 files changed, 144 insertions, 17 deletions
diff --git a/lib/Controller/PollApiController.php b/lib/Controller/PollApiController.php
index 20eb2ea0..c2e4750f 100644
--- a/lib/Controller/PollApiController.php
+++ b/lib/Controller/PollApiController.php
@@ -203,6 +203,25 @@
}
/**
+ * Collect email addresses from particitipants
+ * @NoAdminRequired
+ * @CORS
+ * @NoCSRFRequired
+ * @param Array $poll
+ * @return DataResponse
+ */
+
+ public function getParticipantsEmailAddresses($pollId) {
+ try {
+ return new DataResponse($this->pollService->getParticipantsEmailAddresses($pollId), Http::STATUS_OK);
+ } catch (DoesNotExistException $e) {
+ return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
+ } catch (NotAuthorizedException $e) {
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
+ }
+ }
+
+ /**
* Get valid values for configuration options
* @NoAdminRequired
* @CORS
diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php
index d1b4945b..04445482 100644
--- a/lib/Controller/PollController.php
+++ b/lib/Controller/PollController.php
@@ -267,4 +267,21 @@ class PollController extends Controller {
}
}
+ /**
+ * Collect email addresses from particitipants
+ * @NoAdminRequired
+ * @param Array $poll
+ * @return DataResponse
+ */
+
+ public function getParticipantsEmailAddresses($pollId) {
+ try {
+ return new DataResponse($this->pollService->getParticipantsEmailAddresses($pollId), Http::STATUS_OK);
+ } catch (DoesNotExistException $e) {
+ return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
+ } catch (NotAuthorizedException $e) {
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
+ }
+ }
+
}
diff --git a/lib/Db/ShareMapper.php b/lib/Db/ShareMapper.php
index 3a4408f3..87df1051 100644
--- a/lib/Db/ShareMapper.php
+++ b/lib/Db/ShareMapper.php
@@ -71,6 +71,28 @@ class ShareMapper extends QBMapper {
}
/**
+ * @param int $pollId
+ * @param string $userId
+ * @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->findEntity($qb);
+ }
+
+ /**
* @param string $token
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @return Share
diff --git a/lib/Db/Vote.php b/lib/Db/Vote.php
index 85b63c09..b304c149 100644
--- a/lib/Db/Vote.php
+++ b/lib/Db/Vote.php
@@ -71,7 +71,7 @@ class Vote extends Entity implements JsonSerializable {
];
}
- private function getDisplayName() {
+ public function getDisplayName() {
if (\OC::$server->getUserManager()->get($this->userId) instanceof IUser) {
return \OC::$server->getUserManager()->get($this->userId)->getDisplayName();
} else {
diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php
index 54fe8a34..2456fb84 100644
--- a/lib/Service/MailService.php
+++ b/lib/Service/MailService.php
@@ -156,6 +156,32 @@ class MailService {
}
+
+ /**
+ * @param integer $pollId
+ * @param string $userId
+ * @return string
+ */
+ public function resolveEmailAddress($pollId, $userId) {
+ $contactsManager = \OC::$server->getContactsManager();
+
+ if ($this->userManager->get($userId) instanceof IUser) {
+ return \OC::$server->getConfig()->getUserValue($userId, 'settings', 'email');
+ }
+
+ // if $userId is no site user, eval via shares
+ try {
+ $share = $this->shareMapper->findByPollAndUser($pollId, $userId);
+ if ($share->getUserEmail()) {
+ return $share->getUserEmail();
+ }
+ } catch (\Exception $e) {
+ // catch silently
+ }
+ return $userId;
+ }
+
+
/**
* @param Share $share
* @param String $defaultLang
@@ -219,7 +245,7 @@ class MailService {
return;
}
- } elseif ($share->getType() === 'external' || $share->getType() === 'email') {
+ } elseif ($share->getType() === 'external') {
$recipients[] = array(
'userId' => $share->getUserId(),
'eMailAddress' => $share->getUserEmail(),
@@ -341,6 +367,7 @@ class MailService {
if ($this->userManager->get($subscription->getUserId()) instanceof IUser) {
$lang = $this->config->getUserValue($subscription->getUserId(), 'core', 'lang');
} else {
+ $lang = $this->config->getUserValue($poll->getOwner(), 'core', 'lang');
continue;
}
diff --git a/lib/Service/PollService.php b/lib/Service/PollService.php
index e730b575..73b2044c 100644
--- a/lib/Service/PollService.php
+++ b/lib/Service/PollService.php
@@ -21,23 +21,26 @@
*
*/
- namespace OCA\Polls\Service;
+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;
- use OCA\Polls\Exceptions\InvalidPollTypeException;
- use OCA\Polls\Exceptions\NotAuthorizedException;
+use Exception;
+use OCP\AppFramework\Db\DoesNotExistException;
+use OCA\Polls\Exceptions\EmptyTitleException;
+use OCA\Polls\Exceptions\InvalidAccessException;
+use OCA\Polls\Exceptions\InvalidShowResultsException;
+use OCA\Polls\Exceptions\InvalidPollTypeException;
+use OCA\Polls\Exceptions\NotAuthorizedException;
- use OCA\Polls\Db\PollMapper;
- use OCA\Polls\Db\Poll;
- use OCA\Polls\Service\LogService;
- use OCA\Polls\Model\Acl;
+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 {
+class PollService {
/** @var PollMapper */
private $pollMapper;
@@ -45,9 +48,18 @@
/** @var Poll */
private $poll;
+ /** @var VoteMapper */
+ private $voteMapper;
+
+ /** @var Vote */
+ private $vote;
+
/** @var LogService */
private $logService;
+ /** @var MailService */
+ private $mailService;
+
/** @var Acl */
private $acl;
@@ -55,19 +67,28 @@
* 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,
- LogService $logService,
+ VoteMapper $voteMapper,
+ Vote $vote,
+ LogService $logService,
+ MailService $mailService,
Acl $acl
) {
$this->pollMapper = $pollMapper;
$this->poll = $poll;
- $this->logService = $logService;
+ $this->voteMapper = $voteMapper;
+ $this->vote = $vote;
+ $this->logService = $logService;
+ $this->mailService = $mailService;
$this->acl = $acl;
}
@@ -305,6 +326,27 @@
}
/**
+ * Collect email addresses from particitipants
+ * @NoAdminRequired
+ * @param Array $poll
+ * @return DataResponse
+ */
+
+ public function getParticipantsEmailAddresses($pollId) {
+ $this->poll = $this->pollMapper->find($pollId);
+ if (!$this->acl->setPollId($pollId)->getAllowEdit()) {
+ return [];
+ }
+
+ $votes = $this->voteMapper->findParticipantsByPoll($pollId);
+ foreach ($votes as $vote) {
+ $list[] = $vote->getDisplayName() . ' <' . $this->mailService->resolveEmailAddress($pollId, $vote->getUserId()) . '>';
+ }
+ return array_unique($list);
+ }
+
+
+ /**
* Get valid values for configuration options
* @NoAdminRequired
* @return array