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-10-04 15:07:27 +0300
committerdartcafe <github@dartcafe.de>2020-10-04 15:07:27 +0300
commit59b7898c502e3c5970999c1acc9f10cdde297441 (patch)
treee510d7420e0da0dade0c21f15ac34c55dfdd4976 /lib
parente01e3a7581d8b4be285423667c81540bc7a4f503 (diff)
some refactoring
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/ShareController.php25
-rw-r--r--lib/Controller/SystemController.php7
-rw-r--r--lib/Db/Share.php28
-rw-r--r--lib/Exceptions/CirclesNotEnabled.php39
-rw-r--r--lib/Exceptions/ContactGroupNotFound.php39
-rw-r--r--lib/Exceptions/ContactsNotEnabled.php39
-rw-r--r--lib/Exceptions/MultipleContactsFound.php39
-rw-r--r--lib/Interfaces/IUserObj.php96
-rw-r--r--lib/Model/Circle.php234
-rw-r--r--lib/Model/Contact.php261
-rw-r--r--lib/Model/ContactGroup.php225
-rw-r--r--lib/Model/Email.php182
-rw-r--r--lib/Model/Group.php204
-rw-r--r--lib/Model/User.php254
-rw-r--r--lib/Service/CirclesService.php111
-rw-r--r--lib/Service/ContactsService.php112
-rw-r--r--lib/Service/MailService.php46
-rw-r--r--lib/Service/ShareService.php28
-rw-r--r--lib/Service/SystemService.php130
19 files changed, 1568 insertions, 531 deletions
diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php
index 3ad41c27..a8d5c524 100644
--- a/lib/Controller/ShareController.php
+++ b/lib/Controller/ShareController.php
@@ -36,20 +36,14 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCA\Polls\DB\Share;
-use OCA\Polls\Service\CirclesService;
-use OCA\Polls\Service\ContactsService;
use OCA\Polls\Service\MailService;
use OCA\Polls\Service\ShareService;
use OCA\Polls\Service\SystemService;
+use OCA\Polls\Model\Circle;
+use OCA\Polls\Model\ContactGroup;
class ShareController extends Controller {
- /** @var CirclesService */
- private $circlesService;
-
- /** @var ContactsService */
- private $contactsService;
-
/** @var MailService */
private $mailService;
@@ -63,8 +57,6 @@ class ShareController extends Controller {
* ShareController constructor.
* @param string $appName
* @param IRequest $request
- * @param CirclesService $circlesService
- * @param ContactsService $contactsService
* @param MailService $mailService
* @param ShareService $shareService
* @param SystemService $systemService
@@ -72,15 +64,11 @@ class ShareController extends Controller {
public function __construct(
string $appName,
IRequest $request,
- CirclesService $circlesService,
- ContactsService $contactsService,
MailService $mailService,
ShareService $shareService,
SystemService $systemService
) {
parent::__construct($appName, $request);
- $this->circlesService = $circlesService;
- $this->contactsService = $contactsService;
$this->mailService = $mailService;
$this->shareService = $shareService;
$this->systemService = $systemService;
@@ -212,13 +200,12 @@ class ShareController extends Controller {
try {
$share = $this->shareService->get($token);
if ($share->getType() === Share::TYPE_CIRCLE) {
- foreach ($this->circlesService->getCircleMembers($share->getUserId()) as $user) {
- \OC::$server->getLogger()->alert(json_encode($user));
- $shares[] = $this->shareService->add($share->getPollId(), $user->getType(), $user->getUserId());
+ foreach (new Circle($share->getUserId()->getMembers()) as $member) {
+ $shares[] = $this->shareService->add($share->getPollId(), $member->getType(), $member->getId());
}
} elseif ($share->getType() === Share::TYPE_CONTACTGROUP) {
- foreach ($this->contactsService->getContactsGroupMembers($share->getUserId()) as $member) {
- $shares[] = $this->shareService->add($share->getPollId(), Share::TYPE_CONTACT, $member['user'], $member['emailAddress']);
+ foreach (new ContactGroup($share->getUserId()->getMembers()) as $contact) {
+ $shares[] = $this->shareService->add($share->getPollId(), Share::TYPE_CONTACT, $contact->getId(), $contact->getEmailAddress());
}
}
diff --git a/lib/Controller/SystemController.php b/lib/Controller/SystemController.php
index 7a18d1bb..0cd50625 100644
--- a/lib/Controller/SystemController.php
+++ b/lib/Controller/SystemController.php
@@ -26,16 +26,12 @@ namespace OCA\Polls\Controller;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
-use OCA\Polls\Service\ContactsService;
use OCA\Polls\Service\SystemService;
use OCP\IRequest;
class SystemController extends Controller {
- /** @var ContactsService */
- private $contactsService;
-
/** @var SystemService */
private $systemService;
@@ -44,17 +40,14 @@ class SystemController extends Controller {
* @param string $appName
* @param IRequest $request
* @param SystemService $systemService
- * @param ContactsService $contactsService
*/
public function __construct(
string $appName,
IRequest $request,
- ContactsService $contactsService,
SystemService $systemService
) {
parent::__construct($appName, $request);
- $this->contactsService = $contactsService;
$this->systemService = $systemService;
}
diff --git a/lib/Db/Share.php b/lib/Db/Share.php
index 13e93078..7df6df6e 100644
--- a/lib/Db/Share.php
+++ b/lib/Db/Share.php
@@ -27,7 +27,6 @@ use JsonSerializable;
use OCP\IUser;
use OCP\AppFramework\Db\Entity;
-use OCA\Polls\Model\User;
/**
* @method string getId()
@@ -44,14 +43,16 @@ use OCA\Polls\Model\User;
* @method void setUserEmail(string $value)
* @method int getInvitationSent()
* @method void setInvitationSent(integer $value)
+ * @method int getDisplayName()
+ * @method void setDisplayName(string $value)
*/
class Share extends Entity implements JsonSerializable {
- public const TYPE_USER = User::TYPE_USER;
- public const TYPE_EMAIL = User::TYPE_EMAIL;
- public const TYPE_CIRCLE = User::TYPE_CIRCLE;
- public const TYPE_GROUP = User::TYPE_GROUP;
- public const TYPE_CONTACTGROUP = User::TYPE_CONTACTGROUP;
- public const TYPE_CONTACT = User::TYPE_CONTACT;
+ public const TYPE_USER = 'user';
+ public const TYPE_EMAIL = 'email';
+ public const TYPE_CIRCLE = 'circle';
+ public const TYPE_GROUP = 'group';
+ public const TYPE_CONTACTGROUP = 'contactGroup';
+ public const TYPE_CONTACT = 'contact';
public const TYPE_PUBLIC = 'public';
public const TYPE_EXTERNAL = 'external';
@@ -85,22 +86,11 @@ class Share extends Entity implements JsonSerializable {
'userId' => $this->userId,
'userEmail' => $this->userEmail,
'invitationSent' => intval($this->invitationSent),
- 'displayName' => $this->getDisplayName(),
+ 'displayName' => $this->displayName,
'externalUser' => $this->externalUser()
];
}
- private function getDisplayName() {
- if ($this->type === self::TYPE_EMAIL && !$this->userId) {
- $user = new User($this->type, $this->userEmail, $this->userEmail, $this->displayName);
- } elseif ($this->type === self::TYPE_CONTACT && !$this->userId) {
- $user = new User($this->type, $this->userId, $this->userEmail, $this->displayName);
- } else {
- $user = new User($this->type, $this->userId);
- }
- return $user->getDisplayName();
- }
-
private function externalUser() {
return (!\OC::$server->getUserManager()->get($this->userId) instanceof IUser);
}
diff --git a/lib/Exceptions/CirclesNotEnabled.php b/lib/Exceptions/CirclesNotEnabled.php
new file mode 100644
index 00000000..075d53c5
--- /dev/null
+++ b/lib/Exceptions/CirclesNotEnabled.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * @copyright Copyright (c) 2020 René Gieling <github@dartcafe.de>
+ *
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Polls\Exceptions;
+
+use OCP\AppFramework\Http;
+
+class CirclesNotEnabled extends \Exception {
+ /**
+ * TooShortException Constructor
+ * @param string $e exception message
+ */
+ public function __construct($e = 'Circles is not enabled for this user') {
+ parent::__construct($e);
+ }
+ public function getStatus() {
+ return Http::STATUS_NOT_FOUND;
+ }
+}
diff --git a/lib/Exceptions/ContactGroupNotFound.php b/lib/Exceptions/ContactGroupNotFound.php
new file mode 100644
index 00000000..8b71d1d4
--- /dev/null
+++ b/lib/Exceptions/ContactGroupNotFound.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * @copyright Copyright (c) 2020 René Gieling <github@dartcafe.de>
+ *
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Polls\Exceptions;
+
+use OCP\AppFramework\Http;
+
+class ContactGroupNotFound extends \Exception {
+ /**
+ * TooShortException Constructor
+ * @param string $e exception message
+ */
+ public function __construct($e = 'Contact Group not found') {
+ parent::__construct($e);
+ }
+ public function getStatus() {
+ return Http::STATUS_NOT_FOUND;
+ }
+}
diff --git a/lib/Exceptions/ContactsNotEnabled.php b/lib/Exceptions/ContactsNotEnabled.php
new file mode 100644
index 00000000..0a49e39f
--- /dev/null
+++ b/lib/Exceptions/ContactsNotEnabled.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * @copyright Copyright (c) 2020 René Gieling <github@dartcafe.de>
+ *
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Polls\Exceptions;
+
+use OCP\AppFramework\Http;
+
+class ContactsNotEnabled extends \Exception {
+ /**
+ * TooShortException Constructor
+ * @param string $e exception message
+ */
+ public function __construct($e = 'Contacts is not enabled') {
+ parent::__construct($e);
+ }
+ public function getStatus() {
+ return Http::STATUS_NOT_FOUND;
+ }
+}
diff --git a/lib/Exceptions/MultipleContactsFound.php b/lib/Exceptions/MultipleContactsFound.php
new file mode 100644
index 00000000..ab91fb31
--- /dev/null
+++ b/lib/Exceptions/MultipleContactsFound.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * @copyright Copyright (c) 2020 René Gieling <github@dartcafe.de>
+ *
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Polls\Exceptions;
+
+use OCP\AppFramework\Http;
+
+class MultipleContactsFound extends \Exception {
+ /**
+ * TooShortException Constructor
+ * @param string $e exception message
+ */
+ public function __construct($e = 'Multiple Contacts found') {
+ parent::__construct($e);
+ }
+ public function getStatus() {
+ return Http::STATUS_CONFLICT;
+ }
+}
diff --git a/lib/Interfaces/IUserObj.php b/lib/Interfaces/IUserObj.php
new file mode 100644
index 00000000..677fcbd1
--- /dev/null
+++ b/lib/Interfaces/IUserObj.php
@@ -0,0 +1,96 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ *
+ * @author Andrew Brown <andrew@casabrown.com>
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @author Jakob Sack <mail@jakobsack.de>
+ * @author Jörn Friedrich Dreyer <jfd@butonic.de>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Polls\Interfaces;
+
+/**
+ * IUserObj Interface
+ */
+interface IUserObj {
+
+ /**
+ * getId
+ * @return string
+ */
+ public function getId();
+
+ /**
+ * getId
+ * @return string
+ */
+ public function getUser();
+
+ /**
+ * getType
+ * @return string
+ */
+ public function getType();
+
+ /**
+ * getLanguage
+ * @return string
+ */
+ public function getLanguage();
+
+
+ /**
+ * getDisplayName
+ * @return string
+ */
+ public function getDisplayName();
+
+ /**
+ * getDesc
+ * @return string
+ */
+ public function getDesc();
+
+ /**
+ * getIcon
+ * @return string
+ */
+ public function getIcon();
+
+ /**
+ * getOrganisation
+ * @return string
+ */
+ public function getOrganisation();
+
+ /**
+ * getEmailAddress
+ * @return string
+ */
+ public function getEmailAddress();
+
+ /**
+ * search
+ * @param string $query
+ * @param array $skip - list of items zu skip
+ * @return self[]
+ */
+ public static function search($query);
+}
diff --git a/lib/Model/Circle.php b/lib/Model/Circle.php
new file mode 100644
index 00000000..d8b0f981
--- /dev/null
+++ b/lib/Model/Circle.php
@@ -0,0 +1,234 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ *
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\Polls\Model;
+
+use OCP\IL10N;
+use OCA\Circles\Api\v1\Circles;
+
+use OCA\Polls\Exceptions\CirclesNotEnabled;
+use OCA\Polls\Interfaces\IUserObj;
+
+class Circle implements \JsonSerializable, IUserObj {
+ public const TYPE = 'circle';
+
+ /** @var IL10N */
+ private $l10n;
+
+ /** @var string */
+ private $id;
+
+ private $circle;
+
+ /**
+ * Group constructor.
+ * @param $id
+ * @param $displayName
+ */
+ public function __construct(
+ $id
+ ) {
+ $this->id = $id;
+ $this->load();
+ }
+
+ /**
+ * getId
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getId() {
+ return $this->id;
+ }
+
+ /**
+ * getUser
+ * Necessary for the avatar component
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getUser() {
+ return $this->id;
+ }
+
+ /**
+ * getType
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getType() {
+ return self::TYPE;
+ }
+
+ /**
+ * getlanguage
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getLanguage() {
+ return '';
+ }
+
+ /**
+ * getDisplayName
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getDisplayName() {
+ return Circles::detailsCircle($this->id)->getName();
+ }
+
+ /**
+ * getOrganisation
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getOrganisation() {
+ return '';
+ }
+
+ /**
+ * getEmailAddress
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getEmailAddress() {
+ return '';
+ }
+
+ /**
+ * getDesc
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getDesc() {
+ return Circles::detailsCircle($this->id)->gettypeLongString();
+ }
+
+ /**
+ * getIcon
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getIcon() {
+ return 'icon-circles';
+ }
+
+ /**
+ * load
+ * @NoAdminRequired
+ * @return Array
+ * @throws CirclesNotEnabled
+ */
+ private function load() {
+ if (\OC::$server->getAppManager()->isEnabledForUser('circles')) {
+ $this->circle = Circles::detailsCircle($this->id);
+ } else {
+ throw new CirclesNotEnabled();
+ }
+ }
+
+ /**
+ * isEnabled
+ * @NoAdminRequired
+ * @return Boolean
+ */
+ public static function isEnabled() {
+ return \OC::$server->getAppManager()->isEnabledForUser('circles');
+ }
+
+ /**
+ * listRaw
+ * @NoAdminRequired
+ * @param string $query
+ * @return Array
+ */
+ public static function listRaw($query = '') {
+ $circles = [];
+ if (\OC::$server->getAppManager()->isEnabledForUser('circles')) {
+ $circles = Circles::listCircles(\OCA\Circles\Model\Circle::CIRCLES_ALL, $query);
+ }
+
+ return $circles;
+ }
+
+ /**
+ * search
+ * @NoAdminRequired
+ * @param string $query
+ * @param array $skip - group names to skip in return array
+ * @return Circle[]
+ */
+ public static function search($query = '', $skip = []) {
+ $circles = [];
+ foreach (self::listRaw($query) as $circle) {
+ if (!in_array($circle->getUniqueId(), $skip)) {
+ $circles[] = new Self($circle->getUniqueId());
+ }
+ }
+
+ return $circles;
+ }
+
+ /**
+ * Get a list of circle members
+ * @NoAdminRequired
+ * @param string $query
+ * @return User[]
+ */
+ public function getMembers() {
+ $members = [];
+ if (\OC::$server->getAppManager()->isEnabledForUser('circles')) {
+ foreach (Circles::detailsCircle($this->id)->getMembers() as $circleMember) {
+ if ($circleMember->getType() === Circles::TYPE_USER) {
+ $members[] = new User($circleMember->getUserId());
+ } elseif ($circleMember->getType() === Circles::TYPE_MAIL) {
+ $members[] = new Email($circleMember->getUserId());
+ } elseif ($circleMember->getType() === Circles::TYPE_CONTACT) {
+ $members[] = new Contact($circleMember->getUserId());
+ } else {
+ continue;
+ }
+ }
+ }
+ return $members;
+ }
+
+ /**
+ * @return array
+ */
+ public function jsonSerialize(): array {
+ return [
+ 'id' => $this->id,
+ 'user' => $this->id,
+ 'type' => $this->getType(),
+ 'displayName' => $this->getDisplayName(),
+ 'organisation' => $this->getOrganisation(),
+ 'emailAddress' => $this->getEmailAddress(),
+ 'desc' => $this->getDesc(),
+ 'icon' => $this->getIcon(),
+ 'isNoUser' => true,
+ ];
+ }
+}
diff --git a/lib/Model/Contact.php b/lib/Model/Contact.php
new file mode 100644
index 00000000..1609b52b
--- /dev/null
+++ b/lib/Model/Contact.php
@@ -0,0 +1,261 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ *
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Polls\Model;
+
+use OCP\IL10N;
+use OCA\Polls\Exceptions\MultipleContactsFound;
+use OCA\Polls\Exceptions\ContactsNotEnabled;
+use OCA\Polls\Interfaces\IUserObj;
+
+class Contact implements \JsonSerializable, IUserObj {
+ public const TYPE = 'contact';
+
+ /** @var IL10N */
+ private $l10n;
+
+ /** @var string */
+ private $id;
+
+ /** @var string */
+ private $type;
+
+ /** @var string */
+ private $displayName = '';
+
+ /** @var string */
+ private $desc = '';
+
+ /** @var array */
+ private $contact;
+
+ /**
+ * User constructor.
+ * @param $type
+ * @param $id
+ * @param $displayName
+ */
+ public function __construct(
+ $id,
+ $displayName = ''
+ ) {
+ $this->id = $id;
+ $this->displayName = $displayName;
+
+ $this->l10n = \OC::$server->getL10N('polls');
+ $this->load();
+ }
+
+ /**
+ * Get id
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getId() {
+ return $this->id;
+ }
+
+ /**
+ * getUser
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getUser() {
+ return $this->id;
+ }
+
+ /**
+ * Get user type
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getType() {
+ return self::TYPE;
+ }
+
+ /**
+ * Get language of user, if type = TYPE_USER
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getLanguage() {
+ return '';
+ }
+
+ /**
+ * Get displayName
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getDisplayName() {
+ return isset($this->contact['FN']) ? $this->contact['FN'] : $this->displayName;
+ }
+
+ /**
+ * Get additional description, if available
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getDesc() {
+ $desc = $this->getCategories();
+ if (isset($this->contact['ORG'])) {
+ array_unshift($desc, $this->getOrganisation());
+ }
+ if (count($desc) > 0) {
+ return implode(", ", $desc);
+ } else {
+ return \OC::$server->getL10N('polls')->t('Contact');
+ }
+ }
+
+ /**
+ * Get email address
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getEmailAddress() {
+ return isset($this->contact['EMAIL'][0]) ? $this->contact['EMAIL'][0] : '';
+ }
+
+ /**
+ * Get organisation, if type = TYPE_CONTACT
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getOrganisation() {
+ return isset($this->contact['ORG']) ? $this->contact['ORG'] : '';
+ }
+
+ /**
+ * getCategories
+ * @NoAdminRequired
+ * @return Array
+ */
+ public function getCategories() {
+ if (isset($this->contact['CATEGORIES'])) {
+ return explode(',', $this->contact['CATEGORIES']);
+ } else {
+ return [];
+ }
+ }
+
+ /**
+ * Get icon class
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getIcon() {
+ return 'icon-mail';
+ }
+
+ /**
+ * Load contact, if type = TYPE_CONTACT
+ * @NoAdminRequired
+ * @return String
+ * @throws MultipleContactsFound
+ * @throws ContactsNotEnabled
+ */
+ private function load() {
+ $this->contact = [];
+ $parts = explode(":", $this->id);
+ $this->id = end($parts);
+ if (\OC::$server->getAppManager()->isEnabledForUser('contacts')) {
+ // Search for UID and FN
+ // Before this implementation contacts where stored with their FN property
+ // From now on, the contact's UID is used as identifier
+ // TODO: Remove FN as search range for loading a contact in a polls version later than 1.6
+ $contacts = \OC::$server->getContactsManager()->search($this->id, ['UID', 'FN']);
+
+ if (count($contacts) === 1) {
+ $this->contact = $contacts[0];
+ $this->id = $this->contact['UID'];
+ } elseif (count($contacts) > 1) {
+ throw new MultipleContactsFound('Multiple contacts found for id '. $this->id);
+ }
+ } else {
+ throw new ContactsNotEnabled();
+ }
+ }
+
+ /**
+ * isEnabled
+ * @NoAdminRequired
+ * @return Boolean
+ */
+ public static function isEnabled() {
+ return \OC::$server->getAppManager()->isEnabledForUser('contacts');
+ }
+
+ /**
+ * listRaw
+ * @NoAdminRequired
+ * @param string $query
+ * @return Array
+ */
+ public static function listRaw($query = '', $queryRange = ['FN', 'EMAIL', 'ORG', 'CATEGORIES']) {
+ $contacts = [];
+ if (\OC::$server->getAppManager()->isEnabledForUser('contacts')) {
+ foreach (\OC::$server->getContactsManager()->search($query, $queryRange) as $contact) {
+ if (!array_key_exists('isLocalSystemBook', $contact) && array_key_exists('EMAIL', $contact)) {
+ $contacts[] = $contact;
+ }
+ }
+ }
+ return $contacts;
+ }
+
+ /**
+ * list
+ * @NoAdminRequired
+ * @param string $query
+ * @param array $queryRange
+ * @return self[]
+ */
+ public static function search($query = '', $queryRange = ['FN', 'EMAIL', 'ORG', 'CATEGORIES']) {
+ $contacts = [];
+ foreach (self::listRaw($query, $queryRange) as $contact) {
+ $contacts[] = new Self($contact['UID']);
+ }
+ return $contacts;
+ }
+
+
+ /**
+ * @return array
+ */
+ public function jsonSerialize(): array {
+ return [
+ 'id' => $this->getId(),
+ 'user' => $this->id,
+ 'type' => $this->getType(),
+ 'displayName' => $this->getDisplayName(),
+ 'organisation' => $this->getOrganisation(),
+ 'emailAddress' => $this->getEmailAddress(),
+ 'desc' => $this->getDesc(),
+ 'icon' => $this->getIcon(),
+ 'categories' => $this->getCategories(),
+ 'isNoUser' => true,
+ 'isGuest' => true,
+ ];
+ }
+}
diff --git a/lib/Model/ContactGroup.php b/lib/Model/ContactGroup.php
new file mode 100644
index 00000000..24a81aca
--- /dev/null
+++ b/lib/Model/ContactGroup.php
@@ -0,0 +1,225 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ *
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\Polls\Model;
+
+use OCP\IL10N;
+use OCA\Polls\Interfaces\IUserObj;
+
+class ContactGroup implements \JsonSerializable, IUserObj {
+ public const TYPE = 'contactGroup';
+
+ /** @var IL10N */
+ private $l10n;
+
+ /** @var string */
+ private $id;
+
+ /** @var string */
+ private $displayName = '';
+
+ private $group;
+
+ /**
+ * Group constructor.
+ * @param $id
+ * @param $displayName
+ */
+ public function __construct(
+ $id,
+ $displayName = ''
+ ) {
+ $this->id = $id;
+ $this->displayName = $displayName;
+ }
+
+ /**
+ * getId
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getId() {
+ return $this->id;
+ }
+
+ /**
+ * getType
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getType() {
+ return self::TYPE;
+ }
+
+ /**
+ * getUser
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getUser() {
+ return $this->id;
+ }
+
+ /**
+ * getlanguage
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getLanguage() {
+ return '';
+ }
+
+ /**
+ * getDisplayName
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getDisplayName() {
+ return $this->id;
+ }
+
+ /**
+ * getOrganisation
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getOrganisation() {
+ return '';
+ }
+
+ /**
+ * getEmailAddress
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getEmailAddress() {
+ return '';
+ }
+
+ /**
+ * getDesc
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getDesc() {
+ return \OC::$server->getL10N('polls')->t('Contact group');
+ }
+
+ /**
+ * getIcon
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getIcon() {
+ return 'icon-group';
+ }
+
+ /**
+ * listRaw
+ * @NoAdminRequired
+ * @param string $query
+ * @return Array
+ */
+ public static function listRaw($query = '') {
+ $contactGroups = [];
+ if (\OC::$server->getContactsManager()->isEnabled()) {
+ // find contact, which are member of the requested Group
+ foreach (\OC::$server->getContactsManager()->search($query, ['CATEGORIES']) as $contact) {
+ // get all groups from the found contact and explode to array
+ $temp = explode(',', $contact['CATEGORIES']);
+ foreach ($temp as $contactGroup) {
+ if (stripos($contactGroup, $query) === 0) {
+ $contactGroups[] = $contactGroup;
+ }
+ }
+ }
+ }
+ return array_unique($contactGroups);
+ }
+
+ /**
+ * Get a list of contact groups
+ * @NoAdminRequired
+ * @param string $query
+ * @return Array
+ */
+ public static function search($query = '') {
+ if (\OC::$server->getContactsManager()->isEnabled() && $query) {
+ $contactGroups = [];
+ foreach (self::listRaw($query) as $contactGroup) {
+ $contactGroups[] = new self($contactGroup);
+ }
+ }
+ return $contactGroups;
+ }
+
+ /**
+ * Get a list of contacts group members
+ * @NoAdminRequired
+ * @param string $query
+ * @return Contact[]
+ */
+ public function getMembers() {
+ if (\OC::$server->getContactsManager()->isEnabled()) {
+ $contacts = [];
+ foreach (\OC::$server->getContactsManager()->search($this->id, ['CATEGORIES']) as $contact) {
+ if (!array_key_exists('isLocalSystemBook', $contact)
+ && array_key_exists('EMAIL', $contact)
+ && in_array($query, explode(',', $contact['CATEGORIES']))
+ ) {
+ $emailAdresses = $contact['EMAIL'];
+
+ if (!is_array($emailAdresses)) {
+ $emailAdress = $emailAdresses;
+ } else {
+ // take the first eMail address for now
+ $emailAdress = $emailAdresses[0];
+ }
+ $contacts[] = new Contact($contact['UID']);
+ }
+ }
+ return $contacts;
+ }
+ return [];
+ }
+
+
+ /**
+ * @return array
+ */
+ public function jsonSerialize(): array {
+ return [
+ 'id' => $this->id,
+ 'user' => $this->id,
+ 'type' => $this->getType(),
+ 'displayName' => $this->getDisplayName(),
+ 'organisation' => $this->getOrganisation(),
+ 'emailAddress' => $this->getEmailAddress(),
+ 'desc' => $this->getDesc(),
+ 'icon' => $this->getIcon(),
+ 'isNoUser' => true,
+ 'isGuest' => true,
+ ];
+ }
+}
diff --git a/lib/Model/Email.php b/lib/Model/Email.php
new file mode 100644
index 00000000..51e5af03
--- /dev/null
+++ b/lib/Model/Email.php
@@ -0,0 +1,182 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ *
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\Polls\Model;
+
+use OCP\IL10N;
+use OCA\Polls\Interfaces\IUserObj;
+
+class Email implements \JsonSerializable, IUserObj {
+ public const TYPE = 'email';
+
+ /** @var IL10N */
+ private $l10n;
+
+ /** @var string */
+ private $id;
+
+ /** @var string */
+ private $type;
+
+ /** @var string */
+ private $displayName = '';
+
+ /** @var string */
+ private $desc = '';
+
+ /** @var string */
+ private $emailAddress = '';
+
+ /** @var array */
+ private $contact;
+
+ /**
+ * User constructor.
+ * @param $type
+ * @param $id
+ * @param $emailAddress
+ * @param $displayName
+ */
+ public function __construct(
+ $id,
+ $emailAddress = '',
+ $displayName = ''
+ ) {
+ $this->id = $id;
+ $this->emailAddress = $emailAddress;
+ $this->displayName = $displayName;
+
+ $this->l10n = \OC::$server->getL10N('polls');
+ }
+
+ /**
+ * Get id
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getId() {
+ return $this->id;
+ }
+
+ /**
+ * getUser
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getUser() {
+ return $this->id;
+ }
+
+ /**
+ * Get user type
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getType() {
+ return self::TYPE;
+ }
+
+ /**
+ * Get language of user, if type = TYPE_USER
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getLanguage() {
+ return '';
+ }
+
+ /**
+ * Get displayName
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getDisplayName() {
+ if ($this->displayName) {
+ return $this->displayName;
+ }
+ return $this->id;
+ }
+
+ /**
+ * Get additional description, if available
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getDesc() {
+ return \OC::$server->getL10N('polls')->t('External Email');
+ }
+
+ /**
+ * Get email address
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getEmailAddress() {
+ if ($this->emailAddress) {
+ return $this->emailAddress;
+ }
+ return $this->id;
+ }
+
+ /**
+ * Get organisation, if type = TYPE_CONTACT
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getOrganisation() {
+ return '';
+ }
+
+ /**
+ * Get icon class
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getIcon() {
+ return 'icon-mail';
+ }
+
+ // no search right now
+ public static function search($query) {
+ return [];
+ }
+
+ /**
+ * @return array
+ */
+ public function jsonSerialize(): array {
+ return [
+ 'id' => $this->id,
+ 'user' => $this->id,
+ 'type' => $this->getType(),
+ 'displayName' => $this->getDisplayName(),
+ 'organisation' => $this->getOrganisation(),
+ 'emailAddress' => $this->getEmailAddress(),
+ 'desc' => $this->getDesc(),
+ 'icon' => $this->getIcon(),
+ 'isNoUser' => true,
+ 'isGuest' => true,
+ ];
+ }
+}
diff --git a/lib/Model/Group.php b/lib/Model/Group.php
new file mode 100644
index 00000000..12d0f34b
--- /dev/null
+++ b/lib/Model/Group.php
@@ -0,0 +1,204 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ *
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\Polls\Model;
+
+use OCP\IL10N;
+use OCA\Polls\Interfaces\IUserObj;
+
+class Group implements \JsonSerializable, IUserObj {
+ public const TYPE = 'group';
+
+ /** @var IL10N */
+ private $l10n;
+
+ /** @var string */
+ private $id;
+
+ /** @var IGroup */
+ private $group;
+
+ /**
+ * Group constructor.
+ * @param $id
+ * @param $displayName
+ */
+ public function __construct(
+ $id
+ ) {
+ $this->id = $id;
+ $this->load();
+ }
+
+ /**
+ * getId
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getId() {
+ return $this->id;
+ }
+
+ /**
+ * getUser
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getUser() {
+ return $this->id;
+ }
+
+ /**
+ * getType
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getType() {
+ return self::TYPE;
+ }
+
+ /**
+ * getlanguage
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getLanguage() {
+ return '';
+ }
+
+ /**
+ * getDisplayName
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getDisplayName() {
+ try {
+ // since NC19
+ return $this->group->getDisplayName();
+ } catch (\Exception $e) {
+ // until NC18
+ return $this->id;
+ }
+ }
+
+ /**
+ * getOrganisation
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getOrganisation() {
+ return '';
+ }
+
+ /**
+ * getEmailAddress
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getEmailAddress() {
+ return '';
+ }
+
+ /**
+ * getDesc
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getDesc() {
+ return \OC::$server->getL10N('polls')->t('Group');
+ }
+
+ /**
+ * getIcon
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getIcon() {
+ return 'icon-group';
+ }
+
+ private function load() {
+ $this->group = \OC::$server->getGroupManager()->get($this->id);
+ }
+
+ /**
+ * listRaw
+ * @NoAdminRequired
+ * @param string $query
+ * @return Array
+ */
+ public static function listRaw($query = '') {
+ return \OC::$server->getGroupManager()->search($query);
+ }
+
+ /**
+ * search
+ * @NoAdminRequired
+ * @param string $query
+ * @param array $skip - group names to skip in return array
+ * @return Group[]
+ */
+ public static function search($query = '', $skip = []) {
+ $groups = [];
+ foreach (self::listRaw($query) as $group) {
+ if (!in_array($group->getGID(), $skip)) {
+ $groups[] = new Self($group->getGID());
+ }
+ }
+ return $groups;
+ }
+
+ /**
+ * Get a list of circle members
+ * @NoAdminRequired
+ * @param string $query
+ * @return User[]
+ */
+ public function getMembers() {
+ $members = [];
+ foreach (array_keys(\OC::$server->getGroupManager()->displayNamesInGroup($this->id)) as $member) {
+ $members[] = new user($member);
+ }
+ return $members;
+ }
+
+
+
+ /**
+ * @return array
+ */
+ public function jsonSerialize(): array {
+ return [
+ 'id' => $this->id,
+ 'user' => $this->id,
+ 'type' => $this->getType(),
+ 'displayName' => $this->getDisplayName(),
+ 'organisation' => $this->getOrganisation(),
+ 'emailAddress' => $this->getEmailAddress(),
+ 'desc' => $this->getDesc(),
+ 'icon' => $this->getIcon(),
+ 'isNoUser' => true,
+ ];
+ }
+}
diff --git a/lib/Model/User.php b/lib/Model/User.php
index 98513a0b..154cea9e 100644
--- a/lib/Model/User.php
+++ b/lib/Model/User.php
@@ -25,8 +25,10 @@
namespace OCA\Polls\Model;
use OCP\IL10N;
+use OCA\Polls\Interfaces\IUserObj;
-class User implements \JsonSerializable {
+class User implements \JsonSerializable, IUserObj {
+ public const TYPE = 'user';
public const TYPE_USER = 'user';
public const TYPE_GROUP = 'group';
public const TYPE_CONTACTGROUP = 'contactGroup';
@@ -34,185 +36,159 @@ class User implements \JsonSerializable {
public const TYPE_EMAIL = 'email';
public const TYPE_CIRCLE = 'circle';
public const TYPE_EXTERNAL = 'external';
+ public const TYPE_INVALID = 'invalid';
/** @var IL10N */
private $l10n;
/** @var string */
- private $userId;
+ private $id;
- /** @var string */
- private $type;
-
- /** @var string */
- private $displayName = '';
-
- /** @var string */
- private $desc = '';
-
- /** @var string */
- private $emailAddress = '';
-
- private $contact;
- private $circlesEnabled = false;
- private $contactsEnabled = false;
+ /** @var IUser */
+ private $user;
/**
* User constructor.
* @param $type
- * @param $userId
+ * @param $id
* @param $emailAddress
* @param $displayName
*/
public function __construct(
- $type,
- $userId,
- $emailAddress = '',
- $displayName = ''
+ $id
) {
- $this->l10n = \OC::$server->getL10N('polls');
- $this->type = $type;
- $this->userId = $userId;
- $this->emailAddress = $emailAddress;
- $this->displayName = $displayName;
- $this->loadContact();
- $this->circlesEnabled = \OC::$server->getAppManager()->isEnabledForUser('circles') &&
- (version_compare(\OC::$server->getAppManager()->getAppVersion('circles'), '0.17.1') >= 0);
- $this->contactsEnabled = \OC::$server->getContactsManager()->isEnabled();
+ $this->id = $id;
+ $this->load();
}
-
- public function setDisplayName($displayName) {
- $this->displayName = $displayName;
+ /**
+ * Get userId
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getUserId() {
+ return $this->id;
}
- public function setEmailAddress($emailAddress) {
- $this->emailAddress = $emailAddress;
+ /**
+ * Get userId
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getId() {
+ return $this->id;
}
- public function getUserId() {
- return $this->userId;
+ /**
+ * getUser
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getUser() {
+ return $this->id;
}
+ /**
+ * Get user type
+ * @NoAdminRequired
+ * @return String
+ */
public function getType() {
- return $this->type;
+ return self::TYPE;
}
+ /**
+ * Get language of user, if type = TYPE_USER
+ * @NoAdminRequired
+ * @return String
+ */
public function getLanguage() {
- if ($this->type === self::TYPE_USER) {
- // Variant: $this->config->getUserValue($this->userId, 'core', 'lang')
- return \OC::$server->getConfig()->getUserValue($this->userId, 'core', 'lang');
- } else {
- return '';
- }
+ return \OC::$server->getConfig()->getUserValue($this->id, 'core', 'lang');
}
+ /**
+ * Get displayName
+ * @NoAdminRequired
+ * @return String
+ */
public function getDisplayName() {
- if ($this->type === self::TYPE_USER) {
- return \OC::$server->getUserManager()->get($this->userId)->getDisplayName();
- } elseif ($this->type === self::TYPE_GROUP) {
- try {
- // since NC19
- return \OC::$server->getGroupManager()->get($this->userId)->getDisplayName();
- } catch (\Exception $e) {
- // until NC18
- return $this->userId;
- }
- } elseif ($this->type === self::TYPE_CONTACTGROUP && $this->contactsEnabled) {
- return $this->userId;
- } elseif ($this->type === self::TYPE_CIRCLE && $this->circlesEnabled) {
- return \OCA\Circles\Api\v1\Circles::detailsCircle($this->userId)->getName();
- } elseif ($this->type === self::TYPE_CONTACT && $this->contactsEnabled) {
- return isset($this->contact['FN']) ? $this->contact['FN'] : '';
- } elseif ($this->displayName) {
- return $this->displayName;
- } else {
- return $this->userId;
- }
+ return \OC::$server->getUserManager()->get($this->id)->getDisplayName();
}
+ /**
+ * Get organisation, if type = TYPE_CONTACT
+ * @NoAdminRequired
+ * @return String
+ */
public function getOrganisation() {
- if ($this->type === self::TYPE_CONTACT && $this->contactsEnabled) {
- return isset($this->contact['ORG']) ? $this->contact['ORG'] : '';
- } else {
- return '';
- }
+ return '';
}
+ /**
+ * Get email address
+ * @NoAdminRequired
+ * @return String
+ */
public function getEmailAddress() {
- if ($this->type === self::TYPE_USER) {
- // Variant: \OC::$server->getConfig()->getUserValue($this->userId, 'settings', 'email'),
- return \OC::$server->getUserManager()->get($this->userId)->getEMailAddress();
- } elseif ($this->type === self::TYPE_CONTACT && $this->contactsEnabled) {
- return isset($this->contact['EMAIL'][0]) ? $this->contact['EMAIL'][0] : '';
- } elseif ($this->type === self::TYPE_EMAIL) {
- return $this->userId;
- } else {
- return $this->emailAddress;
- }
+ return $this->user->getEMailAddress();
}
+ /**
+ * Get additional description, if available
+ * @NoAdminRequired
+ * @return String
+ */
public function getDesc() {
- if ($this->type === self::TYPE_USER) {
- return $this->l10n->t('User');
- } elseif ($this->type === self::TYPE_GROUP) {
- return $this->l10n->t('Group');
- } elseif ($this->type === self::TYPE_CONTACT && $this->contactsEnabled) {
- $this->desc = $this->l10n->t('Contact');
- if (isset($this->contact['ORG'])) {
- // Add organisation to description
- $this->desc = $this->contact['ORG'];
- }
-
- if (isset($this->contact['CATEGORIES'])) {
- // Add contact groups to description
- // Add aspace before each comma
- if ($this->desc === $this->l10n->t('Contact')) {
- $this->desc = $this->contact['CATEGORIES'];
- } else {
- $this->desc = $this->desc . ', ' . $this->contact['CATEGORIES'];
- }
- }
- return $this->desc;
- } elseif ($this->type === self::TYPE_CONTACTGROUP && $this->contactsEnabled) {
- return $this->l10n->t('Contact group');
- } elseif ($this->type === self::TYPE_CIRCLE && $this->circlesEnabled) {
- return \OCA\Circles\Api\v1\Circles::detailsCircle($this->userId)->gettypeLongString();
- } elseif ($this->type === self::TYPE_EMAIL) {
- return $this->l10n->t('External email');
- } else {
- return '';
- }
+ return \OC::$server->getL10N('polls')->t('User');
}
+ /**
+ * Get icon class
+ * @NoAdminRequired
+ * @return String
+ */
public function getIcon() {
- if ($this->type === self::TYPE_USER) {
- return 'icon-user';
- } elseif ($this->type === self::TYPE_GROUP) {
- return 'icon-group';
- } elseif ($this->type === self::TYPE_CONTACT && $this->contactsEnabled) {
- return 'icon-mail';
- } elseif ($this->type === self::TYPE_EMAIL) {
- return 'icon-mail';
- } elseif ($this->type === self::TYPE_CONTACTGROUP && $this->contactsEnabled) {
- return 'icon-group';
- } elseif ($this->type === self::TYPE_CIRCLE && $this->circlesEnabled) {
- return 'icon-circle';
- } else {
- return '';
- }
+ return 'icon-user';
}
- private function loadContact() {
- if ($this->type === self::TYPE_CONTACT && \OC::$server->getContactsManager()->isEnabled()) {
- // TODO: remove FN in a later version than 1.5
- $contacts = \OC::$server->getContactsManager()->search($this->userId, ['UID', 'FN']);
- if (!$contacts) {
- $this->contact = [];
- } else {
- $this->contact = $contacts[0];
+ /**
+ * Get icon class
+ * @NoAdminRequired
+ * @return String
+ */
+ public function getUserIsDisabled() {
+ return !\OC::$server->getUserManager()->get($user)->isEnabled();
+ }
+
+ /**
+ * listRaw
+ * @NoAdminRequired
+ * @param string $query
+ * @return Array
+ */
+ public static function listRaw($query = '') {
+ return \OC::$server->getUserManager()->search($query);
+ }
+
+ /**
+ * search
+ * @NoAdminRequired
+ * @param string $query
+ * @param array $skip - group names to skip in return array
+ * @return Group[]
+ */
+ public static function search($query = '', $skip = []) {
+ $users = [];
+ foreach (self::listRaw($query) as $user) {
+ if (!in_array($user->getUID(), $skip)) {
+ $users[] = new Self($user->getUID());
}
}
+ return $users;
+ }
+
+ private function load() {
+ $this->user = \OC::$server->getUserManager()->get($this->id);
}
/**
@@ -220,15 +196,15 @@ class User implements \JsonSerializable {
*/
public function jsonSerialize(): array {
return [
- 'userId' => $this->userId,
- 'type' => $this->type,
- 'user' => $this->userId,
+ 'user' => $this->id,
+ 'id' => $this->id,
+ 'userId' => $this->id,
+ 'type' => $this->getType(),
'displayName' => $this->getDisplayName(),
- 'Organisation' => $this->getOrganisation(),
+ 'organisation' => $this->getOrganisation(),
'emailAddress' => $this->getEmailAddress(),
'desc' => $this->getDesc(),
'icon' => $this->getIcon(),
- 'contact' => $this->contact,
];
}
}
diff --git a/lib/Service/CirclesService.php b/lib/Service/CirclesService.php
deleted file mode 100644
index 372c970b..00000000
--- a/lib/Service/CirclesService.php
+++ /dev/null
@@ -1,111 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
- *
- * @author René Gieling <github@dartcafe.de>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\Polls\Service;
-
-use OCA\Polls\Model\User;
-use \OCA\Circles\Api\v1\Circles;
-
-class CirclesService {
- public function __construct(
- ) {
- $this->enabled = \OC::$server->getAppManager()->isEnabledForUser('circles');
- }
-
- /**
- * Get a list of avaiable circles
- * @NoAdminRequired
- * @param string $query
- * @param array $skip - circle names to skip in return array
- * @return Array
- */
- public function getCircles($query = '', $skip = []) {
- if (!$this->enabled || $query === '') {
- return [];
- }
-
- $circles = [];
-
-
- foreach (\OCA\Circles\Api\v1\Circles::listCircles(\OCA\Circles\Model\Circle::CIRCLES_ALL, $query) as $circle) {
- if (!in_array($circle->getId(), $skip)) {
- $displayName = $circle->getName();
-
- $circles[] = new User(User::TYPE_CIRCLE, $circle->getUniqueId());
- }
- }
- return $circles;
- }
-
-
- /**
- * Get circle details
- * @NoAdminRequired
- * @param string $circleId
- * @return String
- */
- public function getDisplayName($circleId = 0) {
- if (!$this->enabled) {
- return 'NixCircle';
- }
- return \OCA\Circles\Api\v1\Circles::detailsCircle($circleId)->getName();
- }
-
- /**
- * Get circle details
- * @NoAdminRequired
- * @param string $circleId
- * @return Array
- */
- public function getDetails($circleId = 0) {
- if (!$this->enabled) {
- return 'Unknown circle';
- }
- return \OCA\Circles\Api\v1\Circles::detailsCircle($circleId);
- }
-
- /**
- * Get a list of contacts
- * @NoAdminRequired
- * @param string $query
- * @return User[]
- */
- public function getCircleMembers($circleId) {
- if (!$this->enabled) {
- return [];
- }
- $members = [];
- foreach (\OCA\Circles\Api\v1\Circles::detailsCircle($circleId)->getMembers() as $circleMember) {
- if ($circleMember->getType() === Circles::TYPE_USER) {
- $members[] = new User(User::TYPE_USER, $circleMember->getUserId());
- } elseif ($circleMember->getType() === Circles::TYPE_GROUP) {
- $members[] = new User(User::TYPE_GROUP, $circleMember->getUserId());
- } elseif ($circleMember->getType() === Circles::TYPE_MAIL) {
- $members[] = new User(User::TYPE_EMAIL, $circleMember->getUserId());
- } elseif ($circleMember->getType() === Circles::TYPE_CONTACT) {
- $members[] = new User(User::TYPE_CONTACT, $circleMember->getUserId());
- }
- }
- return $members;
- }
-}
diff --git a/lib/Service/ContactsService.php b/lib/Service/ContactsService.php
deleted file mode 100644
index a344aeac..00000000
--- a/lib/Service/ContactsService.php
+++ /dev/null
@@ -1,112 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
- *
- * @author René Gieling <github@dartcafe.de>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\Polls\Service;
-
-use OCA\Polls\Model\User;
-
-class ContactsService {
- public function __construct(
- ) {
- $this->enabled = \OC::$server->getContactsManager()->isEnabled();
- }
-
- /**
- * Get a list of contacts
- * @NoAdminRequired
- * @param string $query
- * @return User[]
- */
- public function getContacts($query = '', $queryRange = ['FN', 'EMAIL', 'ORG', 'CATEGORIES']) {
- if (!$this->enabled || $query === '') {
- return [];
- }
-
- $contacts = [];
-
- foreach (\OC::$server->getContactsManager()->search($query, $queryRange) as $contact) {
- if (!array_key_exists('isLocalSystemBook', $contact) && array_key_exists('EMAIL', $contact)) {
- $contacts[] = new User(User::TYPE_CONTACT, $contact['UID']);
- }
- }
- return $contacts;
- }
-
- /**
- * Get a list of contacts
- * @NoAdminRequired
- * @param string $query
- * @return User[]
- */
- public function getContactsGroupMembers($query = '') {
- if (!$this->enabled || $query === '') {
- return [];
- }
-
- $contacts = [];
- foreach (\OC::$server->getContactsManager()->search($query, ['CATEGORIES']) as $contact) {
- if (!array_key_exists('isLocalSystemBook', $contact)
- && array_key_exists('EMAIL', $contact)
- && in_array($query, explode(',', $contact['CATEGORIES']))
- ) {
- $emailAdresses = $contact['EMAIL'];
-
- if (!is_array($emailAdresses)) {
- $emailAdresses = [$emailAdresses];
- } else {
- // take the first eMail address for now
- $emailAdresses = [$emailAdresses[0]];
- }
-
- foreach ($emailAdresses as $emailAddress) {
- $contacts[] = new User(User::TYPE_CONTACT, $contact['UID']);
- }
- }
- }
- return $contacts;
- }
-
- /**
- * Get a list of contact groups
- * @NoAdminRequired
- * @param string $query
- * @return Array
- */
- public function getContactsGroups($query = '') {
- if (!$this->enabled || $query === '') {
- return [];
- }
-
- $contactGroups = [];
- $foundContacts = [];
- foreach (\OC::$server->getContactsManager()->search($query, ['CATEGORIES']) as $contact) {
- foreach (explode(',', $contact['CATEGORIES']) as $contactGroup) {
- if (strpos($contactGroup, $query) === 0 && !in_array($contactGroup, $foundContacts)) {
- $foundContacts[] = $contactGroup;
- $contactGroups[] = new User(User::TYPE_CONTACTGROUP, $contactGroup);
- };
- }
- }
- return $contactGroups;
- }
-}
diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php
index bc36e3c8..9d6c91c9 100644
--- a/lib/Service/MailService.php
+++ b/lib/Service/MailService.php
@@ -40,6 +40,9 @@ use OCA\Polls\Db\PollMapper;
use OCA\Polls\Db\ShareMapper;
use OCA\Polls\Db\Share;
use OCA\Polls\Db\LogMapper;
+use OCA\Polls\Model\User;
+use OCA\Polls\Model\Contact;
+use OCA\Polls\Model\Group;
class MailService {
@@ -76,9 +79,6 @@ class MailService {
/** @var LogMapper */
private $logMapper;
- /** @var ContactsService */
- private $contactsService;
-
/**
* MailService constructor.
* @param IUserManager $userManager
@@ -92,7 +92,6 @@ class MailService {
* @param ShareMapper $shareMapper
* @param PollMapper $pollMapper
* @param LogMapper $logMapper
- * @param ContactsService $contactsService
*/
public function __construct(
@@ -106,8 +105,7 @@ class MailService {
ShareMapper $shareMapper,
SubscriptionMapper $subscriptionMapper,
PollMapper $pollMapper,
- LogMapper $logMapper,
- ContactsService $contactsService
+ LogMapper $logMapper
) {
$this->config = $config;
$this->userManager = $userManager;
@@ -120,7 +118,6 @@ class MailService {
$this->subscriptionMapper = $subscriptionMapper;
$this->pollMapper = $pollMapper;
$this->logMapper = $logMapper;
- $this->contactsService = $contactsService;
}
@@ -205,7 +202,7 @@ class MailService {
);
if ($share->getType() === Share::TYPE_USER) {
- $user = new User(User::TYPE_USER, $share->getUserId());
+ $user = new User($share->getUserId());
$recipients[] = [
'userId' => $user->getUserId(),
'eMailAddress' => $user->getEmailAddress(),
@@ -214,7 +211,8 @@ class MailService {
'link' => $internalLink,
];
} elseif ($share->getType() === Share::TYPE_EMAIL) {
- $user = new User(User::TYPE_EMAIL, $share->getUserId());
+ $user = new Email($share->getUserId());
+
$recipients[] = [
'userId' => $user->getUserId(),
'eMailAddress' => $user->getEmailAddress(),
@@ -223,20 +221,15 @@ class MailService {
'link' => $tokenLink,
];
} elseif ($share->getType() === Share::TYPE_CONTACT) {
- $contacts = $this->contactsService->getContacts($share->getUserId(), ['FN', 'UID']);
- if (count($contacts)) {
- $user = $contacts[0];
+ $user = new Contact($share->getUserId());
- $recipients[] = [
- 'userId' => $user->getUserId(),
- 'eMailAddress' => $user->getEmailAddress(),
- 'displayName' => $user->getDisplayname(),
- 'language' => $defaultLang,
- 'link' => $tokenLink,
- ];
- } else {
- return;
- }
+ $recipients[] = [
+ 'userId' => $user->getUserId(),
+ 'eMailAddress' => $user->getEmailAddress(),
+ 'displayName' => $user->getDisplayname(),
+ 'language' => $defaultLang,
+ 'link' => $tokenLink,
+ ];
} elseif ($share->getType() === Share::TYPE_EXTERNAL) {
$recipients[] = [
'userId' => $share->getUserId(),
@@ -246,16 +239,13 @@ class MailService {
'link' => $tokenLink,
];
} elseif ($share->getType() === Share::TYPE_GROUP) {
- $groupMembers = array_keys($this->groupManager->displayNamesInGroup($share->getUserId()));
-
- foreach ($groupMembers as $user) {
- if ($skipUser === $user || !$this->userManager->get($user)->isEnabled()) {
+ foreach ((new Group($share->getUserId()))->getMembers() as $user) {
+ if ($skipUser === $user->getId() || !$user->isUserDisabled()) {
continue;
}
- $user = new User(User::TYPE_USER, $user->getUserId());
$recipients[] = [
- 'userId' => $user->getUserId(),
+ 'userId' => $user->getId(),
'eMailAddress' => $user->getEmailAddress(),
'displayName' => $user->getDisplayName(),
'language' => $user->getLanguage(),
diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php
index 3404f882..f94fd136 100644
--- a/lib/Service/ShareService.php
+++ b/lib/Service/ShareService.php
@@ -31,6 +31,11 @@ use OCP\Security\ISecureRandom;
use OCA\Polls\Db\ShareMapper;
use OCA\Polls\Db\Share;
use OCA\Polls\Model\Acl;
+use OCA\Polls\Model\Circle;
+use OCA\Polls\Model\Contact;
+use OCA\Polls\Model\ContactGroup;
+use OCA\Polls\Model\Email;
+use OCA\Polls\Model\Group;
use OCA\Polls\Model\User;
class ShareService {
@@ -114,14 +119,27 @@ class ShareService {
if (!$this->acl->set($pollId)->getAllowEdit()) {
throw new NotAuthorizedException;
}
- $user = new User($type, $userId, $emailAddress);
+ if ($type === Group::TYPE) {
+ $share = new Group($userId);
+ } elseif ($type === Circle::TYPE) {
+ $share = new Circle($userId);
+ } elseif ($type === Contact::TYPE) {
+ $share = new Contact($userId);
+ } elseif ($type === ContactGroup::TYPE) {
+ $share = new ContactGroup($userId);
+ } elseif ($type === User::TYPE) {
+ $share = new User($userId);
+ } elseif ($type === Email::TYPE) {
+ $share = new Email($userId);
+ }
+ \OC::$server->getLogger()->alert(json_encode($share));
$this->share = new Share();
$this->share->setPollId($pollId);
- $this->share->setType($user->getType());
- $this->share->setUserId($user->getUserId());
- $this->share->setDisplayName($user->getDisplayName());
- $this->share->setUserEmail($user->getEmailAddress());
+ $this->share->setType($share->getType());
+ $this->share->setUserId($share->getId());
+ $this->share->setDisplayName($share->getDisplayName());
+ $this->share->setUserEmail($share->getEmailAddress());
$this->share->setInvitationSent(0);
$this->share->setToken(\OC::$server->getSecureRandom()->generate(
16,
diff --git a/lib/Service/SystemService.php b/lib/Service/SystemService.php
index ab02cead..9e6b479c 100644
--- a/lib/Service/SystemService.php
+++ b/lib/Service/SystemService.php
@@ -28,27 +28,18 @@ use OCA\Polls\Exceptions\TooShortException;
use OCA\Polls\Exceptions\InvalidUsernameException;
use OCA\Polls\Exceptions\InvalidEmailAddress;
-use OCP\IGroupManager;
-use OCP\IUserManager;
use OCA\Polls\Db\Share;
use OCA\Polls\Db\ShareMapper;
use OCA\Polls\Db\VoteMapper;
+use OCA\Polls\Model\Circle;
+use OCA\Polls\Model\Contact;
+use OCA\Polls\Model\ContactGroup;
+use OCA\Polls\Model\Email;
+use OCA\Polls\Model\Group;
use OCA\Polls\Model\User;
class SystemService {
- /** @var IGroupManager */
- private $groupManager;
-
- /** @var IUserManager */
- private $userManager;
-
- /** @var CirclesService */
- private $circlesService;
-
- /** @var ContactsService */
- private $contactsService;
-
/** @var VoteMapper */
private $voteMapper;
@@ -57,26 +48,14 @@ class SystemService {
/**
* SystemService constructor.
- * @param IGroupManager $groupManager
- * @param IUserManager $userManager
- * @param CirclesService $circlesService,
- * @param ContactsService $contactsService,
* @param VoteMapper $voteMapper
* @param ShareMapper $shareMapper
*/
public function __construct(
- IGroupManager $groupManager,
- IUserManager $userManager,
VoteMapper $voteMapper,
- CirclesService $circlesService,
- ContactsService $contactsService,
ShareMapper $shareMapper
) {
- $this->groupManager = $groupManager;
- $this->userManager = $userManager;
$this->voteMapper = $voteMapper;
- $this->circlesService = $circlesService;
- $this->contactsService = $contactsService;
$this->shareMapper = $shareMapper;
}
@@ -90,43 +69,39 @@ class SystemService {
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;
}
-
/**
- * Get a list of users
+ * Validate email address and throw an exception
+ * return true, if email address is a valid
* @NoAdminRequired
- * @param string $query
- * @param array $skip - usernames to skip in return array
- * @return User[]
+ * @return Boolean
+ * @throws InvalidEmailAddress
*/
- public function getSiteUsers($query = '', $skip = []) {
- $users = [];
- foreach ($this->userManager->searchDisplayName($query) as $user) {
- if (!in_array($user->getUID(), $skip) && $user->isEnabled()) {
- $users[] = new User(User::TYPE_USER, $user->getUID());
- }
+ public static function validateEmailAddress($emailAddress) {
+ if (!self::isValidEmail($emailAddress)) {
+ throw new InvalidEmailAddress;
}
- return $users;
+ return true;
}
/**
- * Get a list of user groups
+ * Get a list of users
* @NoAdminRequired
* @param string $query
- * @param array $skip - group names to skip in return array
+ * @param array $skip - usernames to skip in return array
* @return User[]
*/
- public function getSiteGroups($query = '', $skip = []) {
- $groups = [];
- foreach ($this->groupManager->search($query) as $group) {
- if (!in_array($group->getGID(), $skip)) {
- $groups[] = new User(User::TYPE_GROUP, $group->getGID());
+ public static function getSiteUsers($query = '', $skip = []) {
+ $users = [];
+ foreach (\OC::$server->getUserManager()->searchDisplayName($query) as $user) {
+ if (!in_array($user->getUID(), $skip) && $user->isEnabled()) {
+ $users[] = new User($user->getUID());
}
}
- return $groups;
+ return $users;
}
/**
- * Get a combined list of NC users, groups and contacts
+ * Get a combined list of users, groups, circles, contact groups and contacts
* @NoAdminRequired
* @param string $query
* @param bool $getGroups - search in groups
@@ -135,7 +110,7 @@ class SystemService {
* @param bool $getContactGroups - search in contacs
* @param array $skipGroups - group names to skip in return array
* @param array $skipUsers - user names to skip in return array
- * @return Array
+ * @return User[]
*/
public function getSiteUsersAndGroups(
$query = '',
@@ -149,26 +124,26 @@ class SystemService {
) {
$list = [];
if ($query !== '') {
- if ($getMail && $this->isValidEmail($query)) {
- $list[] = new User(User::TYPE_EMAIL, $query);
+ if ($getMail && self::isValidEmail($query)) {
+ $list[] = new Email($query);
}
if ($getGroups) {
- $list = array_merge($list, $this->getSiteGroups($query, $skipGroups));
+ $list = array_merge($list, Group::search($query, $skipGroups));
}
if ($getUsers) {
- $list = array_merge($list, $this->getSiteUsers($query, $skipUsers));
+ $list = array_merge($list, User::search($query, $skipUsers));
}
if ($getContacts) {
- $list = array_merge($list, $this->contactsService->getContacts($query));
+ $list = array_merge($list, Contact::search($query));
}
if ($getContacts) {
- $list = array_merge($list, $this->contactsService->getContactsGroups($query));
+ $list = array_merge($list, ContactGroup::search($query));
}
- $list = array_merge($list, $this->circlesService->getCircles($query));
+ $list = array_merge($list, Circle::search($query));
}
return $list;
@@ -180,22 +155,6 @@ class SystemService {
* a participant of the poll
* @NoAdminRequired
* @return Boolean
- * @throws InvalidEmailAddress
- */
- public function validateEmailAddress($emailAddress) {
- if (!$this->isValidEmail($emailAddress)) {
- throw new InvalidEmailAddress;
- }
- return true;
- }
-
-
- /**
- * Validate it the user name is reservrd
- * return false, if this username already exists as a user or as
- * a participant of the poll
- * @NoAdminRequired
- * @return Boolean
* @throws NotAuthorizedException
* @throws TooShortException
* @throws InvalidUsernameException
@@ -212,32 +171,27 @@ class SystemService {
if (strlen($userName) < 3) {
return new TooShortException('Username must have at least 3 characters');
}
- $list = [];
// get all groups
- foreach ($this->getSiteGroups() as $user) {
- if ($userName === strtolower(trim($user->getUserId()))
- || $userName === strtolower(trim($user->getDisplayName()))) {
+ foreach (Group::search() as $group) {
+ if ($userName === strtolower(trim($group->getId()))
+ || $userName === strtolower(trim($group->getDisplayName()))) {
throw new InvalidUsernameException;
}
- $list[] = $user;
}
// get all users
- foreach ($this->getSiteUsers() as $user) {
+ foreach (User::search() as $user) {
if ($userName === strtolower(trim($user->getUserId()))
|| $userName === strtolower(trim($user->getDisplayName()))) {
throw new InvalidUsernameException;
}
- $list[] = $user;
}
// get all participants
foreach ($this->voteMapper->findParticipantsByPoll($pollId) as $vote) {
- if ($vote->getUserId() !== '' && $vote->getUserId() !== null) {
- $list[] = new User(User::TYPE_USER, $vote->getUserId());
- if ($userName === strtolower(trim(end($list)->getUserId()))
- || $userName === strtolower(trim(end($list)->getDisplayName()))) {
+ if ($vote->getUserId()) {
+ if ($userName === strtolower(trim($vote->getUserId()))) {
throw new InvalidUsernameException;
}
}
@@ -245,17 +199,11 @@ class SystemService {
// get all shares for this poll
foreach ($this->shareMapper->findByPoll($pollId) as $share) {
- if ($share->getUserId() !== ''
- && $share->getUserId() !== null
- && $share->getType() !== User::TYPE_CIRCLE) {
- $user = new User($share->getType(), $share->getUserId());
- \OC::$server->getLogger()->alert(json_encode($user));
- if ($userName === strtolower(trim($user->getUserId()))
- || $userName === strtolower(trim($share->getDisplayName()))
- || $userName === strtolower(trim($user->getDisplayName()))) {
+ if ($share->getUserId() && $share->getType() !== User::TYPE_CIRCLE) {
+ if ($userName === strtolower(trim($share->getUserId()))
+ || $userName === strtolower(trim($share->getDisplayName()))) {
throw new InvalidUsernameException;
}
- $list[] = new User($share->getType(), $share->getUserId());
}
}
// return true, if username is allowed