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
diff options
context:
space:
mode:
authorRené Gieling <github@dartcafe.de>2021-01-02 02:48:46 +0300
committerGitHub <noreply@github.com>2021-01-02 02:48:46 +0300
commit4729f28c4c1afd48fd8083f4ccd6f6055873a326 (patch)
tree79b987a460387ee46c6331a7ea8fe7a6ab43e88d /lib/Service/ShareService.php
parenta90dd386b855d21d18e9734df7d7a13ed35dfa0b (diff)
Avoid duplicate entries via unique index in certain dbs (#1284)
Squashing due to many commits
Diffstat (limited to 'lib/Service/ShareService.php')
-rw-r--r--lib/Service/ShareService.php22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php
index f06002a8..64b01b97 100644
--- a/lib/Service/ShareService.php
+++ b/lib/Service/ShareService.php
@@ -128,32 +128,36 @@ class ShareService {
/**
* * crate share - MUST BE PRIVATE!
- * * convert type contact to type email
*
* @return Share
*/
private function create(int $pollId, UserGroupClass $userGroup, bool $preventInvitation = false): Share {
- $this->share = new Share();
- $this->share->setToken(\OC::$server->getSecureRandom()->generate(
+ $preventInvitation = $userGroup->getType() === UserGroupClass::TYPE_PUBLIC ? true : $preventInvitation;
+ $token = \OC::$server->getSecureRandom()->generate(
16,
ISecureRandom::CHAR_DIGITS .
ISecureRandom::CHAR_LOWER .
ISecureRandom::CHAR_UPPER
- ));
+ );
+
+ $this->share = new Share();
+ $this->share->setToken($token);
$this->share->setPollId($pollId);
- $this->share->setInvitationSent($preventInvitation ? time() : 0);
- $this->share->setDisplayName($userGroup->getDisplayName());
- $this->share->setEmailAddress($userGroup->getEmailAddress());
// Convert user type contact to share type email
- if ($userGroup->getType() === Share::TYPE_CONTACT) {
+ if ($userGroup->getType() === UserGroupClass::TYPE_CONTACT) {
$this->share->setType(UserGroupClass::TYPE_EMAIL);
$this->share->setUserId($userGroup->getEmailAddress());
} else {
$this->share->setType($userGroup->getType());
- $this->share->setUserId($userGroup->getPublicId());
+ $this->share->setUserId($userGroup->getType() === UserGroupClass::TYPE_PUBLIC ? $token : $userGroup->getPublicId());
}
+ $this->share->setInvitationSent($preventInvitation ? time() : 0);
+ $this->share->setType($userGroup->getType());
+ $this->share->setDisplayName($userGroup->getDisplayName());
+ $this->share->setEmailAddress($userGroup->getEmailAddress());
+
return $this->shareMapper->insert($this->share);
}