-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Opt out of birthday calendar #6884
Merged
MorrisJobke
merged 9 commits into
master
from
feature/3003/opt_out_of_birthday_calendar
Dec 12, 2017
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8b22bfe
Add admin checkbox to disable birthday calendars
georgehrke dc34622
remember when a user deleted their contact birthdays calendar
georgehrke 5068d56
add CalDAV interface that allows users to re-enable their birthday ca…
georgehrke 1c106a6
adapt occ 'dav:sync-birthday-calendar command
georgehrke d59b339
disallow users to create calendars with reserved names
georgehrke ef6f41a
respect admin / user choice about birthday calendars in corresponding…
georgehrke 4d5ed13
update autoloaders
georgehrke a87d986
create a user's birthday calendar right after they requested it
georgehrke 2b51d84
generate birthday calendars in a background job after admin enabled them
georgehrke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?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/>. | ||
* | ||
*/ | ||
|
||
return [ | ||
'routes' => [ | ||
['name' => 'birthday_calendar#enable', 'url' => '/enableBirthdayCalendar', 'verb' => 'POST'], | ||
['name' => 'birthday_calendar#disable', 'url' => '/disableBirthdayCalendar', 'verb' => 'POST'], | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
apps/dav/lib/BackgroundJob/GenerateBirthdayCalendarBackgroundJob.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the same route and POST+DELETE?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If using the same route, it would make more sense to send the enable/disable part in the payload and send everything over POST.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, what's the benefit of using POST+DELETE instead of the two routes in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleting something with a POST request just doesn't feel right to me, anyway not very important