summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib')
-rw-r--r--apps/dav/lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php69
-rw-r--r--apps/dav/lib/CalDAV/BirthdayCalendar/EnablePlugin.php139
-rw-r--r--apps/dav/lib/CalDAV/BirthdayService.php52
-rw-r--r--apps/dav/lib/CalDAV/CalDavBackend.php16
-rw-r--r--apps/dav/lib/CalDAV/Calendar.php18
-rw-r--r--apps/dav/lib/CalDAV/CalendarHome.php23
-rw-r--r--apps/dav/lib/CalDAV/PublicCalendarRoot.php21
-rw-r--r--apps/dav/lib/Command/SyncBirthdayCalendar.php34
-rw-r--r--apps/dav/lib/Controller/BirthdayCalendarController.php116
-rw-r--r--apps/dav/lib/RootCollection.php3
-rw-r--r--apps/dav/lib/Server.php5
-rw-r--r--apps/dav/lib/Settings/CalDAVSettings.php1
12 files changed, 487 insertions, 10 deletions
diff --git a/apps/dav/lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php b/apps/dav/lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php
new file mode 100644
index 00000000000..c4279c5108c
--- /dev/null
+++ b/apps/dav/lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * @copyright 2017 Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @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\DAV\BackgroundJob;
+
+use OC\BackgroundJob\QueuedJob;
+use OCA\DAV\CalDAV\BirthdayService;
+use OCP\IConfig;
+
+class GenerateBirthdayCalendarBackgroundJob extends QueuedJob {
+
+ /** @var BirthdayService */
+ private $birthdayService;
+
+ /** @var IConfig */
+ private $config;
+
+ /**
+ * GenerateAllBirthdayCalendarsBackgroundJob constructor.
+ *
+ * @param BirthdayService $birthdayService
+ * @param IConfig $config
+ */
+ public function __construct(BirthdayService $birthdayService,
+ IConfig $config) {
+ $this->birthdayService = $birthdayService;
+ $this->config = $config;
+ }
+
+ /**
+ * @param array $arguments
+ */
+ public function run($arguments) {
+ $userId = $arguments['userId'];
+
+ // make sure admin didn't change his mind
+ $isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
+ if ($isGloballyEnabled !== 'yes') {
+ return;
+ }
+
+ // did the user opt out?
+ $isUserEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
+ if ($isUserEnabled !== 'yes') {
+ return;
+ }
+
+ $this->birthdayService->syncUser($userId);
+ }
+}
diff --git a/apps/dav/lib/CalDAV/BirthdayCalendar/EnablePlugin.php b/apps/dav/lib/CalDAV/BirthdayCalendar/EnablePlugin.php
new file mode 100644
index 00000000000..497d7112b3c
--- /dev/null
+++ b/apps/dav/lib/CalDAV/BirthdayCalendar/EnablePlugin.php
@@ -0,0 +1,139 @@
+<?php
+/**
+ * @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @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\DAV\CalDAV\BirthdayCalendar;
+
+use OCA\DAV\CalDAV\BirthdayService;
+use OCA\DAV\CalDAV\CalendarHome;
+use Sabre\DAV\Server;
+use Sabre\DAV\ServerPlugin;
+use Sabre\HTTP\RequestInterface;
+use Sabre\HTTP\ResponseInterface;
+use OCP\IConfig;
+
+/**
+ * Class EnablePlugin
+ * allows users to re-enable the birthday calendar via CalDAV
+ *
+ * @package OCA\DAV\CalDAV\BirthdayCalendar
+ */
+class EnablePlugin extends ServerPlugin {
+ const NS_Nextcloud = 'http://nextcloud.com/ns';
+
+ /**
+ * @var IConfig
+ */
+ protected $config;
+
+ /**
+ * @var BirthdayService
+ */
+ protected $birthdayService;
+
+ /**
+ * @var Server
+ */
+ protected $server;
+
+ /**
+ * PublishPlugin constructor.
+ *
+ * @param IConfig $config
+ * @param BirthdayService $birthdayService
+ */
+ public function __construct(IConfig $config, BirthdayService $birthdayService) {
+ $this->config = $config;
+ $this->birthdayService = $birthdayService;
+ }
+
+ /**
+ * This method should return a list of server-features.
+ *
+ * This is for example 'versioning' and is added to the DAV: header
+ * in an OPTIONS response.
+ *
+ * @return string[]
+ */
+ public function getFeatures() {
+ return ['nc-enable-birthday-calendar'];
+ }
+
+ /**
+ * Returns a plugin name.
+ *
+ * Using this name other plugins will be able to access other plugins
+ * using Sabre\DAV\Server::getPlugin
+ *
+ * @return string
+ */
+ public function getPluginName() {
+ return 'nc-enable-birthday-calendar';
+ }
+
+ /**
+ * This initializes the plugin.
+ *
+ * This function is called by Sabre\DAV\Server, after
+ * addPlugin is called.
+ *
+ * This method should set up the required event subscriptions.
+ *
+ * @param Server $server
+ */
+ public function initialize(Server $server) {
+ $this->server = $server;
+
+ $this->server->on('method:POST', [$this, 'httpPost']);
+ }
+
+ /**
+ * We intercept this to handle POST requests on calendar homes.
+ *
+ * @param RequestInterface $request
+ * @param ResponseInterface $response
+ *
+ * @return bool|void
+ */
+ public function httpPost(RequestInterface $request, ResponseInterface $response) {
+ $node = $this->server->tree->getNodeForPath($this->server->getRequestUri());
+ if (!($node instanceof CalendarHome)) {
+ return;
+ }
+
+ $requestBody = $request->getBodyAsString();
+ $this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
+ if ($documentType !== '{'.self::NS_Nextcloud.'}enable-birthday-calendar') {
+ return;
+ }
+
+ $principalUri = $node->getOwner();
+ $userId = substr($principalUri, 17);
+
+ $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
+ $this->birthdayService->syncUser($userId);
+
+ $this->server->httpResponse->setStatus(204);
+
+ return false;
+ }
+}
diff --git a/apps/dav/lib/CalDAV/BirthdayService.php b/apps/dav/lib/CalDAV/BirthdayService.php
index aa902bacc53..62d218f0a2a 100644
--- a/apps/dav/lib/CalDAV/BirthdayService.php
+++ b/apps/dav/lib/CalDAV/BirthdayService.php
@@ -31,6 +31,7 @@ namespace OCA\DAV\CalDAV;
use Exception;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\DAV\GroupPrincipalBackend;
+use OCP\IConfig;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Component\VCard;
use Sabre\VObject\DateTimeParser;
@@ -52,17 +53,22 @@ class BirthdayService {
/** @var CardDavBackend */
private $cardDavBackEnd;
+ /** @var IConfig */
+ private $config;
+
/**
* BirthdayService constructor.
*
* @param CalDavBackend $calDavBackEnd
* @param CardDavBackend $cardDavBackEnd
* @param GroupPrincipalBackend $principalBackend
+ * @param IConfig $config;
*/
- public function __construct(CalDavBackend $calDavBackEnd, CardDavBackend $cardDavBackEnd, GroupPrincipalBackend $principalBackend) {
+ public function __construct(CalDavBackend $calDavBackEnd, CardDavBackend $cardDavBackEnd, GroupPrincipalBackend $principalBackend, IConfig $config) {
$this->calDavBackEnd = $calDavBackEnd;
$this->cardDavBackEnd = $cardDavBackEnd;
$this->principalBackend = $principalBackend;
+ $this->config = $config;
}
/**
@@ -71,8 +77,11 @@ class BirthdayService {
* @param string $cardData
*/
public function onCardChanged($addressBookId, $cardUri, $cardData) {
+ if (!$this->isGloballyEnabled()) {
+ return;
+ }
+
$targetPrincipals = $this->getAllAffectedPrincipals($addressBookId);
-
$book = $this->cardDavBackEnd->getAddressBookById($addressBookId);
$targetPrincipals[] = $book['principaluri'];
$datesToSync = [
@@ -81,6 +90,10 @@ class BirthdayService {
['postfix' => '-anniversary', 'field' => 'ANNIVERSARY', 'symbol' => "⚭"],
];
foreach ($targetPrincipals as $principalUri) {
+ if (!$this->isUserEnabled($principalUri)) {
+ continue;
+ }
+
$calendar = $this->ensureCalendarExists($principalUri);
foreach ($datesToSync as $type) {
$this->updateCalendar($cardUri, $cardData, $book, $calendar['id'], $type);
@@ -93,10 +106,18 @@ class BirthdayService {
* @param string $cardUri
*/
public function onCardDeleted($addressBookId, $cardUri) {
+ if (!$this->isGloballyEnabled()) {
+ return;
+ }
+
$targetPrincipals = $this->getAllAffectedPrincipals($addressBookId);
$book = $this->cardDavBackEnd->getAddressBookById($addressBookId);
$targetPrincipals[] = $book['principaluri'];
foreach ($targetPrincipals as $principalUri) {
+ if (!$this->isUserEnabled($principalUri)) {
+ continue;
+ }
+
$calendar = $this->ensureCalendarExists($principalUri);
foreach (['', '-death', '-anniversary'] as $tag) {
$objectUri = $book['uri'] . '-' . $cardUri . $tag .'.ics';
@@ -293,4 +314,31 @@ class BirthdayService {
}
}
+ /**
+ * checks if the admin opted-out of birthday calendars
+ *
+ * @return bool
+ */
+ private function isGloballyEnabled() {
+ $isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
+ return $isGloballyEnabled === 'yes';
+ }
+
+ /**
+ * checks if the user opted-out of birthday calendars
+ *
+ * @param $userPrincipal
+ * @return bool
+ */
+ private function isUserEnabled($userPrincipal) {
+ if (strpos($userPrincipal, 'principals/users/') === 0) {
+ $userId = substr($userPrincipal, 17);
+ $isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
+ return $isEnabled === 'yes';
+ }
+
+ // not sure how we got here, just be on the safe side and return true
+ return true;
+ }
+
}
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php
index 8ecd64723a2..169bf6ff6a5 100644
--- a/apps/dav/lib/CalDAV/CalDavBackend.php
+++ b/apps/dav/lib/CalDAV/CalDavBackend.php
@@ -2285,6 +2285,22 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
}
/**
+ * deletes all birthday calendars
+ */
+ public function deleteAllBirthdayCalendars() {
+ $query = $this->db->getQueryBuilder();
+ $result = $query->select(['id'])->from('calendars')
+ ->where($query->expr()->eq('uri',
+ $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI)))
+ ->execute();
+
+ $ids = $result->fetchAll();
+ foreach($ids as $id) {
+ $this->deleteCalendar($id['id']);
+ }
+ }
+
+ /**
* read VCalendar data into a VCalendar object
*
* @param string $objectData
diff --git a/apps/dav/lib/CalDAV/Calendar.php b/apps/dav/lib/CalDAV/Calendar.php
index ac3bcec6173..02808ab5662 100644
--- a/apps/dav/lib/CalDAV/Calendar.php
+++ b/apps/dav/lib/CalDAV/Calendar.php
@@ -27,6 +27,7 @@
namespace OCA\DAV\CalDAV;
use OCA\DAV\DAV\Sharing\IShareable;
+use OCP\IConfig;
use OCP\IL10N;
use Sabre\CalDAV\Backend\BackendInterface;
use Sabre\DAV\Exception\Forbidden;
@@ -41,7 +42,10 @@ use Sabre\DAV\PropPatch;
*/
class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
- public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) {
+ /** @var IConfig */
+ private $config;
+
+ public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) {
parent::__construct($caldavBackend, $calendarInfo);
if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
@@ -51,6 +55,8 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
$this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
}
+
+ $this->config = $config;
}
/**
@@ -201,6 +207,16 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
]);
return;
}
+
+ // Remember when a user deleted their birthday calendar
+ // in order to not regenerate it on the next contacts change
+ if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
+ $principalURI = $this->getPrincipalURI();
+ $userId = substr($principalURI, 17);
+
+ $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no');
+ }
+
parent::delete();
}
diff --git a/apps/dav/lib/CalDAV/CalendarHome.php b/apps/dav/lib/CalDAV/CalendarHome.php
index 3429c24705d..3e645db459f 100644
--- a/apps/dav/lib/CalDAV/CalendarHome.php
+++ b/apps/dav/lib/CalDAV/CalendarHome.php
@@ -32,15 +32,21 @@ use Sabre\CalDAV\Schedule\Inbox;
use Sabre\CalDAV\Schedule\Outbox;
use Sabre\CalDAV\Subscriptions\Subscription;
use Sabre\DAV\Exception\NotFound;
+use Sabre\DAV\Exception\MethodNotAllowed;
+use Sabre\DAV\MkCol;
class CalendarHome extends \Sabre\CalDAV\CalendarHome {
/** @var \OCP\IL10N */
private $l10n;
+ /** @var \OCP\IConfig */
+ private $config;
+
public function __construct(BackendInterface $caldavBackend, $principalInfo) {
parent::__construct($caldavBackend, $principalInfo);
$this->l10n = \OC::$server->getL10N('dav');
+ $this->config = \OC::$server->getConfig();
}
/**
@@ -53,11 +59,24 @@ class CalendarHome extends \Sabre\CalDAV\CalendarHome {
/**
* @inheritdoc
*/
+ function createExtendedCollection($name, MkCol $mkCol) {
+ $reservedNames = [BirthdayService::BIRTHDAY_CALENDAR_URI];
+
+ if (in_array($name, $reservedNames)) {
+ throw new MethodNotAllowed('The resource you tried to create has a reserved name');
+ }
+
+ parent::createExtendedCollection($name, $mkCol);
+ }
+
+ /**
+ * @inheritdoc
+ */
function getChildren() {
$calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
$objects = [];
foreach ($calendars as $calendar) {
- $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
+ $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
}
if ($this->caldavBackend instanceof SchedulingSupport) {
@@ -98,7 +117,7 @@ class CalendarHome extends \Sabre\CalDAV\CalendarHome {
// Calendars
foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
if ($calendar['uri'] === $name) {
- return new Calendar($this->caldavBackend, $calendar, $this->l10n);
+ return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
}
}
diff --git a/apps/dav/lib/CalDAV/PublicCalendarRoot.php b/apps/dav/lib/CalDAV/PublicCalendarRoot.php
index 55f969e2167..9385f487bda 100644
--- a/apps/dav/lib/CalDAV/PublicCalendarRoot.php
+++ b/apps/dav/lib/CalDAV/PublicCalendarRoot.php
@@ -24,6 +24,8 @@
*/
namespace OCA\DAV\CalDAV;
+use OCP\IConfig;
+use OCP\IL10N;
use Sabre\DAV\Collection;
class PublicCalendarRoot extends Collection {
@@ -34,9 +36,22 @@ class PublicCalendarRoot extends Collection {
/** @var \OCP\IL10N */
protected $l10n;
- function __construct(CalDavBackend $caldavBackend) {
+ /** @var \OCP\IConfig */
+ protected $config;
+
+ /**
+ * PublicCalendarRoot constructor.
+ *
+ * @param CalDavBackend $caldavBackend
+ * @param IL10N $l10n
+ * @param IConfig $config
+ */
+ function __construct(CalDavBackend $caldavBackend, IL10N $l10n,
+ IConfig $config) {
$this->caldavBackend = $caldavBackend;
- $this->l10n = \OC::$server->getL10N('dav');
+ $this->l10n = $l10n;
+ $this->config = $config;
+
}
/**
@@ -51,7 +66,7 @@ class PublicCalendarRoot extends Collection {
*/
function getChild($name) {
$calendar = $this->caldavBackend->getPublicCalendar($name);
- return new PublicCalendar($this->caldavBackend, $calendar, $this->l10n);
+ return new PublicCalendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
}
/**
diff --git a/apps/dav/lib/Command/SyncBirthdayCalendar.php b/apps/dav/lib/Command/SyncBirthdayCalendar.php
index a99e2ea4b89..88f85a98812 100644
--- a/apps/dav/lib/Command/SyncBirthdayCalendar.php
+++ b/apps/dav/lib/Command/SyncBirthdayCalendar.php
@@ -23,6 +23,7 @@
namespace OCA\DAV\Command;
use OCA\DAV\CalDAV\BirthdayService;
+use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\Console\Command\Command;
@@ -36,16 +37,22 @@ class SyncBirthdayCalendar extends Command {
/** @var BirthdayService */
private $birthdayService;
+ /** @var IConfig */
+ private $config;
+
/** @var IUserManager */
private $userManager;
/**
* @param IUserManager $userManager
+ * @param IConfig $config
* @param BirthdayService $birthdayService
*/
- function __construct(IUserManager $userManager, BirthdayService $birthdayService) {
+ function __construct(IUserManager $userManager, IConfig $config,
+ BirthdayService $birthdayService) {
parent::__construct();
$this->birthdayService = $birthdayService;
+ $this->config = $config;
$this->userManager = $userManager;
}
@@ -63,11 +70,21 @@ class SyncBirthdayCalendar extends Command {
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output) {
+ $this->verifyEnabled();
+
$user = $input->getArgument('user');
if (!is_null($user)) {
if (!$this->userManager->userExists($user)) {
throw new \InvalidArgumentException("User <$user> in unknown.");
}
+
+ // re-enable the birthday calendar in case it's called directly with a user name
+ $isEnabled = $this->config->getUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes');
+ if ($isEnabled !== 'yes') {
+ $this->config->setUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes');
+ $output->writeln("Re-enabling birthday calendar for $user");
+ }
+
$output->writeln("Start birthday calendar sync for $user");
$this->birthdayService->syncUser($user);
return;
@@ -77,6 +94,13 @@ class SyncBirthdayCalendar extends Command {
$p->start();
$this->userManager->callForAllUsers(function($user) use ($p) {
$p->advance();
+
+ $userId = $user->getUID();
+ $isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
+ if ($isEnabled !== 'yes') {
+ return;
+ }
+
/** @var IUser $user */
$this->birthdayService->syncUser($user->getUID());
});
@@ -84,4 +108,12 @@ class SyncBirthdayCalendar extends Command {
$p->finish();
$output->writeln('');
}
+
+ protected function verifyEnabled () {
+ $isEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
+
+ if ($isEnabled !== 'yes') {
+ throw new \InvalidArgumentException('Birthday calendars are disabled');
+ }
+ }
}
diff --git a/apps/dav/lib/Controller/BirthdayCalendarController.php b/apps/dav/lib/Controller/BirthdayCalendarController.php
new file mode 100644
index 00000000000..244111e3aec
--- /dev/null
+++ b/apps/dav/lib/Controller/BirthdayCalendarController.php
@@ -0,0 +1,116 @@
+<?php
+/**
+ * @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @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\DAV\Controller;
+
+use OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob;
+use OCA\DAV\CalDAV\CalDavBackend;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\JSONResponse;
+use OCP\AppFramework\Http\Response;
+use OCP\BackgroundJob\IJobList;
+use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\IRequest;
+use OCP\IUser;
+use OCP\IUserManager;
+
+class BirthdayCalendarController extends Controller {
+
+ /**
+ * @var IDBConnection
+ */
+ protected $db;
+
+ /**
+ * @var IConfig
+ */
+ protected $config;
+
+ /**
+ * @var IUserManager
+ */
+ protected $userManager;
+
+ /**
+ * @var CalDavBackend
+ */
+ protected $caldavBackend;
+
+ /**
+ * @var IJobList
+ */
+ protected $jobList;
+
+ /**
+ * BirthdayCalendar constructor.
+ *
+ * @param string $appName
+ * @param IRequest $request
+ * @param IDBConnection $db
+ * @param IConfig $config
+ * @param IJobList $jobList
+ * @param IUserManager $userManager
+ * @param CalDavBackend $calDavBackend
+ */
+ public function __construct($appName, IRequest $request,
+ IDBConnection $db, IConfig $config,
+ IJobList $jobList,
+ IUserManager $userManager,
+ CalDavBackend $calDavBackend){
+ parent::__construct($appName, $request);
+ $this->db = $db;
+ $this->config = $config;
+ $this->userManager = $userManager;
+ $this->jobList = $jobList;
+ $this->caldavBackend = $calDavBackend;
+ }
+
+ /**
+ * @return Response
+ */
+ public function enable() {
+ $this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'yes');
+
+ // add background job for each user
+ $this->userManager->callForAllUsers(function(IUser $user) {
+ $this->jobList->add(GenerateBirthdayCalendarBackgroundJob::class, [
+ 'userId' => $user->getUID(),
+ ]);
+ });
+
+ return new JSONResponse([]);
+ }
+
+ /**
+ * @return Response
+ */
+ public function disable() {
+ $this->config->setAppValue($this->appName, 'generateBirthdayCalendar', 'no');
+
+ $this->jobList->remove(GenerateBirthdayCalendarBackgroundJob::class);
+ $this->caldavBackend->deleteAllBirthdayCalendars();
+
+ return new JSONResponse([]);
+ }
+}
diff --git a/apps/dav/lib/RootCollection.php b/apps/dav/lib/RootCollection.php
index f2e9350c101..a39b8716110 100644
--- a/apps/dav/lib/RootCollection.php
+++ b/apps/dav/lib/RootCollection.php
@@ -39,6 +39,7 @@ class RootCollection extends SimpleCollection {
public function __construct() {
$config = \OC::$server->getConfig();
+ $l10n = \OC::$server->getL10N('dav');
$random = \OC::$server->getSecureRandom();
$logger = \OC::$server->getLogger();
$userManager = \OC::$server->getUserManager();
@@ -68,7 +69,7 @@ class RootCollection extends SimpleCollection {
$caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher);
$calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
$calendarRoot->disableListing = $disableListing;
- $publicCalendarRoot = new PublicCalendarRoot($caldavBackend);
+ $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config);
$publicCalendarRoot->disableListing = $disableListing;
$systemTagCollection = new SystemTag\SystemTagsByIdCollection(
diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php
index 8267c656988..4e8a9fd0a51 100644
--- a/apps/dav/lib/Server.php
+++ b/apps/dav/lib/Server.php
@@ -33,6 +33,7 @@
namespace OCA\DAV;
use OC\AppFramework\Utility\TimeFactory;
+use OCA\DAV\CalDAV\BirthdayService;
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
use OCA\DAV\CardDAV\ImageExportPlugin;
use OCA\DAV\CardDAV\PhotoCache;
@@ -256,6 +257,10 @@ class Server {
$view
)));
}
+ $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin(
+ \OC::$server->getConfig(),
+ \OC::$server->query(BirthdayService::class)
+ ));
}
// register plugins from apps
diff --git a/apps/dav/lib/Settings/CalDAVSettings.php b/apps/dav/lib/Settings/CalDAVSettings.php
index 1c85d19432c..a419afa1c55 100644
--- a/apps/dav/lib/Settings/CalDAVSettings.php
+++ b/apps/dav/lib/Settings/CalDAVSettings.php
@@ -47,6 +47,7 @@ class CalDAVSettings implements ISettings {
public function getForm() {
$parameters = [
'send_invitations' => $this->config->getAppValue('dav', 'sendInvitations', 'yes'),
+ 'generate_birthday_calendar' => $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'),
];
return new TemplateResponse('dav', 'settings-admin-caldav', $parameters);