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-08-11 22:56:26 +0300
committerdartcafe <github@dartcafe.de>2020-08-11 22:56:26 +0300
commita7d96426e31d8853a2def37c587b27fe1c1ff3f6 (patch)
tree35b9333582f1ad69f97dfc8c7af129a17a4de3d2 /lib
parentdad6b97a38348f620d20e5d20108a628269645ee (diff)
user can add own email address
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/PollController.php12
-rw-r--r--lib/Controller/ShareController.php24
-rw-r--r--lib/Model/Acl.php40
-rw-r--r--lib/Service/ShareService.php30
4 files changed, 84 insertions, 22 deletions
diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php
index a564fe40..494cb59a 100644
--- a/lib/Controller/PollController.php
+++ b/lib/Controller/PollController.php
@@ -151,8 +151,15 @@ class PollController extends Controller {
}
try {
- $shares = $this->shareService->list($pollId, $token);
+ if ($token) {
+ $share = $this->shareService->get($token);
+ $shares = [];
+ } else {
+ $share = null;
+ $shares = $this->shareService->list($pollId, $token);
+ }
} catch (Exception $e) {
+ $share = null;
$shares = [];
}
@@ -161,8 +168,9 @@ class PollController extends Controller {
'poll' => $poll,
'comments' => $comments,
'options' => $options,
+ 'share' => $share,
'shares' => $shares,
- 'votes' => $votes
+ 'votes' => $votes,
], Http::STATUS_OK);
}
diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php
index 9cd5f554..0c50b4c7 100644
--- a/lib/Controller/ShareController.php
+++ b/lib/Controller/ShareController.php
@@ -94,6 +94,26 @@ class ShareController extends Controller {
* @param string $userEmail
* @return DataResponse
*/
+ public function get($token) {
+ try {
+ return new DataResponse(['share' => $this->shareService->get($token)], Http::STATUS_CREATED);
+ } catch (NotAuthorizedException $e) {
+ return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
+ } catch (\Exception $e) {
+ return new DataResponse($e, Http::STATUS_CONFLICT);
+ }
+ }
+
+ /**
+ * Add share
+ * @NoAdminRequired
+ * @param int $pollId
+ * @param int $pollId
+ * @param string $type
+ * @param string $userId
+ * @param string $userEmail
+ * @return DataResponse
+ */
public function setEmailAddress($token, $userEmail) {
try {
return new DataResponse(['share' => $this->shareService->setEmailAddress($token, $userEmail)], Http::STATUS_OK);
@@ -115,10 +135,10 @@ class ShareController extends Controller {
* @param string $userName
* @return DataResponse
*/
- public function personal($token, $userName) {
+ public function personal($token, $userName, $emailAddress = '') {
try {
- return new DataResponse($this->shareService->personal($token, $userName), Http::STATUS_CREATED);
+ return new DataResponse($this->shareService->personal($token, $userName, $emailAddress), Http::STATUS_CREATED);
} catch (NotAuthorizedException $e) {
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
} catch (InvalidUsername $e) {
diff --git a/lib/Model/Acl.php b/lib/Model/Acl.php
index ee7b627b..86743c67 100644
--- a/lib/Model/Acl.php
+++ b/lib/Model/Acl.php
@@ -75,6 +75,9 @@ class Acl implements JsonSerializable {
/** @var Poll */
private $poll;
+ /** @var Share */
+ private $share;
+
/**
* Acl constructor.
* @param string $appName
@@ -84,7 +87,8 @@ class Acl implements JsonSerializable {
* @param PollMapper $pollMapper
* @param VoteMapper $voteMapper
* @param ShareMapper $shareMapper
- * @param Poll $pollMapper
+ * @param Poll $poll
+ * @param Share $share
*
*/
public function __construct(
@@ -94,7 +98,8 @@ class Acl implements JsonSerializable {
PollMapper $pollMapper,
VoteMapper $voteMapper,
ShareMapper $shareMapper,
- Poll $poll
+ Poll $poll,
+ Share $share
) {
$this->userId = $userId;
$this->userManager = $userManager;
@@ -103,6 +108,7 @@ class Acl implements JsonSerializable {
$this->voteMapper = $voteMapper;
$this->shareMapper = $shareMapper;
$this->poll = $poll;
+ $this->share = $share;
}
/**
@@ -117,26 +123,27 @@ class Acl implements JsonSerializable {
$this->token = $token;
$this->pollId = 0;
$this->userId = null;
- $share = $this->shareMapper->findByToken($token);
+ $this->share = $this->shareMapper->findByToken($token);
if (\OC::$server->getUserSession()->isLoggedIn()) {
- if ($share->getType() !== 'group' && $share->getType() !== 'public') {
+ if ($this->share->getType() !== 'group' && $this->share->getType() !== 'public') {
throw new NotAuthorizedException;
}
$this->userId = \OC::$server->getUserSession()->getUser()->getUID();
} else {
- if ($share->getType() === 'group' || $share->getType() === 'user') {
+ if ($this->share->getType() === 'group' || $this->share->getType() === 'user') {
throw new NotAuthorizedException;
}
- $this->userId = $share->getUserId();
+ $this->userId = $this->share->getUserId();
}
- $this->pollId = $share->getPollId();
+ $this->pollId = $this->share->getPollId();
} elseif ($pollId) {
$this->user = \OC::$server->getUserSession()->getUser()->getUID();
$this->pollId = $pollId;
+ $this->share = null;
}
$this->poll = $this->pollMapper->find($this->pollId);
@@ -310,6 +317,16 @@ class Acl implements JsonSerializable {
* @NoAdminRequired
* @return bool
*/
+ public function getAllowSubscribe(): bool {
+ return ($this->hasEmail())
+ && !$this->poll->getDeleted()
+ && $this->getAllowView();
+ }
+
+ /**
+ * @NoAdminRequired
+ * @return bool
+ */
public function getAllowComment(): bool {
return !$this->poll->getDeleted() && boolval($this->userId);
}
@@ -348,6 +365,14 @@ class Acl implements JsonSerializable {
return $this->token;
}
+ private function hasEmail():bool {
+ if ($this->share) {
+ return strlen($this->share->getUserEmail()) > 0;
+ } else {
+ return \OC::$server->getUserSession()->isLoggedIn();
+ }
+ }
+
/**
* @return array
*/
@@ -367,6 +392,7 @@ class Acl implements JsonSerializable {
'allowEdit' => $this->getAllowEdit(),
'allowSeeResults' => $this->getAllowSeeResults(),
'allowSeeUsernames' => $this->getAllowSeeUsernames(),
+ 'allowSubscribe' => $this->getAllowSubscribe(),
'userHasVoted' => $this->getUserHasVoted(),
'groupShare' => $this->getGroupShare(),
'personalShare' => $this->getPersonalShare(),
diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php
index 70881cf9..83f6233f 100644
--- a/lib/Service/ShareService.php
+++ b/lib/Service/ShareService.php
@@ -120,6 +120,10 @@ class ShareService {
throw new NotAuthorizedException;
}
+ if ($type === 'contact') {
+ $type = 'external';
+ }
+
$this->share = new Share();
$this->share->setType($type);
$this->share->setPollId($pollId);
@@ -168,19 +172,20 @@ class ShareService {
* @throws NotAuthorizedException
* @throws InvalidUsername
*/
- public function personal($token, $userName) {
- $publicShare = $this->shareMapper->findByToken($token);
+ public function personal($token, $userName, $emailAddress) {
+ $this->share = $this->shareMapper->findByToken($token);
// Return of validatePublicUsername is a DataResponse
- $checkUsername = $this->systemController->validatePublicUsername($publicShare->getPollId(), $userName, $token);
+ $checkUsername = $this->systemController->validatePublicUsername($this->share->getPollId(), $userName, $token);
// if status is not 200, return DataResponse from validatePublicUsername
if ($checkUsername->getStatus() !== 200) {
throw new InvalidUsername;
}
- if ($publicShare->getType() === 'public') {
+ if ($this->share->getType() === 'public') {
+ $pollId = $this->share->getPollId();
$this->share = new Share();
$this->share->setToken(\OC::$server->getSecureRandom()->generate(
16,
@@ -189,17 +194,20 @@ class ShareService {
ISecureRandom::CHAR_UPPER
));
$this->share->setType('external');
- $this->share->setPollId($publicShare->getPollId());
+ $this->share->setPollId($pollId);
$this->share->setUserId($userName);
- $this->share->setUserEmail('');
+ $this->share->setUserEmail($emailAddress);
$this->share->setInvitationSent(time());
- return $this->shareMapper->insert($this->share);
+ $this->shareMapper->insert($this->share);
+ $this->mailService->sendInvitationMail($this->share->getToken());
+ return $this->share;
- } elseif ($publicShare->getType() === 'email') {
+ } elseif ($this->share->getType() === 'email') {
- $publicShare->setType('external');
- $publicShare->setUserId($userName);
- return $this->shareMapper->update($publicShare);
+ $this->share->setType('external');
+ $this->share->setUserId($userName);
+ $this->share->setUserEmail($emailAddress);
+ return $this->shareMapper->update($this->share);
} else {
throw new NotAuthorizedException;