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-06-14 13:15:00 +0300
committerdartcafe <github@dartcafe.de>2020-06-14 13:15:00 +0300
commitc6d2e376387755e10d6c4bf4107a14e65a3a5886 (patch)
tree65cae4bd1605224c4cc080132ada21b828ced1df /lib
parent734c217253323caa202e257b5187736ec28419ec (diff)
comment changed error handling
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/CommentApiController.php14
-rw-r--r--lib/Controller/CommentController.php6
-rw-r--r--lib/Model/Acl.php4
-rw-r--r--lib/Service/CommentService.php29
4 files changed, 28 insertions, 25 deletions
diff --git a/lib/Controller/CommentApiController.php b/lib/Controller/CommentApiController.php
index 83cbb16e..97d2ecf7 100644
--- a/lib/Controller/CommentApiController.php
+++ b/lib/Controller/CommentApiController.php
@@ -24,13 +24,13 @@
namespace OCA\Polls\Controller;
use Exception;
+use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IRequest;
-use OCP\ILogger;
use OCP\AppFramework\ApiController;
-use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
+
use OCA\Polls\Exceptions\NotAuthorizedException;
use OCA\Polls\Service\CommentService;
@@ -39,6 +39,7 @@ use OCA\Polls\Service\CommentService;
class CommentApiController extends ApiController {
+ private $optionService;
/**
* CommentApiController constructor.
* @param string $appName
@@ -74,6 +75,8 @@ class CommentApiController extends ApiController {
return new DataResponse($this->commentService->get($pollId, $token), Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
return new DataResponse($e, Http::STATUS_FORBIDDEN);
+ } catch (DoesNotExistException $e) {
+ return new DataResponse($pollId, Http::STATUS_NOT_FOUND);
}
}
@@ -125,9 +128,12 @@ class CommentApiController extends ApiController {
*/
public function delete($commentId, $token) {
try {
- return new DataResponse($this->commentService->delete($commentId, $token), Http::STATUS_OK);
+ $this->commentService->delete($commentId, $token);
+ return new DataResponse($commentId, Http::STATUS_OK);
} catch (NotAuthorizedException $e) {
- return new DataResponse($e, Http::STATUS_FORBIDDEN);
+ return new DataResponse($commentId, Http::STATUS_FORBIDDEN);
+ } catch (DoesNotExistException $e) {
+ return new DataResponse($commentId, Http::STATUS_NOT_FOUND);
}
}
diff --git a/lib/Controller/CommentController.php b/lib/Controller/CommentController.php
index 8e5f8680..84cfd01a 100644
--- a/lib/Controller/CommentController.php
+++ b/lib/Controller/CommentController.php
@@ -107,8 +107,10 @@ class CommentController extends Controller {
public function delete($commentId, $token) {
try {
return new DataResponse($this->commentService->delete($commentId, $token), Http::STATUS_OK);
- } catch (Exception $e) {
- return new DataResponse($e, Http::STATUS_UNAUTHORIZED);
+ } catch (NotAuthorizedException $e) {
+ return new DataResponse($e, Http::STATUS_FORBIDDEN);
+ } catch (DoesNotExistException $e) {
+ return new DataResponse($e, Http::STATUS_OK);
}
}
diff --git a/lib/Model/Acl.php b/lib/Model/Acl.php
index 4072f81f..12fbc741 100644
--- a/lib/Model/Acl.php
+++ b/lib/Model/Acl.php
@@ -143,7 +143,7 @@ class Acl implements JsonSerializable {
*/
public function checkAuthorize($pollId = 0, $token = '') {
- if ($token && !\OC::$server->getUserSession()->isLoggedIn()) {
+ if ($token) {
$this->setToken($token);
} elseif ($pollId) {
$this->setPollId($pollId);
@@ -388,12 +388,14 @@ class Acl implements JsonSerializable {
* @return string
*/
public function setToken(string $token): Acl {
+ $this->logger->debug('Share PollId' . $token);
try {
$this->token = $token;
$share = $this->shareMapper->findByToken($token);
$this->foundByToken = true;
$this->setPollId($share->getPollId());
+ $this->logger->debug('Share PollId' . $share->getPollId());
if (($share->getType() === 'group' || $share->getType() === 'user') && !\OC::$server->getUserSession()->isLoggedIn()) {
// User must be logged in for shareType user and group
diff --git a/lib/Service/CommentService.php b/lib/Service/CommentService.php
index c92bb80d..5cc29045 100644
--- a/lib/Service/CommentService.php
+++ b/lib/Service/CommentService.php
@@ -93,22 +93,20 @@ class CommentService {
$this->logger->debug('call commentService->get(' . $pollId . ', '. $token . ')');
if (!$this->acl->checkAuthorize($pollId, $token)) {
+ $this->logger->debug('Acl UserId ' . $this->acl->getUserId());
+ $this->logger->debug('Acl PollId ' . $this->acl->getPollId());
+ $this->logger->debug('Unauthorized access');
throw new NotAuthorizedException;
}
- try {
- if (!$this->acl->getAllowSeeUsernames()) {
- $this->anonymizer->set($this->acl->getPollId(), $this->acl->getUserId());
- return $this->anonymizer->getComments();
- } else {
- return $this->commentMapper->findByPoll($this->acl->getPollId());
- }
-
- } catch (\Exception $e) {
- $this->logger->alert('Error reading comments for pollId ' . $pollId . ': '. $e);
- throw new DoesNotExistException($e);
+ if (!$this->acl->getAllowSeeUsernames()) {
+ $this->anonymizer->set($this->acl->getPollId(), $this->acl->getUserId());
+ return $this->anonymizer->getComments();
+ } else {
+ return $this->commentMapper->findByPoll($this->acl->getPollId());
}
+
}
/**
@@ -156,17 +154,12 @@ class CommentService {
public function delete($commentId, $token = '') {
$this->logger->debug('call commentService->delete(' . $commentId . ', "' .$token . '")');
- try {
- $this->comment = $this->commentMapper->find($commentId);
- } catch (DoesNotExistException $e) {
- return new DoesNotExistException($e);
- }
-
+ $this->comment = $this->commentMapper->find($commentId);
if (!$this->acl->checkAuthorize($this->comment->getPollId(), $token) || $this->comment->getUserId() !== $this->acl->getUserId()) {
throw new NotAuthorizedException;
}
-
$this->commentMapper->delete($this->comment);
+
return $this->comment;
}