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:
authorRené Gieling <github@dartcafe.de>2022-04-15 13:21:05 +0300
committerGitHub <noreply@github.com>2022-04-15 13:21:05 +0300
commit676b357b0fd26926e7d59fd1f123f30e51c9cf95 (patch)
treeb2592012eca60c30594efdb925c10c7418ef9944 /lib
parent0cf60c7946d947a86603f00b915094280fe893e7 (diff)
Allow email share adding using common email formats with name (#2375)
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/ShareController.php6
-rw-r--r--lib/Model/UserGroup/Email.php9
-rw-r--r--lib/Model/UserGroup/UserBase.php2
-rw-r--r--lib/Service/ShareService.php4
-rw-r--r--lib/Service/SystemService.php13
5 files changed, 20 insertions, 14 deletions
diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php
index b0494f2e..53843f66 100644
--- a/lib/Controller/ShareController.php
+++ b/lib/Controller/ShareController.php
@@ -79,9 +79,9 @@ class ShareController extends Controller {
* Add share
* @NoAdminRequired
*/
- public function add(int $pollId, string $type, string $userId = ''): DataResponse {
- return $this->responseCreate(function () use ($pollId, $type, $userId) {
- return ['share' => $this->shareService->add($pollId, $type, $userId)];
+ public function add(int $pollId, string $type, string $userId = '', string $displayName = ''): DataResponse {
+ return $this->responseCreate(function () use ($pollId, $type, $userId, $displayName) {
+ return ['share' => $this->shareService->add($pollId, $type, $userId, $displayName)];
});
}
diff --git a/lib/Model/UserGroup/Email.php b/lib/Model/UserGroup/Email.php
index 510c1f2b..09e62237 100644
--- a/lib/Model/UserGroup/Email.php
+++ b/lib/Model/UserGroup/Email.php
@@ -32,14 +32,15 @@ class Email extends UserBase {
public function __construct(
string $id,
- string $displayName = ''
+ string $displayName = '',
+ string $emailAddress = ''
) {
parent::__construct($id, self::TYPE);
$this->icon = self::ICON;
- $this->description = Container::getL10N()->t('External Email');
+ $this->description = $emailAddress ? $emailAddress : Container::getL10N()->t('External Email');
$this->richObjectType = 'email';
-
- $this->emailAddress = $id;
+
+ $this->emailAddress = $emailAddress ? $emailAddress : $id;
$this->displayName = $displayName ? $displayName : $this->displayName;
}
diff --git a/lib/Model/UserGroup/UserBase.php b/lib/Model/UserGroup/UserBase.php
index 5e8cb65b..bf085798 100644
--- a/lib/Model/UserGroup/UserBase.php
+++ b/lib/Model/UserGroup/UserBase.php
@@ -285,7 +285,7 @@ class UserBase implements \JsonSerializable {
case Admin::TYPE:
return new Admin($id);
case Email::TYPE:
- return new Email($id);
+ return new Email($id, $displayName, $emailAddress);
case self::TYPE_PUBLIC:
return new GenericUser($id, self::TYPE_PUBLIC);
case self::TYPE_EXTERNAL:
diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php
index 30e17530..706ccd88 100644
--- a/lib/Service/ShareService.php
+++ b/lib/Service/ShareService.php
@@ -281,7 +281,7 @@ class ShareService {
*
* @return Share
*/
- public function add(int $pollId, string $type, string $userId = ''): Share {
+ public function add(int $pollId, string $type, string $userId = '', string $displayName = '', string $emailAddress = ''): Share {
$this->acl->setPollId($pollId, Acl::PERMISSION_POLL_EDIT);
if ($type === UserBase::TYPE_PUBLIC) {
@@ -297,7 +297,7 @@ class ShareService {
}
}
- $this->create($pollId, UserBase::getUserGroupChild($type, $userId));
+ $this->create($pollId, UserBase::getUserGroupChild($type, $userId, $displayName, $emailAddress));
$this->eventDispatcher->dispatchTyped(new ShareCreateEvent($this->share));
diff --git a/lib/Service/SystemService.php b/lib/Service/SystemService.php
index c3f5e763..2a370337 100644
--- a/lib/Service/SystemService.php
+++ b/lib/Service/SystemService.php
@@ -41,7 +41,9 @@ use OCA\Polls\Model\UserGroup\UserBase;
use OCP\IUserManager;
class SystemService {
-
+ private const REGEX_VALID_MAIL = '/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/';
+ private const REGEX_PARSE_MAIL = '/(?:"?([^"]*)"?\s)?(?:<?(.+@[^>]+)>?)/';
+
/** @var VoteMapper */
private $voteMapper;
@@ -62,7 +64,7 @@ class SystemService {
* @return bool
*/
private static function isValidEmail(string $emailAddress): bool {
- return (!preg_match('/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/', $emailAddress)) ? false : true;
+ return (!preg_match(self::REGEX_VALID_MAIL, $emailAddress)) ? false : true;
}
/**
@@ -118,8 +120,11 @@ class SystemService {
public function getSiteUsersAndGroups(string $query = ''): array {
$list = [];
if ($query !== '') {
- if (self::isValidEmail($query)) {
- $list[] = new Email($query);
+ preg_match_all(self::REGEX_PARSE_MAIL, $query, $parsedQuery);
+ $emailAddress = $parsedQuery[2][0];
+ $displayName = $parsedQuery[1][0];
+ if ($emailAddress && self::isValidEmail($emailAddress)) {
+ $list[] = new Email($emailAddress, $displayName, $emailAddress);
}
$list = array_merge($list, UserBase::search($query));