Skip to content

Commit 4d3f33c

Browse files
committed
create a user's birthday calendar right after they requested it
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
1 parent 4d5ed13 commit 4d3f33c

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

apps/dav/lib/BackgroundJob/AbstractBirthdayCalendarGeneratorBackgroundJob.php

Whitespace-only changes.

apps/dav/lib/CalDAV/BirthdayCalendar/EnablePlugin.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
namespace OCA\DAV\CalDAV\BirthdayCalendar;
2525

26+
use OCA\DAV\CalDAV\BirthdayService;
2627
use OCA\DAV\CalDAV\CalendarHome;
2728
use Sabre\DAV\Server;
2829
use Sabre\DAV\ServerPlugin;
@@ -44,6 +45,11 @@ class EnablePlugin extends ServerPlugin {
4445
*/
4546
protected $config;
4647

48+
/**
49+
* @var BirthdayService
50+
*/
51+
protected $birthdayService;
52+
4753
/**
4854
* @var Server
4955
*/
@@ -53,9 +59,11 @@ class EnablePlugin extends ServerPlugin {
5359
* PublishPlugin constructor.
5460
*
5561
* @param IConfig $config
62+
* @param BirthdayService $birthdayService
5663
*/
57-
public function __construct(IConfig $config) {
64+
public function __construct(IConfig $config, BirthdayService $birthdayService) {
5865
$this->config = $config;
66+
$this->birthdayService = $birthdayService;
5967
}
6068

6169
/**
@@ -122,6 +130,7 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
122130
$userId = substr($principalUri, 17);
123131

124132
$this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
133+
$this->birthdayService->syncUser($userId);
125134

126135
$this->server->httpResponse->setStatus(204);
127136

apps/dav/lib/Server.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
namespace OCA\DAV;
3434

3535
use OC\AppFramework\Utility\TimeFactory;
36+
use OCA\DAV\CalDAV\BirthdayService;
3637
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
3738
use OCA\DAV\CardDAV\ImageExportPlugin;
3839
use OCA\DAV\CardDAV\PhotoCache;
@@ -260,7 +261,8 @@ public function __construct(IRequest $request, $baseUri) {
260261
)));
261262
}
262263
$this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin(
263-
\OC::$server->getConfig()
264+
\OC::$server->getConfig(),
265+
\OC::$server->query(BirthdayService::class)
264266
));
265267
}
266268

apps/dav/tests/unit/CalDAV/BirthdayCalendar/EnablePluginTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace OCA\DAV\Tests\unit\CalDAV\BirthdayCalendar;
2323

2424
use OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin;
25+
use OCA\DAV\CalDAV\BirthdayService;
2526
use OCA\DAV\CalDAV\Calendar;
2627
use OCA\DAV\CalDAV\CalendarHome;
2728
use OCP\IConfig;
@@ -35,6 +36,9 @@ class EnablePluginTest extends TestCase {
3536
/** @var \OCP\IConfig|\PHPUnit_Framework_MockObject_MockObject */
3637
protected $config;
3738

39+
/** @var BirthdayService |\PHPUnit_Framework_MockObject_MockObject */
40+
protected $birthdayService;
41+
3842
/** @var \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin $plugin */
3943
protected $plugin;
4044

@@ -51,8 +55,9 @@ public function setUp() {
5155
$this->server->xml = $this->createMock(\Sabre\DAV\Xml\Service::class);
5256

5357
$this->config = $this->createMock(IConfig::class);
58+
$this->birthdayService = $this->createMock(BirthdayService::class);
5459

55-
$this->plugin = new EnablePlugin($this->config);
60+
$this->plugin = new EnablePlugin($this->config, $this->birthdayService);
5661
$this->plugin->initialize($this->server);
5762

5863
$this->request = $this->createMock(\Sabre\HTTP\RequestInterface::class);
@@ -70,7 +75,7 @@ public function testGetName() {
7075
public function testInitialize() {
7176
$server = $this->createMock(\Sabre\DAV\Server::class);
7277

73-
$plugin = new EnablePlugin($this->config);
78+
$plugin = new EnablePlugin($this->config, $this->birthdayService);
7479

7580
$server->expects($this->at(0))
7681
->method('on')
@@ -93,6 +98,9 @@ public function testHttpPostNoCalendarHome() {
9398
$this->config->expects($this->never())
9499
->method('setUserValue');
95100

101+
$this->birthdayService->expects($this->never())
102+
->method('syncUser');
103+
96104
$this->plugin->httpPost($this->request, $this->response);
97105
}
98106

@@ -124,6 +132,9 @@ public function testHttpPostWrongRequest() {
124132
$this->config->expects($this->never())
125133
->method('setUserValue');
126134

135+
$this->birthdayService->expects($this->never())
136+
->method('syncUser');
137+
127138
$this->plugin->httpPost($this->request, $this->response);
128139
}
129140

@@ -160,6 +171,10 @@ public function testHttpPost() {
160171
->method('setUserValue')
161172
->with('BlaBlub', 'dav', 'generateBirthdayCalendar', 'yes');
162173

174+
$this->birthdayService->expects($this->once())
175+
->method('syncUser')
176+
->with('BlaBlub');
177+
163178
$this->server->httpResponse->expects($this->once())
164179
->method('setStatus')
165180
->with(204);

0 commit comments

Comments
 (0)