Translate contacts birthday - fixes #23982

This commit is contained in:
Thomas Müller 2016-04-14 15:38:00 +02:00
parent 068e73cc47
commit 55735e1450
No known key found for this signature in database
GPG key ID: A943788A3BBEC44C
5 changed files with 54 additions and 17 deletions

View file

@ -22,17 +22,19 @@
namespace OCA\DAV\CalDAV;
use OCA\DAV\DAV\Sharing\IShareable;
use OCP\IL10N;
use Sabre\CalDAV\Backend\BackendInterface;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\PropPatch;
class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
public function __construct(BackendInterface $caldavBackend, $calendarInfo) {
public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) {
parent::__construct($caldavBackend, $calendarInfo);
if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
$this->calendarInfo['{http://sabredav.org/ns}read-only'] = true;
$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
}
}

View file

@ -21,6 +21,7 @@
*/
namespace OCA\DAV\CalDAV;
use Sabre\CalDAV\Backend\BackendInterface;
use Sabre\CalDAV\Backend\NotificationSupport;
use Sabre\CalDAV\Backend\SchedulingSupport;
use Sabre\CalDAV\Backend\SubscriptionSupport;
@ -31,34 +32,42 @@ use Sabre\DAV\Exception\NotFound;
class CalendarHome extends \Sabre\CalDAV\CalendarHome {
/** @var \OCP\IL10N */
private $l10n;
public function __construct(BackendInterface $caldavBackend, $principalInfo) {
parent::__construct($caldavBackend, $principalInfo);
$this->l10n = \OC::$server->getL10N('dav');
}
/**
* @inheritdoc
*/
function getChildren() {
$calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
$objs = [];
$objects = [];
foreach ($calendars as $calendar) {
$objs[] = new Calendar($this->caldavBackend, $calendar);
$objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
}
if ($this->caldavBackend instanceof SchedulingSupport) {
$objs[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
$objs[] = new Outbox($this->principalInfo['uri']);
$objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
$objects[] = new Outbox($this->principalInfo['uri']);
}
// We're adding a notifications node, if it's supported by the backend.
if ($this->caldavBackend instanceof NotificationSupport) {
$objs[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
$objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
}
// If the backend supports subscriptions, we'll add those as well,
if ($this->caldavBackend instanceof SubscriptionSupport) {
foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
$objs[] = new Subscription($this->caldavBackend, $subscription);
$objects[] = new Subscription($this->caldavBackend, $subscription);
}
}
return $objs;
return $objects;
}
/**
@ -79,7 +88,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);
return new Calendar($this->caldavBackend, $calendar, $this->l10n);
}
}
@ -94,4 +103,4 @@ class CalendarHome extends \Sabre\CalDAV\CalendarHome {
throw new NotFound('Node with name \'' . $name . '\' could not be found');
}
}
}

View file

@ -136,14 +136,23 @@ class CalDavBackendTest extends TestCase {
*/
public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead, $groupCanWrite, $add) {
$l10n = $this->getMockBuilder('\OCP\IL10N')
->disableOriginalConstructor()->getMock();
$l10n
->expects($this->any())
->method('t')
->will($this->returnCallback(function ($text, $parameters = array()) {
return vsprintf($text, $parameters);
}));
$calendarId = $this->createTestCalendar();
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertEquals(1, count($books));
$calendar = new Calendar($this->backend, $books[0]);
$calendar = new Calendar($this->backend, $books[0], $l10n);
$this->backend->updateShares($calendar, $add, []);
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1);
$this->assertEquals(1, count($books));
$calendar = new Calendar($this->backend, $books[0]);
$calendar = new Calendar($this->backend, $books[0], $l10n);
$acl = $calendar->getACL();
$this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl);
$this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl);

View file

@ -23,11 +23,27 @@ namespace OCA\DAV\Tests\Unit\CalDAV;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\Calendar;
use OCP\IL10N;
use Sabre\DAV\PropPatch;
use Test\TestCase;
class CalendarTest extends TestCase {
/** @var IL10N */
private $l10n;
public function setUp() {
parent::setUp();
$this->l10n = $this->getMockBuilder('\OCP\IL10N')
->disableOriginalConstructor()->getMock();
$this->l10n
->expects($this->any())
->method('t')
->will($this->returnCallback(function ($text, $parameters = array()) {
return vsprintf($text, $parameters);
}));
}
public function testDelete() {
/** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */
$backend = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend')->disableOriginalConstructor()->getMock();
@ -41,7 +57,7 @@ class CalendarTest extends TestCase {
'id' => 666,
'uri' => 'cal',
];
$c = new Calendar($backend, $calendarInfo);
$c = new Calendar($backend, $calendarInfo, $this->l10n);
$c->delete();
}
@ -61,7 +77,7 @@ class CalendarTest extends TestCase {
'id' => 666,
'uri' => 'cal',
];
$c = new Calendar($backend, $calendarInfo);
$c = new Calendar($backend, $calendarInfo, $this->l10n);
$c->delete();
}
@ -93,7 +109,7 @@ class CalendarTest extends TestCase {
'id' => 666,
'uri' => 'default'
];
$c = new Calendar($backend, $calendarInfo);
$c = new Calendar($backend, $calendarInfo, $this->l10n);
if ($throws) {
$this->setExpectedException('\Sabre\DAV\Exception\Forbidden');
@ -122,7 +138,7 @@ class CalendarTest extends TestCase {
if ($hasOwnerSet) {
$calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1';
}
$c = new Calendar($backend, $calendarInfo);
$c = new Calendar($backend, $calendarInfo, $this->l10n);
$acl = $c->getACL();
$childAcl = $c->getChildACL();

View file

@ -74,6 +74,7 @@ use OC\Security\SecureRandom;
use OC\Security\TrustedDomainHelper;
use OC\Session\CryptoWrapper;
use OC\Tagging\TagMapper;
use OCP\IL10N;
use OCP\IServerContainer;
use OCP\Security\IContentSecurityPolicyManager;
use Symfony\Component\EventDispatcher\EventDispatcher;
@ -857,7 +858,7 @@ class Server extends ServerContainer implements IServerContainer {
*
* @param string $app appid
* @param string $lang
* @return \OC_L10N
* @return IL10N
*/
public function getL10N($app, $lang = null) {
return $this->getL10NFactory()->get($app, $lang);