Merge pull request #2514 from nextcloud/ref/controllers-and-session
Ref/controllers and session
This commit is contained in:
Коммит
5cb91892ed
|
@ -23,16 +23,14 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCA\Polls\Service\PollService;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\ISession;
|
||||
use OCP\IRequest;
|
||||
use OCP\IURLGenerator;
|
||||
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Service\PollService;
|
||||
|
||||
class AdminController extends Controller {
|
||||
class AdminController extends BaseController {
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
@ -40,22 +38,16 @@ class AdminController extends Controller {
|
|||
/** @var PollService */
|
||||
private $pollService;
|
||||
|
||||
/** @var Poll */
|
||||
private $poll;
|
||||
|
||||
use ResponseHandle;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
ISession $session,
|
||||
IURLGenerator $urlGenerator,
|
||||
PollService $pollService,
|
||||
Poll $poll
|
||||
PollService $pollService
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
parent::__construct($appName, $request, $session);
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->pollService = $pollService;
|
||||
$this->poll = $poll;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,18 +20,28 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use Closure;
|
||||
|
||||
use OCA\Polls\Exceptions\Exception;
|
||||
use OCA\Polls\Exceptions\NoUpdatesException;
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IRequest;
|
||||
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCA\Polls\Exceptions\NoUpdatesException;
|
||||
use OCA\Polls\Exceptions\Exception;
|
||||
|
||||
trait ResponseHandle {
|
||||
class BaseApiController extends ApiController {
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
string $corsMethods = 'PUT, POST, GET, DELETE',
|
||||
string $corsAllowedHeaders = 'Authorization, Content-Type, Accept',
|
||||
int $corsMaxAge = 1728000
|
||||
) {
|
||||
parent::__construct($appName, $request, $corsMethods, $corsAllowedHeaders, $corsMaxAge);
|
||||
}
|
||||
|
||||
/**
|
||||
* response
|
|
@ -0,0 +1,115 @@
|
|||
<?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 OCA\Polls\Exceptions\Exception;
|
||||
use OCA\Polls\Exceptions\NoUpdatesException;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\ISession;
|
||||
use OCP\IRequest;
|
||||
|
||||
class BaseController extends Controller {
|
||||
|
||||
/** @var ISession */
|
||||
protected $session;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
ISession $session
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* response
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
protected function response(Closure $callback, string $token = ''): JSONResponse {
|
||||
if ($token) {
|
||||
$this->session->set('publicPollToken', $token);
|
||||
}
|
||||
|
||||
try {
|
||||
return new JSONResponse($callback(), Http::STATUS_OK);
|
||||
} catch (Exception $e) {
|
||||
return new JSONResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* response
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
protected function responseLong(Closure $callback, string $token = ''): JSONResponse {
|
||||
if ($token) {
|
||||
$this->session->set('publicPollToken', $token);
|
||||
}
|
||||
|
||||
try {
|
||||
return new JSONResponse($callback(), Http::STATUS_OK);
|
||||
} catch (NoUpdatesException $e) {
|
||||
return new JSONResponse([], Http::STATUS_NOT_MODIFIED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* responseCreate
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
protected function responseCreate(Closure $callback, string $token = ''): JSONResponse {
|
||||
if ($token) {
|
||||
$this->session->set('publicPollToken', $token);
|
||||
}
|
||||
|
||||
try {
|
||||
return new JSONResponse($callback(), Http::STATUS_CREATED);
|
||||
} catch (Exception $e) {
|
||||
return new JSONResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* responseDeleteTolerant
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
protected function responseDeleteTolerant(Closure $callback, string $token = ''): JSONResponse {
|
||||
if ($token) {
|
||||
$this->session->set('publicPollToken', $token);
|
||||
}
|
||||
|
||||
try {
|
||||
return new JSONResponse($callback(), Http::STATUS_OK);
|
||||
} catch (DoesNotExistException $e) {
|
||||
return new JSONResponse(['message' => 'Not found, assume already deleted'], Http::STATUS_OK);
|
||||
} catch (Exception $e) {
|
||||
return new JSONResponse(['message' => $e->getMessage()], $e->getStatus());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,29 +23,21 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCA\Polls\Service\CommentService;
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
use OCA\Polls\Service\CommentService;
|
||||
|
||||
class CommentApiController extends ApiController {
|
||||
class CommentApiController extends BaseApiController {
|
||||
|
||||
/** @var CommentService */
|
||||
private $commentService;
|
||||
|
||||
use ResponseHandle;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
CommentService $commentService
|
||||
) {
|
||||
parent::__construct($appName,
|
||||
$request,
|
||||
'POST, GET, DELETE',
|
||||
'Authorization, Content-Type, Accept',
|
||||
1728000);
|
||||
parent::__construct($appName, $request);
|
||||
$this->commentService = $commentService;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,24 +23,23 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCA\Polls\Service\CommentService;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IRequest;
|
||||
use OCP\ISession;
|
||||
|
||||
class CommentController extends Controller {
|
||||
class CommentController extends BaseController {
|
||||
|
||||
/** @var CommentService */
|
||||
private $commentService;
|
||||
|
||||
use ResponseHandle;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
ISession $session,
|
||||
IRequest $request,
|
||||
CommentService $commentService
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
parent::__construct($appName, $request, $session);
|
||||
$this->commentService = $commentService;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,29 +23,21 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCA\Polls\Service\OptionService;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IRequest;
|
||||
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCA\Polls\Service\OptionService;
|
||||
|
||||
class OptionApiController extends ApiController {
|
||||
class OptionApiController extends BaseApiController {
|
||||
|
||||
/** @var OptionService */
|
||||
private $optionService;
|
||||
|
||||
use ResponseHandle;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
OptionService $optionService
|
||||
) {
|
||||
parent::__construct($appName,
|
||||
$request,
|
||||
'POST, PUT, GET, DELETE',
|
||||
'Authorization, Content-Type, Accept',
|
||||
1728000);
|
||||
parent::__construct($appName, $request);
|
||||
$this->optionService = $optionService;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,13 +23,13 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCA\Polls\Service\OptionService;
|
||||
use OCA\Polls\Service\CalendarService;
|
||||
use OCA\Polls\Service\OptionService;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IRequest;
|
||||
use OCP\ISession;
|
||||
|
||||
class OptionController extends Controller {
|
||||
class OptionController extends BaseController {
|
||||
|
||||
/** @var OptionService */
|
||||
private $optionService;
|
||||
|
@ -37,15 +37,14 @@ class OptionController extends Controller {
|
|||
/** @var CalendarService */
|
||||
private $calendarService;
|
||||
|
||||
use ResponseHandle;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
ISession $session,
|
||||
OptionService $optionService,
|
||||
CalendarService $calendarService
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
parent::__construct($appName, $request, $session);
|
||||
$this->optionService = $optionService;
|
||||
$this->calendarService = $calendarService;
|
||||
}
|
||||
|
|
|
@ -23,18 +23,15 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCA\Polls\Exceptions\Exception;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
use OCA\Polls\Model\Acl;
|
||||
use OCA\Polls\Service\PollService;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IRequest;
|
||||
|
||||
class PollApiController extends ApiController {
|
||||
class PollApiController extends BaseApiController {
|
||||
|
||||
/** @var Acl */
|
||||
private $acl;
|
||||
|
|
|
@ -24,16 +24,15 @@
|
|||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Service\PollService;
|
||||
use OCA\Polls\Service\OptionService;
|
||||
use OCA\Polls\Model\Acl;
|
||||
use OCA\Polls\Model\Settings\AppSettings;
|
||||
use OCP\ISession;
|
||||
|
||||
class PollController extends Controller {
|
||||
class PollController extends BaseController {
|
||||
|
||||
/** @var Acl */
|
||||
private $acl;
|
||||
|
@ -44,24 +43,18 @@ class PollController extends Controller {
|
|||
/** @var PollService */
|
||||
private $pollService;
|
||||
|
||||
/** @var Poll */
|
||||
private $poll;
|
||||
|
||||
use ResponseHandle;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
ISession $session,
|
||||
Acl $acl,
|
||||
OptionService $optionService,
|
||||
PollService $pollService,
|
||||
Poll $poll
|
||||
PollService $pollService
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
parent::__construct($appName, $request, $session);
|
||||
$this->acl = $acl;
|
||||
$this->optionService = $optionService;
|
||||
$this->pollService = $pollService;
|
||||
$this->poll = $poll;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,13 +25,13 @@ namespace OCA\Polls\Controller;
|
|||
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserSession;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCA\Polls\Service\PreferencesService;
|
||||
use OCA\Polls\Service\CalendarService;
|
||||
use OCP\ISession;
|
||||
|
||||
class PreferencesController extends Controller {
|
||||
class PreferencesController extends BaseController {
|
||||
|
||||
/** @var PreferencesService */
|
||||
private $preferencesService;
|
||||
|
@ -42,16 +42,15 @@ class PreferencesController extends Controller {
|
|||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
|
||||
use ResponseHandle;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
ISession $session,
|
||||
PreferencesService $preferencesService,
|
||||
CalendarService $calendarService,
|
||||
IUserSession $userSession
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
parent::__construct($appName, $request, $session);
|
||||
$this->calendarService = $calendarService;
|
||||
$this->preferencesService = $preferencesService;
|
||||
$this->userSession = $userSession;
|
||||
|
|
|
@ -23,17 +23,6 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUserSession;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
|
||||
|
||||
use OCA\Polls\Db\Share;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Db\Comment;
|
||||
use OCA\Polls\Model\Acl;
|
||||
use OCA\Polls\Service\CommentService;
|
||||
use OCA\Polls\Service\MailService;
|
||||
|
@ -44,56 +33,56 @@ use OCA\Polls\Service\SubscriptionService;
|
|||
use OCA\Polls\Service\VoteService;
|
||||
use OCA\Polls\Service\SystemService;
|
||||
use OCA\Polls\Service\WatchService;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
|
||||
use OCP\ISession;
|
||||
use OCP\IRequest;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUserSession;
|
||||
|
||||
class PublicController extends Controller {
|
||||
class PublicController extends BaseController {
|
||||
|
||||
/** @var Acl */
|
||||
private $acl;
|
||||
|
||||
/** @var CommentService */
|
||||
private $commentService;
|
||||
|
||||
/** @var MailService */
|
||||
private $mailService;
|
||||
|
||||
/** @var OptionService */
|
||||
private $optionService;
|
||||
|
||||
/** @var PollService */
|
||||
private $pollService;
|
||||
|
||||
/** @var ShareService */
|
||||
private $shareService;
|
||||
|
||||
/** @var SubscriptionService */
|
||||
private $subscriptionService;
|
||||
|
||||
/** @var SystemService */
|
||||
private $systemService;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
|
||||
/** @var Acl */
|
||||
private $acl;
|
||||
|
||||
/** @var CommentService */
|
||||
private $commentService;
|
||||
|
||||
/** @var OptionService */
|
||||
private $optionService;
|
||||
|
||||
/** @var MailService */
|
||||
private $mailService;
|
||||
|
||||
/** @var PollService */
|
||||
private $pollService;
|
||||
|
||||
/** @var Poll */
|
||||
private $poll;
|
||||
|
||||
/** @var ShareService */
|
||||
private $shareService;
|
||||
|
||||
/** @var Share */
|
||||
private $share;
|
||||
|
||||
/** @var SubscriptionService */
|
||||
private $subscriptionService;
|
||||
|
||||
/** @var SystemService */
|
||||
private $systemService;
|
||||
|
||||
|
||||
/** @var VoteService */
|
||||
private $voteService;
|
||||
|
||||
/** @var WatchService */
|
||||
private $watchService;
|
||||
|
||||
use ResponseHandle;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
ISession $session,
|
||||
IURLGenerator $urlGenerator,
|
||||
IUserSession $userSession,
|
||||
Acl $acl,
|
||||
|
@ -101,15 +90,13 @@ class PublicController extends Controller {
|
|||
MailService $mailService,
|
||||
OptionService $optionService,
|
||||
PollService $pollService,
|
||||
Poll $poll,
|
||||
ShareService $shareService,
|
||||
Share $share,
|
||||
SubscriptionService $subscriptionService,
|
||||
SystemService $systemService,
|
||||
VoteService $voteService,
|
||||
WatchService $watchService
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
parent::__construct($appName, $request, $session);
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->userSession = $userSession;
|
||||
$this->acl = $acl;
|
||||
|
@ -117,9 +104,7 @@ class PublicController extends Controller {
|
|||
$this->mailService = $mailService;
|
||||
$this->optionService = $optionService;
|
||||
$this->pollService = $pollService;
|
||||
$this->poll = $poll;
|
||||
$this->shareService = $shareService;
|
||||
$this->share = $share;
|
||||
$this->subscriptionService = $subscriptionService;
|
||||
$this->systemService = $systemService;
|
||||
$this->voteService = $voteService;
|
||||
|
@ -150,7 +135,7 @@ class PublicController extends Controller {
|
|||
return $this->response(fn () => [
|
||||
'acl' => $this->acl,
|
||||
'poll' => $this->pollService->get($this->acl->getPollId()),
|
||||
]);
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -160,7 +145,9 @@ class PublicController extends Controller {
|
|||
*/
|
||||
public function watchPoll(string $token, ?int $offset): JSONResponse {
|
||||
$pollId = $this->acl->setToken($token)->getPollId();
|
||||
return $this->responseLong(fn () => ['updates' => $this->watchService->watchUpdates($pollId, $offset)]);
|
||||
return $this->responseLong(fn () => [
|
||||
'updates' => $this->watchService->watchUpdates($pollId, $offset)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,7 +157,9 @@ class PublicController extends Controller {
|
|||
*/
|
||||
public function getShare(string $token): JSONResponse {
|
||||
$validateShareType = true;
|
||||
return $this->response(fn () => ['share' => $this->shareService->get($token, $validateShareType)]);
|
||||
return $this->response(fn () => [
|
||||
'share' => $this->shareService->get($token, $validateShareType)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -179,7 +168,9 @@ class PublicController extends Controller {
|
|||
* @PublicPage
|
||||
*/
|
||||
public function getComments(string $token): JSONResponse {
|
||||
return $this->response(fn () => ['comments' => $this->commentService->list(null, $token)]);
|
||||
return $this->response(fn () => [
|
||||
'comments' => $this->commentService->list(null, $token)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -188,7 +179,9 @@ class PublicController extends Controller {
|
|||
* @PublicPage
|
||||
*/
|
||||
public function getVotes(string $token): JSONResponse {
|
||||
return $this->response(fn () => ['votes' => $this->voteService->list(null, $token)]);
|
||||
return $this->response(fn () => [
|
||||
'votes' => $this->voteService->list(null, $token)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,7 +190,9 @@ class PublicController extends Controller {
|
|||
* @PublicPage
|
||||
*/
|
||||
public function deleteUser(string $token): JSONResponse {
|
||||
return $this->response(fn () => ['deleted' => $this->voteService->delete(null, null, $token)]);
|
||||
return $this->response(fn () => [
|
||||
'deleted' => $this->voteService->delete(null, null, $token)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -206,7 +201,9 @@ class PublicController extends Controller {
|
|||
* @PublicPage
|
||||
*/
|
||||
public function getOptions(string $token): JSONResponse {
|
||||
return $this->response(fn () => ['options' => $this->optionService->list(null, $token)]);
|
||||
return $this->response(fn () => [
|
||||
'options' => $this->optionService->list(null, $token)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -215,7 +212,9 @@ class PublicController extends Controller {
|
|||
* @PublicPage
|
||||
*/
|
||||
public function addOption(string $token, int $timestamp = 0, string $text = '', int $duration = 0): JSONResponse {
|
||||
return $this->responseCreate(fn () => ['option' => $this->optionService->add(null, $timestamp, $text, $duration, $token)]);
|
||||
return $this->responseCreate(fn () => [
|
||||
'option' => $this->optionService->add(null, $timestamp, $text, $duration, $token)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -224,7 +223,9 @@ class PublicController extends Controller {
|
|||
* @PublicPage
|
||||
*/
|
||||
public function deleteOption(string $token, int $optionId): JSONResponse {
|
||||
return $this->responseDeleteTolerant(fn () => ['option' => $this->optionService->delete($optionId, $token)]);
|
||||
return $this->responseDeleteTolerant(fn () => [
|
||||
'option' => $this->optionService->delete($optionId, $token)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,7 +234,9 @@ class PublicController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function getSubscription(string $token): JSONResponse {
|
||||
return $this->response(fn () => ['subscribed' => $this->subscriptionService->get(null, $token)]);
|
||||
return $this->response(fn () => [
|
||||
'subscribed' => $this->subscriptionService->get(null, $token)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -242,7 +245,9 @@ class PublicController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function setVote(int $optionId, string $setTo, string $token): JSONResponse {
|
||||
return $this->response(fn () => ['vote' => $this->voteService->set($optionId, $setTo, $token)]);
|
||||
return $this->response(fn () => [
|
||||
'vote' => $this->voteService->set($optionId, $setTo, $token)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -251,7 +256,9 @@ class PublicController extends Controller {
|
|||
* @PublicPage
|
||||
*/
|
||||
public function addComment(string $token, string $message): JSONResponse {
|
||||
return $this->response(fn () => ['comment' => $this->commentService->add($message, null, $token)]);
|
||||
return $this->response(fn () => [
|
||||
'comment' => $this->commentService->add($message, null, $token)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -260,7 +267,9 @@ class PublicController extends Controller {
|
|||
* @PublicPage
|
||||
*/
|
||||
public function deleteComment(int $commentId, string $token): JSONResponse {
|
||||
return $this->responseDeleteTolerant(fn () => ['comment' => $this->commentService->delete($commentId, $token)]);
|
||||
return $this->responseDeleteTolerant(fn () => [
|
||||
'comment' => $this->commentService->delete($commentId, $token)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -269,7 +278,9 @@ class PublicController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function subscribe(string $token): JSONResponse {
|
||||
return $this->response(fn () => ['subscribed' => $this->subscriptionService->set(true, null, $token)]);
|
||||
return $this->response(fn () => [
|
||||
'subscribed' => $this->subscriptionService->set(true, null, $token)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -278,7 +289,9 @@ class PublicController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function unsubscribe(string $token): JSONResponse {
|
||||
return $this->response(fn () => ['subscribed' => $this->subscriptionService->set(false, null, $token)]);
|
||||
return $this->response(fn () => [
|
||||
'subscribed' => $this->subscriptionService->set(false, null, $token)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -289,7 +302,9 @@ class PublicController extends Controller {
|
|||
* @PublicPage
|
||||
*/
|
||||
public function validatePublicUsername(string $userName, string $token): JSONResponse {
|
||||
return $this->response(fn () => ['result' => $this->systemService->validatePublicUsername($userName, $token), 'name' => $userName]);
|
||||
return $this->response(fn () => [
|
||||
'result' => $this->systemService->validatePublicUsername($userName, $token), 'name' => $userName
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -298,7 +313,9 @@ class PublicController extends Controller {
|
|||
* @PublicPage
|
||||
*/
|
||||
public function validateEmailAddress(string $emailAddress): JSONResponse {
|
||||
return $this->response(fn () => ['result' => $this->systemService->validateEmailAddress($emailAddress), 'emailAddress' => $emailAddress]);
|
||||
return $this->response(fn () => [
|
||||
'result' => $this->systemService->validateEmailAddress($emailAddress), 'emailAddress' => $emailAddress
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -307,7 +324,9 @@ class PublicController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function setDisplayName(string $token, string $displayName): JSONResponse {
|
||||
return $this->response(fn () => ['share' => $this->shareService->setDisplayname($token, $displayName)]);
|
||||
return $this->response(fn () => [
|
||||
'share' => $this->shareService->setDisplayname($token, $displayName)
|
||||
], $token);
|
||||
}
|
||||
|
||||
|
||||
|
@ -317,7 +336,9 @@ class PublicController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function setEmailAddress(string $token, string $emailAddress = ''): JSONResponse {
|
||||
return $this->response(fn () => ['share' => $this->shareService->setEmailAddress($token, $emailAddress, true)]);
|
||||
return $this->response(fn () => [
|
||||
'share' => $this->shareService->setEmailAddress($token, $emailAddress, true)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -326,7 +347,9 @@ class PublicController extends Controller {
|
|||
* @NoAdminRequired
|
||||
*/
|
||||
public function deleteEmailAddress(string $token): JSONResponse {
|
||||
return $this->response(fn () => ['share' => $this->shareService->deleteEmailAddress($token)]);
|
||||
return $this->response(fn () => [
|
||||
'share' => $this->shareService->deleteEmailAddress($token)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -336,7 +359,9 @@ class PublicController extends Controller {
|
|||
* @PublicPage
|
||||
*/
|
||||
public function register(string $token, string $userName, string $emailAddress = ''): JSONResponse {
|
||||
return $this->responseCreate(fn () => ['share' => $this->shareService->register($token, $userName, $emailAddress)]);
|
||||
return $this->responseCreate(fn () => [
|
||||
'share' => $this->shareService->register($token, $userName, $emailAddress)
|
||||
], $token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -346,6 +371,8 @@ class PublicController extends Controller {
|
|||
* @PublicPage
|
||||
*/
|
||||
public function resendInvitation(string $token): JSONResponse {
|
||||
return $this->response(fn () => ['share' => $this->mailService->resendInvitation($token)]);
|
||||
return $this->response(fn () => [
|
||||
'share' => $this->mailService->resendInvitation($token)
|
||||
], $token);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,24 +23,23 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCA\Polls\Service\SettingsService;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IRequest;
|
||||
use OCP\ISession;
|
||||
|
||||
class SettingsController extends Controller {
|
||||
class SettingsController extends BaseController {
|
||||
|
||||
/** @var SettingsService */
|
||||
private $settingsService;
|
||||
|
||||
use ResponseHandle;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
ISession $session,
|
||||
SettingsService $settingsService
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
parent::__construct($appName, $request, $session);
|
||||
$this->settingsService = $settingsService;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,16 +23,12 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
use OCA\Polls\Service\ShareService;
|
||||
use OCA\Polls\Service\MailService;
|
||||
use OCA\Polls\Service\ShareService;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IRequest;
|
||||
|
||||
class ShareApiController extends ApiController {
|
||||
use ResponseHandle;
|
||||
|
||||
class ShareApiController extends BaseApiController {
|
||||
/** @var ShareService */
|
||||
private $shareService;
|
||||
|
||||
|
@ -45,11 +41,7 @@ class ShareApiController extends ApiController {
|
|||
MailService $mailService,
|
||||
ShareService $shareService
|
||||
) {
|
||||
parent::__construct($appName,
|
||||
$request,
|
||||
'POST, PUT, GET, DELETE',
|
||||
'Authorization, Content-Type, Accept',
|
||||
1728000);
|
||||
parent::__construct($appName, $request);
|
||||
$this->shareService = $shareService;
|
||||
$this->mailService = $mailService;
|
||||
}
|
||||
|
|
|
@ -23,43 +23,33 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCA\Polls\Db\Share;
|
||||
use OCA\Polls\Exceptions\ShareAlreadyExistsException;
|
||||
use OCA\Polls\Exceptions\InvalidShareTypeException;
|
||||
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
use OCA\Polls\Db\Share;
|
||||
use OCA\Polls\Service\MailService;
|
||||
use OCA\Polls\Service\ShareService;
|
||||
use OCA\Polls\Service\SystemService;
|
||||
use OCA\Polls\Model\UserGroup\UserBase;
|
||||
use OCA\Polls\Service\UserService;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\ISession;
|
||||
use OCP\IRequest;
|
||||
|
||||
class ShareController extends Controller {
|
||||
use ResponseHandle;
|
||||
|
||||
/** @var MailService */
|
||||
private $mailService;
|
||||
class ShareController extends BaseController {
|
||||
|
||||
/** @var ShareService */
|
||||
private $shareService;
|
||||
|
||||
/** @var SystemService */
|
||||
private $systemService;
|
||||
/** @var UserService */
|
||||
private $userService;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
MailService $mailService,
|
||||
ISession $session,
|
||||
ShareService $shareService,
|
||||
SystemService $systemService
|
||||
UserService $userService
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->mailService = $mailService;
|
||||
parent::__construct($appName, $request, $session);
|
||||
$this->shareService = $shareService;
|
||||
$this->systemService = $systemService;
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -160,7 +150,7 @@ class ShareController extends Controller {
|
|||
throw new InvalidShareTypeException('Cannot resolve members from share type ' . $share->getType());
|
||||
}
|
||||
|
||||
foreach (UserBase::getUserGroupChild($share->getType(), $share->getUserId())->getMembers() as $member) {
|
||||
foreach ($this->userService->getUser($share->getType(), $share->getUserId())->getMembers() as $member) {
|
||||
try {
|
||||
$newShare = $this->shareService->add($share->getPollId(), $member->getType(), $member->getId());
|
||||
$shares[] = $newShare;
|
||||
|
|
|
@ -23,18 +23,14 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCA\Polls\Exceptions\Exception;
|
||||
|
||||
use OCP\IRequest;
|
||||
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
use OCA\Polls\Service\SubscriptionService;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http;
|
||||
|
||||
class SubscriptionApiController extends ApiController {
|
||||
class SubscriptionApiController extends BaseApiController {
|
||||
|
||||
/** @var SubscriptionService */
|
||||
private $subscriptionService;
|
||||
|
@ -45,11 +41,7 @@ class SubscriptionApiController extends ApiController {
|
|||
IRequest $request
|
||||
|
||||
) {
|
||||
parent::__construct($appName,
|
||||
$request,
|
||||
'PUT, GET, DELETE',
|
||||
'Authorization, Content-Type, Accept',
|
||||
1728000);
|
||||
parent::__construct($appName, $request);
|
||||
$this->subscriptionService = $subscriptionService;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,25 +23,23 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
use OCA\Polls\Service\SubscriptionService;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IRequest;
|
||||
use OCP\ISession;
|
||||
|
||||
class SubscriptionController extends Controller {
|
||||
class SubscriptionController extends BaseController {
|
||||
|
||||
/** @var SubscriptionService */
|
||||
private $subscriptionService;
|
||||
|
||||
use ResponseHandle;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
SubscriptionService $subscriptionService,
|
||||
IRequest $request
|
||||
ISession $session,
|
||||
IRequest $request,
|
||||
SubscriptionService $subscriptionService
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
parent::__construct($appName, $request, $session);
|
||||
$this->subscriptionService = $subscriptionService;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,14 +23,13 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCA\Polls\Service\SystemService;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCA\Polls\Service\SystemService;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\ISession;
|
||||
|
||||
class SystemController extends Controller {
|
||||
class SystemController extends BaseController {
|
||||
|
||||
/** @var SystemService */
|
||||
private $systemService;
|
||||
|
@ -38,9 +37,10 @@ class SystemController extends Controller {
|
|||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
ISession $session,
|
||||
SystemService $systemService
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
parent::__construct($appName, $request, $session);
|
||||
$this->systemService = $systemService;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,17 +23,14 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCA\Polls\Exceptions\Exception;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCA\Polls\Service\VoteService;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IRequest;
|
||||
|
||||
use OCA\Polls\Service\VoteService;
|
||||
|
||||
class VoteApiController extends ApiController {
|
||||
class VoteApiController extends BaseApiController {
|
||||
|
||||
/** @var VoteService */
|
||||
private $voteService;
|
||||
|
@ -43,11 +40,7 @@ class VoteApiController extends ApiController {
|
|||
IRequest $request,
|
||||
VoteService $voteService
|
||||
) {
|
||||
parent::__construct($appName,
|
||||
$request,
|
||||
'PUT, GET, DELETE',
|
||||
'Authorization, Content-Type, Accept',
|
||||
1728000);
|
||||
parent::__construct($appName, $request);
|
||||
$this->voteService = $voteService;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,25 +23,23 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
|
||||
use OCA\Polls\Service\VoteService;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IRequest;
|
||||
use OCP\ISession;
|
||||
|
||||
class VoteController extends Controller {
|
||||
class VoteController extends BaseController {
|
||||
|
||||
/** @var VoteService */
|
||||
private $voteService;
|
||||
|
||||
use ResponseHandle;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
ISession $session,
|
||||
VoteService $voteService
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
parent::__construct($appName, $request, $session);
|
||||
$this->voteService = $voteService;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,24 +23,23 @@
|
|||
|
||||
namespace OCA\Polls\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCA\Polls\Service\WatchService;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IRequest;
|
||||
use OCP\ISession;
|
||||
|
||||
class WatchController extends Controller {
|
||||
class WatchController extends BaseController {
|
||||
|
||||
/** @var WatchService */
|
||||
private $watchService;
|
||||
|
||||
use ResponseHandle;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
ISession $session,
|
||||
WatchService $watchService
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
parent::__construct($appName, $request, $session);
|
||||
$this->watchService = $watchService;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,13 +26,13 @@
|
|||
namespace OCA\Polls\Db;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
use OCA\Polls\Exceptions\NoDeadLineException;
|
||||
use OCA\Polls\Helper\Container;
|
||||
use OCA\Polls\Model\UserGroup\User;
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
use OCA\Polls\Model\UserGroup\User;
|
||||
|
||||
/**
|
||||
* @method string getType()
|
||||
|
@ -94,6 +94,11 @@ class Poll extends Entity implements JsonSerializable {
|
|||
public const PROPOSAL_ALLOW = 'allow';
|
||||
public const PROPOSAL_REVIEW = 'review';
|
||||
public const URI_PREFIX = 'poll/';
|
||||
public const FIVE_DAYS = 432000;
|
||||
public const FOUR_DAYS = 345600;
|
||||
public const THREE_DAYS = 259200;
|
||||
public const TWO_DAYS = 172800;
|
||||
public const ONE_AND_HALF_DAY = 129600;
|
||||
|
||||
/** @var string $type */
|
||||
protected $type;
|
||||
|
@ -164,6 +169,9 @@ class Poll extends Entity implements JsonSerializable {
|
|||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var OptionMapper */
|
||||
private $optionMapper;
|
||||
|
||||
public function __construct() {
|
||||
$this->addType('created', 'int');
|
||||
$this->addType('expire', 'int');
|
||||
|
@ -180,6 +188,7 @@ class Poll extends Entity implements JsonSerializable {
|
|||
$this->addType('useNo', 'int');
|
||||
$this->urlGenerator = Container::queryClass(IURLGenerator::class);
|
||||
$this->userManager = Container::queryClass(IUserManager::class);
|
||||
$this->optionMapper = Container::queryClass(OptionMapper::class);
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
|
@ -329,6 +338,43 @@ class Poll extends Entity implements JsonSerializable {
|
|||
return json_decode($this->getMiscSettings(), true);
|
||||
}
|
||||
|
||||
public function getTimeToDeadline(int $time = 0): ?int {
|
||||
if ($time === 0) {
|
||||
$time = time();
|
||||
}
|
||||
$deadline = $this->getDeadline();
|
||||
if (
|
||||
$deadline - $this->getCreated() > self::FIVE_DAYS
|
||||
&& $deadline - $time < self::TWO_DAYS
|
||||
&& $deadline > $time
|
||||
) {
|
||||
return self::TWO_DAYS;
|
||||
}
|
||||
|
||||
if (
|
||||
$deadline - $this->getCreated() > self::TWO_DAYS
|
||||
&& $deadline - $time < self::ONE_AND_HALF_DAY
|
||||
&& $deadline > $time
|
||||
) {
|
||||
return self::ONE_AND_HALF_DAY;
|
||||
}
|
||||
throw new NoDeadLineException();
|
||||
}
|
||||
|
||||
public function getDeadline(): ?int {
|
||||
if ($this->getExpire()) {
|
||||
return $this->getExpire();
|
||||
}
|
||||
|
||||
if ($this->getType() === Poll::TYPE_DATE) {
|
||||
// use first date option as reminder deadline
|
||||
$options = $this->optionMapper->findByPoll($this->getId());
|
||||
return $options[0]->getTimestamp();
|
||||
}
|
||||
throw new NoDeadLineException();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param bool|string|int|array $value
|
||||
*/
|
||||
|
|
|
@ -30,6 +30,7 @@ use OCP\IURLGenerator;
|
|||
use OCA\Polls\Model\UserGroup\UserBase;
|
||||
use OCA\Polls\Model\Settings\AppSettings;
|
||||
use OCA\Polls\Helper\Container;
|
||||
use OCA\Polls\Service\UserService;
|
||||
|
||||
/**
|
||||
* @method int getId()
|
||||
|
@ -125,11 +126,15 @@ class Share extends Entity implements JsonSerializable {
|
|||
/** @var AppSettings */
|
||||
protected $appSettings;
|
||||
|
||||
/** @var UserService */
|
||||
protected $userService;
|
||||
|
||||
public function __construct() {
|
||||
$this->addType('pollId', 'int');
|
||||
$this->addType('invitationSent', 'int');
|
||||
$this->addType('reminderSent', 'int');
|
||||
$this->urlGenerator = Container::queryClass(IURLGenerator::class);
|
||||
$this->userService = Container::queryClass(UserService::class);
|
||||
$this->appSettings = new AppSettings;
|
||||
}
|
||||
|
||||
|
@ -187,7 +192,7 @@ class Share extends Entity implements JsonSerializable {
|
|||
}
|
||||
|
||||
public function getUserObject(): UserBase {
|
||||
return UserBase::getUserGroupChild(
|
||||
return $this->userService->getUser(
|
||||
$this->type,
|
||||
$this->userId,
|
||||
$this->displayName,
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class BadRequestException extends Exception {
|
||||
public function __construct(string $e = 'Not allowed') {
|
||||
public function __construct(
|
||||
string $e = 'Not allowed'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class CirclesNotEnabledException extends Exception {
|
||||
public function __construct(string $e = 'Circles is not enabled for this user') {
|
||||
public function __construct(
|
||||
string $e = 'Circles is not enabled for this user'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class ContactGroupNotFound extends Exception {
|
||||
public function __construct(string $e = 'Contact Group not found') {
|
||||
public function __construct(
|
||||
string $e = 'Contact Group not found'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class ContactsNotEnabledExceptions extends Exception {
|
||||
public function __construct(string $e = 'Contacts is not enabled') {
|
||||
public function __construct(
|
||||
string $e = 'Contacts is not enabled'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class DuplicateEntryException extends Exception {
|
||||
public function __construct(string $e = 'Duplicate Entry') {
|
||||
public function __construct(
|
||||
string $e = 'Duplicate Entry'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class EmptyTitleException extends Exception {
|
||||
public function __construct(string $e = 'Poll title must not be empty') {
|
||||
public function __construct(
|
||||
string $e = 'Poll title must not be empty'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class InvalidAccessException extends Exception {
|
||||
public function __construct(string $e = 'Invalid access value') {
|
||||
public function __construct(
|
||||
string $e = 'Invalid access value'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class InvalidClassException extends Exception {
|
||||
public function __construct(string $e = 'Invalid class value') {
|
||||
public function __construct(
|
||||
string $e = 'Invalid class value'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class InvalidEmailAddress extends Exception {
|
||||
public function __construct(string $e = 'Invalid email address') {
|
||||
public function __construct(
|
||||
string $e = 'Invalid email address'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_FORBIDDEN);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class InvalidOptionPropertyException extends Exception {
|
||||
public function __construct(string $e = 'Invalid option attributes') {
|
||||
public function __construct(
|
||||
string $e = 'Invalid option attributes'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class InvalidPollTypeException extends Exception {
|
||||
public function __construct(string $e = 'Invalid pollType value') {
|
||||
public function __construct(
|
||||
string $e = 'Invalid pollType value'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class InvalidShareTypeException extends Exception {
|
||||
public function __construct(string $e = 'Invalid share type') {
|
||||
public function __construct(
|
||||
string $e = 'Invalid share type'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class InvalidShowResultsException extends Exception {
|
||||
public function __construct(string $e = 'Invalid showResults value') {
|
||||
public function __construct(
|
||||
string $e = 'Invalid showResults value'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,9 @@ class InvalidUsernameException extends Exception {
|
|||
/**
|
||||
* InvalidUsernameException Constructor
|
||||
*/
|
||||
public function __construct(string $e = 'Username not allowed') {
|
||||
public function __construct(
|
||||
string $e = 'Username not allowed'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_FORBIDDEN);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class MultipleContactsFound extends Exception {
|
||||
public function __construct(string $e = 'Multiple Contacts found') {
|
||||
public function __construct(
|
||||
string $e = 'Multiple Contacts found'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?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 NoDeadLineException extends Exception {
|
||||
public function __construct(
|
||||
string $e = 'No deadline calculated'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_OK);
|
||||
}
|
||||
}
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class NoUpdatesException extends Exception {
|
||||
public function __construct(string $e = 'No updates') {
|
||||
public function __construct(
|
||||
string $e = 'No updates'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_NOT_MODIFIED);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class NotAuthorizedException extends Exception {
|
||||
public function __construct(string $e = 'Unauthorized or not found') {
|
||||
public function __construct(
|
||||
string $e = 'Unauthorized or not found'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ use OCP\AppFramework\Http;
|
|||
class NotFoundException extends Exception {
|
||||
public function __construct(
|
||||
string $e = 'Not found',
|
||||
int $status = Http::STATUS_NOT_FOUND) {
|
||||
int $status = Http::STATUS_NOT_FOUND
|
||||
) {
|
||||
parent::__construct($e, $status);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class OCPEventException extends Exception {
|
||||
public function __construct(string $e = 'OCP namespace event') {
|
||||
public function __construct(
|
||||
string $e = 'OCP namespace event'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_OK);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class ShareAlreadyExistsException extends Exception {
|
||||
public function __construct(string $e = 'Share already exists') {
|
||||
public function __construct(
|
||||
string $e = 'Share already exists'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_OK);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class TooShortException extends Exception {
|
||||
public function __construct(string $e = 'String too short') {
|
||||
public function __construct(
|
||||
string $e = 'String too short'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_FORBIDDEN);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace OCA\Polls\Exceptions;
|
|||
use OCP\AppFramework\Http;
|
||||
|
||||
class VoteLimitExceededException extends Exception {
|
||||
public function __construct(string $e = 'Vote limit exceeded') {
|
||||
public function __construct(
|
||||
string $e = 'Vote limit exceeded'
|
||||
) {
|
||||
parent::__construct($e, Http::STATUS_CONFLICT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,15 +24,15 @@
|
|||
|
||||
namespace OCA\Polls\Model\Mail;
|
||||
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Exceptions\InvalidEmailAddress;
|
||||
use OCA\Polls\Helper\Container;
|
||||
use OCA\Polls\Model\Settings\AppSettings;
|
||||
use OCA\Polls\Model\UserGroup\UserBase;
|
||||
use OCA\Polls\Model\UserGroup\User;
|
||||
use OCA\Polls\Model\Settings\AppSettings;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Helper\Container;
|
||||
use OCP\IL10N;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCA\Polls\Exceptions\InvalidEmailAddress;
|
||||
use OCP\L10N\IFactory;
|
||||
use OCP\Mail\IEMailTemplate;
|
||||
use OCP\Mail\IMailer;
|
||||
|
@ -160,8 +160,6 @@ abstract class MailBase {
|
|||
return $this->emailTemplate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function getSubject(): string {
|
||||
return $this->l10n->t('Notification for poll "%s"', $this->poll->getTitle());
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
namespace OCA\Polls\Model\Mail;
|
||||
|
||||
use OCA\Polls\Db\Log;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Db\Subscription;
|
||||
use OCA\Polls\Event\CommentEvent;
|
||||
use OCA\Polls\Event\PollEvent;
|
||||
|
@ -63,19 +64,22 @@ class NotificationMail extends MailBase {
|
|||
));
|
||||
|
||||
foreach ($this->subscription->getNotifyLogs() as $logItem) {
|
||||
if ($this->poll->getAnonymous() || $this->poll->getShowResults() !== "always") {
|
||||
// hide actor's name if poll is anonymous or results are hidden
|
||||
$displayName = $this->l10n->t('A user');
|
||||
} else {
|
||||
$displayName = $this->getUser($logItem->getUserId())->getDisplayName();
|
||||
}
|
||||
|
||||
$displayName = $this->evaluateDisplayName($logItem);
|
||||
$this->emailTemplate->addBodyListItem($this->getComposedLogString($logItem, $displayName));
|
||||
}
|
||||
|
||||
$this->emailTemplate->addBodyButton($this->getButtonText(), $this->url);
|
||||
}
|
||||
|
||||
private function evaluateDisplayName(Log $logItem) {
|
||||
if ($this->poll->getAnonymous() || $this->poll->getShowResults() !== Poll::SHOW_RESULTS_ALWAYS) {
|
||||
// hide actor's name if poll is anonymous or results are hidden
|
||||
return $this->l10n->t('A user');
|
||||
}
|
||||
|
||||
return $this->getUser($logItem->getUserId())->getDisplayName();
|
||||
}
|
||||
|
||||
private function getComposedLogString(Log $logItem, string $displayName): string {
|
||||
$logStrings = [
|
||||
Log::MSG_ID_SETVOTE => $this->l10n->t('%s has voted.', [$displayName]),
|
||||
|
|
|
@ -46,13 +46,11 @@ class ReminderMail extends MailBase {
|
|||
|
||||
public function __construct(
|
||||
string $recipientId,
|
||||
int $pollId,
|
||||
int $deadline,
|
||||
int $timeToDeadline
|
||||
int $pollId
|
||||
) {
|
||||
parent::__construct($recipientId, $pollId);
|
||||
$this->deadline = $deadline;
|
||||
$this->timeToDeadline = $timeToDeadline;
|
||||
$this->deadline = $this->poll->getDeadline();
|
||||
$this->timeToDeadline = $this->poll->getTimeToDeadline();
|
||||
}
|
||||
|
||||
protected function getSubject(): string {
|
||||
|
@ -68,6 +66,14 @@ class ReminderMail extends MailBase {
|
|||
}
|
||||
|
||||
protected function buildBody(): void {
|
||||
$this->addBoddyText();
|
||||
$this->emailTemplate->addBodyButton($this->getButtonText(), $this->url);
|
||||
$this->emailTemplate->addBodyText($this->l10n->t('This link gives you personal access to the poll named above. Press the button above or copy the following link and add it in your browser\'s location bar:'));
|
||||
$this->emailTemplate->addBodyText($this->url);
|
||||
$this->emailTemplate->addBodyText($this->l10n->t('Do not share this link with other people, because it is connected to your votes.'));
|
||||
}
|
||||
|
||||
private function addBoddyText(): void {
|
||||
$dtDeadline = new DateTime('now', $this->recipient->getTimeZone());
|
||||
$dtDeadline->setTimestamp($this->deadline);
|
||||
$deadlineText = (string) $this->l10n->l('datetime', $dtDeadline, ['width' => 'long']);
|
||||
|
@ -78,25 +84,23 @@ class ReminderMail extends MailBase {
|
|||
[($this->timeToDeadline / 3600), $deadlineText, $this->recipient->getTimeZone()->getName()],
|
||||
$this->l10n->t('The first poll option is away less than {leftPeriod} hours ({dateTime}, {timezone}).')
|
||||
));
|
||||
} elseif ($this->getReminderReason() === self::REASON_EXPIRATION) {
|
||||
$this->emailTemplate->addBodyText(str_replace(
|
||||
['{leftPeriod}', '{dateTime}', '{timezone}'],
|
||||
[($this->timeToDeadline / 3600), $deadlineText, $this->recipient->getTimeZone()->getName()],
|
||||
$this->l10n->t('The poll is about to expire in less than {leftPeriod} hours ({dateTime}, {timezone}).')
|
||||
));
|
||||
} else {
|
||||
$this->emailTemplate->addBodyText(str_replace(
|
||||
['{owner}'],
|
||||
[$this->owner->getDisplayName()],
|
||||
$this->l10n->t('{owner} sends you this reminder to make sure, your votes are set.')
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
$this->emailTemplate->addBodyButton($this->getButtonText(), $this->url);
|
||||
if ($this->getReminderReason() === self::REASON_EXPIRATION) {
|
||||
$this->emailTemplate->addBodyText(str_replace(
|
||||
['{leftPeriod}', '{dateTime}', '{timezone}'],
|
||||
[($this->timeToDeadline / 3600), $deadlineText, $this->recipient->getTimeZone()->getName()],
|
||||
$this->l10n->t('The poll is about to expire in less than {leftPeriod} hours ({dateTime}, {timezone}).')
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
$this->emailTemplate->addBodyText($this->l10n->t('This link gives you personal access to the poll named above. Press the button above or copy the following link and add it in your browser\'s location bar:'));
|
||||
$this->emailTemplate->addBodyText($this->url);
|
||||
$this->emailTemplate->addBodyText($this->l10n->t('Do not share this link with other people, because it is connected to your votes.'));
|
||||
$this->emailTemplate->addBodyText(str_replace(
|
||||
['{owner}'],
|
||||
[$this->owner->getDisplayName()],
|
||||
$this->l10n->t('{owner} sends you this reminder to make sure, your votes are set.')
|
||||
));
|
||||
}
|
||||
|
||||
private function getReminderReason() : ?string {
|
||||
|
|
|
@ -23,15 +23,13 @@
|
|||
|
||||
namespace OCA\Polls\Model\UserGroup;
|
||||
|
||||
use OCA\Polls\Exceptions\InvalidShareTypeException;
|
||||
|
||||
use DateTimeZone;
|
||||
use OCP\IL10N;
|
||||
use OCA\Polls\Db\ShareMapper;
|
||||
use OCA\Polls\Helper\Container;
|
||||
use OCP\Collaboration\Collaborators\ISearch;
|
||||
use OCP\Share\IShare;
|
||||
use OCP\IDateTimeZone;
|
||||
use OCP\IUserSession;
|
||||
|
||||
class UserBase implements \JsonSerializable {
|
||||
public const TYPE = 'generic';
|
||||
|
@ -87,6 +85,9 @@ class UserBase implements \JsonSerializable {
|
|||
/** @var IDateTimeZone */
|
||||
protected $timezone;
|
||||
|
||||
/** @var IUserSession */
|
||||
protected $userSession;
|
||||
|
||||
public function __construct(
|
||||
string $id,
|
||||
string $type,
|
||||
|
@ -99,6 +100,7 @@ class UserBase implements \JsonSerializable {
|
|||
|
||||
$this->l10n = Container::getL10N();
|
||||
$this->timezone = Container::queryClass(IDateTimeZone::class);
|
||||
$this->userSession = Container::queryClass(IUserSession::class);
|
||||
|
||||
$this->id = $id;
|
||||
$this->type = $type;
|
||||
|
@ -116,10 +118,6 @@ class UserBase implements \JsonSerializable {
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
public function getUser(): string {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getType(): string {
|
||||
return $this->type;
|
||||
}
|
||||
|
@ -161,6 +159,10 @@ class UserBase implements \JsonSerializable {
|
|||
return $this->organisation;
|
||||
}
|
||||
|
||||
public function getIsLoggedIn(): bool {
|
||||
return $this->userSession->isLoggedIn();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*
|
||||
|
@ -261,7 +263,6 @@ class UserBase implements \JsonSerializable {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
@ -273,48 +274,6 @@ class UserBase implements \JsonSerializable {
|
|||
return [$this];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Admin|Circle|Contact|ContactGroup|Email|GenericUser|Group|User
|
||||
*/
|
||||
public static function getUserGroupChildFromShare(string $token) {
|
||||
$shareMapper = Container::queryClass(ShareMapper::class);
|
||||
$share = $shareMapper->findByToken($token);
|
||||
return self::getUserGroupChild(
|
||||
$share->getType(),
|
||||
$share->getUserId(),
|
||||
$share->getDisplayName(),
|
||||
$share->getEmailAddress()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Circle|Contact|ContactGroup|Email|GenericUser|Group|User|Admin
|
||||
*/
|
||||
public static function getUserGroupChild(string $type, string $id, string $displayName = '', string $emailAddress = '') {
|
||||
switch ($type) {
|
||||
case Group::TYPE:
|
||||
return new Group($id);
|
||||
case Circle::TYPE:
|
||||
return new Circle($id);
|
||||
case Contact::TYPE:
|
||||
return new Contact($id);
|
||||
case ContactGroup::TYPE:
|
||||
return new ContactGroup($id);
|
||||
case User::TYPE:
|
||||
return new User($id);
|
||||
case Admin::TYPE:
|
||||
return new Admin($id);
|
||||
case Email::TYPE:
|
||||
return new Email($id, $displayName, $emailAddress);
|
||||
case self::TYPE_PUBLIC:
|
||||
return new GenericUser($id, self::TYPE_PUBLIC);
|
||||
case self::TYPE_EXTERNAL:
|
||||
return new GenericUser($id, self::TYPE_EXTERNAL, $displayName, $emailAddress);
|
||||
default:
|
||||
throw new InvalidShareTypeException('Invalid share type (' . $type . ')');
|
||||
}
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
|
|
|
@ -23,11 +23,6 @@
|
|||
|
||||
namespace OCA\Polls\Service;
|
||||
|
||||
use OCP\Activity\IManager as ActivityManager;
|
||||
use OCP\Activity\IEvent as ActivityEvent;
|
||||
use OCP\IL10N;
|
||||
use OCP\IUserSession;
|
||||
use OCP\L10N\IFactory;
|
||||
use OCA\Polls\Db\Share;
|
||||
use OCA\Polls\Event\BaseEvent;
|
||||
use OCA\Polls\Event\CommentEvent;
|
||||
|
@ -35,6 +30,11 @@ use OCA\Polls\Event\PollEvent;
|
|||
use OCA\Polls\Event\OptionEvent;
|
||||
use OCA\Polls\Event\ShareEvent;
|
||||
use OCA\Polls\Event\VoteEvent;
|
||||
use OCP\Activity\IManager as ActivityManager;
|
||||
use OCP\Activity\IEvent as ActivityEvent;
|
||||
use OCP\IL10N;
|
||||
use OCP\IUserSession;
|
||||
use OCP\L10N\IFactory;
|
||||
|
||||
class ActivityService {
|
||||
/** @var ActivityManager */
|
||||
|
|
|
@ -34,35 +34,35 @@ use OCA\Polls\Db\Poll;
|
|||
|
||||
class AnonymizeService {
|
||||
|
||||
/** @var VoteMapper */
|
||||
private $voteMapper;
|
||||
|
||||
/** @var CommentMapper */
|
||||
private $commentMapper;
|
||||
|
||||
/** @var OptionMapper */
|
||||
private $optionMapper;
|
||||
|
||||
/** @var array */
|
||||
private $anonList;
|
||||
|
||||
/** @var string|null */
|
||||
private $userId;
|
||||
|
||||
|
||||
/** @var CommentMapper */
|
||||
private $commentMapper;
|
||||
|
||||
/** @var int */
|
||||
private $pollId;
|
||||
|
||||
/** @var OptionMapper */
|
||||
private $optionMapper;
|
||||
|
||||
/** @var string|null */
|
||||
private $userId;
|
||||
|
||||
/** @var VoteMapper */
|
||||
private $voteMapper;
|
||||
|
||||
public function __construct(
|
||||
VoteMapper $voteMapper,
|
||||
CommentMapper $commentMapper,
|
||||
OptionMapper $optionMapper
|
||||
OptionMapper $optionMapper,
|
||||
VoteMapper $voteMapper
|
||||
) {
|
||||
$this->voteMapper = $voteMapper;
|
||||
$this->anonList = [];
|
||||
$this->commentMapper = $commentMapper;
|
||||
$this->optionMapper = $optionMapper;
|
||||
$this->anonList = [];
|
||||
$this->userId = null;
|
||||
$this->pollId = 0;
|
||||
$this->userId = null;
|
||||
$this->voteMapper = $voteMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,13 +29,13 @@ use DateTime;
|
|||
use DateInterval;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use OCA\Polls\Db\OptionMapper;
|
||||
use OCA\Polls\Db\Preferences;
|
||||
use OCA\Polls\Model\CalendarEvent;
|
||||
use OCA\Polls\Model\UserGroup\CurrentUser;
|
||||
use OCP\Calendar\ICalendar;
|
||||
use OCP\Calendar\IManager as CalendarManager;
|
||||
use OCP\Util;
|
||||
use OCA\Polls\Model\CalendarEvent;
|
||||
use OCA\Polls\Db\OptionMapper;
|
||||
use OCA\Polls\Db\Preferences;
|
||||
use OCA\Polls\Model\UserGroup\CurrentUser;
|
||||
|
||||
class CalendarService {
|
||||
/** @var CurrentUser */
|
||||
|
@ -47,9 +47,6 @@ class CalendarService {
|
|||
/** @var ICalendar[] */
|
||||
private $calendars;
|
||||
|
||||
/** @var array */
|
||||
private $calendarMapKeys;
|
||||
|
||||
/** @var PreferencesService */
|
||||
private $preferencesService;
|
||||
|
||||
|
|
|
@ -23,12 +23,12 @@
|
|||
|
||||
namespace OCA\Polls\Service;
|
||||
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCA\Polls\Db\Comment;
|
||||
use OCA\Polls\Db\CommentMapper;
|
||||
use OCA\Polls\Event\CommentAddEvent;
|
||||
use OCA\Polls\Event\CommentDeleteEvent;
|
||||
use OCA\Polls\Model\Acl;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
|
||||
class CommentService {
|
||||
|
||||
|
|
|
@ -23,12 +23,6 @@
|
|||
|
||||
namespace OCA\Polls\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IConfig;
|
||||
use OCP\IURLGenerator;
|
||||
use OCA\Polls\Db\SubscriptionMapper;
|
||||
use OCA\Polls\Db\OptionMapper;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
|
@ -38,76 +32,56 @@ use OCA\Polls\Db\Share;
|
|||
use OCA\Polls\Db\LogMapper;
|
||||
use OCA\Polls\Db\Log;
|
||||
use OCA\Polls\Exceptions\InvalidEmailAddress;
|
||||
use OCA\Polls\Exceptions\NoDeadLineException;
|
||||
use OCA\Polls\Model\UserGroup\User;
|
||||
use OCA\Polls\Model\Mail\InvitationMail;
|
||||
use OCA\Polls\Model\Mail\ReminderMail;
|
||||
use OCA\Polls\Model\Mail\NotificationMail;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class MailService {
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var string */
|
||||
private $appName;
|
||||
|
||||
|
||||
/** @var LogMapper */
|
||||
private $logMapper;
|
||||
|
||||
/** @var Log[] **/
|
||||
private $logs;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var IGroupManager */
|
||||
private $groupManager;
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var OptionMapper */
|
||||
private $optionMapper;
|
||||
|
||||
/** @var PollMapper */
|
||||
private $pollMapper;
|
||||
|
||||
/** @var SubscriptionMapper */
|
||||
private $subscriptionMapper;
|
||||
|
||||
/** @var ShareMapper */
|
||||
private $shareMapper;
|
||||
|
||||
/** @var PollMapper */
|
||||
private $pollMapper;
|
||||
|
||||
/** @var OptionMapper */
|
||||
private $optionMapper;
|
||||
|
||||
/** @var LogMapper */
|
||||
private $logMapper;
|
||||
|
||||
/** @var Log[] **/
|
||||
private $logs;
|
||||
|
||||
/** @var Poll **/
|
||||
private $poll;
|
||||
|
||||
|
||||
public function __construct(
|
||||
string $AppName,
|
||||
LoggerInterface $logger,
|
||||
IUserManager $userManager,
|
||||
IGroupManager $groupManager,
|
||||
IConfig $config,
|
||||
IURLGenerator $urlGenerator,
|
||||
ShareMapper $shareMapper,
|
||||
SubscriptionMapper $subscriptionMapper,
|
||||
LoggerInterface $logger,
|
||||
LogMapper $logMapper,
|
||||
OptionMapper $optionMapper,
|
||||
PollMapper $pollMapper,
|
||||
LogMapper $logMapper
|
||||
ShareMapper $shareMapper,
|
||||
SubscriptionMapper $subscriptionMapper
|
||||
) {
|
||||
$this->appName = $AppName;
|
||||
$this->logger = $logger;
|
||||
$this->config = $config;
|
||||
$this->userManager = $userManager;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->logMapper = $logMapper;
|
||||
$this->optionMapper = $optionMapper;
|
||||
$this->pollMapper = $pollMapper;
|
||||
$this->shareMapper = $shareMapper;
|
||||
$this->subscriptionMapper = $subscriptionMapper;
|
||||
$this->poll = new Poll;
|
||||
$this->userManager = $userManager;
|
||||
$this->logs = [];
|
||||
}
|
||||
|
||||
|
@ -129,96 +103,6 @@ class MailService {
|
|||
return '';
|
||||
}
|
||||
|
||||
public function resendInvitation(string $token): Share {
|
||||
$this->sendInvitation($token);
|
||||
return $this->shareMapper->findByToken($token);
|
||||
}
|
||||
|
||||
public function sendInvitation(string $token): array {
|
||||
$share = $this->shareMapper->findByToken($token);
|
||||
$sentMails = [];
|
||||
$abortedMails = [];
|
||||
|
||||
foreach ($share->getUserObject()->getMembers() as $recipient) {
|
||||
$invitation = new InvitationMail($recipient->getId(), $share);
|
||||
|
||||
try {
|
||||
$invitation->send();
|
||||
$sentMails[] = $recipient;
|
||||
} catch (InvalidEmailAddress $e) {
|
||||
$abortedMails[] = $recipient;
|
||||
$this->logger->warning('Invalid or no email address for invitation: ' . json_encode($recipient));
|
||||
} catch (\Exception $e) {
|
||||
$abortedMails[] = $recipient;
|
||||
$this->logger->error('Error sending Invitation to ' . json_encode($recipient));
|
||||
}
|
||||
}
|
||||
|
||||
$share->setInvitationSent(time());
|
||||
$this->shareMapper->update($share);
|
||||
return ['sentMails' => $sentMails, 'abortedMails' => $abortedMails];
|
||||
}
|
||||
|
||||
public function sendAutoReminder(): void {
|
||||
$polls = $this->pollMapper->findAutoReminderPolls();
|
||||
$time = time();
|
||||
$remindPolls = [];
|
||||
|
||||
foreach ($polls as $poll) {
|
||||
if ($poll->getExpire()) {
|
||||
$deadline = $poll->getExpire();
|
||||
$reminderReason = ReminderMail::REASON_EXPIRATION;
|
||||
} elseif ($poll->getType() === Poll::TYPE_DATE) {
|
||||
// use first date option as reminder deadline
|
||||
$options = $this->optionMapper->findByPoll($poll->getId());
|
||||
$deadline = $options[0]->getTimestamp();
|
||||
$reminderReason = ReminderMail::REASON_OPTION;
|
||||
} else {
|
||||
// Textpolls without expirations are not processed
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($deadline - $poll->getCreated() > ReminderMail::FIVE_DAYS
|
||||
&& $deadline - $time < ReminderMail::TWO_DAYS
|
||||
&& $deadline > $time) {
|
||||
$timeToDeadline = ReminderMail::TWO_DAYS;
|
||||
} elseif ($deadline - $poll->getCreated() > ReminderMail::TWO_DAYS
|
||||
&& $deadline - $time < ReminderMail::ONE_AND_HALF_DAY
|
||||
&& $deadline > $time) {
|
||||
$timeToDeadline = ReminderMail::ONE_AND_HALF_DAY;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
$shares = $this->shareMapper->findByPollUnreminded($poll->getId());
|
||||
foreach ($shares as $share) {
|
||||
if (in_array($share->getType(), [Share::TYPE_CIRCLE, Share::TYPE_CONTACTGROUP])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($share->getUserObject()->getMembers() as $recipient) {
|
||||
$reminder = new ReminderMail(
|
||||
$recipient->getId(),
|
||||
$poll->getId(),
|
||||
$deadline,
|
||||
$timeToDeadline
|
||||
);
|
||||
|
||||
try {
|
||||
$reminder->send();
|
||||
} catch (InvalidEmailAddress $e) {
|
||||
$this->logger->warning('Invalid or no email address for reminder: ' . json_encode($share));
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error('Error sending Reminder to ' . json_encode($share));
|
||||
}
|
||||
}
|
||||
|
||||
$share->setReminderSent(time());
|
||||
$this->shareMapper->update($share);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function sendNotifications(): void {
|
||||
$subscriptions = [];
|
||||
$this->logs = $this->logMapper->findUnprocessed();
|
||||
|
@ -251,4 +135,76 @@ class MailService {
|
|||
$this->logMapper->update($logItem);
|
||||
}
|
||||
}
|
||||
|
||||
public function resendInvitation(string $token): Share {
|
||||
$this->sendInvitation($token);
|
||||
return $this->shareMapper->findByToken($token);
|
||||
}
|
||||
|
||||
public function sendInvitation(string $token): array {
|
||||
$share = $this->shareMapper->findByToken($token);
|
||||
$sentMails = [];
|
||||
$abortedMails = [];
|
||||
|
||||
foreach ($share->getUserObject()->getMembers() as $recipient) {
|
||||
$invitation = new InvitationMail($recipient->getId(), $share);
|
||||
|
||||
try {
|
||||
$invitation->send();
|
||||
$sentMails[] = $recipient;
|
||||
} catch (InvalidEmailAddress $e) {
|
||||
$abortedMails[] = $recipient;
|
||||
$this->logger->warning('Invalid or no email address for invitation: ' . json_encode($recipient));
|
||||
} catch (\Exception $e) {
|
||||
$abortedMails[] = $recipient;
|
||||
$this->logger->error('Error sending Invitation to ' . json_encode($recipient));
|
||||
}
|
||||
}
|
||||
|
||||
$share->setInvitationSent(time());
|
||||
$this->shareMapper->update($share);
|
||||
return ['sentMails' => $sentMails, 'abortedMails' => $abortedMails];
|
||||
}
|
||||
|
||||
public function sendAutoReminder(): void {
|
||||
$polls = $this->pollMapper->findAutoReminderPolls();
|
||||
|
||||
foreach ($polls as $poll) {
|
||||
try {
|
||||
$this->processSharesForAutoReminder($poll);
|
||||
} catch (NoDeadLineException $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function processSharesForAutoReminder(Poll $poll) {
|
||||
$shares = $this->shareMapper->findByPollUnreminded($poll->getId());
|
||||
foreach ($shares as $share) {
|
||||
if (in_array($share->getType(), [Share::TYPE_CIRCLE, Share::TYPE_CONTACTGROUP])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->sendAutoReminderToRecipients($share, $poll);
|
||||
$share->setReminderSent(time());
|
||||
$this->shareMapper->update($share);
|
||||
}
|
||||
}
|
||||
|
||||
private function sendAutoReminderToRecipients(Share $share, Poll $poll) {
|
||||
foreach ($share->getUserObject()->getMembers() as $recipient) {
|
||||
$reminder = new ReminderMail(
|
||||
$recipient->getId(),
|
||||
$poll->getId()
|
||||
);
|
||||
|
||||
try {
|
||||
$reminder->send();
|
||||
} catch (InvalidEmailAddress $e) {
|
||||
$this->logger->warning('Invalid or no email address for reminder: ' . json_encode($share));
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error('Error sending Reminder to ' . json_encode($share));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
namespace OCA\Polls\Service;
|
||||
|
||||
use DateTime;
|
||||
use OCP\Notification\IManager;
|
||||
use OCA\Polls\Notification\Notifier;
|
||||
use OCP\Notification\IManager;
|
||||
|
||||
class NotificationService {
|
||||
public const APP_ID = 'polls';
|
||||
|
|
|
@ -25,15 +25,6 @@ namespace OCA\Polls\Service;
|
|||
|
||||
use DateTime;
|
||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\DB\Exception;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
|
||||
use OCA\Polls\Exceptions\DuplicateEntryException;
|
||||
use OCA\Polls\Exceptions\InvalidPollTypeException;
|
||||
use OCA\Polls\Exceptions\InvalidOptionPropertyException;
|
||||
|
||||
use OCA\Polls\Db\OptionMapper;
|
||||
use OCA\Polls\Db\VoteMapper;
|
||||
use OCA\Polls\Db\Vote;
|
||||
|
@ -45,7 +36,14 @@ use OCA\Polls\Event\OptionCreatedEvent;
|
|||
use OCA\Polls\Event\OptionDeletedEvent;
|
||||
use OCA\Polls\Event\OptionUnconfirmedEvent;
|
||||
use OCA\Polls\Event\PollOptionReorderedEvent;
|
||||
use OCA\Polls\Exceptions\DuplicateEntryException;
|
||||
use OCA\Polls\Exceptions\InvalidPollTypeException;
|
||||
use OCA\Polls\Exceptions\InvalidOptionPropertyException;
|
||||
use OCA\Polls\Model\Acl;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\DB\Exception;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class OptionService {
|
||||
|
||||
|
@ -55,9 +53,6 @@ class OptionService {
|
|||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var string */
|
||||
private $appName;
|
||||
|
||||
/** @var Acl */
|
||||
private $acl;
|
||||
|
||||
|
@ -83,7 +78,6 @@ class OptionService {
|
|||
private $voteMapper;
|
||||
|
||||
public function __construct(
|
||||
string $AppName,
|
||||
Acl $acl,
|
||||
AnonymizeService $anonymizer,
|
||||
IEventDispatcher $eventDispatcher,
|
||||
|
@ -92,7 +86,6 @@ class OptionService {
|
|||
OptionMapper $optionMapper,
|
||||
VoteMapper $voteMapper
|
||||
) {
|
||||
$this->appName = $AppName;
|
||||
$this->acl = $acl;
|
||||
$this->anonymizer = $anonymizer;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
|
|
|
@ -23,21 +23,9 @@
|
|||
|
||||
namespace OCA\Polls\Service;
|
||||
|
||||
use OCP\IUserSession;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Search\ISearchQuery;
|
||||
|
||||
use OCA\Polls\Exceptions\EmptyTitleException;
|
||||
use OCA\Polls\Exceptions\InvalidAccessException;
|
||||
use OCA\Polls\Exceptions\InvalidShowResultsException;
|
||||
use OCA\Polls\Exceptions\InvalidPollTypeException;
|
||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Db\VoteMapper;
|
||||
use OCA\Polls\Db\Vote;
|
||||
use OCA\Polls\Event\PollArchivedEvent;
|
||||
use OCA\Polls\Event\PollCreatedEvent;
|
||||
use OCA\Polls\Event\PollDeletedEvent;
|
||||
|
@ -45,17 +33,24 @@ use OCA\Polls\Event\PollOwnerChangeEvent;
|
|||
use OCA\Polls\Event\PollRestoredEvent;
|
||||
use OCA\Polls\Event\PollTakeoverEvent;
|
||||
use OCA\Polls\Event\PollUpdatedEvent;
|
||||
use OCA\Polls\Exceptions\EmptyTitleException;
|
||||
use OCA\Polls\Exceptions\InvalidAccessException;
|
||||
use OCA\Polls\Exceptions\InvalidShowResultsException;
|
||||
use OCA\Polls\Exceptions\InvalidPollTypeException;
|
||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
||||
use OCA\Polls\Exceptions\InvalidUsernameException;
|
||||
use OCA\Polls\Model\Acl;
|
||||
use OCA\Polls\Model\Settings\AppSettings;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Search\ISearchQuery;
|
||||
|
||||
class PollService {
|
||||
|
||||
/** @var string|null */
|
||||
private $userId;
|
||||
|
||||
/** @var IEventDispatcher */
|
||||
private $eventDispatcher;
|
||||
|
||||
|
@ -77,9 +72,6 @@ class PollService {
|
|||
/** @var VoteMapper */
|
||||
private $voteMapper;
|
||||
|
||||
/** @var Vote */
|
||||
private $vote;
|
||||
|
||||
/** @var MailService */
|
||||
private $mailService;
|
||||
|
||||
|
@ -99,9 +91,7 @@ class PollService {
|
|||
MailService $mailService,
|
||||
Poll $poll,
|
||||
PollMapper $pollMapper,
|
||||
?string $UserId,
|
||||
VoteMapper $voteMapper,
|
||||
Vote $vote
|
||||
VoteMapper $voteMapper
|
||||
) {
|
||||
$this->acl = $acl;
|
||||
$this->appSettings = $appSettings;
|
||||
|
@ -110,11 +100,9 @@ class PollService {
|
|||
$this->mailService = $mailService;
|
||||
$this->poll = $poll;
|
||||
$this->pollMapper = $pollMapper;
|
||||
$this->userId = $UserId;
|
||||
$this->userManager = $userManager;
|
||||
$this->userSession = $userSession;
|
||||
$this->voteMapper = $voteMapper;
|
||||
$this->vote = $vote;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,18 +23,13 @@
|
|||
|
||||
namespace OCA\Polls\Service;
|
||||
|
||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\IConfig;
|
||||
|
||||
use OCA\Polls\Db\Preferences;
|
||||
use OCA\Polls\Db\PreferencesMapper;
|
||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
|
||||
class PreferencesService {
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var PreferencesMapper */
|
||||
private $preferencesMapper;
|
||||
|
||||
|
@ -46,11 +41,9 @@ class PreferencesService {
|
|||
|
||||
public function __construct(
|
||||
?string $UserId,
|
||||
IConfig $config,
|
||||
PreferencesMapper $preferencesMapper
|
||||
) {
|
||||
$this->userId = $UserId;
|
||||
$this->config = $config;
|
||||
$this->preferencesMapper = $preferencesMapper;
|
||||
$this->preferences = new Preferences;
|
||||
$this->load();
|
||||
|
|
|
@ -23,27 +23,14 @@
|
|||
|
||||
namespace OCA\Polls\Service;
|
||||
|
||||
use OCP\IConfig;
|
||||
use OCA\Polls\Model\Settings\AppSettings;
|
||||
use OCA\Polls\Model\UserGroup\Group;
|
||||
|
||||
class SettingsService {
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var AppSettings */
|
||||
private $appSettings;
|
||||
|
||||
/** @var string|null */
|
||||
private $userId;
|
||||
|
||||
public function __construct(
|
||||
?string $UserId,
|
||||
IConfig $config
|
||||
) {
|
||||
$this->userId = $UserId;
|
||||
$this->config = $config;
|
||||
public function __construct() {
|
||||
$this->appSettings = new AppSettings;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,20 +23,6 @@
|
|||
|
||||
namespace OCA\Polls\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Security\ISecureRandom;
|
||||
|
||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
||||
use OCA\Polls\Exceptions\InvalidShareTypeException;
|
||||
use OCA\Polls\Exceptions\ShareAlreadyExistsException;
|
||||
use OCA\Polls\Exceptions\NotFoundException;
|
||||
use OCA\Polls\Exceptions\InvalidUsernameException;
|
||||
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Db\ShareMapper;
|
||||
use OCA\Polls\Db\Share;
|
||||
|
@ -47,19 +33,25 @@ use OCA\Polls\Event\ShareChangedEmailEvent;
|
|||
use OCA\Polls\Event\ShareChangedRegistrationConstraintEvent;
|
||||
use OCA\Polls\Event\ShareDeletedEvent;
|
||||
use OCA\Polls\Event\ShareRegistrationEvent;
|
||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
||||
use OCA\Polls\Exceptions\InvalidShareTypeException;
|
||||
use OCA\Polls\Exceptions\ShareAlreadyExistsException;
|
||||
use OCA\Polls\Exceptions\NotFoundException;
|
||||
use OCA\Polls\Exceptions\InvalidUsernameException;
|
||||
use OCA\Polls\Model\Acl;
|
||||
use OCA\Polls\Model\UserGroup\UserBase;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class ShareService {
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var string */
|
||||
private $appName;
|
||||
|
||||
/** @var string|null */
|
||||
private $userId;
|
||||
/** @var Acl */
|
||||
private $acl;
|
||||
|
||||
/** @var IEventDispatcher */
|
||||
private $eventDispatcher;
|
||||
|
@ -67,38 +59,43 @@ class ShareService {
|
|||
/** @var IGroupManager */
|
||||
private $groupManager;
|
||||
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
|
||||
/** @var SystemService */
|
||||
private $systemService;
|
||||
|
||||
/** @var ShareMapper */
|
||||
private $shareMapper;
|
||||
|
||||
/** @var PollMapper */
|
||||
private $pollMapper;
|
||||
|
||||
/** @var ISecureRandom */
|
||||
private $secureRandom;
|
||||
|
||||
/** @var Share */
|
||||
private $share;
|
||||
|
||||
/** @var array */
|
||||
private $shares = [];
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var MailService */
|
||||
private $mailService;
|
||||
|
||||
/** @var Acl */
|
||||
private $acl;
|
||||
|
||||
/** @var NotificationService */
|
||||
private $notificationService;
|
||||
|
||||
/** @var PollMapper */
|
||||
private $pollMapper;
|
||||
|
||||
/** @var ShareMapper */
|
||||
private $shareMapper;
|
||||
|
||||
/** @var ISecureRandom */
|
||||
private $secureRandom;
|
||||
|
||||
/** @var Share */
|
||||
private $share;
|
||||
|
||||
/** @var array */
|
||||
private $shares = [];
|
||||
|
||||
/** @var SystemService */
|
||||
private $systemService;
|
||||
|
||||
/** @var string|null */
|
||||
private $userId;
|
||||
|
||||
/** @var UserService */
|
||||
private $userService;
|
||||
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
|
||||
public function __construct(
|
||||
string $AppName,
|
||||
LoggerInterface $logger,
|
||||
?string $UserId,
|
||||
IEventDispatcher $eventDispatcher,
|
||||
|
@ -111,9 +108,9 @@ class ShareService {
|
|||
Share $share,
|
||||
MailService $mailService,
|
||||
Acl $acl,
|
||||
NotificationService $notificationService
|
||||
NotificationService $notificationService,
|
||||
UserService $userService
|
||||
) {
|
||||
$this->appName = $AppName;
|
||||
$this->logger = $logger;
|
||||
$this->userId = $UserId;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
|
@ -127,6 +124,7 @@ class ShareService {
|
|||
$this->acl = $acl;
|
||||
$this->notificationService = $notificationService;
|
||||
$this->userSession = $userSession;
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -165,24 +163,26 @@ class ShareService {
|
|||
* or is accessibale for use by the current user
|
||||
*/
|
||||
private function validateShareType() : void {
|
||||
$currentUser = $this->userService->getCurrentUser();
|
||||
|
||||
switch ($this->share->getType()) {
|
||||
case Share::TYPE_PUBLIC:
|
||||
// public shares are always valid
|
||||
break;
|
||||
case Share::TYPE_USER:
|
||||
if ($this->share->getUserId() !== $this->userId) {
|
||||
if ($this->share->getUserId() !== $currentUser->getId()) {
|
||||
// share is not valid for user
|
||||
throw new NotAuthorizedException;
|
||||
}
|
||||
break;
|
||||
case Share::TYPE_ADMIN:
|
||||
if ($this->share->getUserId() !== $this->userId) {
|
||||
if ($this->share->getUserId() !== $currentUser->getId()) {
|
||||
// share is not valid for user
|
||||
throw new NotAuthorizedException;
|
||||
}
|
||||
break;
|
||||
case Share::TYPE_GROUP:
|
||||
if (!$this->userSession->isLoggedIn()) {
|
||||
if (!$currentUser->getIsLoggedIn()) {
|
||||
throw new NotAuthorizedException;
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ class ShareService {
|
|||
// Return the created share
|
||||
return $this->createNewShare(
|
||||
$this->share->getPollId(),
|
||||
UserBase::getUserGroupChild(Share::TYPE_USER, $this->userSession->getUser()->getUID()),
|
||||
$this->userService->getUser(Share::TYPE_USER, $this->userSession->getUser()->getUID()),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ class ShareService {
|
|||
}
|
||||
}
|
||||
|
||||
$this->createNewShare($pollId, UserBase::getUserGroupChild($type, $userId, $displayName, $emailAddress));
|
||||
$this->createNewShare($pollId, $this->userService->getUser($type, $userId, $displayName, $emailAddress));
|
||||
|
||||
$this->eventDispatcher->dispatchTyped(new ShareCreateEvent($this->share));
|
||||
|
||||
|
@ -463,7 +463,7 @@ class ShareService {
|
|||
// prevent invtation sending, when no email address is given
|
||||
$this->createNewShare(
|
||||
$this->share->getPollId(),
|
||||
UserBase::getUserGroupChild(Share::TYPE_EXTERNAL, $userId, $userName, $emailAddress),
|
||||
$this->userService->getUser(Share::TYPE_EXTERNAL, $userId, $userName, $emailAddress),
|
||||
!$emailAddress
|
||||
);
|
||||
$this->eventDispatcher->dispatchTyped(new ShareRegistrationEvent($this->share));
|
||||
|
|
|
@ -24,12 +24,11 @@
|
|||
namespace OCA\Polls\Service;
|
||||
|
||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\DB\Exception;
|
||||
|
||||
use OCA\Polls\Db\Subscription;
|
||||
use OCA\Polls\Db\SubscriptionMapper;
|
||||
use OCA\Polls\Model\Acl;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\DB\Exception;
|
||||
|
||||
class SubscriptionService {
|
||||
|
||||
|
|
|
@ -23,38 +23,41 @@
|
|||
|
||||
namespace OCA\Polls\Service;
|
||||
|
||||
use OCA\Polls\Db\ShareMapper;
|
||||
use OCA\Polls\Db\VoteMapper;
|
||||
use OCA\Polls\Exceptions\TooShortException;
|
||||
use OCA\Polls\Exceptions\InvalidUsernameException;
|
||||
use OCA\Polls\Exceptions\InvalidEmailAddress;
|
||||
use OCA\Polls\Exceptions\NotAuthorizedException;
|
||||
use OCA\Polls\Helper\Container;
|
||||
|
||||
use OCA\Polls\Db\ShareMapper;
|
||||
use OCA\Polls\Db\VoteMapper;
|
||||
use OCA\Polls\Model\UserGroup\Circle;
|
||||
use OCA\Polls\Model\UserGroup\Contact;
|
||||
use OCA\Polls\Model\UserGroup\ContactGroup;
|
||||
use OCA\Polls\Model\UserGroup\Email;
|
||||
use OCA\Polls\Model\UserGroup\Group;
|
||||
use OCA\Polls\Model\UserGroup\User;
|
||||
use OCA\Polls\Model\UserGroup\UserBase;
|
||||
use OCP\IUserManager;
|
||||
|
||||
class SystemService {
|
||||
private const REGEX_VALID_MAIL = '/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/';
|
||||
private const REGEX_PARSE_MAIL = '/(?:"?([^"]*)"?\s)?(?:<?(.+@[^>]+)>?)/';
|
||||
|
||||
/** @var ShareMapper */
|
||||
private $shareMapper;
|
||||
|
||||
/** @var UserService */
|
||||
private $userService;
|
||||
|
||||
/** @var VoteMapper */
|
||||
private $voteMapper;
|
||||
|
||||
/** @var ShareMapper */
|
||||
private $shareMapper;
|
||||
|
||||
public function __construct(
|
||||
ShareMapper $shareMapper,
|
||||
UserService $userService,
|
||||
VoteMapper $voteMapper
|
||||
) {
|
||||
$this->shareMapper = $shareMapper;
|
||||
$this->userService = $userService;
|
||||
$this->voteMapper = $voteMapper;
|
||||
}
|
||||
|
||||
|
@ -128,7 +131,7 @@ class SystemService {
|
|||
$list[] = new Email($emailAddress, $displayName, $emailAddress);
|
||||
}
|
||||
|
||||
$list = array_merge($list, UserBase::search($query));
|
||||
$list = array_merge($list, $this->userService->search($query));
|
||||
}
|
||||
|
||||
return $list;
|
||||
|
|
|
@ -0,0 +1,206 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
|
||||
*
|
||||
* @author René Gieling <github@dartcafe.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Polls\Service;
|
||||
|
||||
use OCA\Polls\Db\ShareMapper;
|
||||
use OCA\Polls\Exceptions\Exception;
|
||||
use OCA\Polls\Exceptions\InvalidShareTypeException;
|
||||
use OCA\Polls\Model\UserGroup\Admin;
|
||||
use OCA\Polls\Model\UserGroup\Circle;
|
||||
use OCA\Polls\Model\UserGroup\Contact;
|
||||
use OCA\Polls\Model\UserGroup\ContactGroup;
|
||||
use OCA\Polls\Model\UserGroup\Email;
|
||||
use OCA\Polls\Model\UserGroup\GenericUser;
|
||||
use OCA\Polls\Model\UserGroup\Group;
|
||||
use OCA\Polls\Model\UserGroup\User;
|
||||
use OCA\Polls\Model\UserGroup\UserBase;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\Collaboration\Collaborators\ISearch;
|
||||
use OCP\ISession;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Share\IShare;
|
||||
|
||||
class UserService {
|
||||
|
||||
/** @var ShareMapper */
|
||||
private $shareMapper;
|
||||
|
||||
/** @var ISession */
|
||||
private $session;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
|
||||
/** @var ISearch */
|
||||
private $userSearch;
|
||||
|
||||
public function __construct(
|
||||
ISearch $userSearch,
|
||||
ISession $session,
|
||||
IUserSession $userSession,
|
||||
IUserManager $userManager,
|
||||
ShareMapper $shareMapper
|
||||
) {
|
||||
$this->userSearch = $userSearch;
|
||||
$this->session = $session;
|
||||
$this->shareMapper = $shareMapper;
|
||||
$this->userSession = $userSession;
|
||||
$this->userManager = $userManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCurrentUser - Get current user from userbase or from share in public polls
|
||||
*/
|
||||
|
||||
public function getCurrentUser() {
|
||||
if ($this->userSession->getUser()) {
|
||||
return $this->getUserFromShare($this->userSession->getUser()->getUID());
|
||||
}
|
||||
|
||||
$token = $this->session->get('publicPollToken');
|
||||
|
||||
if ($token) {
|
||||
return $this->getUserFromShare($token);
|
||||
}
|
||||
|
||||
throw new DoesNotExistException('User not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* evaluateUser - Get user by name; and poll in case of a share user of the particulair poll
|
||||
*/
|
||||
|
||||
public function evaluateUser(string $userId, int $pollId = 0): ?UserBase {
|
||||
$user = $this->userManager->get($userId);
|
||||
if ($user) {
|
||||
return new User($userId);
|
||||
}
|
||||
try {
|
||||
$share = $this->shareMapper->findByPollAndUser($pollId, $userId);
|
||||
return $this->getUser(
|
||||
$share->getType(),
|
||||
$share->getUserId(),
|
||||
$share->getDisplayName(),
|
||||
$share->getEmailAddress()
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user from share
|
||||
* @return Admin|Circle|Contact|ContactGroup|Email|GenericUser|Group|User
|
||||
*/
|
||||
public function getUserFromShare(string $token) {
|
||||
$share = $this->shareMapper->findByToken($token);
|
||||
return $this->getUser(
|
||||
$share->getType(),
|
||||
$share->getUserId(),
|
||||
$share->getDisplayName(),
|
||||
$share->getEmailAddress()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* search all possible sharees - use ISearch to respect autocomplete restrictions
|
||||
*/
|
||||
public function search(string $query = ''): array {
|
||||
$items = [];
|
||||
$types = [
|
||||
IShare::TYPE_USER,
|
||||
IShare::TYPE_GROUP,
|
||||
IShare::TYPE_EMAIL
|
||||
];
|
||||
if (Circle::isEnabled() && class_exists('\OCA\Circles\ShareByCircleProvider')) {
|
||||
$types[] = IShare::TYPE_CIRCLE;
|
||||
}
|
||||
|
||||
[$result, $more] = $this->userSearch->search($query, $types, false, 200, 0);
|
||||
|
||||
foreach (($result['users'] ?? []) as $item) {
|
||||
$items[] = new User($item['value']['shareWith']);
|
||||
}
|
||||
|
||||
foreach (($result['exact']['users'] ?? []) as $item) {
|
||||
$items[] = new User($item['value']['shareWith']);
|
||||
}
|
||||
|
||||
foreach (($result['groups'] ?? []) as $item) {
|
||||
$items[] = new Group($item['value']['shareWith']);
|
||||
}
|
||||
|
||||
foreach (($result['exact']['groups'] ?? []) as $item) {
|
||||
$items[] = new Group($item['value']['shareWith']);
|
||||
}
|
||||
|
||||
$items = array_merge($items, Contact::search($query));
|
||||
$items = array_merge($items, ContactGroup::search($query));
|
||||
|
||||
if (Circle::isEnabled()) {
|
||||
foreach (($result['circles'] ?? []) as $item) {
|
||||
$items[] = new Circle($item['value']['shareWith']);
|
||||
}
|
||||
foreach (($result['exact']['circles'] ?? []) as $item) {
|
||||
$items[] = new Circle($item['value']['shareWith']);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new user object
|
||||
* @return Circle|Contact|ContactGroup|Email|GenericUser|Group|User|Admin
|
||||
*/
|
||||
public function getUser(string $type, string $id, string $displayName = '', string $emailAddress = ''): UserBase {
|
||||
switch ($type) {
|
||||
case Group::TYPE:
|
||||
return new Group($id);
|
||||
case Circle::TYPE:
|
||||
return new Circle($id);
|
||||
case Contact::TYPE:
|
||||
return new Contact($id);
|
||||
case ContactGroup::TYPE:
|
||||
return new ContactGroup($id);
|
||||
case User::TYPE:
|
||||
return new User($id);
|
||||
case Admin::TYPE:
|
||||
return new Admin($id);
|
||||
case Email::TYPE:
|
||||
return new Email($id, $displayName, $emailAddress);
|
||||
case UserBase::TYPE_PUBLIC:
|
||||
return new GenericUser($id, UserBase::TYPE_PUBLIC);
|
||||
case UserBase::TYPE_EXTERNAL:
|
||||
return new GenericUser($id, UserBase::TYPE_EXTERNAL, $displayName, $emailAddress);
|
||||
default:
|
||||
throw new InvalidShareTypeException('Invalid user type (' . $type . ')');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,17 +23,15 @@
|
|||
|
||||
namespace OCA\Polls\Service;
|
||||
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
|
||||
use OCA\Polls\Exceptions\VoteLimitExceededException;
|
||||
|
||||
use OCA\Polls\Db\OptionMapper;
|
||||
use OCA\Polls\Db\Option;
|
||||
use OCA\Polls\Db\VoteMapper;
|
||||
use OCA\Polls\Db\Vote;
|
||||
use OCA\Polls\Event\VoteSetEvent;
|
||||
use OCA\Polls\Exceptions\VoteLimitExceededException;
|
||||
use OCA\Polls\Model\Acl;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
|
||||
class VoteService {
|
||||
|
||||
|
|
|
@ -23,12 +23,11 @@
|
|||
|
||||
namespace OCA\Polls\Service;
|
||||
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
|
||||
use OCA\Polls\Db\Watch;
|
||||
use OCA\Polls\Db\WatchMapper;
|
||||
use OCA\Polls\Exceptions\NoUpdatesException;
|
||||
use OCA\Polls\Model\Settings\AppSettings;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
|
||||
class WatchService {
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче