Коммит
1f3f7cb5f0
|
@ -40,7 +40,7 @@ jobs:
|
||||||
path: apps/${{ env.APP_NAME }}
|
path: apps/${{ env.APP_NAME }}
|
||||||
|
|
||||||
- name: Set up php ${{ matrix.php-versions }}
|
- name: Set up php ${{ matrix.php-versions }}
|
||||||
uses: shivammathur/setup-php@v1
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: ${{ matrix.php-versions }}
|
php-version: ${{ matrix.php-versions }}
|
||||||
tools: phpunit
|
tools: phpunit
|
||||||
|
|
|
@ -23,12 +23,8 @@
|
||||||
|
|
||||||
namespace OCA\Polls\Controller;
|
namespace OCA\Polls\Controller;
|
||||||
|
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\AppFramework\ApiController;
|
use OCP\AppFramework\ApiController;
|
||||||
use OCP\AppFramework\Http;
|
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
|
|
||||||
use OCA\Polls\Service\CommentService;
|
use OCA\Polls\Service\CommentService;
|
||||||
|
@ -38,6 +34,8 @@ class CommentApiController extends ApiController {
|
||||||
/** @var CommentService */
|
/** @var CommentService */
|
||||||
private $commentService;
|
private $commentService;
|
||||||
|
|
||||||
|
use ResponseHandle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CommentApiController constructor
|
* CommentApiController constructor
|
||||||
* @param string $appName
|
* @param string $appName
|
||||||
|
@ -67,13 +65,9 @@ class CommentApiController extends ApiController {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function list($pollId) {
|
public function list($pollId) {
|
||||||
try {
|
return $this->response(function () use ($pollId) {
|
||||||
return new DataResponse(['comments' => $this->commentService->list($pollId)], Http::STATUS_OK);
|
return ['comments' => $this->commentService->list($pollId)];
|
||||||
} catch (DoesNotExistException $e) {
|
});
|
||||||
return new DataResponse(['error' => 'Poll with id ' . $pollId . ' not found'], Http::STATUS_NOT_FOUND);
|
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,13 +80,9 @@ class CommentApiController extends ApiController {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function add($pollId, $message) {
|
public function add($pollId, $message) {
|
||||||
try {
|
return $this->response(function () use ($pollId, $message) {
|
||||||
return new DataResponse(['comment' => $this->commentService->add($pollId, $message)], Http::STATUS_CREATED);
|
return ['comment'=> $this->commentService->add($pollId, $message)];
|
||||||
} catch (DoesNotExistException $e) {
|
});
|
||||||
return new DataResponse(['error' => 'Poll with id ' . $pollId . ' not found'], Http::STATUS_NOT_FOUND);
|
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,12 +94,8 @@ class CommentApiController extends ApiController {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function delete($commentId) {
|
public function delete($commentId) {
|
||||||
try {
|
return $this->responseDeleteTolerant(function () use ($commentId) {
|
||||||
return new DataResponse(['comment' => $this->commentService->delete($commentId)], Http::STATUS_OK);
|
return ['comment'=> $this->commentService->delete($commentId)];
|
||||||
} catch (DoesNotExistException $e) {
|
});
|
||||||
return new DataResponse(['error' => 'Comment id ' . $commentId . ' does not exist'], Http::STATUS_NOT_FOUND);
|
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,15 +23,9 @@
|
||||||
|
|
||||||
namespace OCA\Polls\Controller;
|
namespace OCA\Polls\Controller;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http;
|
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
|
|
||||||
use OCA\Polls\Service\CommentService;
|
use OCA\Polls\Service\CommentService;
|
||||||
|
|
||||||
class CommentController extends Controller {
|
class CommentController extends Controller {
|
||||||
|
@ -39,6 +33,8 @@ class CommentController extends Controller {
|
||||||
/** @var CommentService */
|
/** @var CommentService */
|
||||||
private $commentService;
|
private $commentService;
|
||||||
|
|
||||||
|
use ResponseHandle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CommentController constructor
|
* CommentController constructor
|
||||||
* @param string $appName
|
* @param string $appName
|
||||||
|
@ -65,11 +61,9 @@ class CommentController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function add($pollId, $message, $token) {
|
public function add($pollId, $message, $token) {
|
||||||
try {
|
return $this->response(function () use ($pollId, $message, $token) {
|
||||||
return new DataResponse($this->commentService->add($pollId, $message, $token), Http::STATUS_OK);
|
return ['comment'=> $this->commentService->add($pollId, $message, $token)];
|
||||||
} catch (Exception $e) {
|
});
|
||||||
return new DataResponse($e, Http::STATUS_UNAUTHORIZED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,12 +75,8 @@ class CommentController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function delete($commentId, $token) {
|
public function delete($commentId, $token) {
|
||||||
try {
|
return $this->responseDeleteTolerant(function () use ($commentId, $token) {
|
||||||
return new DataResponse($this->commentService->delete($commentId, $token), Http::STATUS_OK);
|
return ['comment'=> $this->commentService->delete($commentId, $token)];
|
||||||
} catch (NotAuthorizedException $e) {
|
});
|
||||||
return new DataResponse($e, Http::STATUS_FORBIDDEN);
|
|
||||||
} catch (DoesNotExistException $e) {
|
|
||||||
return new DataResponse($e, Http::STATUS_OK);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,14 +23,9 @@
|
||||||
|
|
||||||
namespace OCA\Polls\Controller;
|
namespace OCA\Polls\Controller;
|
||||||
|
|
||||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
|
||||||
use OCP\AppFramework\ApiController;
|
use OCP\AppFramework\ApiController;
|
||||||
use OCP\AppFramework\Http;
|
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCA\Polls\Service\OptionService;
|
use OCA\Polls\Service\OptionService;
|
||||||
|
|
||||||
|
@ -39,6 +34,8 @@ class OptionApiController extends ApiController {
|
||||||
/** @var OptionService */
|
/** @var OptionService */
|
||||||
private $optionService;
|
private $optionService;
|
||||||
|
|
||||||
|
use ResponseHandle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OptionApiController constructor.
|
* OptionApiController constructor.
|
||||||
* @param string $appName
|
* @param string $appName
|
||||||
|
@ -68,13 +65,9 @@ class OptionApiController extends ApiController {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function list($pollId) {
|
public function list($pollId) {
|
||||||
try {
|
return $this->response(function () use ($pollId) {
|
||||||
return new DataResponse(['options' => $this->optionService->list($pollId)], Http::STATUS_OK);
|
return ['options' => $this->optionService->list($pollId)];
|
||||||
} catch (DoesNotExistException $e) {
|
});
|
||||||
return new DataResponse([], Http::STATUS_NOT_FOUND);
|
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,13 +82,9 @@ class OptionApiController extends ApiController {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function add($pollId, $timestamp = 0, $pollOptionText = '') {
|
public function add($pollId, $timestamp = 0, $pollOptionText = '') {
|
||||||
try {
|
return $this->responseCreate(function () use ($pollId, $timestamp, $pollOptionText) {
|
||||||
return new DataResponse(['option' => $this->optionService->add($pollId, $timestamp, $pollOptionText)], Http::STATUS_CREATED);
|
return ['option' => $this->optionService->add($pollId, $timestamp, $pollOptionText)];
|
||||||
} catch (UniqueConstraintViolationException $e) {
|
});
|
||||||
return new DataResponse(['error' => 'Option exists'], Http::STATUS_CONFLICT);
|
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,11 +97,9 @@ class OptionApiController extends ApiController {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function update($optionId, $timestamp = 0, $pollOptionText = '') {
|
public function update($optionId, $timestamp = 0, $pollOptionText = '') {
|
||||||
try {
|
return $this->response(function () use ($optionId, $timestamp, $pollOptionText) {
|
||||||
return new DataResponse(['option' => $this->optionService->update($optionId, $timestamp, $pollOptionText)], Http::STATUS_OK);
|
return ['option' => $this->optionService->update($optionId, $timestamp, $pollOptionText)];
|
||||||
} catch (NotAuthorizedException $e) {
|
});
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,13 +111,9 @@ class OptionApiController extends ApiController {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function delete($optionId) {
|
public function delete($optionId) {
|
||||||
try {
|
return $this->responseDeleteTolerant(function () use ($optionId) {
|
||||||
return new DataResponse(['option' => $this->optionService->delete($optionId)], Http::STATUS_OK);
|
return ['option' => $this->optionService->delete($optionId)];
|
||||||
} catch (DoesNotExistException $e) {
|
});
|
||||||
return new DataResponse(['error' => 'Option does not exist'], Http::STATUS_NOT_FOUND);
|
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -142,13 +125,9 @@ class OptionApiController extends ApiController {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function confirm($optionId) {
|
public function confirm($optionId) {
|
||||||
try {
|
return $this->response(function () use ($optionId) {
|
||||||
return new DataResponse(['option' => $this->optionService->confirm($optionId)], Http::STATUS_OK);
|
return ['option' => $this->optionService->confirm($optionId)];
|
||||||
} catch (DoesNotExistException $e) {
|
});
|
||||||
return new DataResponse(['error' => 'Option does not exist'], Http::STATUS_NOT_FOUND);
|
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -160,10 +139,8 @@ class OptionApiController extends ApiController {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function setOrder($optionId, $order) {
|
public function setOrder($optionId, $order) {
|
||||||
try {
|
return $this->response(function () use ($optionId, $order) {
|
||||||
return new DataResponse(['option' => $this->optionService->setOrder($optionId, $order)], Http::STATUS_OK);
|
return ['option' => $this->optionService->setOrder($optionId, $order)];
|
||||||
} catch (NotAuthorizedException $e) {
|
});
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,12 +25,8 @@ namespace OCA\Polls\Controller;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use OCA\Polls\Exceptions\DuplicateEntryException;
|
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http;
|
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCA\Polls\Service\OptionService;
|
use OCA\Polls\Service\OptionService;
|
||||||
use OCA\Polls\Service\CalendarService;
|
use OCA\Polls\Service\CalendarService;
|
||||||
|
@ -43,6 +39,8 @@ class OptionController extends Controller {
|
||||||
/** @var CalendarService */
|
/** @var CalendarService */
|
||||||
private $calendarService;
|
private $calendarService;
|
||||||
|
|
||||||
|
use ResponseHandle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OptionController constructor.
|
* OptionController constructor.
|
||||||
* @param string $appName
|
* @param string $appName
|
||||||
|
@ -68,7 +66,9 @@ class OptionController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function list($pollId) {
|
public function list($pollId) {
|
||||||
return new DataResponse(['options' => $this->optionService->list($pollId)], Http::STATUS_OK);
|
return $this->response(function () use ($pollId) {
|
||||||
|
return ['options' => $this->optionService->list($pollId)];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,11 +78,9 @@ class OptionController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function add($pollId, $timestamp = 0, $pollOptionText = '') {
|
public function add($pollId, $timestamp = 0, $pollOptionText = '') {
|
||||||
try {
|
return $this->responseCreate(function () use ($pollId, $timestamp, $pollOptionText) {
|
||||||
return new DataResponse(['option' => $this->optionService->add($pollId, $timestamp, $pollOptionText)], Http::STATUS_OK);
|
return ['option' => $this->optionService->add($pollId, $timestamp, $pollOptionText)];
|
||||||
} catch (DuplicateEntryException $e) {
|
});
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,7 +90,9 @@ class OptionController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function update($optionId, $timestamp, $pollOptionText) {
|
public function update($optionId, $timestamp, $pollOptionText) {
|
||||||
return new DataResponse(['option' => $this->optionService->update($optionId, $timestamp, $pollOptionText)], Http::STATUS_OK);
|
return $this->response(function () use ($optionId, $timestamp, $pollOptionText) {
|
||||||
|
return ['option' => $this->optionService->update($optionId, $timestamp, $pollOptionText)];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,9 +102,10 @@ class OptionController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function delete($optionId) {
|
public function delete($optionId) {
|
||||||
return new DataResponse(['option' => $this->optionService->delete($optionId)], Http::STATUS_OK);
|
return $this->responseDeleteTolerant(function () use ($optionId) {
|
||||||
|
return ['option' => $this->optionService->delete($optionId)];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switch option confirmation
|
* Switch option confirmation
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
|
@ -112,7 +113,9 @@ class OptionController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function confirm($optionId) {
|
public function confirm($optionId) {
|
||||||
return new DataResponse(['option' => $this->optionService->confirm($optionId)], Http::STATUS_OK);
|
return $this->response(function () use ($optionId) {
|
||||||
|
return ['option' => $this->optionService->confirm($optionId)];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -123,7 +126,9 @@ class OptionController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function reorder($pollId, $options) {
|
public function reorder($pollId, $options) {
|
||||||
return new DataResponse(['options' => $this->optionService->reorder($pollId, $options)], Http::STATUS_OK);
|
return $this->response(function () use ($pollId, $options) {
|
||||||
|
return ['options' => $this->optionService->reorder($pollId, $options)];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,7 +141,9 @@ class OptionController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function sequence($optionId, $step, $unit, $amount) {
|
public function sequence($optionId, $step, $unit, $amount) {
|
||||||
return new DataResponse(['options' => $this->optionService->sequence($optionId, $step, $unit, $amount)], Http::STATUS_OK);
|
return $this->response(function () use ($optionId, $step, $unit, $amount) {
|
||||||
|
return ['options' => $this->optionService->sequence($optionId, $step, $unit, $amount)];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,11 +154,18 @@ class OptionController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function findCalendarEvents($optionId) {
|
public function findCalendarEvents($optionId) {
|
||||||
$searchFrom = new DateTime();
|
return $this->response(function () use ($optionId) {
|
||||||
$searchFrom = $searchFrom->setTimestamp($this->optionService->get($optionId)->getTimestamp())->sub(new DateInterval('PT1H'));
|
// try {
|
||||||
$searchTo = clone $searchFrom;
|
$searchFrom = new DateTime();
|
||||||
$searchTo = $searchTo->add(new DateInterval('PT3H'));
|
$searchFrom = $searchFrom->setTimestamp($this->optionService->get($optionId)->getTimestamp())->sub(new DateInterval('PT1H'));
|
||||||
|
$searchTo = clone $searchFrom;
|
||||||
|
$searchTo = $searchTo->add(new DateInterval('PT3H'));
|
||||||
|
$events = $this->calendarService->getEvents($searchFrom, $searchTo);
|
||||||
|
|
||||||
return new DataResponse(['events' => array_values($this->calendarService->getEvents($searchFrom, $searchTo))], Http::STATUS_OK);
|
return ['events' => $events];
|
||||||
|
// } catch (\Exception $e) {
|
||||||
|
// return ['events' => []];
|
||||||
|
// }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,7 @@
|
||||||
namespace OCA\Polls\Controller;
|
namespace OCA\Polls\Controller;
|
||||||
|
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCA\Polls\Exceptions\EmptyTitleException;
|
use OCA\Polls\Exceptions\Exception;
|
||||||
use OCA\Polls\Exceptions\InvalidAccessException;
|
|
||||||
use OCA\Polls\Exceptions\InvalidShowResultsException;
|
|
||||||
use OCA\Polls\Exceptions\InvalidPollTypeException;
|
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\AppFramework\ApiController;
|
use OCP\AppFramework\ApiController;
|
||||||
|
@ -73,8 +69,8 @@
|
||||||
return new DataResponse(['polls' => $this->pollService->list()], Http::STATUS_OK);
|
return new DataResponse(['polls' => $this->pollService->list()], Http::STATUS_OK);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse([], Http::STATUS_NOT_FOUND);
|
return new DataResponse([], Http::STATUS_NOT_FOUND);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,8 +88,8 @@
|
||||||
return new DataResponse(['poll' => $this->pollService->get($pollId, '')], Http::STATUS_OK);
|
return new DataResponse(['poll' => $this->pollService->get($pollId, '')], Http::STATUS_OK);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'Not found'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['error' => 'Not found'], Http::STATUS_NOT_FOUND);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,12 +105,8 @@
|
||||||
public function add($type, $title) {
|
public function add($type, $title) {
|
||||||
try {
|
try {
|
||||||
return new DataResponse(['poll' => $this->pollService->add($type, $title)], Http::STATUS_CREATED);
|
return new DataResponse(['poll' => $this->pollService->add($type, $title)], Http::STATUS_CREATED);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
} catch (InvalidPollTypeException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (EmptyTitleException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,14 +125,8 @@
|
||||||
return new DataResponse(['poll' => $this->pollService->update($pollId, $poll)], Http::STATUS_OK);
|
return new DataResponse(['poll' => $this->pollService->update($pollId, $poll)], Http::STATUS_OK);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
} catch (InvalidAccessException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (InvalidShowResultsException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (EmptyTitleException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,8 +144,8 @@
|
||||||
return new DataResponse(['poll' => $this->pollService->delete($pollId)], Http::STATUS_OK);
|
return new DataResponse(['poll' => $this->pollService->delete($pollId)], Http::STATUS_OK);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,9 +162,9 @@
|
||||||
try {
|
try {
|
||||||
return new DataResponse(['poll' => $this->pollService->deletePermanently($pollId)], Http::STATUS_OK);
|
return new DataResponse(['poll' => $this->pollService->deletePermanently($pollId)], Http::STATUS_OK);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_OK);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,8 +181,8 @@
|
||||||
return new DataResponse(['poll' => $this->pollService->clone($pollId)], Http::STATUS_CREATED);
|
return new DataResponse(['poll' => $this->pollService->clone($pollId)], Http::STATUS_CREATED);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,8 +200,8 @@
|
||||||
return new DataResponse($this->pollService->getParticipantsEmailAddresses($pollId), Http::STATUS_OK);
|
return new DataResponse($this->pollService->getParticipantsEmailAddresses($pollId), Http::STATUS_OK);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,13 +23,8 @@
|
||||||
|
|
||||||
namespace OCA\Polls\Controller;
|
namespace OCA\Polls\Controller;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCA\Polls\Exceptions\EmptyTitleException;
|
use OCA\Polls\Exceptions\Exception;
|
||||||
use OCA\Polls\Exceptions\InvalidAccessException;
|
|
||||||
use OCA\Polls\Exceptions\InvalidShowResultsException;
|
|
||||||
use OCA\Polls\Exceptions\InvalidPollTypeException;
|
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
|
@ -104,10 +99,8 @@ class PollController extends Controller {
|
||||||
public function list() {
|
public function list() {
|
||||||
try {
|
try {
|
||||||
return new DataResponse($this->pollService->list(), Http::STATUS_OK);
|
return new DataResponse($this->pollService->list(), Http::STATUS_OK);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse([], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,14 +113,12 @@ class PollController extends Controller {
|
||||||
* @param string $token
|
* @param string $token
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function get($pollId, $token) {
|
public function get($pollId = 0, $token = '') {
|
||||||
try {
|
try {
|
||||||
$acl = $this->acl->set($pollId, $token);
|
$acl = $this->acl->set($pollId, $token);
|
||||||
$poll = $this->pollService->get($pollId, $token);
|
$poll = $this->pollService->get($pollId, $token);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => 'Not found'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -183,12 +174,8 @@ class PollController extends Controller {
|
||||||
public function add($type, $title) {
|
public function add($type, $title) {
|
||||||
try {
|
try {
|
||||||
return new DataResponse($this->pollService->add($type, $title), Http::STATUS_OK);
|
return new DataResponse($this->pollService->add($type, $title), Http::STATUS_OK);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
} catch (InvalidPollTypeException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (EmptyTitleException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,14 +192,8 @@ class PollController extends Controller {
|
||||||
return new DataResponse($this->pollService->update($pollId, $poll), Http::STATUS_OK);
|
return new DataResponse($this->pollService->update($pollId, $poll), Http::STATUS_OK);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
} catch (InvalidAccessException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (InvalidShowResultsException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (EmptyTitleException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,8 +209,8 @@ class PollController extends Controller {
|
||||||
return new DataResponse($this->pollService->delete($pollId), Http::STATUS_OK);
|
return new DataResponse($this->pollService->delete($pollId), Http::STATUS_OK);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,9 +225,9 @@ class PollController extends Controller {
|
||||||
try {
|
try {
|
||||||
return new DataResponse($this->pollService->deletePermanently($pollId), Http::STATUS_OK);
|
return new DataResponse($this->pollService->deletePermanently($pollId), Http::STATUS_OK);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_OK);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,8 +245,8 @@ class PollController extends Controller {
|
||||||
return new DataResponse($poll, Http::STATUS_OK);
|
return new DataResponse($poll, Http::STATUS_OK);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,8 +262,8 @@ class PollController extends Controller {
|
||||||
return new DataResponse($this->pollService->getParticipantsEmailAddresses($pollId), Http::STATUS_OK);
|
return new DataResponse($this->pollService->getParticipantsEmailAddresses($pollId), Http::STATUS_OK);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['error' => 'Poll not found'], Http::STATUS_NOT_FOUND);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,6 @@
|
||||||
|
|
||||||
namespace OCA\Polls\Controller;
|
namespace OCA\Polls\Controller;
|
||||||
|
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
@ -37,6 +35,7 @@ class PreferencesController extends Controller {
|
||||||
private $preferencesService;
|
private $preferencesService;
|
||||||
private $calendarService;
|
private $calendarService;
|
||||||
|
|
||||||
|
use ResponseHandle;
|
||||||
/**
|
/**
|
||||||
* PreferencesController constructor.
|
* PreferencesController constructor.
|
||||||
* @param string $appName
|
* @param string $appName
|
||||||
|
@ -63,11 +62,10 @@ class PreferencesController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function get() {
|
public function get() {
|
||||||
try {
|
return $this->response(function () {
|
||||||
return new DataResponse($this->preferencesService->get(), Http::STATUS_OK);
|
return $this->preferencesService->get();
|
||||||
} catch (DoesNotExistException $e) {
|
});
|
||||||
return new DataResponse($e, Http::STATUS_NOT_FOUND);
|
// return new DataResponse($this->preferencesService->get(), Http::STATUS_OK);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,14 +77,13 @@ class PreferencesController extends Controller {
|
||||||
*/
|
*/
|
||||||
public function write($settings) {
|
public function write($settings) {
|
||||||
if (!\OC::$server->getUserSession()->isLoggedIn()) {
|
if (!\OC::$server->getUserSession()->isLoggedIn()) {
|
||||||
return new DataResponse(null, Http::STATUS_UNAUTHORIZED);
|
return new DataResponse([], Http::STATUS_OK);
|
||||||
}
|
}
|
||||||
|
return $this->response(function () use ($settings) {
|
||||||
|
return $this->preferencesService->write($settings);
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
// return new DataResponse($this->preferencesService->write($settings), Http::STATUS_OK);
|
||||||
return new DataResponse($this->preferencesService->write($settings), Http::STATUS_OK);
|
|
||||||
} catch (DoesNotExistException $e) {
|
|
||||||
return new DataResponse($e, Http::STATUS_NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
<?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\Controller;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Http;
|
||||||
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
|
use OCA\Polls\Exceptions\Exception;
|
||||||
|
|
||||||
|
trait ResponseHandle {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* response
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @param Closure $callback
|
||||||
|
* @return DataResponse
|
||||||
|
*/
|
||||||
|
protected function response(Closure $callback) {
|
||||||
|
try {
|
||||||
|
return new DataResponse($callback(), Http::STATUS_OK);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* responseCreate
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @param Closure $callback
|
||||||
|
* @return DataResponse
|
||||||
|
*/
|
||||||
|
protected function responseCreate(Closure $callback) {
|
||||||
|
try {
|
||||||
|
return new DataResponse($callback(), Http::STATUS_CREATED);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* responseDeleteTolerant
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @param Closure $callback
|
||||||
|
* @return DataResponse
|
||||||
|
*/
|
||||||
|
protected function responseDeleteTolerant(Closure $callback) {
|
||||||
|
try {
|
||||||
|
return new DataResponse($callback(), Http::STATUS_OK);
|
||||||
|
} catch (DoesNotExistException $e) {
|
||||||
|
return new DataResponse(['message' => 'Not found, assume already deleted'], Http::STATUS_OK);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,19 +23,15 @@
|
||||||
|
|
||||||
namespace OCA\Polls\Controller;
|
namespace OCA\Polls\Controller;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\AppFramework\ApiController;
|
use OCP\AppFramework\ApiController;
|
||||||
use OCP\AppFramework\Http;
|
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
|
|
||||||
use OCA\Polls\Service\ShareService;
|
use OCA\Polls\Service\ShareService;
|
||||||
use OCA\Polls\Service\MailService;
|
use OCA\Polls\Service\MailService;
|
||||||
|
|
||||||
class ShareApiController extends ApiController {
|
class ShareApiController extends ApiController {
|
||||||
|
use ResponseHandle;
|
||||||
|
|
||||||
/** @var ShareService */
|
/** @var ShareService */
|
||||||
private $shareService;
|
private $shareService;
|
||||||
|
@ -74,13 +70,9 @@ class ShareApiController extends ApiController {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function list($pollId) {
|
public function list($pollId) {
|
||||||
try {
|
return $this->response(function () use ($pollId) {
|
||||||
return new DataResponse(['shares' => $this->shareService->list($pollId)], Http::STATUS_OK);
|
return ['shares' => $this->shareService->list($pollId)];
|
||||||
} catch (DoesNotExistException $e) {
|
});
|
||||||
return new DataResponse(['error' => 'No shares for poll with id ' . $pollId . ' not found'], Http::STATUS_NOT_FOUND);
|
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,13 +84,9 @@ class ShareApiController extends ApiController {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function get($token) {
|
public function get($token) {
|
||||||
try {
|
return $this->response(function () use ($token) {
|
||||||
return new DataResponse(['share' => $this->shareService->get($token)], Http::STATUS_OK);
|
return ['share' => $this->shareService->get($token)];
|
||||||
} catch (DoesNotExistException $e) {
|
});
|
||||||
return new DataResponse(['error' => 'Token ' . $token . ' not found'], Http::STATUS_NOT_FOUND);
|
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,13 +100,9 @@ class ShareApiController extends ApiController {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function add($pollId, $type, $userId = '') {
|
public function add($pollId, $type, $userId = '') {
|
||||||
try {
|
return $this->responseCreate(function () use ($pollId, $type, $userId) {
|
||||||
return new DataResponse(['share' => $this->shareService->add($pollId, $type, $userId)], Http::STATUS_CREATED);
|
return ['share' => $this->shareService->add($pollId, $type, $userId)];
|
||||||
} catch (NotAuthorizedException $e) {
|
});
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (Exception $e) {
|
|
||||||
return new DataResponse(['error' => $e], Http::STATUS_CONFLICT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,13 +115,9 @@ class ShareApiController extends ApiController {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function delete($token) {
|
public function delete($token) {
|
||||||
try {
|
return $this->responseDeleteTolerant(function () use ($token) {
|
||||||
return new DataResponse(['share' => $this->shareService->delete($token)], Http::STATUS_OK);
|
return ['share' => $this->shareService->delete($token)];
|
||||||
} catch (NotAuthorizedException $e) {
|
});
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (DoesNotExistException $e) {
|
|
||||||
return new DataResponse($e, Http::STATUS_NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,10 +129,13 @@ class ShareApiController extends ApiController {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function sendInvitation($token) {
|
public function sendInvitation($token) {
|
||||||
try {
|
return $this->response(function () use ($token) {
|
||||||
return new DataResponse($this->mailService->sendInvitationMail($token), Http::STATUS_OK);
|
$sentResult = $this->mailService->sendInvitationMail($token);
|
||||||
} catch (Exception $e) {
|
$share = $this->shareService->get($token);
|
||||||
return new DataResponse(['error' => $e], Http::STATUS_CONFLICT);
|
return [
|
||||||
}
|
'share' => $share,
|
||||||
|
'sentResult' => $sentResult
|
||||||
|
];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,17 +23,11 @@
|
||||||
|
|
||||||
namespace OCA\Polls\Controller;
|
namespace OCA\Polls\Controller;
|
||||||
|
|
||||||
use Exception;
|
use OCA\Polls\Exceptions\ShareAlreadyExistsException;
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
|
||||||
use OCA\Polls\Exceptions\InvalidUsernameException;
|
|
||||||
use OCA\Polls\Exceptions\InvalidShareType;
|
|
||||||
use OCA\Polls\Exceptions\ShareAlreadyExists;
|
|
||||||
|
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http;
|
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
|
|
||||||
use OCA\Polls\DB\Share;
|
use OCA\Polls\DB\Share;
|
||||||
|
@ -44,6 +38,7 @@ use OCA\Polls\Model\Circle;
|
||||||
use OCA\Polls\Model\ContactGroup;
|
use OCA\Polls\Model\ContactGroup;
|
||||||
|
|
||||||
class ShareController extends Controller {
|
class ShareController extends Controller {
|
||||||
|
use ResponseHandle;
|
||||||
|
|
||||||
/** @var MailService */
|
/** @var MailService */
|
||||||
private $mailService;
|
private $mailService;
|
||||||
|
@ -82,13 +77,21 @@ class ShareController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function list($pollId) {
|
public function list($pollId) {
|
||||||
try {
|
return $this->response(function () use ($pollId) {
|
||||||
return new DataResponse(['shares' => $this->shareService->list($pollId)], Http::STATUS_OK);
|
return ['shares' => $this->shareService->list($pollId)];
|
||||||
} catch (NotAuthorizedException $e) {
|
});
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
}
|
||||||
} catch (\Exception $e) {
|
|
||||||
return new DataResponse($e, Http::STATUS_CONFLICT);
|
/**
|
||||||
}
|
* Get share
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @param string $token
|
||||||
|
* @return DataResponse
|
||||||
|
*/
|
||||||
|
public function get($token) {
|
||||||
|
return $this->response(function () use ($token) {
|
||||||
|
return ['share' => $this->shareService->get($token)];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,29 +103,9 @@ class ShareController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function add($pollId, $type, $userId = '') {
|
public function add($pollId, $type, $userId = '') {
|
||||||
try {
|
return $this->responseCreate(function () use ($pollId, $type, $userId) {
|
||||||
return new DataResponse(['share' => $this->shareService->add($pollId, $type, $userId)], Http::STATUS_CREATED);
|
return ['share' => $this->shareService->add($pollId, $type, $userId)];
|
||||||
} catch (NotAuthorizedException $e) {
|
});
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (ShareAlreadyExists $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get share
|
|
||||||
* @NoAdminRequired
|
|
||||||
* @param string $token
|
|
||||||
* @return DataResponse
|
|
||||||
*/
|
|
||||||
public function get($token) {
|
|
||||||
try {
|
|
||||||
return new DataResponse(['share' => $this->shareService->get($token)], Http::STATUS_CREATED);
|
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return new DataResponse($e, Http::STATUS_CONFLICT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,15 +120,9 @@ class ShareController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function setEmailAddress($token, $emailAddress) {
|
public function setEmailAddress($token, $emailAddress) {
|
||||||
try {
|
return $this->response(function () use ($token, $emailAddress) {
|
||||||
return new DataResponse(['share' => $this->shareService->setEmailAddress($token, $emailAddress)], Http::STATUS_OK);
|
return ['share' => $this->shareService->setEmailAddress($token, $emailAddress)];
|
||||||
} catch (NotAuthorizedException $e) {
|
});
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (InvalidShareType $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return new DataResponse($e, Http::STATUS_CONFLICT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,16 +135,9 @@ class ShareController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function personal($token, $userName, $emailAddress = '') {
|
public function personal($token, $userName, $emailAddress = '') {
|
||||||
try {
|
return $this->responseCreate(function () use ($token, $userName, $emailAddress) {
|
||||||
return new DataResponse($this->shareService->personal($token, $userName, $emailAddress), Http::STATUS_CREATED);
|
return ['share' => $this->shareService->personal($token, $userName, $emailAddress)];
|
||||||
} catch (NotAuthorizedException $e) {
|
});
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (InvalidUsernameException $e) {
|
|
||||||
return new DataResponse(['error' => $userName . ' is not valid'], Http::STATUS_CONFLICT);
|
|
||||||
} catch (DoesNotExistException $e) {
|
|
||||||
// return forbidden in all not catched error cases
|
|
||||||
return new DataResponse($e, Http::STATUS_FORBIDDEN);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -178,13 +148,9 @@ class ShareController extends Controller {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function delete($token) {
|
public function delete($token) {
|
||||||
try {
|
return $this->responseDeleteTolerant(function () use ($token) {
|
||||||
return new DataResponse($this->shareService->delete($token), Http::STATUS_OK);
|
return ['share' => $this->shareService->delete($token)];
|
||||||
} catch (NotAuthorizedException $e) {
|
});
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (Exception $e) {
|
|
||||||
return new DataResponse($e, Http::STATUS_NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -195,13 +161,14 @@ class ShareController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function sendInvitation($token) {
|
public function sendInvitation($token) {
|
||||||
try {
|
return $this->response(function () use ($token) {
|
||||||
$sentResult = $this->mailService->sendInvitationMail($token);
|
$sentResult = $this->mailService->sendInvitationMail($token);
|
||||||
$share = $this->shareService->get($token);
|
$share = $this->shareService->get($token);
|
||||||
return new DataResponse(['share' => $share, 'sentResult' => $sentResult], Http::STATUS_OK);
|
return [
|
||||||
} catch (Exception $e) {
|
'share' => $share,
|
||||||
return new DataResponse(['error' => $e], Http::STATUS_CONFLICT);
|
'sentResult' => $sentResult
|
||||||
}
|
];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -211,15 +178,15 @@ class ShareController extends Controller {
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function resolveGroup($token) {
|
public function resolveGroup($token) {
|
||||||
$shares = [];
|
return $this->response(function () use ($token) {
|
||||||
try {
|
$shares = [];
|
||||||
$share = $this->shareService->get($token);
|
$share = $this->shareService->get($token);
|
||||||
if ($share->getType() === Share::TYPE_CIRCLE) {
|
if ($share->getType() === Share::TYPE_CIRCLE) {
|
||||||
foreach ((new Circle($share->getUserId()))->getMembers() as $member) {
|
foreach ((new Circle($share->getUserId()))->getMembers() as $member) {
|
||||||
try {
|
try {
|
||||||
$newShare = $this->shareService->add($share->getPollId(), $member->getType(), $member->getId());
|
$newShare = $this->shareService->add($share->getPollId(), $member->getType(), $member->getId());
|
||||||
$shares[] = $newShare;
|
$shares[] = $newShare;
|
||||||
} catch (ShareAlreadyExists $e) {
|
} catch (ShareAlreadyExistsException $e) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,15 +195,13 @@ class ShareController extends Controller {
|
||||||
try {
|
try {
|
||||||
$newShare = $this->shareService->add($share->getPollId(), Share::TYPE_CONTACT, $contact->getId());
|
$newShare = $this->shareService->add($share->getPollId(), Share::TYPE_CONTACT, $contact->getId());
|
||||||
$shares[] = $newShare;
|
$shares[] = $newShare;
|
||||||
} catch (ShareAlreadyExists $e) {
|
} catch (ShareAlreadyExistsException $e) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->shareService->delete($token);
|
$this->shareService->delete($token);
|
||||||
return new DataResponse(['shares' => $shares], Http::STATUS_OK);
|
return ['shares' => $shares];
|
||||||
} catch (Exception $e) {
|
});
|
||||||
return new DataResponse(['error' => $e], Http::STATUS_CONFLICT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
namespace OCA\Polls\Controller;
|
namespace OCA\Polls\Controller;
|
||||||
|
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
use OCA\Polls\Exceptions\Exception;
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
|
||||||
|
@ -68,7 +68,6 @@ class SubscriptionApiController extends ApiController {
|
||||||
* @param int $pollId
|
* @param int $pollId
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
* @throws DoesNotExistException
|
* @throws DoesNotExistException
|
||||||
* @throws NotAuthorizedException
|
|
||||||
*/
|
*/
|
||||||
public function get($pollId) {
|
public function get($pollId) {
|
||||||
try {
|
try {
|
||||||
|
@ -76,8 +75,8 @@ class SubscriptionApiController extends ApiController {
|
||||||
return new DataResponse(['status' => 'Subscribed to poll ' . $pollId], Http::STATUS_OK);
|
return new DataResponse(['status' => 'Subscribed to poll ' . $pollId], Http::STATUS_OK);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['status' => 'Not subscribed to poll ' . $pollId], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['status' => 'Not subscribed to poll ' . $pollId], Http::STATUS_NOT_FOUND);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,14 +86,13 @@ class SubscriptionApiController extends ApiController {
|
||||||
* @CORS
|
* @CORS
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
* @param int $pollId
|
* @param int $pollId
|
||||||
* @throws NotAuthorizedException
|
|
||||||
*/
|
*/
|
||||||
public function subscribe($pollId) {
|
public function subscribe($pollId) {
|
||||||
try {
|
try {
|
||||||
$this->subscriptionService->set($pollId, '', true);
|
$this->subscriptionService->set($pollId, '', true);
|
||||||
return new DataResponse(['status' => 'Subscribed to poll ' . $pollId], Http::STATUS_OK);
|
return new DataResponse(['status' => 'Subscribed to poll ' . $pollId], Http::STATUS_OK);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -103,14 +101,13 @@ class SubscriptionApiController extends ApiController {
|
||||||
* @CORS
|
* @CORS
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
* @param int $pollId
|
* @param int $pollId
|
||||||
* @throws NotAuthorizedException
|
|
||||||
*/
|
*/
|
||||||
public function unsubscribe($pollId) {
|
public function unsubscribe($pollId) {
|
||||||
try {
|
try {
|
||||||
$this->subscriptionService->set($pollId, '', false);
|
$this->subscriptionService->set($pollId, '', false);
|
||||||
return new DataResponse(['status' => 'Unsubscribed from poll ' . $pollId], Http::STATUS_OK);
|
return new DataResponse(['status' => 'Unsubscribed from poll ' . $pollId], Http::STATUS_OK);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
namespace OCA\Polls\Controller;
|
namespace OCA\Polls\Controller;
|
||||||
|
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
use OCA\Polls\Exceptions\Exception;
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
|
@ -61,13 +61,12 @@ class SubscriptionController extends Controller {
|
||||||
* @param int $pollId
|
* @param int $pollId
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
* @throws DoesNotExistException
|
* @throws DoesNotExistException
|
||||||
* @throws NotAuthorizedException
|
|
||||||
*/
|
*/
|
||||||
public function get($pollId, $token) {
|
public function get($pollId, $token) {
|
||||||
try {
|
try {
|
||||||
return new DataResponse(['subscribed' => $this->subscriptionService->get($pollId, $token)], Http::STATUS_OK);
|
return new DataResponse(['subscribed' => $this->subscriptionService->get($pollId, $token)], Http::STATUS_OK);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['subscribed' => false], Http::STATUS_OK);
|
return new DataResponse(['subscribed' => false], Http::STATUS_OK);
|
||||||
}
|
}
|
||||||
|
@ -81,13 +80,12 @@ class SubscriptionController extends Controller {
|
||||||
* @param string $token
|
* @param string $token
|
||||||
* @param boolean $subscribed
|
* @param boolean $subscribed
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
* @throws NotAuthorizedException
|
|
||||||
*/
|
*/
|
||||||
public function set($pollId, $token, $subscribed) {
|
public function set($pollId, $token, $subscribed) {
|
||||||
try {
|
try {
|
||||||
return new DataResponse(['subscribed' => $this->subscriptionService->set($pollId, $token, $subscribed)], Http::STATUS_OK);
|
return new DataResponse(['subscribed' => $this->subscriptionService->set($pollId, $token, $subscribed)], Http::STATUS_OK);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ class SystemController extends Controller {
|
||||||
try {
|
try {
|
||||||
return new DataResponse(['result' => $this->systemService->validatePublicUsername($pollId, $userName, $token), 'name' => $userName], Http::STATUS_OK);
|
return new DataResponse(['result' => $this->systemService->validatePublicUsername($pollId, $userName, $token), 'name' => $userName], Http::STATUS_OK);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_CONFLICT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ class SystemController extends Controller {
|
||||||
try {
|
try {
|
||||||
return new DataResponse(['result' => $this->systemService->validateEmailAddress($emailAddress), 'emailAddress' => $emailAddress], Http::STATUS_OK);
|
return new DataResponse(['result' => $this->systemService->validateEmailAddress($emailAddress), 'emailAddress' => $emailAddress], Http::STATUS_OK);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_CONFLICT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
namespace OCA\Polls\Controller;
|
namespace OCA\Polls\Controller;
|
||||||
|
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
use OCA\Polls\Exceptions\Exception;
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\AppFramework\ApiController;
|
use OCP\AppFramework\ApiController;
|
||||||
|
@ -70,8 +70,8 @@ class VoteApiController extends ApiController {
|
||||||
return new DataResponse(['votes' => $this->voteService->list($pollId)], Http::STATUS_OK);
|
return new DataResponse(['votes' => $this->voteService->list($pollId)], Http::STATUS_OK);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'No votes'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['error' => 'No votes'], Http::STATUS_NOT_FOUND);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,8 +89,8 @@ class VoteApiController extends ApiController {
|
||||||
return new DataResponse(['vote' => $this->voteService->set($optionId, $setTo)], Http::STATUS_OK);
|
return new DataResponse(['vote' => $this->voteService->set($optionId, $setTo)], Http::STATUS_OK);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'Option or poll not found'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['error' => 'Option or poll not found'], Http::STATUS_NOT_FOUND);
|
||||||
} catch (NotAuthorizedException $e) {
|
} catch (Exception $e) {
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,8 @@
|
||||||
|
|
||||||
namespace OCA\Polls\Controller;
|
namespace OCA\Polls\Controller;
|
||||||
|
|
||||||
// use Exception;
|
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
use OCA\Polls\Exceptions\Exception;
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
|
@ -63,10 +62,10 @@ class VoteController extends Controller {
|
||||||
public function get($pollId) {
|
public function get($pollId) {
|
||||||
try {
|
try {
|
||||||
return new DataResponse($this->voteService->list($pollId), Http::STATUS_OK);
|
return new DataResponse($this->voteService->list($pollId), Http::STATUS_OK);
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'No votes'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['error' => 'No votes'], Http::STATUS_NOT_FOUND);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,10 +80,10 @@ class VoteController extends Controller {
|
||||||
public function set($optionId, $setTo) {
|
public function set($optionId, $setTo) {
|
||||||
try {
|
try {
|
||||||
return new DataResponse($this->voteService->set($optionId, $setTo), Http::STATUS_OK);
|
return new DataResponse($this->voteService->set($optionId, $setTo), Http::STATUS_OK);
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'Option or poll not found'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['error' => 'Option or poll not found'], Http::STATUS_NOT_FOUND);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,10 +97,10 @@ class VoteController extends Controller {
|
||||||
public function delete($pollId, $userId) {
|
public function delete($pollId, $userId) {
|
||||||
try {
|
try {
|
||||||
return new DataResponse(['deleted' => $this->voteService->delete($pollId, $userId)], Http::STATUS_OK);
|
return new DataResponse(['deleted' => $this->voteService->delete($pollId, $userId)], Http::STATUS_OK);
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => ''], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_OK);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,10 +120,10 @@ class VoteController extends Controller {
|
||||||
public function setByToken($optionId, $setTo, $token) {
|
public function setByToken($optionId, $setTo, $token) {
|
||||||
try {
|
try {
|
||||||
return new DataResponse($this->voteService->set($optionId, $setTo, $token), Http::STATUS_OK);
|
return new DataResponse($this->voteService->set($optionId, $setTo, $token), Http::STATUS_OK);
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'Option not found'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['error' => 'Option not found'], Http::STATUS_NOT_FOUND);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,10 +137,10 @@ class VoteController extends Controller {
|
||||||
public function getByToken($token) {
|
public function getByToken($token) {
|
||||||
try {
|
try {
|
||||||
return new DataResponse($this->voteService->list(null, $token), Http::STATUS_OK);
|
return new DataResponse($this->voteService->list(null, $token), Http::STATUS_OK);
|
||||||
} catch (NotAuthorizedException $e) {
|
|
||||||
return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
|
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
return new DataResponse(['error' => 'No votes'], Http::STATUS_NOT_FOUND);
|
return new DataResponse(['error' => 'No votes'], Http::STATUS_NOT_FOUND);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return new DataResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,11 @@ use OCP\AppFramework\Db\Entity;
|
||||||
class Poll extends Entity implements JsonSerializable {
|
class Poll extends Entity implements JsonSerializable {
|
||||||
public const TYPE_DATE = 'datePoll';
|
public const TYPE_DATE = 'datePoll';
|
||||||
public const TYPE_TEXT = 'textPoll';
|
public const TYPE_TEXT = 'textPoll';
|
||||||
|
public const ACCESS_HIDDEN = 'hidden';
|
||||||
|
public const ACCESS_PUBLIC = 'public';
|
||||||
|
public const SHOW_RESULTS_ALWAYS = 'always';
|
||||||
|
public const SHOW_RESULTS_CLOSED = 'closed';
|
||||||
|
public const SHOW_RESULTS_NEVER = 'never';
|
||||||
|
|
||||||
/** @var string $type */
|
/** @var string $type */
|
||||||
protected $type;
|
protected $type;
|
||||||
|
@ -136,7 +141,7 @@ class Poll extends Entity implements JsonSerializable {
|
||||||
'allowMaybe' => intval($this->allowMaybe),
|
'allowMaybe' => intval($this->allowMaybe),
|
||||||
'settings' => $this->settings,
|
'settings' => $this->settings,
|
||||||
'voteLimit' => intval($this->voteLimit),
|
'voteLimit' => intval($this->voteLimit),
|
||||||
'showResults' => $this->showResults === 'expired' ? 'closed' : $this->showResults,
|
'showResults' => $this->showResults === 'expired' ? Poll::SHOW_RESULTS_CLOSED : $this->showResults,
|
||||||
'adminAccess' => intVal($this->adminAccess),
|
'adminAccess' => intVal($this->adminAccess),
|
||||||
'ownerDisplayName' => $this->getDisplayName(),
|
'ownerDisplayName' => $this->getDisplayName(),
|
||||||
'important' => intVal($this->important)
|
'important' => intVal($this->important)
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
namespace OCA\Polls\Db;
|
namespace OCA\Polls\Db;
|
||||||
|
|
||||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
use OCP\AppFramework\Db\QBMapper;
|
use OCP\AppFramework\Db\QBMapper;
|
||||||
|
|
||||||
|
@ -39,7 +38,7 @@ class PreferencesMapper extends QBMapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $id
|
* @param string $userId
|
||||||
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
|
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
|
||||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
|
||||||
* @return Preferences
|
* @return Preferences
|
||||||
|
@ -51,7 +50,7 @@ class PreferencesMapper extends QBMapper {
|
||||||
$qb->select('*')
|
$qb->select('*')
|
||||||
->from($this->getTableName())
|
->from($this->getTableName())
|
||||||
->where(
|
->where(
|
||||||
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_INT))
|
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->findEntity($qb);
|
return $this->findEntity($qb);
|
||||||
|
|
|
@ -26,7 +26,6 @@ namespace OCA\Polls\Db;
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
|
|
||||||
use OCP\AppFramework\Db\Entity;
|
use OCP\AppFramework\Db\Entity;
|
||||||
use OCA\Polls\Model\UserGroupClass;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method string getId()
|
* @method string getId()
|
||||||
|
@ -47,15 +46,23 @@ use OCA\Polls\Model\UserGroupClass;
|
||||||
* @method void setDisplayName(string $value)
|
* @method void setDisplayName(string $value)
|
||||||
*/
|
*/
|
||||||
class Share extends Entity implements JsonSerializable {
|
class Share extends Entity implements JsonSerializable {
|
||||||
|
|
||||||
|
// Only authenticated access
|
||||||
public const TYPE_USER = 'user';
|
public const TYPE_USER = 'user';
|
||||||
public const TYPE_EMAIL = 'email';
|
|
||||||
public const TYPE_CIRCLE = 'circle';
|
|
||||||
public const TYPE_GROUP = 'group';
|
public const TYPE_GROUP = 'group';
|
||||||
public const TYPE_CONTACTGROUP = 'contactGroup';
|
|
||||||
public const TYPE_CONTACT = 'contact';
|
// Public and authenticated Access
|
||||||
public const TYPE_PUBLIC = 'public';
|
public const TYPE_PUBLIC = 'public';
|
||||||
|
|
||||||
|
// Only public access
|
||||||
|
public const TYPE_EMAIL = 'email';
|
||||||
|
public const TYPE_CONTACT = 'contact';
|
||||||
public const TYPE_EXTERNAL = 'external';
|
public const TYPE_EXTERNAL = 'external';
|
||||||
|
|
||||||
|
// no direct Access
|
||||||
|
public const TYPE_CIRCLE = 'circle';
|
||||||
|
public const TYPE_CONTACTGROUP = 'contactGroup';
|
||||||
|
|
||||||
/** @var string $token */
|
/** @var string $token */
|
||||||
protected $token;
|
protected $token;
|
||||||
|
|
||||||
|
@ -88,7 +95,8 @@ class Share extends Entity implements JsonSerializable {
|
||||||
'invitationSent' => intval($this->invitationSent),
|
'invitationSent' => intval($this->invitationSent),
|
||||||
'displayName' => $this->displayName,
|
'displayName' => $this->displayName,
|
||||||
'isNoUser' => !($this->type === self::TYPE_USER),
|
'isNoUser' => !($this->type === self::TYPE_USER),
|
||||||
'shareeDetail' => UserGroupClass::getUserGroupChild($this->type, $this->getUserId())
|
'validPublic' => $this->getValidPublic(),
|
||||||
|
'validAuthenticated' => $this->getValidAuthenticated(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,4 +110,19 @@ class Share extends Entity implements JsonSerializable {
|
||||||
}
|
}
|
||||||
return $this->userId;
|
return $this->userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getValidPublic() {
|
||||||
|
return (
|
||||||
|
$this->type === self::TYPE_PUBLIC
|
||||||
|
|| $this->type === self::TYPE_EMAIL
|
||||||
|
|| $this->type === self::TYPE_CONTACT
|
||||||
|
|| $this->type === self::TYPE_EXTERNAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValidAuthenticated() {
|
||||||
|
return (
|
||||||
|
$this->type === self::TYPE_PUBLIC
|
||||||
|
|| $this->type === self::TYPE_USER
|
||||||
|
|| $this->type === self::TYPE_GROUP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class BadRequestException extends \Exception {
|
class BadRequestException extends Exception {
|
||||||
/**
|
/**
|
||||||
* NotAuthorizedException Constructor
|
* NotAuthorizedException Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($e = 'Not allowed') {
|
public function __construct($e = 'Not allowed') {
|
||||||
parent::__construct($e);
|
parent::__construct($e, Http::STATUS_BAD_REQUEST);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_BAD_REQUEST;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class CirclesNotEnabled extends \Exception {
|
class CirclesNotEnabledException extends Exception {
|
||||||
/**
|
/**
|
||||||
* TooShortException Constructor
|
* CirclesNotEnabledException Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($e = 'Circles is not enabled for this user') {
|
public function __construct($e = 'Circles is not enabled for this user') {
|
||||||
parent::__construct($e);
|
parent::__construct($e, Http::STATUS_NOT_FOUND);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_NOT_FOUND;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class ContactGroupNotFound extends \Exception {
|
class ContactGroupNotFound extends Exception {
|
||||||
/**
|
/**
|
||||||
* TooShortException Constructor
|
* TooShortException Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($e = 'Contact Group not found') {
|
public function __construct($e = 'Contact Group not found') {
|
||||||
parent::__construct($e);
|
parent::__construct($e, Http::STATUS_NOT_FOUND);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_NOT_FOUND;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class ContactsNotEnabled extends \Exception {
|
class ContactsNotEnabledExceptions extends Exception {
|
||||||
/**
|
/**
|
||||||
* TooShortException Constructor
|
* ContactsNotEnabledExceptions Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($e = 'Contacts is not enabled') {
|
public function __construct($e = 'Contacts is not enabled') {
|
||||||
parent::__construct($e);
|
parent::__construct($e, Http::STATUS_NOT_FOUND);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_NOT_FOUND;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class DuplicateEntryException extends \Exception {
|
class DuplicateEntryException extends Exception {
|
||||||
/**
|
/**
|
||||||
* DuplicateEntryException Constructor
|
* DuplicateEntryException Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($e = 'Duplicate Entry') {
|
public function __construct($e = 'Duplicate Entry') {
|
||||||
parent::__construct($e);
|
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_CONFLICT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class EmptyTitleException extends \Exception {
|
class EmptyTitleException extends Exception {
|
||||||
/**
|
/**
|
||||||
* EmptyTitleException Constructor
|
* EmptyTitleException Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($message = 'Poll title must not be empty') {
|
public function __construct($e = 'Poll title must not be empty') {
|
||||||
parent::__construct($message);
|
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_CONFLICT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?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 Exception extends \Exception {
|
||||||
|
|
||||||
|
/** @var integer */
|
||||||
|
protected $status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception Constructor
|
||||||
|
* @param string $e exception message
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
$e = 'Unexpected error',
|
||||||
|
$status = Http::STATUS_INTERNAL_SERVER_ERROR
|
||||||
|
) {
|
||||||
|
parent::__construct($e);
|
||||||
|
$this->status = $status;
|
||||||
|
}
|
||||||
|
public function getStatus() {
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class InvalidAccessException extends \Exception {
|
class InvalidAccessException extends Exception {
|
||||||
/**
|
/**
|
||||||
* InvalidAccessException Constructor
|
* InvalidAccessException Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($message = 'Invalid access value') {
|
public function __construct($e = 'Invalid access value') {
|
||||||
parent::__construct($message);
|
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_CONFLICT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class InvalidEmailAddress extends \Exception {
|
class InvalidEmailAddress extends Exception {
|
||||||
/**
|
/**
|
||||||
* InvalidEmailAddress Constructor
|
* InvalidEmailAddress Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($e = 'Invalid email address') {
|
public function __construct($e = 'Invalid email address') {
|
||||||
parent::__construct($e);
|
parent::__construct($e, Http::STATUS_FORBIDDEN);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_FORBIDDEN;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class InvalidPollTypeException extends \Exception {
|
class InvalidPollTypeException extends Exception {
|
||||||
/**
|
/**
|
||||||
* InvalidPollTypeException Constructor
|
* InvalidPollTypeException Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($message = 'Invalid pollType value') {
|
public function __construct($e = 'Invalid pollType value') {
|
||||||
parent::__construct($message);
|
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_CONFLICT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class InvalidShareType extends \Exception {
|
class InvalidShareTypeException extends Exception {
|
||||||
/**
|
/**
|
||||||
* InvalidShareType Constructor
|
* InvalidShareTypeEception Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($e = 'Invalid share type') {
|
public function __construct($e = 'Invalid share type') {
|
||||||
parent::__construct($e);
|
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_CONFLICT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class InvalidShowResultsException extends \Exception {
|
class InvalidShowResultsException extends Exception {
|
||||||
/**
|
/**
|
||||||
* InvalidShowResultsException Constructor
|
* InvalidShowResultsException Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($message = 'Invalid showResults value') {
|
public function __construct($e = 'Invalid showResults value') {
|
||||||
parent::__construct($message);
|
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_CONFLICT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class InvalidUsernameException extends \Exception {
|
class InvalidUsernameException extends Exception {
|
||||||
/**
|
/**
|
||||||
* InvalidUsernameException Constructor
|
* InvalidUsernameException Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($e = 'Username not allowed') {
|
public function __construct($e = 'Username not allowed') {
|
||||||
parent::__construct($e);
|
parent::__construct($e, Http::STATUS_FORBIDDEN);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_FORBIDDEN;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class MultipleContactsFound extends \Exception {
|
class MultipleContactsFound extends Exception {
|
||||||
/**
|
/**
|
||||||
* TooShortException Constructor
|
* TooShortException Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($e = 'Multiple Contacts found') {
|
public function __construct($e = 'Multiple Contacts found') {
|
||||||
parent::__construct($e);
|
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_CONFLICT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class NotAuthorizedException extends \Exception {
|
class NotAuthorizedException extends Exception {
|
||||||
/**
|
/**
|
||||||
* NotAuthorizedException Constructor
|
* NotAuthorizedException Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($e = 'Unauthorized') {
|
public function __construct($e = 'Unauthorized or not found') {
|
||||||
parent::__construct($e);
|
parent::__construct($e, Http::STATUS_UNAUTHORIZED);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_UNAUTHORIZED;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?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 NotFoundException extends Exception {
|
||||||
|
/**
|
||||||
|
* NotFoundException Constructor
|
||||||
|
* @param string $e exception message
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
$e = 'Not found',
|
||||||
|
$status = Http::STATUS_NOT_FOUND) {
|
||||||
|
parent::__construct($e, $status);
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class ShareAlreadyExists extends \Exception {
|
class ShareAlreadyExistsException extends Exception {
|
||||||
/**
|
/**
|
||||||
* TooShortException Constructor
|
* ShareAlreadyExistsException Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($e = 'Share already exists') {
|
public function __construct($e = 'Share already exists') {
|
||||||
parent::__construct($e);
|
parent::__construct($e, Http::STATUS_OK);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_OK;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,15 +25,12 @@ namespace OCA\Polls\Exceptions;
|
||||||
|
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
class TooShortException extends \Exception {
|
class TooShortException extends Exception {
|
||||||
/**
|
/**
|
||||||
* TooShortException Constructor
|
* TooShortException Constructor
|
||||||
* @param string $e exception message
|
* @param string $e exception message
|
||||||
*/
|
*/
|
||||||
public function __construct($e = 'String too short') {
|
public function __construct($e = 'String too short') {
|
||||||
parent::__construct($e);
|
parent::__construct($e, Http::STATUS_FORBIDDEN);
|
||||||
}
|
|
||||||
public function getStatus() {
|
|
||||||
return Http::STATUS_FORBIDDEN;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,50 @@ class Version0106Date20201031080745 extends SimpleMigrationStep {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IOutput $output
|
||||||
|
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
|
||||||
|
* @param array $options
|
||||||
|
* @return null
|
||||||
|
* @since 13.0.0
|
||||||
|
*/
|
||||||
|
public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
|
||||||
|
$schema = $schemaClosure();
|
||||||
|
|
||||||
|
if ($schema->hasTable('polls_preferences')) {
|
||||||
|
|
||||||
|
// remove preferences with empty user_id from oc_polls_preferences
|
||||||
|
$query = $this->connection->getQueryBuilder();
|
||||||
|
$query->delete('polls_preferences')
|
||||||
|
->where('user_id = :userId')
|
||||||
|
->setParameter('userId', '');
|
||||||
|
$query->execute();
|
||||||
|
|
||||||
|
// remove duplicate preferences from oc_polls_preferences
|
||||||
|
// preserve the last user setting in the db
|
||||||
|
$query = $this->connection->getQueryBuilder();
|
||||||
|
$query->select('id', 'user_id')
|
||||||
|
->from('polls_preferences');
|
||||||
|
$users = $query->execute();
|
||||||
|
|
||||||
|
$delete = $this->connection->getQueryBuilder();
|
||||||
|
$delete->delete('polls_preferences')
|
||||||
|
->where('id = :id');
|
||||||
|
|
||||||
|
$userskeep = [];
|
||||||
|
|
||||||
|
while ($row = $users->fetch()) {
|
||||||
|
if (in_array($row['user_id'], $userskeep)) {
|
||||||
|
$delete->setParameter('id', $row['id']);
|
||||||
|
$delete->execute();
|
||||||
|
} else {
|
||||||
|
$userskeep[] = $row['user_id'];
|
||||||
|
\OC::$server->getLogger()->alert('save ' . json_encode($row));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param IOutput $output
|
* @param IOutput $output
|
||||||
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
|
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
|
||||||
|
@ -80,13 +124,24 @@ class Version0106Date20201031080745 extends SimpleMigrationStep {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($schema->hasTable('polls_preferences')) {
|
||||||
|
$table = $schema->getTable('polls_preferences');
|
||||||
|
$table->addUniqueIndex(['user_id']);
|
||||||
|
}
|
||||||
|
|
||||||
return $schema;
|
return $schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
|
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
|
||||||
$query = $this->connection->getQueryBuilder();
|
$schema = $schemaClosure();
|
||||||
$query->update('polls_share')
|
if ($schema->hasTable('polls_share')) {
|
||||||
->set('email_address', 'user_email');
|
$table = $schema->getTable('polls_share');
|
||||||
$query->execute();
|
if ($table->hasColumn('email_address') && $table->hasColumn('user_email')) {
|
||||||
|
$query = $this->connection->getQueryBuilder();
|
||||||
|
$query->update('polls_share')
|
||||||
|
->set('email_address', 'user_email');
|
||||||
|
$query->execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
namespace OCA\Polls\Model;
|
namespace OCA\Polls\Model;
|
||||||
|
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
use OCA\Polls\Exceptions\NotAuthorizedException;
|
||||||
|
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
|
@ -42,18 +43,6 @@ use OCA\Polls\Db\ShareMapper;
|
||||||
*/
|
*/
|
||||||
class Acl implements JsonSerializable {
|
class Acl implements JsonSerializable {
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
private $pollId = 0;
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
private $token = '';
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
private $userId;
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
private $displayName;
|
|
||||||
|
|
||||||
/** @var IUserManager */
|
/** @var IUserManager */
|
||||||
private $userManager;
|
private $userManager;
|
||||||
|
|
||||||
|
@ -77,76 +66,57 @@ class Acl implements JsonSerializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Acl constructor.
|
* Acl constructor.
|
||||||
* @param string $UserId
|
|
||||||
* @param IUserManager $userManager
|
* @param IUserManager $userManager
|
||||||
* @param IGroupManager $groupManager
|
* @param IGroupManager $groupManager
|
||||||
* @param PollMapper $pollMapper
|
* @param PollMapper $pollMapper
|
||||||
* @param VoteMapper $voteMapper
|
* @param VoteMapper $voteMapper
|
||||||
* @param ShareMapper $shareMapper
|
* @param ShareMapper $shareMapper
|
||||||
* @param Poll $poll
|
|
||||||
* @param Share $share
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$UserId,
|
|
||||||
IUserManager $userManager,
|
IUserManager $userManager,
|
||||||
IGroupManager $groupManager,
|
IGroupManager $groupManager,
|
||||||
PollMapper $pollMapper,
|
PollMapper $pollMapper,
|
||||||
VoteMapper $voteMapper,
|
VoteMapper $voteMapper,
|
||||||
ShareMapper $shareMapper,
|
ShareMapper $shareMapper
|
||||||
Poll $poll,
|
|
||||||
Share $share
|
|
||||||
) {
|
) {
|
||||||
$this->userId = $UserId;
|
|
||||||
$this->userManager = $userManager;
|
$this->userManager = $userManager;
|
||||||
$this->groupManager = $groupManager;
|
$this->groupManager = $groupManager;
|
||||||
$this->pollMapper = $pollMapper;
|
$this->pollMapper = $pollMapper;
|
||||||
$this->voteMapper = $voteMapper;
|
$this->voteMapper = $voteMapper;
|
||||||
$this->shareMapper = $shareMapper;
|
$this->shareMapper = $shareMapper;
|
||||||
$this->poll = $poll;
|
$this->poll = new Poll;
|
||||||
$this->share = $share;
|
$this->share = new Share;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @return bool
|
* @return self
|
||||||
|
* @throws NotAuthorizedException
|
||||||
*/
|
*/
|
||||||
public function set($pollId = 0, $token = ''): Acl {
|
public function set($pollId = 0, $token = ''): Acl {
|
||||||
if ($token) {
|
try {
|
||||||
\OC::$server->getLogger()->debug('Share token: ' . $token);
|
|
||||||
|
|
||||||
$this->token = $token;
|
|
||||||
$this->pollId = 0;
|
|
||||||
$this->userId = null;
|
|
||||||
$this->share = $this->shareMapper->findByToken($token);
|
$this->share = $this->shareMapper->findByToken($token);
|
||||||
|
|
||||||
if (\OC::$server->getUserSession()->isLoggedIn()) {
|
if (($this->getLoggedIn() && !$this->share->getValidAuthenticated())
|
||||||
if ($this->share->getType() !== Share::TYPE_GROUP
|
|| (!$this->getLoggedIn() && !$this->share->getValidPublic())
|
||||||
&& $this->share->getType() !== Share::TYPE_PUBLIC) {
|
) {
|
||||||
throw new NotAuthorizedException;
|
throw new NotAuthorizedException;
|
||||||
}
|
|
||||||
|
|
||||||
$this->userId = \OC::$server->getUserSession()->getUser()->getUID();
|
|
||||||
$this->displayName = $this->userManager->get($this->userId)->getDisplayName();
|
|
||||||
} else {
|
|
||||||
if ($this->share->getType() === Share::TYPE_GROUP
|
|
||||||
|| $this->share->getType() === Share::TYPE_USER) {
|
|
||||||
throw new NotAuthorizedException;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->userId = $this->share->getUserId();
|
|
||||||
$this->displayName = $this->share->getDisplayName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pollId = $this->share->getPollId();
|
$pollId = $this->share->getPollId();
|
||||||
} elseif ($pollId) {
|
} catch (DoesNotExistException $e) {
|
||||||
$this->userId = \OC::$server->getUserSession()->getUser()->getUID();
|
if (!$this->getLoggedIn()) {
|
||||||
$this->displayName = $this->userManager->get($this->userId)->getDisplayName();
|
// Token is invalid and user is not logged in. Reject
|
||||||
$this->pollId = $pollId;
|
throw new NotAuthorizedException;
|
||||||
$this->share = null;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->poll = $this->pollMapper->find($this->pollId);
|
try {
|
||||||
|
$this->poll = $this->pollMapper->find($pollId);
|
||||||
|
} catch (DoesNotExistException $e) {
|
||||||
|
throw new NotAuthorizedException;
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -156,7 +126,11 @@ class Acl implements JsonSerializable {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getUserId() {
|
public function getUserId() {
|
||||||
return $this->userId;
|
if ($this->getLoggedIn()) {
|
||||||
|
return \OC::$server->getUserSession()->getUser()->getUID();
|
||||||
|
} else {
|
||||||
|
return $this->share->getUserId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -164,7 +138,11 @@ class Acl implements JsonSerializable {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getDisplayName() {
|
public function getDisplayName() {
|
||||||
return $this->displayName;
|
if ($this->getLoggedIn()) {
|
||||||
|
return $this->userManager->get($this->getUserId())->getDisplayName();
|
||||||
|
} else {
|
||||||
|
return $this->share->getDisplayName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -180,7 +158,7 @@ class Acl implements JsonSerializable {
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getPollId(): int {
|
public function getPollId(): int {
|
||||||
return $this->pollId;
|
return $this->poll->getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -188,11 +166,7 @@ class Acl implements JsonSerializable {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getIsOwner(): bool {
|
public function getIsOwner(): bool {
|
||||||
if (\OC::$server->getUserSession()->isLoggedIn()) {
|
return ($this->getLoggedIn() && $this->poll->getOwner() === $this->getUserId());
|
||||||
return ($this->poll->getOwner() === $this->userId);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -200,11 +174,7 @@ class Acl implements JsonSerializable {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getIsAdmin(): bool {
|
public function getIsAdmin(): bool {
|
||||||
if (\OC::$server->getUserSession()->isLoggedIn()) {
|
return ($this->getLoggedIn() && $this->groupManager->isAdmin($this->getUserId()) && $this->poll->getAdminAccess());
|
||||||
return ($this->groupManager->isAdmin($this->userId) && $this->poll->getAdminAccess());
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -213,14 +183,13 @@ class Acl implements JsonSerializable {
|
||||||
*/
|
*/
|
||||||
public function getAllowView(): bool {
|
public function getAllowView(): bool {
|
||||||
return (
|
return (
|
||||||
$this->getIsOwner()
|
$this->getAllowEdit()
|
||||||
|| ($this->getIsAdmin() && $this->poll->getAdminAccess())
|
|
||||||
|| !$this->poll->getDeleted() && (
|
|| !$this->poll->getDeleted() && (
|
||||||
$this->getUserHasVoted()
|
$this->getUserHasVoted()
|
||||||
|| $this->getGroupShare()
|
|| $this->getGroupShare()
|
||||||
|| $this->getPersonalShare()
|
|| $this->getPersonalShare()
|
||||||
|| $this->getPublicShare()
|
|| $this->getPublicShare()
|
||||||
|| ($this->poll->getAccess() !== 'hidden' && !$this->getPublicShare())
|
|| ($this->poll->getAccess() === Poll::ACCESS_PUBLIC)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -246,7 +215,7 @@ class Acl implements JsonSerializable {
|
||||||
public function getUserHasVoted(): bool {
|
public function getUserHasVoted(): bool {
|
||||||
return count(
|
return count(
|
||||||
$this->voteMapper->findParticipantsVotes($this->getPollId(), $this->getUserId())
|
$this->voteMapper->findParticipantsVotes($this->getPollId(), $this->getUserId())
|
||||||
);
|
) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -303,7 +272,7 @@ class Acl implements JsonSerializable {
|
||||||
return ($this->getAllowView() || $this->getToken())
|
return ($this->getAllowView() || $this->getToken())
|
||||||
&& !$this->getExpired()
|
&& !$this->getExpired()
|
||||||
&& !$this->poll->getDeleted()
|
&& !$this->poll->getDeleted()
|
||||||
&& $this->userId;
|
&& $this->getUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -321,7 +290,7 @@ class Acl implements JsonSerializable {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getAllowComment(): bool {
|
public function getAllowComment(): bool {
|
||||||
return !$this->poll->getDeleted() && boolval($this->userId);
|
return !$this->poll->getDeleted() && boolval($this->getUserID());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -337,7 +306,7 @@ class Acl implements JsonSerializable {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getAllowSeeResults(): bool {
|
public function getAllowSeeResults(): bool {
|
||||||
return $this->poll->getShowResults() === 'always'
|
return $this->poll->getShowResults() === Poll::SHOW_RESULTS_ALWAYS
|
||||||
|| ($this->poll->getShowResults() === 'expired' && $this->getExpired())
|
|| ($this->poll->getShowResults() === 'expired' && $this->getExpired())
|
||||||
|| $this->getIsOwner();
|
|| $this->getIsOwner();
|
||||||
}
|
}
|
||||||
|
@ -355,14 +324,14 @@ class Acl implements JsonSerializable {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getToken(): string {
|
public function getToken(): string {
|
||||||
return $this->token;
|
return strval($this->share->getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function hasEmail():bool {
|
private function hasEmail():bool {
|
||||||
if ($this->share) {
|
if ($this->share) {
|
||||||
return strlen($this->share->getEmailAddress()) > 0;
|
return strlen($this->share->getEmailAddress()) > 0;
|
||||||
} else {
|
} else {
|
||||||
return \OC::$server->getUserSession()->isLoggedIn();
|
return $this->getLoggedIn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace OCA\Polls\Model;
|
||||||
|
|
||||||
use OCA\Circles\Api\v1\Circles;
|
use OCA\Circles\Api\v1\Circles;
|
||||||
|
|
||||||
use OCA\Polls\Exceptions\CirclesNotEnabled;
|
use OCA\Polls\Exceptions\CirclesNotEnabledException;
|
||||||
|
|
||||||
class Circle extends UserGroupClass {
|
class Circle extends UserGroupClass {
|
||||||
public const TYPE = 'circle';
|
public const TYPE = 'circle';
|
||||||
|
@ -38,6 +38,7 @@ class Circle extends UserGroupClass {
|
||||||
* Group constructor.
|
* Group constructor.
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param $displayName
|
* @param $displayName
|
||||||
|
* @throws CirclesNotEnabledException
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$id
|
$id
|
||||||
|
@ -49,7 +50,7 @@ class Circle extends UserGroupClass {
|
||||||
$this->displayName = $this->circle->getName();
|
$this->displayName = $this->circle->getName();
|
||||||
$this->description = $this->circle->gettypeLongString();
|
$this->description = $this->circle->gettypeLongString();
|
||||||
} else {
|
} else {
|
||||||
throw new CirclesNotEnabled();
|
throw new CirclesNotEnabledException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
namespace OCA\Polls\Model;
|
namespace OCA\Polls\Model;
|
||||||
|
|
||||||
use OCA\Polls\Exceptions\MultipleContactsFound;
|
use OCA\Polls\Exceptions\MultipleContactsFound;
|
||||||
use OCA\Polls\Exceptions\ContactsNotEnabled;
|
use OCA\Polls\Exceptions\ContactsNotEnabledExceptions;
|
||||||
|
|
||||||
class Contact extends UserGroupClass {
|
class Contact extends UserGroupClass {
|
||||||
public const TYPE = 'contact';
|
public const TYPE = 'contact';
|
||||||
|
@ -79,6 +79,7 @@ class Contact extends UserGroupClass {
|
||||||
/**
|
/**
|
||||||
* loadContact
|
* loadContact
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
|
* @throws MultipleContactsFound
|
||||||
* The contacts app just provides a search, so we have to load the contact
|
* The contacts app just provides a search, so we have to load the contact
|
||||||
* after searching via the contact's id and use the first contact.
|
* after searching via the contact's id and use the first contact.
|
||||||
*
|
*
|
||||||
|
@ -101,6 +102,11 @@ class Contact extends UserGroupClass {
|
||||||
$this->contact = $contacts[0];
|
$this->contact = $contacts[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getContact
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @throws ContactsNotEnabledExceptions
|
||||||
|
*/
|
||||||
private function getContact() {
|
private function getContact() {
|
||||||
if (\OC::$server->getAppManager()->isEnabledForUser('contacts')) {
|
if (\OC::$server->getAppManager()->isEnabledForUser('contacts')) {
|
||||||
$this->resolveContactId();
|
$this->resolveContactId();
|
||||||
|
@ -131,7 +137,7 @@ class Contact extends UserGroupClass {
|
||||||
$this->description = \OC::$server->getL10N('polls')->t('Contact');
|
$this->description = \OC::$server->getL10N('polls')->t('Contact');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new ContactsNotEnabled();
|
throw new ContactsNotEnabledExceptions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
namespace OCA\Polls\Model;
|
namespace OCA\Polls\Model;
|
||||||
|
|
||||||
use OCA\Polls\Exceptions\InvalidShareType;
|
use OCA\Polls\Exceptions\InvalidShareTypeException;
|
||||||
|
|
||||||
class UserGroupClass implements \JsonSerializable {
|
class UserGroupClass implements \JsonSerializable {
|
||||||
public const TYPE = 'generic';
|
public const TYPE = 'generic';
|
||||||
|
@ -267,11 +267,17 @@ class UserGroupClass implements \JsonSerializable {
|
||||||
* search
|
* search
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @return Array
|
* @return Array
|
||||||
|
* @throws InvalidShareTypeException
|
||||||
*/
|
*/
|
||||||
public static function search() {
|
public static function search() {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getUserGroupChild
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @return UserGroupClass
|
||||||
|
*/
|
||||||
public static function getUserGroupChild($type, $id, $displayName = '', $emailAddress = '') {
|
public static function getUserGroupChild($type, $id, $displayName = '', $emailAddress = '') {
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case Group::TYPE:
|
case Group::TYPE:
|
||||||
|
@ -291,7 +297,7 @@ class UserGroupClass implements \JsonSerializable {
|
||||||
case self::TYPE_EXTERNAL:
|
case self::TYPE_EXTERNAL:
|
||||||
return new GenericUser($id, self::TYPE_EXTERNAL, $displayName, $emailAddress);
|
return new GenericUser($id, self::TYPE_EXTERNAL, $displayName, $emailAddress);
|
||||||
default:
|
default:
|
||||||
throw new InvalidShareType('Invalid share type (' . $type . ')');
|
throw new InvalidShareTypeException('Invalid share type (' . $type . ')');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ class CalendarService {
|
||||||
|
|
||||||
// search for all events which
|
// search for all events which
|
||||||
// - start before the end of the requested timespan ($to) and
|
// - start before the end of the requested timespan ($to) and
|
||||||
// - end before the start of the requested timespan ($from)
|
// - end after the start of the requested timespan ($from)
|
||||||
$foundEvents = $calendar->search('', ['SUMMARY'], ['timerange' => ['start' => $from, 'end' => $to]]);
|
$foundEvents = $calendar->search('', ['SUMMARY'], ['timerange' => ['start' => $from, 'end' => $to]]);
|
||||||
foreach ($foundEvents as $event) {
|
foreach ($foundEvents as $event) {
|
||||||
$calendarEvent = new CalendarEvent($event, $calendar);
|
$calendarEvent = new CalendarEvent($event, $calendar);
|
||||||
|
@ -76,7 +76,6 @@ class CalendarService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $events;
|
return $events;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
namespace OCA\Polls\Service;
|
namespace OCA\Polls\Service;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
use OCA\Polls\Exceptions\NotAuthorizedException;
|
||||||
|
|
||||||
use OCA\Polls\Db\Comment;
|
use OCA\Polls\Db\Comment;
|
||||||
|
@ -112,8 +111,7 @@ class CommentService {
|
||||||
} else {
|
} else {
|
||||||
throw new NotAuthorizedException;
|
throw new NotAuthorizedException;
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\OC::$server->getLogger()->alert('Error writing comment for pollId ' . $pollId . ': ' . $e);
|
|
||||||
throw new NotAuthorizedException($e);
|
throw new NotAuthorizedException($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,6 @@
|
||||||
|
|
||||||
namespace OCA\Polls\Service;
|
namespace OCA\Polls\Service;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use OCP\IGroupManager;
|
use OCP\IGroupManager;
|
||||||
|
@ -140,7 +138,7 @@ class MailService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$emailAddress || !filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) {
|
if (!$emailAddress || !filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) {
|
||||||
throw new Exception('Invalid email address (' . $emailAddress . ')');
|
throw new \Exception('Invalid email address (' . $emailAddress . ')');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -151,7 +149,7 @@ class MailService {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\OC::$server->getLogger()->logException($e, ['app' => 'polls']);
|
\OC::$server->getLogger()->logException($e->getMessage(), ['app' => 'polls']);
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -313,7 +311,7 @@ class MailService {
|
||||||
$share->setInvitationSent(time());
|
$share->setInvitationSent(time());
|
||||||
$this->shareMapper->update($share);
|
$this->shareMapper->update($share);
|
||||||
$sentMails[] = $recipient;
|
$sentMails[] = $recipient;
|
||||||
} catch (Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$abortedMails[] = $recipient;
|
$abortedMails[] = $recipient;
|
||||||
\OC::$server->getLogger()->alert('Error sending Mail to ' . json_encode($recipient));
|
\OC::$server->getLogger()->alert('Error sending Mail to ' . json_encode($recipient));
|
||||||
}
|
}
|
||||||
|
@ -439,7 +437,7 @@ class MailService {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->sendMail($emailTemplate, $subscription->getUserId(), $emailAddress, $displayName);
|
$this->sendMail($emailTemplate, $subscription->getUserId(), $emailAddress, $displayName);
|
||||||
} catch (Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\OC::$server->getLogger()->alert('Error sending Mail to ' . $subscription->getUserId());
|
\OC::$server->getLogger()->alert('Error sending Mail to ' . $subscription->getUserId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
use OCA\Polls\Exceptions\NotAuthorizedException;
|
||||||
use OCA\Polls\Exceptions\BadRequestException;
|
use OCA\Polls\Exceptions\BadRequestException;
|
||||||
use OCA\Polls\Exceptions\DuplicateEntryException;
|
use OCA\Polls\Exceptions\DuplicateEntryException;
|
||||||
|
use OCA\Polls\Exceptions\NotFoundException;
|
||||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||||
|
|
||||||
use OCA\Polls\Db\OptionMapper;
|
use OCA\Polls\Db\OptionMapper;
|
||||||
|
@ -47,12 +48,6 @@ class OptionService {
|
||||||
/** @var PollMapper */
|
/** @var PollMapper */
|
||||||
private $pollMapper;
|
private $pollMapper;
|
||||||
|
|
||||||
/** @var Poll */
|
|
||||||
private $poll;
|
|
||||||
|
|
||||||
/** @var LogService */
|
|
||||||
private $logService;
|
|
||||||
|
|
||||||
/** @var Acl */
|
/** @var Acl */
|
||||||
private $acl;
|
private $acl;
|
||||||
|
|
||||||
|
@ -61,8 +56,6 @@ class OptionService {
|
||||||
* @param OptionMapper $optionMapper
|
* @param OptionMapper $optionMapper
|
||||||
* @param Option $option
|
* @param Option $option
|
||||||
* @param PollMapper $pollMapper
|
* @param PollMapper $pollMapper
|
||||||
* @param Poll $poll
|
|
||||||
* @param LogService $logService
|
|
||||||
* @param Acl $acl
|
* @param Acl $acl
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -70,15 +63,11 @@ class OptionService {
|
||||||
OptionMapper $optionMapper,
|
OptionMapper $optionMapper,
|
||||||
Option $option,
|
Option $option,
|
||||||
PollMapper $pollMapper,
|
PollMapper $pollMapper,
|
||||||
Poll $poll,
|
|
||||||
LogService $logService,
|
|
||||||
Acl $acl
|
Acl $acl
|
||||||
) {
|
) {
|
||||||
$this->optionMapper = $optionMapper;
|
$this->optionMapper = $optionMapper;
|
||||||
$this->option = $option;
|
$this->option = $option;
|
||||||
$this->pollMapper = $pollMapper;
|
$this->pollMapper = $pollMapper;
|
||||||
$this->poll = $poll;
|
|
||||||
$this->logService = $logService;
|
|
||||||
$this->acl = $acl;
|
$this->acl = $acl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,14 +119,14 @@ class OptionService {
|
||||||
* @throws NotAuthorizedException
|
* @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->set($pollId)->getAllowEdit()) {
|
if (!$this->acl->set($pollId)->getAllowEdit()) {
|
||||||
throw new NotAuthorizedException;
|
throw new NotAuthorizedException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->option = new Option();
|
$this->option = new Option();
|
||||||
$this->option->setPollId($pollId);
|
$this->option->setPollId($pollId);
|
||||||
$this->setOption($timestamp, $pollOptionText, 0);
|
$this->option->setOrder($this->getHighestOrder($this->option->getPollId()) + 1);
|
||||||
|
$this->setOption($timestamp, $pollOptionText);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $this->optionMapper->insert($this->option);
|
return $this->optionMapper->insert($this->option);
|
||||||
|
@ -156,15 +145,14 @@ class OptionService {
|
||||||
* @return Option
|
* @return Option
|
||||||
* @throws NotAuthorizedException
|
* @throws NotAuthorizedException
|
||||||
*/
|
*/
|
||||||
public function update($optionId, $timestamp = 0, $pollOptionText = '', $order = 0) {
|
public function update($optionId, $timestamp = 0, $pollOptionText = '') {
|
||||||
$this->option = $this->optionMapper->find($optionId);
|
$this->option = $this->optionMapper->find($optionId);
|
||||||
$this->poll = $this->pollMapper->find($this->option->getPollId());
|
|
||||||
|
|
||||||
if (!$this->acl->set($this->option->getPollId())->getAllowEdit()) {
|
if (!$this->acl->set($this->option->getPollId())->getAllowEdit()) {
|
||||||
throw new NotAuthorizedException;
|
throw new NotAuthorizedException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setOption($timestamp, $pollOptionText, $order);
|
$this->setOption($timestamp, $pollOptionText);
|
||||||
|
|
||||||
return $this->optionMapper->update($this->option);
|
return $this->optionMapper->update($this->option);
|
||||||
}
|
}
|
||||||
|
@ -260,8 +248,12 @@ class OptionService {
|
||||||
* @throws NotAuthorizedException
|
* @throws NotAuthorizedException
|
||||||
*/
|
*/
|
||||||
public function clone($fromPollId, $toPollId) {
|
public function clone($fromPollId, $toPollId) {
|
||||||
if (!$this->acl->set($fromPollId)->getAllowView()) {
|
try {
|
||||||
throw new NotAuthorizedException;
|
if (!$this->acl->set($fromPollId)->getAllowView()) {
|
||||||
|
throw new NotAuthorizedException;
|
||||||
|
}
|
||||||
|
} catch (DoesNotExistException $e) {
|
||||||
|
throw new NotFoundException('Poll ' . $fromPollId . ' does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->optionMapper->findByPoll($fromPollId) as $origin) {
|
foreach ($this->optionMapper->findByPoll($fromPollId) as $origin) {
|
||||||
|
@ -285,18 +277,21 @@ class OptionService {
|
||||||
* @return array Array of Option objects
|
* @return array Array of Option objects
|
||||||
* @throws NotAuthorizedException
|
* @throws NotAuthorizedException
|
||||||
* @throws BadRequestException
|
* @throws BadRequestException
|
||||||
|
* @throws NotFoundException
|
||||||
*/
|
*/
|
||||||
public function reorder($pollId, $options) {
|
public function reorder($pollId, $options) {
|
||||||
$this->poll = $this->pollMapper->find($pollId);
|
try {
|
||||||
|
if (!$this->acl->set($pollId)->getAllowEdit()) {
|
||||||
|
throw new NotAuthorizedException;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$this->acl->set($pollId)->getAllowEdit()) {
|
if ($this->pollMapper->find($pollId)->getType() === Poll::TYPE_DATE) {
|
||||||
|
throw new BadRequestException("Not allowed in date polls");
|
||||||
|
}
|
||||||
|
} catch (DoesNotExistException $e) {
|
||||||
throw new NotAuthorizedException;
|
throw new NotAuthorizedException;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->poll->getType() === Poll::TYPE_DATE) {
|
|
||||||
throw new BadRequestException("Not allowed in date polls");
|
|
||||||
}
|
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($options as $option) {
|
foreach ($options as $option) {
|
||||||
$this->option = $this->optionMapper->find($option['id']);
|
$this->option = $this->optionMapper->find($option['id']);
|
||||||
|
@ -317,50 +312,61 @@ class OptionService {
|
||||||
* @return array Array of Option objects
|
* @return array Array of Option objects
|
||||||
* @throws NotAuthorizedException
|
* @throws NotAuthorizedException
|
||||||
* @throws BadRequestException
|
* @throws BadRequestException
|
||||||
|
* @throws NotFoundException
|
||||||
*/
|
*/
|
||||||
public function setOrder($optionId, $newOrder) {
|
public function setOrder($optionId, $newOrder) {
|
||||||
$this->option = $this->optionMapper->find($optionId);
|
try {
|
||||||
$pollId = $this->option->getPollId();
|
$this->option = $this->optionMapper->find($optionId);
|
||||||
$this->poll = $this->pollMapper->find($pollId);
|
$pollId = $this->option->getPollId();
|
||||||
|
|
||||||
if (!$this->acl->set($pollId)->getAllowEdit()) {
|
if ($this->pollMapper->find($pollId)->getType() === Poll::TYPE_DATE) {
|
||||||
|
throw new BadRequestException("Not allowed in date polls");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->acl->set($pollId)->getAllowEdit()) {
|
||||||
|
throw new NotAuthorizedException;
|
||||||
|
}
|
||||||
|
} catch (DoesNotExistException $e) {
|
||||||
throw new NotAuthorizedException;
|
throw new NotAuthorizedException;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->poll->getType() === Poll::TYPE_DATE) {
|
|
||||||
throw new BadRequestException("Not allowed in date polls");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($newOrder < 1) {
|
if ($newOrder < 1) {
|
||||||
$newOrder = 1;
|
$newOrder = 1;
|
||||||
} elseif ($newOrder > $this->getHighestOrder($pollId)) {
|
} elseif ($newOrder > $this->getHighestOrder($pollId)) {
|
||||||
$newOrder = $this->getHighestOrder($pollId);
|
$newOrder = $this->getHighestOrder($pollId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$oldOrder = $this->option->getOrder();
|
|
||||||
|
|
||||||
foreach ($this->optionMapper->findByPoll($pollId) as $option) {
|
foreach ($this->optionMapper->findByPoll($pollId) as $option) {
|
||||||
$currentOrder = $option->getOrder();
|
$option->setOrder($this->moveModifier($this->option->getOrder(), $newOrder, $option->getOrder()));
|
||||||
if ($currentOrder > $oldOrder && $currentOrder <= $newOrder) {
|
$this->optionMapper->update($option);
|
||||||
$option->setOrder($currentOrder - 1);
|
|
||||||
$this->optionMapper->update($option);
|
|
||||||
} elseif (
|
|
||||||
($currentOrder < $oldOrder && $currentOrder >= $newOrder)
|
|
||||||
|| ($currentOrder < $oldOrder && $currentOrder = $newOrder)
|
|
||||||
) {
|
|
||||||
$option->setOrder($currentOrder + 1);
|
|
||||||
$this->optionMapper->update($option);
|
|
||||||
} elseif ($currentOrder === $oldOrder) {
|
|
||||||
$option->setOrder($newOrder);
|
|
||||||
$this->optionMapper->update($option);
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->optionMapper->findByPoll($this->option->getPollId());
|
return $this->optionMapper->findByPoll($this->option->getPollId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* moveModifier - evaluate new order
|
||||||
|
* depending on the old and the new position of a moved array item
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @param int $moveFrom - old position of the moved item
|
||||||
|
* @param int $moveTo - target posotion of the moved item
|
||||||
|
* @param int $value - current position of the current item
|
||||||
|
* @return int - the modified new new position of the current item
|
||||||
|
*/
|
||||||
|
private function moveModifier($moveFrom, $moveTo, $currentPosition) {
|
||||||
|
$moveModifier = 0;
|
||||||
|
if ($moveFrom < $currentPosition && $currentPosition <= $moveTo) {
|
||||||
|
// moving forward
|
||||||
|
$moveModifier = -1;
|
||||||
|
} elseif ($moveTo <= $currentPosition && $currentPosition < $moveFrom) {
|
||||||
|
//moving backwards
|
||||||
|
$moveModifier = 1;
|
||||||
|
} elseif ($moveFrom === $currentPosition) {
|
||||||
|
return $moveTo;
|
||||||
|
}
|
||||||
|
return $currentPosition + $moveModifier;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set option entities validated
|
* Set option entities validated
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
|
@ -369,26 +375,15 @@ class OptionService {
|
||||||
* @param int $order
|
* @param int $order
|
||||||
* @throws BadRequestException
|
* @throws BadRequestException
|
||||||
*/
|
*/
|
||||||
private function setOption($timestamp = 0, $pollOptionText = '', $order = 0) {
|
private function setOption($timestamp = 0, $pollOptionText = '') {
|
||||||
if ($this->poll->getType() === Poll::TYPE_DATE) {
|
$poll = $this->pollMapper->find($this->option->getPollId());
|
||||||
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");
|
|
||||||
}
|
|
||||||
} elseif ($this->poll->getType() === Poll::TYPE_TEXT) {
|
|
||||||
if ($pollOptionText) {
|
|
||||||
$this->option->setPollOptionText($pollOptionText);
|
|
||||||
} else {
|
|
||||||
throw new BadRequestException("Text poll must have a pollOptionText");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$order && !$this->option->getOrder()) {
|
if ($poll->getType() === Poll::TYPE_DATE) {
|
||||||
$order = $this->getHighestOrder($this->option->getPollId()) + 1;
|
$this->option->setTimestamp($timestamp);
|
||||||
$this->option->setOrder($order);
|
$this->option->setOrder($timestamp);
|
||||||
}
|
$this->option->setPollOptionText(date('c', $timestamp));
|
||||||
|
} else {
|
||||||
|
$this->option->setPollOptionText($pollOptionText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,12 +394,12 @@ class OptionService {
|
||||||
* @return int Highest order number
|
* @return int Highest order number
|
||||||
*/
|
*/
|
||||||
private function getHighestOrder($pollId) {
|
private function getHighestOrder($pollId) {
|
||||||
$order = 0;
|
$highestOrder = 0;
|
||||||
foreach ($this->optionMapper->findByPoll($pollId) as $option) {
|
foreach ($this->optionMapper->findByPoll($pollId) as $option) {
|
||||||
if ($option->getOrder() > $order) {
|
if ($option->getOrder() > $highestOrder) {
|
||||||
$order = $option->getOrder();
|
$highestOrder = $option->getOrder();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $order;
|
return $highestOrder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
namespace OCA\Polls\Service;
|
namespace OCA\Polls\Service;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCA\Polls\Exceptions\EmptyTitleException;
|
use OCA\Polls\Exceptions\EmptyTitleException;
|
||||||
use OCA\Polls\Exceptions\InvalidAccessException;
|
use OCA\Polls\Exceptions\InvalidAccessException;
|
||||||
use OCA\Polls\Exceptions\InvalidShowResultsException;
|
use OCA\Polls\Exceptions\InvalidShowResultsException;
|
||||||
|
@ -93,7 +94,7 @@ class PollService {
|
||||||
/**
|
/**
|
||||||
* Get list of polls
|
* Get list of polls
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @return array Array of Poll
|
* @return Poll[]
|
||||||
* @throws NotAuthorizedException
|
* @throws NotAuthorizedException
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -103,17 +104,22 @@ class PollService {
|
||||||
}
|
}
|
||||||
|
|
||||||
$pollList = [];
|
$pollList = [];
|
||||||
|
try {
|
||||||
|
$polls = $this->pollMapper->findAll();
|
||||||
|
|
||||||
$polls = $this->pollMapper->findAll();
|
// TODO: Not the elegant way. Improvement neccessary
|
||||||
// TODO: Not the elegant way. Improvement neccessary
|
foreach ($polls as $poll) {
|
||||||
foreach ($polls as $poll) {
|
$combinedPoll = (object) array_merge(
|
||||||
$combinedPoll = (object) array_merge(
|
(array) json_decode(json_encode($poll)),
|
||||||
(array) json_decode(json_encode($poll)), (array) json_decode(json_encode($this->acl->set($poll->getId()))));
|
(array) json_decode(json_encode($this->acl->set($poll->getId())))
|
||||||
if ($combinedPoll->allowView) {
|
);
|
||||||
$pollList[] = $combinedPoll;
|
if ($combinedPoll->allowView) {
|
||||||
|
$pollList[] = $combinedPoll;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (DoesNotExistException $e) {
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $pollList;
|
return $pollList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +171,7 @@ class PollService {
|
||||||
$this->poll->setOwner(\OC::$server->getUserSession()->getUser()->getUID());
|
$this->poll->setOwner(\OC::$server->getUserSession()->getUser()->getUID());
|
||||||
$this->poll->setTitle($title);
|
$this->poll->setTitle($title);
|
||||||
$this->poll->setDescription('');
|
$this->poll->setDescription('');
|
||||||
$this->poll->setAccess('hidden');
|
$this->poll->setAccess(Poll::ACCESS_HIDDEN);
|
||||||
$this->poll->setExpire(0);
|
$this->poll->setExpire(0);
|
||||||
$this->poll->setAnonymous(0);
|
$this->poll->setAnonymous(0);
|
||||||
$this->poll->setFullAnonymous(0);
|
$this->poll->setFullAnonymous(0);
|
||||||
|
@ -173,7 +179,7 @@ class PollService {
|
||||||
$this->poll->setVoteLimit(0);
|
$this->poll->setVoteLimit(0);
|
||||||
$this->poll->setSettings('');
|
$this->poll->setSettings('');
|
||||||
$this->poll->setOptions('');
|
$this->poll->setOptions('');
|
||||||
$this->poll->setShowResults('always');
|
$this->poll->setShowResults(Poll::SHOW_RESULTS_ALWAYS);
|
||||||
$this->poll->setDeleted(0);
|
$this->poll->setDeleted(0);
|
||||||
$this->poll->setAdminAccess(0);
|
$this->poll->setAdminAccess(0);
|
||||||
$this->poll->setImportant(0);
|
$this->poll->setImportant(0);
|
||||||
|
@ -207,7 +213,6 @@ class PollService {
|
||||||
if (isset($poll['showResults']) && !in_array($poll['showResults'], $this->getValidShowResults())) {
|
if (isset($poll['showResults']) && !in_array($poll['showResults'], $this->getValidShowResults())) {
|
||||||
throw new InvalidShowResultsException('Invalid value for prop showResults');
|
throw new InvalidShowResultsException('Invalid value for prop showResults');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($poll['access']) && !in_array($poll['access'], $this->getValidAccess())) {
|
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']);
|
||||||
}
|
}
|
||||||
|
@ -287,7 +292,7 @@ class PollService {
|
||||||
$this->poll->setOwner(\OC::$server->getUserSession()->getUser()->getUID());
|
$this->poll->setOwner(\OC::$server->getUserSession()->getUser()->getUID());
|
||||||
$this->poll->setTitle('Clone of ' . $origin->getTitle());
|
$this->poll->setTitle('Clone of ' . $origin->getTitle());
|
||||||
$this->poll->setDeleted(0);
|
$this->poll->setDeleted(0);
|
||||||
$this->poll->setAccess('hidden');
|
$this->poll->setAccess(Poll::ACCESS_HIDDEN);
|
||||||
|
|
||||||
$this->poll->setType($origin->getType());
|
$this->poll->setType($origin->getType());
|
||||||
$this->poll->setDescription($origin->getDescription());
|
$this->poll->setDescription($origin->getDescription());
|
||||||
|
@ -355,7 +360,7 @@ class PollService {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getValidAccess() {
|
private function getValidAccess() {
|
||||||
return ['hidden', 'public'];
|
return [Poll::ACCESS_HIDDEN, Poll::ACCESS_PUBLIC];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -364,6 +369,6 @@ class PollService {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getValidShowResults() {
|
private function getValidShowResults() {
|
||||||
return ['always', 'closed', 'never'];
|
return [Poll::SHOW_RESULTS_ALWAYS, Poll::SHOW_RESULTS_CLOSED, Poll::SHOW_RESULTS_NEVER];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
namespace OCA\Polls\Service;
|
namespace OCA\Polls\Service;
|
||||||
|
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
use OCA\Polls\Exceptions\NotAuthorizedException;
|
||||||
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
|
|
||||||
use OCA\Polls\Db\Preferences;
|
use OCA\Polls\Db\Preferences;
|
||||||
use OCA\Polls\Db\PreferencesMapper;
|
use OCA\Polls\Db\PreferencesMapper;
|
||||||
|
@ -51,10 +52,14 @@ class PreferencesService {
|
||||||
$this->preferencesMapper = $preferencesMapper;
|
$this->preferencesMapper = $preferencesMapper;
|
||||||
try {
|
try {
|
||||||
$this->preferences = $this->preferencesMapper->find($this->userId);
|
$this->preferences = $this->preferencesMapper->find($this->userId);
|
||||||
} catch (\Exception $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
$this->preferences = new Preferences();
|
if ($UserId) {
|
||||||
$this->preferences->setUserId($this->userId);
|
$this->preferences = new Preferences();
|
||||||
$this->preferences = $this->preferencesMapper->insert($this->preferences);
|
$this->preferences->setUserId($this->userId);
|
||||||
|
$this->preferences = $this->preferencesMapper->insert($this->preferences);
|
||||||
|
} else {
|
||||||
|
throw new NotAuthorizedException;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -27,7 +27,8 @@ use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
use OCA\Polls\Exceptions\NotAuthorizedException;
|
||||||
use OCA\Polls\Exceptions\InvalidShareType;
|
use OCA\Polls\Exceptions\InvalidShareType;
|
||||||
use OCA\Polls\Exceptions\ShareAlreadyExists;
|
use OCA\Polls\Exceptions\ShareAlreadyExistsException;
|
||||||
|
use OCA\Polls\Exceptions\NotFoundException;
|
||||||
|
|
||||||
use OCP\Security\ISecureRandom;
|
use OCP\Security\ISecureRandom;
|
||||||
|
|
||||||
|
@ -81,12 +82,19 @@ class ShareService {
|
||||||
* @param int $pollId
|
* @param int $pollId
|
||||||
* @return array array of Share
|
* @return array array of Share
|
||||||
* @throws NotAuthorizedException
|
* @throws NotAuthorizedException
|
||||||
|
* @throws NotFoundException
|
||||||
*/
|
*/
|
||||||
public function list($pollId) {
|
public function list($pollId) {
|
||||||
if (!$this->acl->set($pollId)->getAllowEdit()) {
|
if (!$this->acl->set($pollId)->getAllowEdit()) {
|
||||||
throw new NotAuthorizedException;
|
throw new NotAuthorizedException;
|
||||||
}
|
}
|
||||||
$shares = $this->shareMapper->findByPoll($pollId);
|
|
||||||
|
try {
|
||||||
|
$shares = $this->shareMapper->findByPoll($pollId);
|
||||||
|
} catch (DoesNotExistException $e) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
return $shares;
|
return $shares;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,9 +103,14 @@ class ShareService {
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @param string $token
|
* @param string $token
|
||||||
* @return Share
|
* @return Share
|
||||||
|
* @throws NotFoundException
|
||||||
*/
|
*/
|
||||||
public function get($token) {
|
public function get($token) {
|
||||||
$this->share = $this->shareMapper->findByToken($token);
|
try {
|
||||||
|
$this->share = $this->shareMapper->findByToken($token);
|
||||||
|
} catch (DoesNotExistException $e) {
|
||||||
|
throw new NotFoundException('Token ' . $token . ' does not exist');
|
||||||
|
}
|
||||||
// Allow users entering the poll with a public share access
|
// Allow users entering the poll with a public share access
|
||||||
|
|
||||||
if ($this->share->getType() === Share::TYPE_PUBLIC && \OC::$server->getUserSession()->isLoggedIn()) {
|
if ($this->share->getType() === Share::TYPE_PUBLIC && \OC::$server->getUserSession()->isLoggedIn()) {
|
||||||
|
@ -160,9 +173,9 @@ class ShareService {
|
||||||
if ($type !== UserGroupClass::TYPE_PUBLIC) {
|
if ($type !== UserGroupClass::TYPE_PUBLIC) {
|
||||||
try {
|
try {
|
||||||
$this->shareMapper->findByPollAndUser($pollId, $userId);
|
$this->shareMapper->findByPollAndUser($pollId, $userId);
|
||||||
throw new ShareAlreadyExists;
|
throw new ShareAlreadyExistsException;
|
||||||
} catch (MultipleObjectsReturnedException $e) {
|
} catch (MultipleObjectsReturnedException $e) {
|
||||||
throw new ShareAlreadyExists;
|
throw new ShareAlreadyExistsException;
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
// continue
|
// continue
|
||||||
}
|
}
|
||||||
|
@ -180,9 +193,15 @@ class ShareService {
|
||||||
* @param string $emailAddress
|
* @param string $emailAddress
|
||||||
* @return Share
|
* @return Share
|
||||||
* @throws InvalidShareType
|
* @throws InvalidShareType
|
||||||
|
* @throws NotFoundException
|
||||||
*/
|
*/
|
||||||
public function setEmailAddress($token, $emailAddress) {
|
public function setEmailAddress($token, $emailAddress) {
|
||||||
$this->share = $this->shareMapper->findByToken($token);
|
try {
|
||||||
|
$this->share = $this->shareMapper->findByToken($token);
|
||||||
|
} catch (DoesNotExistException $e) {
|
||||||
|
throw new NotFoundException('Token ' . $token . ' does not exist');
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->share->getType() === Share::TYPE_EXTERNAL) {
|
if ($this->share->getType() === Share::TYPE_EXTERNAL) {
|
||||||
$this->systemService->validateEmailAddress($emailAddress);
|
$this->systemService->validateEmailAddress($emailAddress);
|
||||||
$this->share->setEmailAddress($emailAddress);
|
$this->share->setEmailAddress($emailAddress);
|
||||||
|
@ -201,15 +220,17 @@ class ShareService {
|
||||||
* @param string $userName
|
* @param string $userName
|
||||||
* @return Share
|
* @return Share
|
||||||
* @throws NotAuthorizedException
|
* @throws NotAuthorizedException
|
||||||
|
* @throws NotFoundException
|
||||||
*/
|
*/
|
||||||
public function personal($token, $userName, $emailAddress = '') {
|
public function personal($token, $userName, $emailAddress = '') {
|
||||||
$this->share = $this->shareMapper->findByToken($token);
|
try {
|
||||||
|
$this->share = $this->shareMapper->findByToken($token);
|
||||||
|
} catch (DoesNotExistException $e) {
|
||||||
|
throw new NotFoundException('Token ' . $token . ' does not exist');
|
||||||
|
}
|
||||||
|
|
||||||
$this->systemService->validatePublicUsername($this->share->getPollId(), $userName, $token);
|
$this->systemService->validatePublicUsername($this->share->getPollId(), $userName, $token);
|
||||||
|
$this->systemService->validateEmailAddress($emailAddress, true);
|
||||||
if ($emailAddress) {
|
|
||||||
$this->systemService->validateEmailAddress($emailAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->share->getType() === Share::TYPE_PUBLIC) {
|
if ($this->share->getType() === Share::TYPE_PUBLIC) {
|
||||||
$this->create(
|
$this->create(
|
||||||
|
|
|
@ -76,8 +76,10 @@ class SystemService {
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
* @throws InvalidEmailAddress
|
* @throws InvalidEmailAddress
|
||||||
*/
|
*/
|
||||||
public static function validateEmailAddress($emailAddress) {
|
public static function validateEmailAddress($emailAddress, $emptyIsValid = false) {
|
||||||
if (!self::isValidEmail($emailAddress)) {
|
if (!$emailAddress && $emptyIsValid) {
|
||||||
|
return true;
|
||||||
|
} elseif (!self::isValidEmail($emailAddress)) {
|
||||||
throw new InvalidEmailAddress;
|
throw new InvalidEmailAddress;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -90,13 +90,17 @@ class VoteService {
|
||||||
throw new NotAuthorizedException;
|
throw new NotAuthorizedException;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->acl->getAllowSeeResults()) {
|
try {
|
||||||
return $this->voteMapper->findByPollAndUser($this->acl->getpollId(), $this->acl->getUserId());
|
if (!$this->acl->getAllowSeeResults()) {
|
||||||
} elseif (!$this->acl->getAllowSeeUsernames()) {
|
return $this->voteMapper->findByPollAndUser($this->acl->getpollId(), $this->acl->getUserId());
|
||||||
$this->anonymizer->set($this->acl->getpollId(), $this->acl->getUserId());
|
} elseif (!$this->acl->getAllowSeeUsernames()) {
|
||||||
return $this->anonymizer->getVotes();
|
$this->anonymizer->set($this->acl->getpollId(), $this->acl->getUserId());
|
||||||
} else {
|
return $this->anonymizer->getVotes();
|
||||||
return $this->voteMapper->findByPoll($this->acl->getpollId());
|
} else {
|
||||||
|
return $this->voteMapper->findByPoll($this->acl->getpollId());
|
||||||
|
}
|
||||||
|
} catch (DoesNotExistException $e) {
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
dateLocalFormatUTC() {
|
dateLocalFormatUTC() {
|
||||||
return moment.unix(this.option.timestamp).utc().format('llll').concat(' UTC')
|
return moment.unix(this.option.timestamp).utc().format('llll') + ' UTC'
|
||||||
},
|
},
|
||||||
|
|
||||||
dateBoxMonth() {
|
dateBoxMonth() {
|
||||||
|
|
|
@ -53,12 +53,11 @@ export default {
|
||||||
}),
|
}),
|
||||||
|
|
||||||
personalLink() {
|
personalLink() {
|
||||||
return window.location.origin.concat(
|
return window.location.origin
|
||||||
this.$router.resolve({
|
+ this.$router.resolve({
|
||||||
name: 'publicVote',
|
name: 'publicVote',
|
||||||
params: { token: this.$route.params.token },
|
params: { token: this.$route.params.token },
|
||||||
}).href
|
}).href
|
||||||
)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
|
@ -239,7 +239,7 @@ export default {
|
||||||
|
|
||||||
validateEmailAddress: debounce(function() {
|
validateEmailAddress: debounce(function() {
|
||||||
if (this.emailAddress.length > 0) {
|
if (this.emailAddress.length > 0) {
|
||||||
return axios.get(generateUrl('apps/polls/check/emailaddress').concat('/', this.emailAddress))
|
return axios.get(generateUrl('apps/polls/check/emailaddress') + '/' + this.emailAddress)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.isValidEmailAddress = true
|
this.isValidEmailAddress = true
|
||||||
this.checkingEmailAddress = false
|
this.checkingEmailAddress = false
|
||||||
|
|
|
@ -44,6 +44,7 @@ import { mapState } from 'vuex'
|
||||||
import orderBy from 'lodash/orderBy'
|
import orderBy from 'lodash/orderBy'
|
||||||
import { Popover } from '@nextcloud/vue'
|
import { Popover } from '@nextcloud/vue'
|
||||||
import CalendarInfo from '../Calendar/CalendarInfo'
|
import CalendarInfo from '../Calendar/CalendarInfo'
|
||||||
|
import { showError } from '@nextcloud/dialogs'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'CalendarPeek',
|
name: 'CalendarPeek',
|
||||||
|
@ -124,6 +125,11 @@ export default {
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
this.events = response.events
|
this.events = response.events
|
||||||
})
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
if (error.message === 'Network Error') {
|
||||||
|
showError(t('polls', 'Got a network error while checking calendar events.'))
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapState } from 'vuex'
|
import { mapState } from 'vuex'
|
||||||
import { showSuccess, showError } from '@nextcloud/dialogs'
|
import { showError } from '@nextcloud/dialogs'
|
||||||
import InputDiv from '../Base/InputDiv'
|
import InputDiv from '../Base/InputDiv'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -58,7 +58,6 @@ export default {
|
||||||
if (this.comment) {
|
if (this.comment) {
|
||||||
this.$store.dispatch('poll/comments/add', { message: this.comment })
|
this.$store.dispatch('poll/comments/add', { message: this.comment })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
showSuccess(t('polls', 'Your comment was added'))
|
|
||||||
this.comment = ''
|
this.comment = ''
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|
|
@ -67,16 +67,16 @@
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
|
|
||||||
<ConfigBox :title="t('polls', 'Access')" icon-class="icon-category-auth">
|
<ConfigBox :title="t('polls', 'Access')" icon-class="icon-category-auth">
|
||||||
<input id="public"
|
<input id="hidden"
|
||||||
v-model="pollAccess"
|
v-model="pollAccess"
|
||||||
value="public"
|
value="hidden"
|
||||||
type="radio"
|
type="radio"
|
||||||
class="radio">
|
class="radio">
|
||||||
<label for="public">{{ t('polls', 'Only invited users') }}</label>
|
<label for="public">{{ t('polls', 'Only invited users') }}</label>
|
||||||
|
|
||||||
<input id="hidden"
|
<input id="public"
|
||||||
v-model="pollAccess"
|
v-model="pollAccess"
|
||||||
value="hidden"
|
value="public"
|
||||||
type="radio"
|
type="radio"
|
||||||
class="radio">
|
class="radio">
|
||||||
<label for="hidden">{{ t('polls', 'All users') }}</label>
|
<label for="hidden">{{ t('polls', 'All users') }}</label>
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<ConfigBox :title="t('polls', 'Add a new text option')" icon-class="icon-add">
|
<ConfigBox v-if="!closed" :title="t('polls', 'Add a new text option')" icon-class="icon-add">
|
||||||
<InputDiv v-model="newPollText" :placeholder="t('polls', 'Enter option text')"
|
<InputDiv v-model="newPollText" :placeholder="t('polls', 'Enter option text')"
|
||||||
@input="addOption()" />
|
@input="addOption()" />
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
|
|
|
@ -177,6 +177,16 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
resolveGroup(share) {
|
resolveGroup(share) {
|
||||||
this.$store.dispatch('poll/shares/resolveGroup', { share: share })
|
this.$store.dispatch('poll/shares/resolveGroup', { share: share })
|
||||||
|
.catch((error) => {
|
||||||
|
if (error.response.status === 409 && error.response.data === 'Circles is not enabled for this user') {
|
||||||
|
showError(t('polls', 'Resolving of {name} is not possible. The circles app is not enabled.', { name: share.displayName }))
|
||||||
|
} else if (error.response.status === 409 && error.response.data === 'Contacts is not enabled') {
|
||||||
|
showError(t('polls', 'Resolving of {name} is not possible. The contacts app is not enabled.', { name: share.displayName }))
|
||||||
|
} else {
|
||||||
|
showError(t('polls', 'Error resolving {name}.', { name: share.displayName }))
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
sendInvitation(share) {
|
sendInvitation(share) {
|
||||||
|
|
|
@ -143,9 +143,9 @@ const actions = {
|
||||||
get(context, payload) {
|
get(context, payload) {
|
||||||
let endPoint = 'apps/polls/polls/get'
|
let endPoint = 'apps/polls/polls/get'
|
||||||
if (payload.token) {
|
if (payload.token) {
|
||||||
endPoint = endPoint.concat('/s/', payload.token)
|
endPoint = endPoint + '/s/' + payload.token
|
||||||
} else if (payload.pollId) {
|
} else if (payload.pollId) {
|
||||||
endPoint = endPoint.concat('/', payload.pollId)
|
endPoint = endPoint + '/' + payload.pollId
|
||||||
} else {
|
} else {
|
||||||
context.commit('reset')
|
context.commit('reset')
|
||||||
context.commit('acl/reset')
|
context.commit('acl/reset')
|
||||||
|
@ -188,7 +188,7 @@ const actions = {
|
||||||
|
|
||||||
clone(context, payload) {
|
clone(context, payload) {
|
||||||
const endPoint = 'apps/polls/polls/clone'
|
const endPoint = 'apps/polls/polls/clone'
|
||||||
return axios.get(generateUrl(endPoint.concat('/', payload.pollId)))
|
return axios.get(generateUrl(endPoint + '/' + payload.pollId))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
return response.data
|
return response.data
|
||||||
})
|
})
|
||||||
|
@ -200,7 +200,7 @@ const actions = {
|
||||||
|
|
||||||
update(context) {
|
update(context) {
|
||||||
const endPoint = 'apps/polls/polls/update'
|
const endPoint = 'apps/polls/polls/update'
|
||||||
return axios.put(generateUrl(endPoint.concat('/', state.id)), { poll: state })
|
return axios.put(generateUrl(endPoint + '/' + state.id), { poll: state })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
context.commit('set', { poll: response.data })
|
context.commit('set', { poll: response.data })
|
||||||
return response
|
return response
|
||||||
|
@ -214,7 +214,7 @@ const actions = {
|
||||||
|
|
||||||
switchDeleted(context, payload) {
|
switchDeleted(context, payload) {
|
||||||
const endPoint = 'apps/polls/polls/delete'
|
const endPoint = 'apps/polls/polls/delete'
|
||||||
return axios.get(generateUrl(endPoint.concat('/', payload.pollId)))
|
return axios.get(generateUrl(endPoint + '/' + payload.pollId))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
return response
|
return response
|
||||||
})
|
})
|
||||||
|
@ -225,7 +225,7 @@ const actions = {
|
||||||
|
|
||||||
delete(context, payload) {
|
delete(context, payload) {
|
||||||
const endPoint = 'apps/polls/polls/delete'
|
const endPoint = 'apps/polls/polls/delete'
|
||||||
return axios.get(generateUrl(endPoint.concat('/permanent/', payload.pollId)))
|
return axios.get(generateUrl(endPoint + '/permanent/' + payload.pollId))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
return response
|
return response
|
||||||
})
|
})
|
||||||
|
@ -236,7 +236,7 @@ const actions = {
|
||||||
|
|
||||||
getParticipantsEmailAddresses(context, payload) {
|
getParticipantsEmailAddresses(context, payload) {
|
||||||
const endPoint = 'apps/polls/polls/addresses'
|
const endPoint = 'apps/polls/polls/addresses'
|
||||||
return axios.get(generateUrl(endPoint.concat('/', payload.pollId)))
|
return axios.get(generateUrl(endPoint + '/' + payload.pollId))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
return response
|
return response
|
||||||
})
|
})
|
||||||
|
|
|
@ -45,7 +45,7 @@ const mutations = {
|
||||||
},
|
},
|
||||||
|
|
||||||
add(state, payload) {
|
add(state, payload) {
|
||||||
state.list.push(payload)
|
state.list.push(payload.comment)
|
||||||
},
|
},
|
||||||
|
|
||||||
delete(state, payload) {
|
delete(state, payload) {
|
||||||
|
@ -71,7 +71,7 @@ const actions = {
|
||||||
token: context.rootState.poll.acl.token,
|
token: context.rootState.poll.acl.token,
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
context.commit('add', response.data)
|
context.commit('add', { comment: response.data.comment })
|
||||||
return response.data
|
return response.data
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
@ -83,13 +83,13 @@ const actions = {
|
||||||
delete(context, payload) {
|
delete(context, payload) {
|
||||||
let endPoint = 'apps/polls/comment'
|
let endPoint = 'apps/polls/comment'
|
||||||
if (context.rootState.poll.acl.token) {
|
if (context.rootState.poll.acl.token) {
|
||||||
endPoint = endPoint.concat('/s/', context.rootState.poll.acl.token)
|
endPoint = endPoint + '/s/' + context.rootState.poll.acl.token
|
||||||
}
|
}
|
||||||
context.commit('delete', { comment: payload.comment })
|
|
||||||
|
|
||||||
return axios.delete(generateUrl(endPoint.concat('/', payload.comment.id)))
|
return axios.delete(generateUrl(endPoint + '/' + payload.comment.id))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
context.commit('delete', { comment: response.data.comment })
|
console.debug('deleted', response.data)
|
||||||
|
context.commit('delete', { comment: payload.comment })
|
||||||
return response.data
|
return response.data
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|
|
@ -117,8 +117,7 @@ const actions = {
|
||||||
|
|
||||||
reload(context) {
|
reload(context) {
|
||||||
const endPoint = 'apps/polls/polls'
|
const endPoint = 'apps/polls/polls'
|
||||||
console.error('Reloading options')
|
return axios.get(generateUrl(endPoint + '/' + context.rootState.poll.id + '/options'))
|
||||||
return axios.get(generateUrl(endPoint.concat('/', context.rootState.poll.id, '/options')))
|
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
context.commit('set', { options: response.data.options })
|
context.commit('set', { options: response.data.options })
|
||||||
})
|
})
|
||||||
|
@ -139,7 +138,7 @@ const actions = {
|
||||||
context.commit('setItem', { option: response.data.option })
|
context.commit('setItem', { option: response.data.option })
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Error adding option', { error: error.response }, { payload: payload })
|
console.error('Error adding option: ' + error.response.data, { error: error.response }, { payload: payload })
|
||||||
context.dispatch('reload')
|
context.dispatch('reload')
|
||||||
throw error
|
throw error
|
||||||
})
|
})
|
||||||
|
@ -147,7 +146,7 @@ const actions = {
|
||||||
|
|
||||||
update(context, payload) {
|
update(context, payload) {
|
||||||
const endPoint = 'apps/polls/option'
|
const endPoint = 'apps/polls/option'
|
||||||
return axios.put(generateUrl(endPoint.concat('/', payload.option.id)), {
|
return axios.put(generateUrl(endPoint + '/' + payload.option.id), {
|
||||||
timestamp: payload.option.timestamp,
|
timestamp: payload.option.timestamp,
|
||||||
pollOptionText: payload.option.timeStamp,
|
pollOptionText: payload.option.timeStamp,
|
||||||
})
|
})
|
||||||
|
@ -164,9 +163,9 @@ const actions = {
|
||||||
delete(context, payload) {
|
delete(context, payload) {
|
||||||
const endPoint = 'apps/polls/option'
|
const endPoint = 'apps/polls/option'
|
||||||
|
|
||||||
return axios.delete(generateUrl(endPoint.concat('/', payload.option.id)))
|
return axios.delete(generateUrl(endPoint + '/' + payload.option.id))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
context.commit('delete', { option: response.data.option })
|
context.commit('delete', { option: payload.option })
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Error deleting option', { error: error.response }, { payload: payload })
|
console.error('Error deleting option', { error: error.response }, { payload: payload })
|
||||||
|
@ -179,7 +178,7 @@ const actions = {
|
||||||
context.commit('confirm', { option: payload.option })
|
context.commit('confirm', { option: payload.option })
|
||||||
|
|
||||||
const endPoint = 'apps/polls/option'
|
const endPoint = 'apps/polls/option'
|
||||||
return axios.put(generateUrl(endPoint.concat('/', payload.option.id, '/confirm')))
|
return axios.put(generateUrl(endPoint + '/' + payload.option.id + '/confirm'))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
context.commit('setItem', { option: response.data.option })
|
context.commit('setItem', { option: response.data.option })
|
||||||
})
|
})
|
||||||
|
@ -193,7 +192,7 @@ const actions = {
|
||||||
reorder(context, payload) {
|
reorder(context, payload) {
|
||||||
const endPoint = 'apps/polls/polls'
|
const endPoint = 'apps/polls/polls'
|
||||||
context.commit('reorder', { options: payload })
|
context.commit('reorder', { options: payload })
|
||||||
return axios.post(generateUrl(endPoint.concat('/', context.rootState.poll.id, '/options/reorder')), {
|
return axios.post(generateUrl(endPoint + '/' + context.rootState.poll.id + '/options/reorder'), {
|
||||||
options: payload,
|
options: payload,
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
@ -208,7 +207,7 @@ const actions = {
|
||||||
|
|
||||||
sequence(context, payload) {
|
sequence(context, payload) {
|
||||||
const endPoint = 'apps/polls/option'
|
const endPoint = 'apps/polls/option'
|
||||||
return axios.post(generateUrl(endPoint.concat('/', payload.option.id, '/sequence')), {
|
return axios.post(generateUrl(endPoint + '/' + payload.option.id + '/sequence'), {
|
||||||
step: payload.sequence.step,
|
step: payload.sequence.step,
|
||||||
unit: payload.sequence.unit.value,
|
unit: payload.sequence.unit.value,
|
||||||
amount: payload.sequence.amount,
|
amount: payload.sequence.amount,
|
||||||
|
@ -225,14 +224,17 @@ const actions = {
|
||||||
|
|
||||||
getEvents(context, payload) {
|
getEvents(context, payload) {
|
||||||
const endPoint = 'apps/polls/option'
|
const endPoint = 'apps/polls/option'
|
||||||
return axios.get(generateUrl(endPoint.concat('/', payload.option.id, '/events')))
|
return axios.get(generateUrl(endPoint + '/' + payload.option.id + '/events'))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
return response.data
|
return response.data
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Error loading calendar events', { error: error.response }, { payload: payload })
|
if (error.message === 'Network Error') {
|
||||||
context.dispatch('reload')
|
console.error('Got an ugly network error while loading calendar events', { error: error }, { payload: payload })
|
||||||
throw error
|
throw error
|
||||||
|
}
|
||||||
|
console.error('Error loading calendar events - start whistling and behave as if nothing happened', { error: error }, { payload: payload })
|
||||||
|
return { events: [] }
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ const mutations = {
|
||||||
const actions = {
|
const actions = {
|
||||||
get(context, payload) {
|
get(context, payload) {
|
||||||
const endPoint = 'apps/polls/share'
|
const endPoint = 'apps/polls/share'
|
||||||
return axios.get(generateUrl(endPoint.concat('/', payload.token)))
|
return axios.get(generateUrl(endPoint + '/' + payload.token))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
context.commit('set', { share: response.data.share })
|
context.commit('set', { share: response.data.share })
|
||||||
return response.data
|
return response.data
|
||||||
|
@ -68,7 +68,7 @@ const actions = {
|
||||||
|
|
||||||
sendInvitation(context, payload) {
|
sendInvitation(context, payload) {
|
||||||
const endPoint = 'apps/polls/share/send'
|
const endPoint = 'apps/polls/share/send'
|
||||||
return axios.post(generateUrl(endPoint.concat('/', context.state.token)))
|
return axios.post(generateUrl(endPoint + '/' + context.state.token))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
context.commit('set', { share: response.data.share })
|
context.commit('set', { share: response.data.share })
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -88,7 +88,7 @@ const getters = {
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
list(context) {
|
list(context) {
|
||||||
const endPoint = 'apps/polls/poll/'.concat(context.rootState.poll.id, '/shares')
|
const endPoint = 'apps/polls/poll/' + context.rootState.poll.id + '/shares'
|
||||||
return axios.get(generateUrl(endPoint))
|
return axios.get(generateUrl(endPoint))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
context.commit('set', response.data)
|
context.commit('set', response.data)
|
||||||
|
@ -101,7 +101,7 @@ const actions = {
|
||||||
},
|
},
|
||||||
|
|
||||||
add(context, payload) {
|
add(context, payload) {
|
||||||
const endPoint = 'apps/polls/poll/'.concat(context.rootState.poll.id, '/share')
|
const endPoint = 'apps/polls/poll/' + context.rootState.poll.id + '/share'
|
||||||
|
|
||||||
return axios.post(generateUrl(endPoint), payload.share)
|
return axios.post(generateUrl(endPoint), payload.share)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
@ -118,10 +118,9 @@ const actions = {
|
||||||
|
|
||||||
addPersonal(context, payload) {
|
addPersonal(context, payload) {
|
||||||
const endPoint = 'apps/polls/share/personal'
|
const endPoint = 'apps/polls/share/personal'
|
||||||
context.dispatch('delete', { share: payload })
|
|
||||||
return axios.post(generateUrl(endPoint), { token: payload.token, userName: payload.userName, emailAddress: payload.emailAddress })
|
return axios.post(generateUrl(endPoint), { token: payload.token, userName: payload.userName, emailAddress: payload.emailAddress })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
return { token: response.data.token }
|
return { token: response.data.share.token }
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Error writing personal share', { error: error.response }, { payload: payload })
|
console.error('Error writing personal share', { error: error.response }, { payload: payload })
|
||||||
|
@ -131,7 +130,7 @@ const actions = {
|
||||||
},
|
},
|
||||||
|
|
||||||
delete(context, payload) {
|
delete(context, payload) {
|
||||||
const endPoint = 'apps/polls/share/delete/'.concat(payload.share.token)
|
const endPoint = 'apps/polls/share/delete/' + payload.share.token
|
||||||
context.commit('delete', { share: payload.share })
|
context.commit('delete', { share: payload.share })
|
||||||
|
|
||||||
return axios.delete(generateUrl(endPoint))
|
return axios.delete(generateUrl(endPoint))
|
||||||
|
@ -148,7 +147,7 @@ const actions = {
|
||||||
},
|
},
|
||||||
|
|
||||||
sendInvitation(context, payload) {
|
sendInvitation(context, payload) {
|
||||||
const endPoint = 'apps/polls/share/send/'.concat(payload.share.token)
|
const endPoint = 'apps/polls/share/send/' + payload.share.token
|
||||||
|
|
||||||
return axios.post(generateUrl(endPoint))
|
return axios.post(generateUrl(endPoint))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
@ -164,15 +163,11 @@ const actions = {
|
||||||
},
|
},
|
||||||
|
|
||||||
resolveGroup(context, payload) {
|
resolveGroup(context, payload) {
|
||||||
const endPoint = 'apps/polls/share/resolveGroup/'.concat(payload.share.token)
|
const endPoint = 'apps/polls/share/resolveGroup/' + payload.share.token
|
||||||
|
|
||||||
return axios.get(generateUrl(endPoint))
|
return axios.get(generateUrl(endPoint))
|
||||||
// .then((response) => {
|
|
||||||
// context.commit('delete', { share: payload.share })
|
|
||||||
// return response
|
|
||||||
// })
|
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Error exploding group', { error: error.response }, { payload: payload })
|
console.error('Error exploding group', error.response.data, { error: error.response }, { payload: payload })
|
||||||
throw error
|
throw error
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
|
|
|
@ -100,7 +100,7 @@ const actions = {
|
||||||
let endPoint = 'apps/polls/vote/set'
|
let endPoint = 'apps/polls/vote/set'
|
||||||
|
|
||||||
if (context.rootState.poll.acl.token) {
|
if (context.rootState.poll.acl.token) {
|
||||||
endPoint = endPoint.concat('/s')
|
endPoint = endPoint + '/s'
|
||||||
}
|
}
|
||||||
return axios.post(generateUrl(endPoint), {
|
return axios.post(generateUrl(endPoint), {
|
||||||
optionId: payload.option.id,
|
optionId: payload.option.id,
|
||||||
|
|
|
@ -45,9 +45,9 @@ const actions = {
|
||||||
getSubscription(context, payload) {
|
getSubscription(context, payload) {
|
||||||
let endPoint = 'apps/polls/subscription'
|
let endPoint = 'apps/polls/subscription'
|
||||||
if (payload.token) {
|
if (payload.token) {
|
||||||
endPoint = endPoint.concat('/s/', payload.token)
|
endPoint = endPoint + '/s/' + payload.token
|
||||||
} else if (payload.pollId) {
|
} else if (payload.pollId) {
|
||||||
endPoint = endPoint.concat('/', payload.pollId)
|
endPoint = endPoint + '/' + payload.pollId
|
||||||
}
|
}
|
||||||
|
|
||||||
return axios.get(generateUrl(endPoint))
|
return axios.get(generateUrl(endPoint))
|
||||||
|
|
Загрузка…
Ссылка в новой задаче