remember when a user deleted their contact birthdays calendar
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
This commit is contained in:
parent
8b22bfea4f
commit
dc34622008
8 changed files with 104 additions and 27 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -38,9 +38,13 @@ 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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,7 +61,7 @@ class CalendarHome extends \Sabre\CalDAV\CalendarHome {
|
|||
$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 +102,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,6 +39,7 @@ class RootCollection extends SimpleCollection {
|
|||
|
||||
public function __construct() {
|
||||
$config = \OC::$server->getConfig();
|
||||
$l10n = \OC::$server->getL10N('dav');
|
||||
$random = \OC::$server->getSecureRandom();
|
||||
$userManager = \OC::$server->getUserManager();
|
||||
$groupManager = \OC::$server->getGroupManager();
|
||||
|
@ -64,7 +65,7 @@ class RootCollection extends SimpleCollection {
|
|||
$caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $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(
|
||||
|
|
|
@ -31,6 +31,7 @@ use DateTime;
|
|||
use DateTimeZone;
|
||||
use OCA\DAV\CalDAV\CalDavBackend;
|
||||
use OCA\DAV\CalDAV\Calendar;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use Sabre\DAV\PropPatch;
|
||||
use Sabre\DAV\Xml\Property\Href;
|
||||
|
@ -131,6 +132,8 @@ class CalDavBackendTest extends AbstractCalDavBackend {
|
|||
return vsprintf($text, $parameters);
|
||||
}));
|
||||
|
||||
$config = $this->createMock(IConfig::class);
|
||||
|
||||
$this->userManager->expects($this->any())
|
||||
->method('userExists')
|
||||
->willReturn(true);
|
||||
|
@ -142,14 +145,14 @@ class CalDavBackendTest extends AbstractCalDavBackend {
|
|||
$calendarId = $this->createTestCalendar();
|
||||
$calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
|
||||
$this->assertCount(1, $calendars);
|
||||
$calendar = new Calendar($this->backend, $calendars[0], $l10n);
|
||||
$calendar = new Calendar($this->backend, $calendars[0], $l10n, $config);
|
||||
$this->dispatcher->expects($this->at(0))
|
||||
->method('dispatch')
|
||||
->with('\OCA\DAV\CalDAV\CalDavBackend::updateShares');
|
||||
$this->backend->updateShares($calendar, $add, []);
|
||||
$calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1);
|
||||
$this->assertCount(1, $calendars);
|
||||
$calendar = new Calendar($this->backend, $calendars[0], $l10n);
|
||||
$calendar = new Calendar($this->backend, $calendars[0], $l10n, $config);
|
||||
$acl = $calendar->getACL();
|
||||
$this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl);
|
||||
$this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl);
|
||||
|
@ -505,8 +508,9 @@ EOD;
|
|||
|
||||
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject $l10n */
|
||||
$l10n = $this->createMock(IL10N::class);
|
||||
$config = $this->createMock(IConfig::class);
|
||||
|
||||
$calendar = new Calendar($this->backend, $calendarInfo, $l10n);
|
||||
$calendar = new Calendar($this->backend, $calendarInfo, $l10n, $config);
|
||||
$calendar->setPublishStatus(true);
|
||||
$this->assertNotEquals(false, $calendar->getPublishStatus());
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ namespace OCA\DAV\Tests\unit\CalDAV;
|
|||
use OCA\DAV\CalDAV\BirthdayService;
|
||||
use OCA\DAV\CalDAV\CalDavBackend;
|
||||
use OCA\DAV\CalDAV\Calendar;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use Sabre\DAV\PropPatch;
|
||||
use Sabre\VObject\Reader;
|
||||
|
@ -39,10 +40,14 @@ class CalendarTest extends TestCase {
|
|||
/** @var IL10N */
|
||||
protected $l10n;
|
||||
|
||||
/** @var IConfig */
|
||||
protected $config;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->l10n = $this->getMockBuilder(IL10N::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->l10n
|
||||
->expects($this->any())
|
||||
->method('t')
|
||||
|
@ -64,7 +69,7 @@ class CalendarTest extends TestCase {
|
|||
'id' => 666,
|
||||
'uri' => 'cal',
|
||||
];
|
||||
$c = new Calendar($backend, $calendarInfo, $this->l10n);
|
||||
$c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
|
||||
$c->delete();
|
||||
}
|
||||
|
||||
|
@ -84,7 +89,7 @@ class CalendarTest extends TestCase {
|
|||
'id' => 666,
|
||||
'uri' => 'cal',
|
||||
];
|
||||
$c = new Calendar($backend, $calendarInfo, $this->l10n);
|
||||
$c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
|
||||
$c->delete();
|
||||
}
|
||||
|
||||
|
@ -94,6 +99,8 @@ class CalendarTest extends TestCase {
|
|||
$backend->expects($this->never())->method('updateShares');
|
||||
$backend->expects($this->never())->method('getShares');
|
||||
|
||||
$this->config->expects($this->never())->method('setUserValue');
|
||||
|
||||
$backend->expects($this->once())->method('deleteCalendar')
|
||||
->with(666);
|
||||
|
||||
|
@ -103,7 +110,28 @@ class CalendarTest extends TestCase {
|
|||
'id' => 666,
|
||||
'uri' => 'cal',
|
||||
];
|
||||
$c = new Calendar($backend, $calendarInfo, $this->l10n);
|
||||
$c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
|
||||
$c->delete();
|
||||
}
|
||||
|
||||
public function testDeleteBirthdayCalendar() {
|
||||
/** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */
|
||||
$backend = $this->createMock(CalDavBackend::class);
|
||||
$backend->expects($this->once())->method('deleteCalendar')
|
||||
->with(666);
|
||||
|
||||
$this->config->expects($this->once())
|
||||
->method('setUserValue')
|
||||
->with('user1', 'dav', 'generateBirthdayCalendar', 'no');
|
||||
|
||||
$calendarInfo = [
|
||||
'{http://owncloud.org/ns}owner-principal' => 'principals/users/user1',
|
||||
'principaluri' => 'principals/users/user1',
|
||||
'id' => 666,
|
||||
'uri' => 'contact_birthdays',
|
||||
];
|
||||
|
||||
$c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
|
||||
$c->delete();
|
||||
}
|
||||
|
||||
|
@ -146,7 +174,7 @@ class CalendarTest extends TestCase {
|
|||
'id' => 666,
|
||||
'uri' => 'default'
|
||||
];
|
||||
$c = new Calendar($backend, $calendarInfo, $this->l10n);
|
||||
$c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
|
||||
$propPatch = new PropPatch($mutations);
|
||||
|
||||
if (!$shared) {
|
||||
|
@ -176,7 +204,7 @@ class CalendarTest extends TestCase {
|
|||
if ($hasOwnerSet) {
|
||||
$calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1';
|
||||
}
|
||||
$c = new Calendar($backend, $calendarInfo, $this->l10n);
|
||||
$c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
|
||||
$acl = $c->getACL();
|
||||
$childAcl = $c->getChildACL();
|
||||
|
||||
|
@ -271,7 +299,7 @@ class CalendarTest extends TestCase {
|
|||
$calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1';
|
||||
|
||||
}
|
||||
$c = new Calendar($backend, $calendarInfo, $this->l10n);
|
||||
$c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
|
||||
$children = $c->getChildren();
|
||||
$this->assertEquals($expectedChildren, count($children));
|
||||
$children = $c->getMultipleChildren(['event-0', 'event-1', 'event-2']);
|
||||
|
@ -355,7 +383,7 @@ EOD;
|
|||
'id' => 666,
|
||||
'uri' => 'cal',
|
||||
];
|
||||
$c = new Calendar($backend, $calendarInfo, $this->l10n);
|
||||
$c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
|
||||
|
||||
$this->assertEquals(count($c->getChildren()), $expectedChildren);
|
||||
|
||||
|
@ -531,9 +559,9 @@ EOD;
|
|||
'uri' => 'cal',
|
||||
];
|
||||
|
||||
$ownerCalendar = new Calendar($backend, $calendarInfoOwner, $this->l10n);
|
||||
$rwCalendar = new Calendar($backend, $calendarInfoSharedRW, $this->l10n);
|
||||
$roCalendar = new Calendar($backend, $calendarInfoSharedRO, $this->l10n);
|
||||
$ownerCalendar = new Calendar($backend, $calendarInfoOwner, $this->l10n, $this->config);
|
||||
$rwCalendar = new Calendar($backend, $calendarInfoSharedRW, $this->l10n, $this->config);
|
||||
$roCalendar = new Calendar($backend, $calendarInfoSharedRO, $this->l10n, $this->config);
|
||||
|
||||
$this->assertEquals(count($ownerCalendar->getChildren()), 2);
|
||||
$this->assertEquals(count($rwCalendar->getChildren()), 2);
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace OCA\DAV\Tests\unit\CalDAV;
|
|||
use OCA\DAV\CalDAV\Calendar;
|
||||
use OCA\DAV\CalDAV\PublicCalendar;
|
||||
use OCA\DAV\Connector\Sabre\Principal;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IL10N;
|
||||
use OCA\DAV\CalDAV\CalDavBackend;
|
||||
|
@ -61,6 +62,8 @@ class PublicCalendarRootTest extends TestCase {
|
|||
protected $userManager;
|
||||
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||
protected $groupManager;
|
||||
/** @var IConfig */
|
||||
protected $config;
|
||||
|
||||
/** @var ISecureRandom */
|
||||
private $random;
|
||||
|
@ -87,11 +90,12 @@ class PublicCalendarRootTest extends TestCase {
|
|||
$this->random,
|
||||
$dispatcher
|
||||
);
|
||||
|
||||
$this->publicCalendarRoot = new PublicCalendarRoot($this->backend);
|
||||
|
||||
$this->l10n = $this->getMockBuilder(IL10N::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
|
||||
$this->publicCalendarRoot = new PublicCalendarRoot($this->backend,
|
||||
$this->l10n, $this->config);
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
|
@ -141,11 +145,11 @@ class PublicCalendarRootTest extends TestCase {
|
|||
$this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []);
|
||||
|
||||
$calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0];
|
||||
$calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n);
|
||||
$calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config);
|
||||
$publicUri = $calendar->setPublishStatus(true);
|
||||
|
||||
$calendarInfo = $this->backend->getPublicCalendar($publicUri);
|
||||
$calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n);
|
||||
$calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config);
|
||||
|
||||
return $calendar;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace OCA\DAV\Tests\unit\CalDAV;
|
|||
|
||||
use OCA\DAV\CalDAV\PublicCalendar;
|
||||
use OCA\DAV\CalDAV\CalDavBackend;
|
||||
use OCP\IConfig;
|
||||
use Sabre\VObject\Reader;
|
||||
|
||||
class PublicCalendarTest extends CalendarTest {
|
||||
|
@ -61,8 +62,10 @@ class PublicCalendarTest extends CalendarTest {
|
|||
'id' => 666,
|
||||
'uri' => 'cal',
|
||||
];
|
||||
/** @var \PHPUnit_Framework_MockObject_MockObject | IConfig $config */
|
||||
$config = $this->createMock(IConfig::class);
|
||||
|
||||
$c = new PublicCalendar($backend, $calendarInfo, $this->l10n);
|
||||
$c = new PublicCalendar($backend, $calendarInfo, $this->l10n, $config);
|
||||
$children = $c->getChildren();
|
||||
$this->assertEquals(2, count($children));
|
||||
$children = $c->getMultipleChildren(['event-0', 'event-1', 'event-2']);
|
||||
|
@ -146,7 +149,9 @@ EOD;
|
|||
'id' => 666,
|
||||
'uri' => 'cal',
|
||||
];
|
||||
$c = new PublicCalendar($backend, $calendarInfo, $this->l10n);
|
||||
/** @var \PHPUnit_Framework_MockObject_MockObject | IConfig $config */
|
||||
$config = $this->createMock(IConfig::class);
|
||||
$c = new PublicCalendar($backend, $calendarInfo, $this->l10n, $config);
|
||||
|
||||
$this->assertEquals(count($c->getChildren()), 2);
|
||||
|
||||
|
|
Loading…
Reference in a new issue