create a user's birthday calendar right after they requested it
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
This commit is contained in:
parent
4d5ed1372a
commit
a87d986041
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
namespace OCA\DAV\CalDAV\BirthdayCalendar;
|
namespace OCA\DAV\CalDAV\BirthdayCalendar;
|
||||||
|
|
||||||
|
use OCA\DAV\CalDAV\BirthdayService;
|
||||||
use OCA\DAV\CalDAV\CalendarHome;
|
use OCA\DAV\CalDAV\CalendarHome;
|
||||||
use Sabre\DAV\Server;
|
use Sabre\DAV\Server;
|
||||||
use Sabre\DAV\ServerPlugin;
|
use Sabre\DAV\ServerPlugin;
|
||||||
|
@ -44,6 +45,11 @@ class EnablePlugin extends ServerPlugin {
|
||||||
*/
|
*/
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var BirthdayService
|
||||||
|
*/
|
||||||
|
protected $birthdayService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Server
|
* @var Server
|
||||||
*/
|
*/
|
||||||
|
@ -53,9 +59,11 @@ class EnablePlugin extends ServerPlugin {
|
||||||
* PublishPlugin constructor.
|
* PublishPlugin constructor.
|
||||||
*
|
*
|
||||||
* @param IConfig $config
|
* @param IConfig $config
|
||||||
|
* @param BirthdayService $birthdayService
|
||||||
*/
|
*/
|
||||||
public function __construct(IConfig $config) {
|
public function __construct(IConfig $config, BirthdayService $birthdayService) {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
$this->birthdayService = $birthdayService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,6 +130,7 @@ class EnablePlugin extends ServerPlugin {
|
||||||
$userId = substr($principalUri, 17);
|
$userId = substr($principalUri, 17);
|
||||||
|
|
||||||
$this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
|
$this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes');
|
||||||
|
$this->birthdayService->syncUser($userId);
|
||||||
|
|
||||||
$this->server->httpResponse->setStatus(204);
|
$this->server->httpResponse->setStatus(204);
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
namespace OCA\DAV;
|
namespace OCA\DAV;
|
||||||
|
|
||||||
use OC\AppFramework\Utility\TimeFactory;
|
use OC\AppFramework\Utility\TimeFactory;
|
||||||
|
use OCA\DAV\CalDAV\BirthdayService;
|
||||||
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
|
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
|
||||||
use OCA\DAV\CardDAV\ImageExportPlugin;
|
use OCA\DAV\CardDAV\ImageExportPlugin;
|
||||||
use OCA\DAV\CardDAV\PhotoCache;
|
use OCA\DAV\CardDAV\PhotoCache;
|
||||||
|
@ -260,7 +261,8 @@ class Server {
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
$this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin(
|
$this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin(
|
||||||
\OC::$server->getConfig()
|
\OC::$server->getConfig(),
|
||||||
|
\OC::$server->query(BirthdayService::class)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
namespace OCA\DAV\Tests\unit\CalDAV\BirthdayCalendar;
|
namespace OCA\DAV\Tests\unit\CalDAV\BirthdayCalendar;
|
||||||
|
|
||||||
use OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin;
|
use OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin;
|
||||||
|
use OCA\DAV\CalDAV\BirthdayService;
|
||||||
use OCA\DAV\CalDAV\Calendar;
|
use OCA\DAV\CalDAV\Calendar;
|
||||||
use OCA\DAV\CalDAV\CalendarHome;
|
use OCA\DAV\CalDAV\CalendarHome;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
|
@ -35,6 +36,9 @@ class EnablePluginTest extends TestCase {
|
||||||
/** @var \OCP\IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
|
/** @var BirthdayService |\PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
protected $birthdayService;
|
||||||
|
|
||||||
/** @var \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin $plugin */
|
/** @var \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin $plugin */
|
||||||
protected $plugin;
|
protected $plugin;
|
||||||
|
|
||||||
|
@ -51,8 +55,9 @@ class EnablePluginTest extends TestCase {
|
||||||
$this->server->xml = $this->createMock(\Sabre\DAV\Xml\Service::class);
|
$this->server->xml = $this->createMock(\Sabre\DAV\Xml\Service::class);
|
||||||
|
|
||||||
$this->config = $this->createMock(IConfig::class);
|
$this->config = $this->createMock(IConfig::class);
|
||||||
|
$this->birthdayService = $this->createMock(BirthdayService::class);
|
||||||
|
|
||||||
$this->plugin = new EnablePlugin($this->config);
|
$this->plugin = new EnablePlugin($this->config, $this->birthdayService);
|
||||||
$this->plugin->initialize($this->server);
|
$this->plugin->initialize($this->server);
|
||||||
|
|
||||||
$this->request = $this->createMock(\Sabre\HTTP\RequestInterface::class);
|
$this->request = $this->createMock(\Sabre\HTTP\RequestInterface::class);
|
||||||
|
@ -70,7 +75,7 @@ class EnablePluginTest extends TestCase {
|
||||||
public function testInitialize() {
|
public function testInitialize() {
|
||||||
$server = $this->createMock(\Sabre\DAV\Server::class);
|
$server = $this->createMock(\Sabre\DAV\Server::class);
|
||||||
|
|
||||||
$plugin = new EnablePlugin($this->config);
|
$plugin = new EnablePlugin($this->config, $this->birthdayService);
|
||||||
|
|
||||||
$server->expects($this->at(0))
|
$server->expects($this->at(0))
|
||||||
->method('on')
|
->method('on')
|
||||||
|
@ -93,6 +98,9 @@ class EnablePluginTest extends TestCase {
|
||||||
$this->config->expects($this->never())
|
$this->config->expects($this->never())
|
||||||
->method('setUserValue');
|
->method('setUserValue');
|
||||||
|
|
||||||
|
$this->birthdayService->expects($this->never())
|
||||||
|
->method('syncUser');
|
||||||
|
|
||||||
$this->plugin->httpPost($this->request, $this->response);
|
$this->plugin->httpPost($this->request, $this->response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,6 +132,9 @@ class EnablePluginTest extends TestCase {
|
||||||
$this->config->expects($this->never())
|
$this->config->expects($this->never())
|
||||||
->method('setUserValue');
|
->method('setUserValue');
|
||||||
|
|
||||||
|
$this->birthdayService->expects($this->never())
|
||||||
|
->method('syncUser');
|
||||||
|
|
||||||
$this->plugin->httpPost($this->request, $this->response);
|
$this->plugin->httpPost($this->request, $this->response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,6 +171,10 @@ class EnablePluginTest extends TestCase {
|
||||||
->method('setUserValue')
|
->method('setUserValue')
|
||||||
->with('BlaBlub', 'dav', 'generateBirthdayCalendar', 'yes');
|
->with('BlaBlub', 'dav', 'generateBirthdayCalendar', 'yes');
|
||||||
|
|
||||||
|
$this->birthdayService->expects($this->once())
|
||||||
|
->method('syncUser')
|
||||||
|
->with('BlaBlub');
|
||||||
|
|
||||||
$this->server->httpResponse->expects($this->once())
|
$this->server->httpResponse->expects($this->once())
|
||||||
->method('setStatus')
|
->method('setStatus')
|
||||||
->with(204);
|
->with(204);
|
||||||
|
|
Loading…
Reference in New Issue