Skip to content

Commit d98dea1

Browse files
authored
Merge pull request #6884 from nextcloud/feature/3003/opt_out_of_birthday_calendar
Opt out of birthday calendar
2 parents e1740c9 + 2b51d84 commit d98dea1

26 files changed

+1204
-35
lines changed

apps/dav/appinfo/routes.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
4+
*
5+
* @author Georg Ehrke <oc.list@georgehrke.com>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
return [
25+
'routes' => [
26+
['name' => 'birthday_calendar#enable', 'url' => '/enableBirthdayCalendar', 'verb' => 'POST'],
27+
['name' => 'birthday_calendar#disable', 'url' => '/disableBirthdayCalendar', 'verb' => 'POST'],
28+
]
29+
];

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'OCA\\DAV\\Avatars\\AvatarHome' => $baseDir . '/../lib/Avatars/AvatarHome.php',
1212
'OCA\\DAV\\Avatars\\AvatarNode' => $baseDir . '/../lib/Avatars/AvatarNode.php',
1313
'OCA\\DAV\\Avatars\\RootCollection' => $baseDir . '/../lib/Avatars/RootCollection.php',
14+
'OCA\\DAV\\BackgroundJob\\GenerateBirthdayCalendarBackgroundJob' => $baseDir . '/../lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php',
1415
'OCA\\DAV\\CalDAV\\Activity\\Backend' => $baseDir . '/../lib/CalDAV/Activity/Backend.php',
1516
'OCA\\DAV\\CalDAV\\Activity\\Filter\\Calendar' => $baseDir . '/../lib/CalDAV/Activity/Filter/Calendar.php',
1617
'OCA\\DAV\\CalDAV\\Activity\\Filter\\Todo' => $baseDir . '/../lib/CalDAV/Activity/Filter/Todo.php',
@@ -21,6 +22,7 @@
2122
'OCA\\DAV\\CalDAV\\Activity\\Setting\\Calendar' => $baseDir . '/../lib/CalDAV/Activity/Setting/Calendar.php',
2223
'OCA\\DAV\\CalDAV\\Activity\\Setting\\Event' => $baseDir . '/../lib/CalDAV/Activity/Setting/Event.php',
2324
'OCA\\DAV\\CalDAV\\Activity\\Setting\\Todo' => $baseDir . '/../lib/CalDAV/Activity/Setting/Todo.php',
25+
'OCA\\DAV\\CalDAV\\BirthdayCalendar\\EnablePlugin' => $baseDir . '/../lib/CalDAV/BirthdayCalendar/EnablePlugin.php',
2426
'OCA\\DAV\\CalDAV\\BirthdayService' => $baseDir . '/../lib/CalDAV/BirthdayService.php',
2527
'OCA\\DAV\\CalDAV\\CalDavBackend' => $baseDir . '/../lib/CalDAV/CalDavBackend.php',
2628
'OCA\\DAV\\CalDAV\\Calendar' => $baseDir . '/../lib/CalDAV/Calendar.php',
@@ -107,6 +109,7 @@
107109
'OCA\\DAV\\Connector\\Sabre\\SharesPlugin' => $baseDir . '/../lib/Connector/Sabre/SharesPlugin.php',
108110
'OCA\\DAV\\Connector\\Sabre\\TagList' => $baseDir . '/../lib/Connector/Sabre/TagList.php',
109111
'OCA\\DAV\\Connector\\Sabre\\TagsPlugin' => $baseDir . '/../lib/Connector/Sabre/TagsPlugin.php',
112+
'OCA\\DAV\\Controller\\BirthdayCalendarController' => $baseDir . '/../lib/Controller/BirthdayCalendarController.php',
110113
'OCA\\DAV\\DAV\\CustomPropertiesBackend' => $baseDir . '/../lib/DAV/CustomPropertiesBackend.php',
111114
'OCA\\DAV\\DAV\\GroupPrincipalBackend' => $baseDir . '/../lib/DAV/GroupPrincipalBackend.php',
112115
'OCA\\DAV\\DAV\\PublicAuth' => $baseDir . '/../lib/DAV/PublicAuth.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ComposerStaticInitDAV
2626
'OCA\\DAV\\Avatars\\AvatarHome' => __DIR__ . '/..' . '/../lib/Avatars/AvatarHome.php',
2727
'OCA\\DAV\\Avatars\\AvatarNode' => __DIR__ . '/..' . '/../lib/Avatars/AvatarNode.php',
2828
'OCA\\DAV\\Avatars\\RootCollection' => __DIR__ . '/..' . '/../lib/Avatars/RootCollection.php',
29+
'OCA\\DAV\\BackgroundJob\\GenerateBirthdayCalendarBackgroundJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php',
2930
'OCA\\DAV\\CalDAV\\Activity\\Backend' => __DIR__ . '/..' . '/../lib/CalDAV/Activity/Backend.php',
3031
'OCA\\DAV\\CalDAV\\Activity\\Filter\\Calendar' => __DIR__ . '/..' . '/../lib/CalDAV/Activity/Filter/Calendar.php',
3132
'OCA\\DAV\\CalDAV\\Activity\\Filter\\Todo' => __DIR__ . '/..' . '/../lib/CalDAV/Activity/Filter/Todo.php',
@@ -36,6 +37,7 @@ class ComposerStaticInitDAV
3637
'OCA\\DAV\\CalDAV\\Activity\\Setting\\Calendar' => __DIR__ . '/..' . '/../lib/CalDAV/Activity/Setting/Calendar.php',
3738
'OCA\\DAV\\CalDAV\\Activity\\Setting\\Event' => __DIR__ . '/..' . '/../lib/CalDAV/Activity/Setting/Event.php',
3839
'OCA\\DAV\\CalDAV\\Activity\\Setting\\Todo' => __DIR__ . '/..' . '/../lib/CalDAV/Activity/Setting/Todo.php',
40+
'OCA\\DAV\\CalDAV\\BirthdayCalendar\\EnablePlugin' => __DIR__ . '/..' . '/../lib/CalDAV/BirthdayCalendar/EnablePlugin.php',
3941
'OCA\\DAV\\CalDAV\\BirthdayService' => __DIR__ . '/..' . '/../lib/CalDAV/BirthdayService.php',
4042
'OCA\\DAV\\CalDAV\\CalDavBackend' => __DIR__ . '/..' . '/../lib/CalDAV/CalDavBackend.php',
4143
'OCA\\DAV\\CalDAV\\Calendar' => __DIR__ . '/..' . '/../lib/CalDAV/Calendar.php',
@@ -122,6 +124,7 @@ class ComposerStaticInitDAV
122124
'OCA\\DAV\\Connector\\Sabre\\SharesPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/SharesPlugin.php',
123125
'OCA\\DAV\\Connector\\Sabre\\TagList' => __DIR__ . '/..' . '/../lib/Connector/Sabre/TagList.php',
124126
'OCA\\DAV\\Connector\\Sabre\\TagsPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/TagsPlugin.php',
127+
'OCA\\DAV\\Controller\\BirthdayCalendarController' => __DIR__ . '/..' . '/../lib/Controller/BirthdayCalendarController.php',
125128
'OCA\\DAV\\DAV\\CustomPropertiesBackend' => __DIR__ . '/..' . '/../lib/DAV/CustomPropertiesBackend.php',
126129
'OCA\\DAV\\DAV\\GroupPrincipalBackend' => __DIR__ . '/..' . '/../lib/DAV/GroupPrincipalBackend.php',
127130
'OCA\\DAV\\DAV\\PublicAuth' => __DIR__ . '/..' . '/../lib/DAV/PublicAuth.php',

