Move ShareController::sendInvitation() logic to ShareService
Signed-off-by: Daniel Rudolf <github.com@daniel-rudolf.de>
This commit is contained in:
Родитель
25688c584d
Коммит
d3ba33b644
|
@ -32,7 +32,6 @@ use OCP\AppFramework\Http\DataResponse;
|
|||
|
||||
use OCA\Polls\Db\Share;
|
||||
use OCA\Polls\Service\MailService;
|
||||
use OCA\Polls\Service\NotificationService;
|
||||
use OCA\Polls\Service\ShareService;
|
||||
use OCA\Polls\Service\SystemService;
|
||||
use OCA\Polls\Model\User;
|
||||
|
@ -51,22 +50,17 @@ class ShareController extends Controller {
|
|||
/** @var SystemService */
|
||||
private $systemService;
|
||||
|
||||
/** @var NotificationService */
|
||||
private $notificationService;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
MailService $mailService,
|
||||
ShareService $shareService,
|
||||
SystemService $systemService,
|
||||
NotificationService $notificationService
|
||||
SystemService $systemService
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->mailService = $mailService;
|
||||
$this->shareService = $shareService;
|
||||
$this->systemService = $systemService;
|
||||
$this->notificationService = $notificationService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,21 +138,9 @@ class ShareController extends Controller {
|
|||
*/
|
||||
public function sendInvitation($token): DataResponse {
|
||||
return $this->response(function () use ($token) {
|
||||
$share = $this->shareService->get($token);
|
||||
if ($share->getType() === Share::TYPE_USER) {
|
||||
$this->notificationService->sendInvitation($share->getPollId(), $share->getUserId());
|
||||
// TODO: skip this atm, to send invitations as mail too, if user is a site user
|
||||
// $sentResult = ['sentMails' => [new User($share->getuserId())]];
|
||||
// $this->shareService->setInvitationSent($token);
|
||||
} elseif ($share->getType() === Share::TYPE_GROUP) {
|
||||
foreach ($share->getMembers() as $member) {
|
||||
$this->notificationService->sendInvitation($share->getPollId(), $member->getId());
|
||||
}
|
||||
}
|
||||
$sentResult = $this->mailService->sendInvitation($token);
|
||||
return [
|
||||
'share' => $share,
|
||||
'sentResult' => $sentResult
|
||||
'share' => $this->shareService->get($token),
|
||||
'sentResult' => $this->shareService->sendInvitation($token),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
|
|
@ -67,6 +67,9 @@ class ShareService {
|
|||
/** @var Acl */
|
||||
private $acl;
|
||||
|
||||
/** @var NotificationService */
|
||||
private $notificationService;
|
||||
|
||||
public function __construct(
|
||||
string $AppName,
|
||||
LoggerInterface $logger,
|
||||
|
@ -76,7 +79,8 @@ class ShareService {
|
|||
ShareMapper $shareMapper,
|
||||
Share $share,
|
||||
MailService $mailService,
|
||||
Acl $acl
|
||||
Acl $acl,
|
||||
NotificationService $notificationService
|
||||
) {
|
||||
$this->appName = $AppName;
|
||||
$this->logger = $logger;
|
||||
|
@ -87,6 +91,7 @@ class ShareService {
|
|||
$this->share = $share;
|
||||
$this->mailService = $mailService;
|
||||
$this->acl = $acl;
|
||||
$this->notificationService = $notificationService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -347,4 +352,24 @@ class ShareService {
|
|||
}
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sent invitation mails for a share
|
||||
* Additionally send notification via notifications
|
||||
*/
|
||||
public function sendInvitation(string $token): array {
|
||||
$share = $this->get($token);
|
||||
if ($share->getType() === Share::TYPE_USER) {
|
||||
$this->notificationService->sendInvitation($share->getPollId(), $share->getUserId());
|
||||
// TODO: skip this atm, to send invitations as mail too, if user is a site user
|
||||
// $sentResult = ['sentMails' => [new User($share->getuserId())]];
|
||||
// $this->shareService->setInvitationSent($token);
|
||||
} elseif ($share->getType() === Share::TYPE_GROUP) {
|
||||
foreach ($share->getMembers() as $member) {
|
||||
$this->notificationService->sendInvitation($share->getPollId(), $member->getId());
|
||||
}
|
||||
}
|
||||
|
||||
return $this->mailService->sendInvitation($token);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче