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-07-11 18:32:57 +0300
committerdartcafe <github@dartcafe.de>2020-07-11 18:32:57 +0300
commitcf4fe7174164f6a168bcd60ecf26896e0ea65848 (patch)
tree41f9e0daa3a5be1b24038c42f1ab58eebacb4b14 /lib
parent255a36387351e40f2377a649156c3b0bf90f3ab5 (diff)
code fixes and bugs
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/OptionApiController.php4
-rw-r--r--lib/Controller/OptionController.php10
-rw-r--r--lib/Controller/PollController.php10
-rw-r--r--lib/Controller/ShareApiController.php2
-rw-r--r--lib/Controller/ShareController.php2
-rw-r--r--lib/Controller/SubscriptionApiController.php4
-rw-r--r--lib/Controller/SystemController.php2
-rw-r--r--lib/Controller/VoteController.php1
-rw-r--r--lib/Db/Poll.php14
-rw-r--r--lib/Service/CommentService.php2
-rw-r--r--lib/Service/OptionService.php26
-rw-r--r--lib/Service/PollService.php2
-rw-r--r--lib/Service/SubscriptionService.php4
-rw-r--r--lib/Service/VoteService.php5
14 files changed, 50 insertions, 38 deletions
diff --git a/lib/Controller/OptionApiController.php b/lib/Controller/OptionApiController.php
index f0884435..5c3e6f3c 100644
--- a/lib/Controller/OptionApiController.php
+++ b/lib/Controller/OptionApiController.php
@@ -108,9 +108,9 @@ class OptionApiController extends ApiController {
* @param array $option
* @return DataResponse
*/
- public function update($optionId, $timestamp = 0 , $pollOptionText = '') {
+ public function update($optionId, $timestamp = 0, $pollOptionText = '') {
try {
- return new DataResponse(['option' => $this->optionService->update($optionId, $timestamp, $pollOptionText, $order)], Http::STATUS_OK);
+ return new DataResponse(['option' => $this->optionService->update($optionId, $timestamp, $pollOptionText)], Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
}
diff --git a/lib/Controller/OptionController.php b/lib/Controller/OptionController.php
index 1fa382f6..ea58c79c 100644
--- a/lib/Controller/OptionController.php
+++ b/lib/Controller/OptionController.php
@@ -77,11 +77,11 @@ class OptionController extends Controller {
// }
/**
- * Add a new option
- * @NoAdminRequired
- * @param array $option
- * @return DataResponse
- */
+ * Add a new option
+ * @NoAdminRequired
+ * @param array $option
+ * @return DataResponse
+ */
public function add($pollId, $timestamp = 0, $pollOptionText = '') {
return new DataResponse($this->optionService->add($pollId, $timestamp, $pollOptionText), Http::STATUS_OK);
}
diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php
index 834fb391..73c07347 100644
--- a/lib/Controller/PollController.php
+++ b/lib/Controller/PollController.php
@@ -67,12 +67,12 @@ class PollController extends Controller {
* PollController constructor.
* @param string $appName
* @param IRequest $request
- * @param PollService $pollService
+ * @param PollService $pollService
* @param CommentService $commentService
- * @param OptionService $optionService
- * @param ShareService $shareService
- * @param VoteService $voteService
- * @param Acl $acl
+ * @param OptionService $optionService
+ * @param ShareService $shareService
+ * @param VoteService $voteService
+ * @param Acl $acl
*/
public function __construct(
diff --git a/lib/Controller/ShareApiController.php b/lib/Controller/ShareApiController.php
index 261262b8..e2d8b465 100644
--- a/lib/Controller/ShareApiController.php
+++ b/lib/Controller/ShareApiController.php
@@ -155,7 +155,7 @@ class ShareApiController extends ApiController {
try {
return new DataResponse($this->mailService->sendInvitationMail($token), Http::STATUS_OK);
} catch (Exception $e) {
- return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
+ return new DataResponse(['error' => $e], Http::STATUS_CONFLICT);
}
}
}
diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php
index bb55c5b8..4810ed23 100644
--- a/lib/Controller/ShareController.php
+++ b/lib/Controller/ShareController.php
@@ -136,7 +136,7 @@ class ShareController extends Controller {
$share = $this->shareService->get($token);
return new DataResponse(['share' => $share, 'sentResult' => $sentResult], Http::STATUS_OK);
} catch (Exception $e) {
- return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
+ return new DataResponse(['error' => $e], Http::STATUS_CONFLICT);
}
}
}
diff --git a/lib/Controller/SubscriptionApiController.php b/lib/Controller/SubscriptionApiController.php
index 13ffe3eb..b8a87d16 100644
--- a/lib/Controller/SubscriptionApiController.php
+++ b/lib/Controller/SubscriptionApiController.php
@@ -56,8 +56,8 @@ class SubscriptionApiController extends ApiController {
parent::__construct($appName,
$request,
'PUT, GET, DELETE',
- 'Authorization, Content-Type, Accept',
- 1728000);
+ 'Authorization, Content-Type, Accept',
+ 1728000);
$this->subscriptionService = $subscriptionService;
}
diff --git a/lib/Controller/SystemController.php b/lib/Controller/SystemController.php
index b1e2c606..ef695932 100644
--- a/lib/Controller/SystemController.php
+++ b/lib/Controller/SystemController.php
@@ -91,7 +91,7 @@ class SystemController extends Controller {
* Validate string as email address
* @NoAdminRequired
* @param string $query
- * @return boolval
+ * @return bool
*/
private function isValidEmail($email) {
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,}))$/', $email)) ? false : true;
diff --git a/lib/Controller/VoteController.php b/lib/Controller/VoteController.php
index 02ccc9a0..32fc89a2 100644
--- a/lib/Controller/VoteController.php
+++ b/lib/Controller/VoteController.php
@@ -45,7 +45,6 @@ class VoteController extends Controller {
* @param string $appName
* @param IRequest $request
* @param VoteService $voteService
-
*/
public function __construct(
string $appName,
diff --git a/lib/Db/Poll.php b/lib/Db/Poll.php
index d574a481..5674d0f3 100644
--- a/lib/Db/Poll.php
+++ b/lib/Db/Poll.php
@@ -135,6 +135,20 @@ class Poll extends Entity implements JsonSerializable {
];
}
+ public function deserializeArray($array) {
+ $this->setTitle(isset($array['title']) ? $array['title'] : $this->getTitle());
+ $this->setDescription(isset($array['description']) ? $array['description'] : $this->getDescription());
+ $this->setAccess(isset($array['access']) ? $array['access'] : $this->getAccess());
+ $this->setExpire(isset($array['expire']) ? $array['expire'] : $this->getExpire());
+ $this->setAnonymous(isset($array['anonymous']) ? $array['anonymous'] : $this->getAnonymous());
+ $this->setAllowMaybe(isset($array['allowMaybe']) ? $array['allowMaybe'] : $this->getAllowMaybe());
+ $this->setVoteLimit(isset($array['voteLimit']) ? $array['voteLimit'] : $this->getVoteLimit());
+ $this->setShowResults(isset($array['showResults']) ? $array['showResults'] : $this->getShowResults());
+ $this->setDeleted(isset($array['deleted']) ? $array['deleted'] : $this->getDeleted());
+ $this->setAdminAccess(isset($array['adminAccess']) ? $array['adminAccess'] : $this->getAdminAccess());
+ return $this;
+ }
+
private function getDisplayName() {
if (\OC::$server->getUserManager()->get($this->owner) instanceof IUser) {
diff --git a/lib/Service/CommentService.php b/lib/Service/CommentService.php
index f2c6ef56..6c5f89b6 100644
--- a/lib/Service/CommentService.php
+++ b/lib/Service/CommentService.php
@@ -119,7 +119,7 @@ class CommentService {
}
} catch (Exception $e) {
- \OC::$server->getLogger()->alert('Error writing comment for pollId ' . $pollId . ': '. $e);
+ \OC::$server->getLogger()->alert('Error writing comment for pollId ' . $pollId . ': ' . $e);
throw new NotAuthorizedException($e);
}
diff --git a/lib/Service/OptionService.php b/lib/Service/OptionService.php
index 2bab49a8..84fb9822 100644
--- a/lib/Service/OptionService.php
+++ b/lib/Service/OptionService.php
@@ -35,7 +35,7 @@ use OCA\Polls\Db\Poll;
use OCA\Polls\Service\LogService;
use OCA\Polls\Model\Acl;
-class OptionService {
+class OptionService {
/** @var OptionMapper */
private $optionMapper;
@@ -112,7 +112,7 @@ class OptionService {
* @return Option
* @throws NotAuthorizedException
*/
- public function add($pollId, $timestamp = 0 , $pollOptionText = '') {
+ public function add($pollId, $timestamp = 0, $pollOptionText = '') {
$this->poll = $this->pollMapper->find($pollId);
if (!$this->acl->setPollId($pollId)->getAllowEdit()) {
@@ -136,7 +136,7 @@ class OptionService {
* @return Option
* @throws NotAuthorizedException
*/
- public function update($optionId, $timestamp = 0 , $pollOptionText = '', $order = 0) {
+ public function update($optionId, $timestamp = 0, $pollOptionText = '', $order = 0) {
$this->option = $this->optionMapper->find($optionId);
$this->poll = $this->pollMapper->find($this->option->getPollId());
@@ -183,10 +183,10 @@ class OptionService {
throw new NotAuthorizedException;
}
- if ($this->option->setConfirmation()) {
- $this->option->setConfirmation(0);
+ if ($this->option->getConfirmed()) {
+ $this->option->setConfirmed(0);
} else {
- $this->option->setConfirmation(time());
+ $this->option->setConfirmed(time());
}
return $this->optionMapper->update($this->option);
@@ -237,7 +237,7 @@ class OptionService {
}
if ($this->poll->getType() === 'datePoll') {
- throw new BadRequestException("Not allowed in date polls", 1);
+ throw new BadRequestException("Not allowed in date polls");
}
$i = 0;
@@ -272,13 +272,13 @@ class OptionService {
}
if ($this->poll->getType() === 'datePoll') {
- throw new BadRequestException("Not allowed in date polls", 1);
+ throw new BadRequestException("Not allowed in date polls");
}
if ($newOrder < 1) {
$newOrder = 1;
- } elseif ($newOrder > getHighestOrder($pollId)) {
- $newOrder = getHighestOrder($pollId);
+ } elseif ($newOrder > $this->getHighestOrder($pollId)) {
+ $newOrder = $this->getHighestOrder($pollId);
}
$oldOrder = $this->option->getOrder();
@@ -324,20 +324,20 @@ class OptionService {
* @param int $order
* @throws BadRequestException
*/
- private function setOption($timestamp = 0 , $pollOptionText = '', $order = 0) {
+ private function setOption($timestamp = 0, $pollOptionText = '', $order = 0) {
if ($this->poll->getType() === 'datePoll') {
if ($timestamp) {
$this->option->setTimestamp($timestamp);
$this->option->setOrder($timestamp);
$this->option->setPollOptionText(date('c', $timestamp));
} else {
- throw new BadRequestException("Date poll must have a timestamp", 1);
+ throw new BadRequestException("Date poll must have a timestamp");
}
} elseif ($this->poll->getType() === 'textPoll') {
if ($pollOptionText) {
$this->option->setPollOptionText($pollOptionText);
} else {
- throw new BadRequestException("Text poll must have a pollOptionText", 1);
+ throw new BadRequestException("Text poll must have a pollOptionText");
}
if (!$order && !$this->option->getOrder()) {
diff --git a/lib/Service/PollService.php b/lib/Service/PollService.php
index 946a66d2..e730b575 100644
--- a/lib/Service/PollService.php
+++ b/lib/Service/PollService.php
@@ -208,7 +208,7 @@
}
if (isset($poll['access']) && !in_array($poll['access'], $this->getValidAccess())) {
- throw new InvalidAccessException('Invalid value for prop access '. $poll['access']);
+ throw new InvalidAccessException('Invalid value for prop access ' . $poll['access']);
}
if (isset($poll['title']) && !$poll['title']) {
diff --git a/lib/Service/SubscriptionService.php b/lib/Service/SubscriptionService.php
index 8809f792..0f7d82a7 100644
--- a/lib/Service/SubscriptionService.php
+++ b/lib/Service/SubscriptionService.php
@@ -32,7 +32,7 @@ use OCA\Polls\Db\Subscription;
use OCA\Polls\Db\SubscriptionMapper;
use OCA\Polls\Model\Acl;
-class SubscriptionService {
+class SubscriptionService {
/** @var Acl */
private $acl;
@@ -92,7 +92,7 @@ class SubscriptionService {
return ['status' => 'Subscribed to poll ' . $pollId];
}
- } catch (DoesNotExistException $e){
+ } catch (DoesNotExistException $e) {
if ($subscribed) {
$subscription = new Subscription();
diff --git a/lib/Service/VoteService.php b/lib/Service/VoteService.php
index 5073b732..7534b258 100644
--- a/lib/Service/VoteService.php
+++ b/lib/Service/VoteService.php
@@ -34,7 +34,7 @@ use OCA\Polls\Service\AnonymizeService;
use OCA\Polls\Service\LogService;
use OCA\Polls\Model\Acl;
-class VoteService {
+class VoteService {
/** @var VoteMapper */
private $voteMapper;
@@ -114,13 +114,12 @@ class VoteService {
public function set($optionId, $setTo, $token = '') {
$option = $this->optionMapper->find($optionId);
- $pollId = $option->getPollId();
if (!$this->acl->setPollIdOrToken($option->getPollId(), $token)->getAllowVote()) {
throw new NotAuthorizedException;
}
- if (!$option->getPollId() === $this->acl->getPollId()) {
+ if ($option->getPollId() !== $this->acl->getPollId()) {
throw new NotAuthorizedException;
}