apps/dav/js/settings-admin-caldav.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,13 @@ $('#caldavSendInvitations').change(function() {
2626

2727
OCP.AppConfig.setValue('dav', 'sendInvitations', val ? 'yes' : 'no');
2828
});
29+
30+
$('#caldavGenerateBirthdayCalendar').change(function() {
31+
var val = $(this)[0].checked;
32+
33+
if (val) {
34+
$.post(OC.generateUrl(OC.linkTo("dav", "enableBirthdayCalendar")));
35+
} else {
36+
$.post(OC.generateUrl(OC.linkTo("dav", "disableBirthdayCalendar")));
37+
}
38+
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* @copyright 2017 Georg Ehrke <oc.list@georgehrke.com>
4+
*
5+
* @author Georg Ehrke <oc.list@georgehrke.com>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
namespace OCA\DAV\BackgroundJob;
24+
25+
use OC\BackgroundJob\QueuedJob;
26+
use OCA\DAV\CalDAV\BirthdayService;
27+
use OCP\IConfig;
28+
29+
class GenerateBirthdayCalendarBackgroundJob extends QueuedJob {
30+
31+
/** @var BirthdayService */
32+
private $birthdayService;
33+
34+
/** @var IConfig */
35+
private $config;
36+
37+
/**
38+
* GenerateAllBirthdayCalendarsBackgroundJob constructor.
39+
*
40+
* @param BirthdayService $birthdayService
41+
* @param IConfig $config
42+
*/
43+
public function __construct(BirthdayService $birthdayService,
44+
IConfig $config) {
45+
$this->birthdayService = $birthdayService;
46+
$this->config = $config;
47+
}
48+
49+
/**
50+
* @param array $arguments
51+
*/
52+
public function run($arguments) {
53+
$userId = $arguments['userId'];
54+
55+
// make sure admin didn't change his mind
56+
$isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
57+
if ($isGloballyEnabled !== 'yes') {
58+
return;
59+
}
60+
61+
// did the user opt out?
62+
$isUserEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
63+
if ($isUserEnabled !== 'yes') {
64+
return;
65+
}
66+
67+
$this->birthdayService->syncUser($userId);
68+
}
69+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?php
2+
/**
3+
* @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
4+
*
5+
* @author Georg Ehrke <oc.list@georgehrke.com>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace OCA\DAV\CalDAV\BirthdayCalendar;
25+
26+
use OCA\DAV\CalDAV\BirthdayService;
27+
use OCA\DAV\CalDAV\CalendarHome;
28+
use Sabre\DAV\Server;
29+
use Sabre\DAV\ServerPlugin;
30+
use Sabre\HTTP\RequestInterface;
31+
use Sabre\HTTP\ResponseInterface;
32+
use OCP\IConfig;
33+
34+
/**
35+
* Class EnablePlugin
36+
* allows users to re-enable the birthday calendar via CalDAV
37+
*
38+
* @package OCA\DAV\CalDAV\BirthdayCalendar
39+
*/
40+
class EnablePlugin extends ServerPlugin {
41+
const NS_Nextcloud = 'http://nextcloud.com/ns';
42+
43+
/**
44+
* @var IConfig
45+
*/
46+
protected $config;
47+
48+
/**
49+
* @var BirthdayService
50+
*/
51+
protected $birthdayService;
52+
53+
/**
54+
* @var Server
55+
*/
56+
protected $server;
57+
58+
/**
59+
* PublishPlugin constructor.
60+
*
61+
* @param IConfig $config
62+
* @param BirthdayService $birthdayService
63+
*/
64+
public function __construct(IConfig $config, BirthdayService $birthdayService) {
65+
$this->config = $config;
66+
$this->birthdayService = $birthdayService;
67+
}
68+
69+
/**
70+
* This method should return a list of server-features.
71+
*
72+
* This is for example 'versioning' and is added to the DAV: header
73+
* in an OPTIONS response.
74+
*
75+
* @return string[]
76+
*/
77+
public function getFeatures() {
78+
return ['nc-enable-birthday-calendar'];
79+
}
80+
81+
/**
82+
* Returns a plugin name.
83+
*
84+
* Using this name other plugins will be able to access other plugins
85+
* using Sabre\DAV\Server::getPlugin
86+
*
87+
* @return string
88+
*/
89+
public function getPluginName() {
90+
return 'nc-enable-birthday-calendar';
91+
}
92+
93+
/**
94+
* This initializes the plugin.
95+
*
96+
* This function is called by Sabre\DAV\Server, after
97+
* addPlugin is called.
98+
*
99+
* This method should set up the required event subscriptions.
100+
*
101+
* @param Server $server
102+
*/
103+
public function initialize(Server $server) {
104+
$this->server = $server;
105+
106+
$this->server->on('method:POST', [$this, 'httpPost']);
107+
}
108+
109+
/**
110+
* We intercept this to handle POST requests on calendar homes.
111+
*
112+
* @param RequestInterface $request
113+
* @param ResponseInterface $response
114+
*
115+
* @return bool|void
116+
*/
117+
public function httpPost(RequestInterface $request, ResponseInterface $response) {
118+
$node = $this->server->tree->getNodeForPath($this->server->getRequestUri());
119+
if (!($node instanceof CalendarHome)) {
120+
return;
121+
}
122+
123+
$requestBody = $request->getBodyAsString();
124+
$this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
125+
if ($documentType !== '{'.self::NS_Nextcloud.'}enable-birthday-calendar') {
126+
return;
127+
}
128+
129+
$principalUri = $node->getOwner();
130+
$userId = substr($principalUri, 17);
131+
132+
$this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
133+
$this->birthdayService->syncUser($userId);
134+
135+
$this->server->httpResponse->setStatus(204);
136+
137+
return false;
138+
}
139+
}

0 commit comments

Comments
 (0)