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-01 22:24:33 +0300
committerdartcafe <github@dartcafe.de>2020-10-01 22:24:33 +0300
commit0b6fb4a6d5727b4ed9ace6c3f4a760abeecca718 (patch)
tree95aa5b6a5a463218a8989eb712b9bfaa704463ae /lib
parentb5e35d6547706d8795153cfebd30daf33dbb02a4 (diff)
Diffstat (limited to 'lib')
-rw-r--r--lib/Db/Log.php17
-rw-r--r--lib/Db/Poll.php5
-rw-r--r--lib/Db/Share.php17
-rw-r--r--lib/Model/Acl.php6
-rw-r--r--lib/Model/User.php36
-rw-r--r--lib/Service/CirclesService.php2
-rw-r--r--lib/Service/ContactsService.php4
-rw-r--r--lib/Service/MailService.php5
-rw-r--r--lib/Service/SystemService.php14
9 files changed, 38 insertions, 68 deletions
diff --git a/lib/Db/Log.php b/lib/Db/Log.php
index ba8421dc..6fffe948 100644
--- a/lib/Db/Log.php
+++ b/lib/Db/Log.php
@@ -45,15 +45,14 @@ use OCP\AppFramework\Db\Entity;
* @method void setMessage(string $value)
*/
class Log extends Entity implements JsonSerializable {
-
- const MSG_ID_ADDPOLL = 'addPoll';
- const MSG_ID_UPDATEPOLL = 'updatePoll';
- const MSG_ID_DELETEPOLL = 'deletePoll';
- const MSG_ID_RESTOREPOLL = 'restorePoll';
- const MSG_ID_EXPIREPOLL = 'expirePoll';
- const MSG_ID_ADDOPTION = 'addOption';
- const MSG_ID_DELETEOPTION = 'deleteOption';
- const MSG_ID_SETVOTE = 'setVote';
+ public const MSG_ID_ADDPOLL = 'addPoll';
+ public const MSG_ID_UPDATEPOLL = 'updatePoll';
+ public const MSG_ID_DELETEPOLL = 'deletePoll';
+ public const MSG_ID_RESTOREPOLL = 'restorePoll';
+ public const MSG_ID_EXPIREPOLL = 'expirePoll';
+ public const MSG_ID_ADDOPTION = 'addOption';
+ public const MSG_ID_DELETEOPTION = 'deleteOption';
+ public const MSG_ID_SETVOTE = 'setVote';
/** @var int $pollId */
protected $pollId;
diff --git a/lib/Db/Poll.php b/lib/Db/Poll.php
index 3d3546f3..0f75f13f 100644
--- a/lib/Db/Poll.php
+++ b/lib/Db/Poll.php
@@ -67,9 +67,8 @@ use OCP\AppFramework\Db\Entity;
* @method void setImportant(integer $value)
*/
class Poll extends Entity implements JsonSerializable {
-
- const TYPE_DATE = 'datePoll';
- const TYPE_TEXT = 'textPoll';
+ public const TYPE_DATE = 'datePoll';
+ public const TYPE_TEXT = 'textPoll';
/** @var string $type */
protected $type;
diff --git a/lib/Db/Share.php b/lib/Db/Share.php
index 94809cf2..13e93078 100644
--- a/lib/Db/Share.php
+++ b/lib/Db/Share.php
@@ -46,15 +46,14 @@ use OCA\Polls\Model\User;
* @method void setInvitationSent(integer $value)
*/
class Share extends Entity implements JsonSerializable {
-
- const TYPE_USER = User::TYPE_USER;
- const TYPE_EMAIL = User::TYPE_EMAIL;
- const TYPE_CIRCLE = User::TYPE_CIRCLE;
- const TYPE_GROUP = User::TYPE_GROUP;
- const TYPE_CONTACTGROUP = User::TYPE_CONTACTGROUP;
- const TYPE_CONTACT = User::TYPE_CONTACT;
- const TYPE_PUBLIC = 'public';
- const TYPE_EXTERNAL = 'external';
+ 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_PUBLIC = 'public';
+ public const TYPE_EXTERNAL = 'external';
/** @var string $token */
protected $token;
diff --git a/lib/Model/Acl.php b/lib/Model/Acl.php
index cca2aa69..f478d321 100644
--- a/lib/Model/Acl.php
+++ b/lib/Model/Acl.php
@@ -119,14 +119,14 @@ class Acl implements JsonSerializable {
$this->share = $this->shareMapper->findByToken($token);
if (\OC::$server->getUserSession()->isLoggedIn()) {
- if ( $this->share->getType() !== Share::TYPE_GROUP
+ if ($this->share->getType() !== Share::TYPE_GROUP
&& $this->share->getType() !== Share::TYPE_PUBLIC) {
throw new NotAuthorizedException;
}
$this->userId = \OC::$server->getUserSession()->getUser()->getUID();
} else {
- if ( $this->share->getType() === Share::TYPE_GROUP
+ if ($this->share->getType() === Share::TYPE_GROUP
|| $this->share->getType() === Share::TYPE_USER) {
throw new NotAuthorizedException;
}
@@ -264,7 +264,7 @@ class Acl implements JsonSerializable {
return count(
array_filter($this->shareMapper->findByPoll($this->getPollId()), function ($item) {
if (
- ( $item->getType() === Share::TYPE_USER
+ ($item->getType() === Share::TYPE_USER
|| $item->getType() === Share::TYPE_EXTERNAL
|| $item->getType() === Share::TYPE_EMAIL
|| $item->getType() === Share::TYPE_CONTACT
diff --git a/lib/Model/User.php b/lib/Model/User.php
index 144c9e6d..98513a0b 100644
--- a/lib/Model/User.php
+++ b/lib/Model/User.php
@@ -23,17 +23,17 @@
namespace OCA\Polls\Model;
+
use OCP\IL10N;
class User implements \JsonSerializable {
-
- const TYPE_USER = 'user';
- const TYPE_GROUP = 'group';
- const TYPE_CONTACTGROUP = 'contactGroup';
- const TYPE_CONTACT = 'contact';
- const TYPE_EMAIL = 'email';
- const TYPE_CIRCLE = 'circle';
- const TYPE_EXTERNAL = 'external';
+ public const TYPE_USER = 'user';
+ public const TYPE_GROUP = 'group';
+ public const TYPE_CONTACTGROUP = 'contactGroup';
+ public const TYPE_CONTACT = 'contact';
+ public const TYPE_EMAIL = 'email';
+ public const TYPE_CIRCLE = 'circle';
+ public const TYPE_EXTERNAL = 'external';
/** @var IL10N */
private $l10n;
@@ -110,7 +110,6 @@ class User implements \JsonSerializable {
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
@@ -119,19 +118,14 @@ class User implements \JsonSerializable {
// 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;
}
@@ -149,13 +143,10 @@ class User implements \JsonSerializable {
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;
}
@@ -164,10 +155,8 @@ class User implements \JsonSerializable {
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'])) {
@@ -187,13 +176,10 @@ class User implements \JsonSerializable {
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 '';
}
@@ -202,22 +188,16 @@ class User implements \JsonSerializable {
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 '';
}
diff --git a/lib/Service/CirclesService.php b/lib/Service/CirclesService.php
index ddc3946f..372c970b 100644
--- a/lib/Service/CirclesService.php
+++ b/lib/Service/CirclesService.php
@@ -22,6 +22,7 @@
*/
namespace OCA\Polls\Service;
+
use OCA\Polls\Model\User;
use \OCA\Circles\Api\v1\Circles;
@@ -107,5 +108,4 @@ class CirclesService {
}
return $members;
}
-
}
diff --git a/lib/Service/ContactsService.php b/lib/Service/ContactsService.php
index 51894268..a344aeac 100644
--- a/lib/Service/ContactsService.php
+++ b/lib/Service/ContactsService.php
@@ -22,6 +22,7 @@
*/
namespace OCA\Polls\Service;
+
use OCA\Polls\Model\User;
class ContactsService {
@@ -64,7 +65,7 @@ class ContactsService {
$contacts = [];
foreach (\OC::$server->getContactsManager()->search($query, ['CATEGORIES']) as $contact) {
- if ( !array_key_exists('isLocalSystemBook', $contact)
+ if (!array_key_exists('isLocalSystemBook', $contact)
&& array_key_exists('EMAIL', $contact)
&& in_array($query, explode(',', $contact['CATEGORIES']))
) {
@@ -108,5 +109,4 @@ class ContactsService {
}
return $contactGroups;
}
-
}
diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php
index 6888c455..bc36e3c8 100644
--- a/lib/Service/MailService.php
+++ b/lib/Service/MailService.php
@@ -40,7 +40,6 @@ use OCA\Polls\Db\PollMapper;
use OCA\Polls\Db\ShareMapper;
use OCA\Polls\Db\Share;
use OCA\Polls\Db\LogMapper;
-use OCA\Polls\Service\ContactsService;
class MailService {
@@ -214,7 +213,6 @@ class MailService {
'language' => $user->getLanguage(),
'link' => $internalLink,
];
-
} elseif ($share->getType() === Share::TYPE_EMAIL) {
$user = new User(User::TYPE_EMAIL, $share->getUserId());
$recipients[] = [
@@ -224,7 +222,6 @@ class MailService {
'language' => $defaultLang,
'link' => $tokenLink,
];
-
} elseif ($share->getType() === Share::TYPE_CONTACT) {
$contacts = $this->contactsService->getContacts($share->getUserId(), ['FN', 'UID']);
if (count($contacts)) {
@@ -240,7 +237,6 @@ class MailService {
} else {
return;
}
-
} elseif ($share->getType() === Share::TYPE_EXTERNAL) {
$recipients[] = [
'userId' => $share->getUserId(),
@@ -249,7 +245,6 @@ class MailService {
'language' => $defaultLang,
'link' => $tokenLink,
];
-
} elseif ($share->getType() === Share::TYPE_GROUP) {
$groupMembers = array_keys($this->groupManager->displayNamesInGroup($share->getUserId()));
diff --git a/lib/Service/SystemService.php b/lib/Service/SystemService.php
index 88b8af64..ab02cead 100644
--- a/lib/Service/SystemService.php
+++ b/lib/Service/SystemService.php
@@ -30,8 +30,6 @@ use OCA\Polls\Exceptions\InvalidEmailAddress;
use OCP\IGroupManager;
use OCP\IUserManager;
-use OCA\Polls\Service\CirclesService;
-use OCA\Polls\Service\ContactsService;
use OCA\Polls\Db\Share;
use OCA\Polls\Db\ShareMapper;
use OCA\Polls\Db\VoteMapper;
@@ -218,7 +216,7 @@ class SystemService {
// get all groups
foreach ($this->getSiteGroups() as $user) {
- if ( $userName === strtolower(trim($user->getUserId()))
+ if ($userName === strtolower(trim($user->getUserId()))
|| $userName === strtolower(trim($user->getDisplayName()))) {
throw new InvalidUsernameException;
}
@@ -227,7 +225,7 @@ class SystemService {
// get all users
foreach ($this->getSiteUsers() as $user) {
- if ( $userName === strtolower(trim($user->getUserId()))
+ if ($userName === strtolower(trim($user->getUserId()))
|| $userName === strtolower(trim($user->getDisplayName()))) {
throw new InvalidUsernameException;
}
@@ -238,7 +236,7 @@ class SystemService {
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()))
+ if ($userName === strtolower(trim(end($list)->getUserId()))
|| $userName === strtolower(trim(end($list)->getDisplayName()))) {
throw new InvalidUsernameException;
}
@@ -247,12 +245,12 @@ class SystemService {
// get all shares for this poll
foreach ($this->shareMapper->findByPoll($pollId) as $share) {
- if ( $share->getUserId() !== ''
+ if ($share->getUserId() !== ''
&& $share->getUserId() !== null
- && $share->getType() !== User::TYPE_CIRCLE) {
+ && $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()))
+ if ($userName === strtolower(trim($user->getUserId()))
|| $userName === strtolower(trim($share->getDisplayName()))
|| $userName === strtolower(trim($user->getDisplayName()))) {
throw new InvalidUsernameException;