Merge pull request #6849 from nextcloud/fix-missing-translation-of-personal-calendar-in-activity

Fix missing translation of "Personal" calendar in activities
This commit is contained in:
blizzz 2017-10-31 15:05:26 +01:00 committed by GitHub
commit b3ff9a2248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 235 additions and 33 deletions

View File

@ -174,6 +174,12 @@ class Provider implements IProvider {
}
// Fix subjects from 12.0.3 and older
//
// Do NOT Remove unless necessary
// Removing this will break parsing of activities that were created on
// Nextcloud 12, so we should keep this as long as it's acceptable.
// Otherwise if people upgrade over multiple releases in a short period,
// they will get the dead entries in their stream.
return [
'actor' => $subjectParameters[0],
'fileId' => (int) $event->getObjectId(),

View File

@ -135,8 +135,12 @@ class Backend {
->setSubject(
$user === $currentUser ? $action . '_self' : $action,
[
$currentUser,
$calendarData['{DAV:}displayname'],
'actor' => $currentUser,
'calendar' => [
'id' => (int) $calendarData['id'],
'uri' => $calendarData['uri'],
'name' => $calendarData['{DAV:}displayname'],
],
]
);
$this->activityManager->publish($event);
@ -187,8 +191,13 @@ class Backend {
if ($owner !== $principal[2]) {
$parameters = [
$principal[2],
$calendarData['{DAV:}displayname'],
'actor' => $event->getAuthor(),
'calendar' => [
'id' => (int) $calendarData['id'],
'uri' => $calendarData['uri'],
'name' => $calendarData['{DAV:}displayname'],
],
'user' => $principal[2],
];
if ($owner === $event->getAuthor()) {
@ -201,7 +210,6 @@ class Backend {
$this->activityManager->publish($event);
$subject = Calendar::SUBJECT_UNSHARE_USER . '_by';
$parameters[] = $event->getAuthor();
}
$event->setAffectedUser($owner)
@ -212,8 +220,13 @@ class Backend {
$this->triggerActivityGroup($principal[2], $event, $calendarData, Calendar::SUBJECT_UNSHARE_USER);
$parameters = [
$principal[2],
$calendarData['{DAV:}displayname'],
'actor' => $event->getAuthor(),
'calendar' => [
'id' => (int) $calendarData['id'],
'uri' => $calendarData['uri'],
'name' => $calendarData['{DAV:}displayname'],
],
'group' => $principal[2],
];
if ($owner === $event->getAuthor()) {
@ -224,7 +237,6 @@ class Backend {
$this->activityManager->publish($event);
$subject = Calendar::SUBJECT_UNSHARE_GROUP . '_by';
$parameters[] = $event->getAuthor();
}
$event->setAffectedUser($owner)
@ -250,8 +262,13 @@ class Backend {
if ($owner !== $principal[2]) {
$parameters = [
$principal[2],
$calendarData['{DAV:}displayname'],
'actor' => $event->getAuthor(),
'calendar' => [
'id' => (int) $calendarData['id'],
'uri' => $calendarData['uri'],
'name' => $calendarData['{DAV:}displayname'],
],
'user' => $principal[2],
];
if ($owner === $event->getAuthor()) {
@ -262,7 +279,6 @@ class Backend {
$this->activityManager->publish($event);
$subject = Calendar::SUBJECT_SHARE_USER . '_by';
$parameters[] = $event->getAuthor();
}
$event->setAffectedUser($owner)
@ -273,8 +289,13 @@ class Backend {
$this->triggerActivityGroup($principal[2], $event, $calendarData, Calendar::SUBJECT_SHARE_USER);
$parameters = [
$principal[2],
$calendarData['{DAV:}displayname'],
'actor' => $event->getAuthor(),
'calendar' => [
'id' => (int) $calendarData['id'],
'uri' => $calendarData['uri'],
'name' => $calendarData['{DAV:}displayname'],
],
'group' => $principal[2],
];
if ($owner === $event->getAuthor()) {
@ -285,7 +306,6 @@ class Backend {
$this->activityManager->publish($event);
$subject = Calendar::SUBJECT_SHARE_GROUP . '_by';
$parameters[] = $event->getAuthor();
}
$event->setAffectedUser($owner)
@ -347,8 +367,12 @@ class Backend {
->setSubject(
$user === $event->getAuthor() && $subjectSelf ? $subjectSelf : $subject,
[
$event->getAuthor(),
$properties['{DAV:}displayname'],
'actor' => $event->getAuthor(),
'calendar' => [
'id' => (int) $properties['id'],
'uri' => $properties['uri'],
'name' => $properties['{DAV:}displayname'],
],
]
);
@ -401,9 +425,13 @@ class Backend {
->setSubject(
$user === $currentUser ? $action . '_self' : $action,
[
$currentUser,
$calendarData['{DAV:}displayname'],
[
'actor' => $event->getAuthor(),
'calendar' => [
'id' => (int) $calendarData['id'],
'uri' => $calendarData['uri'],
'name' => $calendarData['{DAV:}displayname'],
],
'object' => [
'id' => $object['id'],
'name' => $object['name'],
],

View File

@ -21,8 +21,10 @@
namespace OCA\DAV\CalDAV\Activity\Provider;
use OCA\DAV\CalDAV\CalDavBackend;
use OCP\Activity\IEvent;
use OCP\Activity\IProvider;
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
@ -64,7 +66,7 @@ abstract class Base implements IProvider {
protected function generateObjectParameter($eventData) {
if (!is_array($eventData) || !isset($eventData['id']) || !isset($eventData['name'])) {
throw new \InvalidArgumentException();
};
}
return [
'type' => 'calendar-event',
@ -73,12 +75,34 @@ abstract class Base implements IProvider {
];
}
/**
* @param array $data
* @param IL10N $l
* @return array
*/
protected function generateCalendarParameter($data, IL10N $l) {
if ($data['uri'] === CalDavBackend::PERSONAL_CALENDAR_URI &&
$data['name'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
return [
'type' => 'calendar',
'id' => $data['id'],
'name' => $l->t('Personal'),
];
}
return [
'type' => 'calendar',
'id' => $data['id'],
'name' => $data['name'],
];
}
/**
* @param int $id
* @param string $name
* @return array
*/
protected function generateCalendarParameter($id, $name) {
protected function generateLegacyCalendarParameter($id, $name) {
return [
'type' => 'calendar',
'id' => $id,

View File

@ -156,6 +156,56 @@ class Calendar extends Base {
$subject = $event->getSubject();
$parameters = $event->getSubjectParameters();
// Nextcloud 13+
if (isset($parameters['calendar'])) {
switch ($subject) {
case self::SUBJECT_ADD:
case self::SUBJECT_ADD . '_self':
case self::SUBJECT_DELETE:
case self::SUBJECT_DELETE . '_self':
case self::SUBJECT_UPDATE:
case self::SUBJECT_UPDATE . '_self':
case self::SUBJECT_SHARE_USER:
case self::SUBJECT_UNSHARE_USER:
case self::SUBJECT_UNSHARE_USER . '_self':
return [
'actor' => $this->generateUserParameter($parameters['actor']),
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
];
case self::SUBJECT_SHARE_USER . '_you':
case self::SUBJECT_UNSHARE_USER . '_you':
return [
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
'user' => $this->generateUserParameter($parameters['user']),
];
case self::SUBJECT_SHARE_USER . '_by':
case self::SUBJECT_UNSHARE_USER . '_by':
return [
'actor' => $this->generateUserParameter($parameters['actor']),
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
'user' => $this->generateUserParameter($parameters['user']),
];
case self::SUBJECT_SHARE_GROUP . '_you':
case self::SUBJECT_UNSHARE_GROUP . '_you':
return [
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
'group' => $this->generateGroupParameter($parameters['group']),
];
case self::SUBJECT_SHARE_GROUP . '_by':
case self::SUBJECT_UNSHARE_GROUP . '_by':
return [
'actor' => $this->generateUserParameter($parameters['actor']),
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
'group' => $this->generateGroupParameter($parameters['group']),
];
}
}
// Legacy - Do NOT Remove unless necessary
// Removing this will break parsing of activities that were created on
// Nextcloud 12, so we should keep this as long as it's acceptable.
// Otherwise if people upgrade over multiple releases in a short period,
// they will get the dead entries in their stream.
switch ($subject) {
case self::SUBJECT_ADD:
case self::SUBJECT_ADD . '_self':
@ -168,32 +218,32 @@ class Calendar extends Base {
case self::SUBJECT_UNSHARE_USER . '_self':
return [
'actor' => $this->generateUserParameter($parameters[0]),
'calendar' => $this->generateCalendarParameter((int)$event->getObjectId(), $parameters[1]),
'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]),
];
case self::SUBJECT_SHARE_USER . '_you':
case self::SUBJECT_UNSHARE_USER . '_you':
return [
'user' => $this->generateUserParameter($parameters[0]),
'calendar' => $this->generateCalendarParameter((int)$event->getObjectId(), $parameters[1]),
'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]),
];
case self::SUBJECT_SHARE_USER . '_by':
case self::SUBJECT_UNSHARE_USER . '_by':
return [
'user' => $this->generateUserParameter($parameters[0]),
'calendar' => $this->generateCalendarParameter((int)$event->getObjectId(), $parameters[1]),
'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]),
'actor' => $this->generateUserParameter($parameters[2]),
];
case self::SUBJECT_SHARE_GROUP . '_you':
case self::SUBJECT_UNSHARE_GROUP . '_you':
return [
'group' => $this->generateGroupParameter($parameters[0]),
'calendar' => $this->generateCalendarParameter((int)$event->getObjectId(), $parameters[1]),
'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]),
];
case self::SUBJECT_SHARE_GROUP . '_by':
case self::SUBJECT_UNSHARE_GROUP . '_by':
return [
'group' => $this->generateGroupParameter($parameters[0]),
'calendar' => $this->generateCalendarParameter((int)$event->getObjectId(), $parameters[1]),
'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]),
'actor' => $this->generateUserParameter($parameters[2]),
];
}

View File

@ -118,20 +118,46 @@ class Event extends Base {
$subject = $event->getSubject();
$parameters = $event->getSubjectParameters();
// Nextcloud 13+
if (isset($parameters['calendar'])) {
switch ($subject) {
case self::SUBJECT_OBJECT_ADD . '_event':
case self::SUBJECT_OBJECT_DELETE . '_event':
case self::SUBJECT_OBJECT_UPDATE . '_event':
return [
'actor' => $this->generateUserParameter($parameters['actor']),
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
'event' => $this->generateObjectParameter($parameters['object']),
];
case self::SUBJECT_OBJECT_ADD . '_event_self':
case self::SUBJECT_OBJECT_DELETE . '_event_self':
case self::SUBJECT_OBJECT_UPDATE . '_event_self':
return [
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
'event' => $this->generateObjectParameter($parameters['object']),
];
}
}
// Legacy - Do NOT Remove unless necessary
// Removing this will break parsing of activities that were created on
// Nextcloud 12, so we should keep this as long as it's acceptable.
// Otherwise if people upgrade over multiple releases in a short period,
// they will get the dead entries in their stream.
switch ($subject) {
case self::SUBJECT_OBJECT_ADD . '_event':
case self::SUBJECT_OBJECT_DELETE . '_event':
case self::SUBJECT_OBJECT_UPDATE . '_event':
return [
'actor' => $this->generateUserParameter($parameters[0]),
'calendar' => $this->generateCalendarParameter((int)$event->getObjectId(), $parameters[1]),
'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]),
'event' => $this->generateObjectParameter($parameters[2]),
];
case self::SUBJECT_OBJECT_ADD . '_event_self':
case self::SUBJECT_OBJECT_DELETE . '_event_self':
case self::SUBJECT_OBJECT_UPDATE . '_event_self':
return [
'calendar' => $this->generateCalendarParameter((int)$event->getObjectId(), $parameters[1]),
'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]),
'event' => $this->generateObjectParameter($parameters[2]),
];
}

View File

@ -87,6 +87,36 @@ class Todo extends Event {
$subject = $event->getSubject();
$parameters = $event->getSubjectParameters();
// Nextcloud 13+
if (isset($parameters['calendar'])) {
switch ($subject) {
case self::SUBJECT_OBJECT_ADD . '_todo':
case self::SUBJECT_OBJECT_DELETE . '_todo':
case self::SUBJECT_OBJECT_UPDATE . '_todo':
case self::SUBJECT_OBJECT_UPDATE . '_todo_completed':
case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action':
return [
'actor' => $this->generateUserParameter($parameters['actor']),
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
'todo' => $this->generateObjectParameter($parameters['object']),
];
case self::SUBJECT_OBJECT_ADD . '_todo_self':
case self::SUBJECT_OBJECT_DELETE . '_todo_self':
case self::SUBJECT_OBJECT_UPDATE . '_todo_self':
case self::SUBJECT_OBJECT_UPDATE . '_todo_completed_self':
case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action_self':
return [
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
'todo' => $this->generateObjectParameter($parameters['object']),
];
}
}
// Legacy - Do NOT Remove unless necessary
// Removing this will break parsing of activities that were created on
// Nextcloud 12, so we should keep this as long as it's acceptable.
// Otherwise if people upgrade over multiple releases in a short period,
// they will get the dead entries in their stream.
switch ($subject) {
case self::SUBJECT_OBJECT_ADD . '_todo':
case self::SUBJECT_OBJECT_DELETE . '_todo':
@ -95,7 +125,7 @@ class Todo extends Event {
case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action':
return [
'actor' => $this->generateUserParameter($parameters[0]),
'calendar' => $this->generateCalendarParameter((int)$event->getObjectId(), $parameters[1]),
'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]),
'todo' => $this->generateObjectParameter($parameters[2]),
];
case self::SUBJECT_OBJECT_ADD . '_todo_self':
@ -104,7 +134,7 @@ class Todo extends Event {
case self::SUBJECT_OBJECT_UPDATE . '_todo_completed_self':
case self::SUBJECT_OBJECT_UPDATE . '_todo_needs_action_self':
return [
'calendar' => $this->generateCalendarParameter((int)$event->getObjectId(), $parameters[1]),
'calendar' => $this->generateLegacyCalendarParameter((int)$event->getObjectId(), $parameters[1]),
'todo' => $this->generateObjectParameter($parameters[2]),
];
}

View File

@ -108,11 +108,13 @@ class BackendTest extends TestCase {
[Calendar::SUBJECT_ADD, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'uri' => 'this-uri',
'{DAV:}displayname' => 'Name of calendar',
], [], [], '', 'admin', null, ['admin']],
[Calendar::SUBJECT_ADD, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'uri' => 'this-uri',
'{DAV:}displayname' => 'Name of calendar',
], [], [], 'test2', 'test2', null, ['admin']],
@ -122,17 +124,20 @@ class BackendTest extends TestCase {
[Calendar::SUBJECT_UPDATE, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'uri' => 'this-uri',
'{DAV:}displayname' => 'Name of calendar',
], ['shares'], [], '', 'admin', null, ['admin']],
// Visible change
[Calendar::SUBJECT_UPDATE, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'uri' => 'this-uri',
'{DAV:}displayname' => 'Name of calendar',
], ['shares'], ['{DAV:}displayname' => 'Name'], '', 'admin', ['user1'], ['user1', 'admin']],
[Calendar::SUBJECT_UPDATE, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'uri' => 'this-uri',
'{DAV:}displayname' => 'Name of calendar',
], ['shares'], ['{DAV:}displayname' => 'Name'], 'test2', 'test2', ['user1'], ['user1', 'admin']],
@ -141,16 +146,19 @@ class BackendTest extends TestCase {
[Calendar::SUBJECT_DELETE, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'uri' => 'this-uri',
'{DAV:}displayname' => 'Name of calendar',
], ['shares'], [], '', 'admin', [], ['admin']],
[Calendar::SUBJECT_DELETE, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'uri' => 'this-uri',
'{DAV:}displayname' => 'Name of calendar',
], ['shares'], [], '', 'admin', ['user1'], ['user1', 'admin']],
[Calendar::SUBJECT_DELETE, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'uri' => 'this-uri',
'{DAV:}displayname' => 'Name of calendar',
], ['shares'], [], 'test2', 'test2', ['user1'], ['user1', 'admin']],
];

View File

@ -24,6 +24,7 @@ namespace OCA\DAV\Tests\unit\CalDAV\Activity\Provider;
use OCA\DAV\CalDAV\Activity\Provider\Base;
use OCP\Activity\IEvent;
use OCP\Activity\IProvider;
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
use Test\TestCase;
@ -112,6 +113,35 @@ class BaseTest extends TestCase {
}
public function dataGenerateCalendarParameter() {
return [
[['id' => 23, 'uri' => 'foo', 'name' => 'bar'], 'bar'],
[['id' => 42, 'uri' => 'foo', 'name' => 'Personal'], 'Personal'],
[['id' => 42, 'uri' => 'personal', 'name' => 'bar'], 'bar'],
[['id' => 42, 'uri' => 'personal', 'name' => 'Personal'], 't(Personal)'],
];
}
/**
* @dataProvider dataGenerateCalendarParameter
* @param array $data
* @param string $name
*/
public function testGenerateCalendarParameter(array $data, $name) {
$l = $this->createMock(IL10N::class);
$l->expects($this->any())
->method('t')
->willReturnCallback(function($string, $args) {
return 't(' . vsprintf($string, $args) . ')';
});
$this->assertEquals([
'type' => 'calendar',
'id' => $data['id'],
'name' => $name,
], $this->invokePrivate($this->provider, 'generateCalendarParameter', [$data, $l]));
}
public function dataGenerateLegacyCalendarParameter() {
return [
[23, 'c1'],
[42, 'c2'],
@ -119,16 +149,16 @@ class BaseTest extends TestCase {
}
/**
* @dataProvider dataGenerateCalendarParameter
* @dataProvider dataGenerateLegacyCalendarParameter
* @param int $id
* @param string $name
*/
public function testGenerateCalendarParameter($id, $name) {
public function testGenerateLegacyCalendarParameter($id, $name) {
$this->assertEquals([
'type' => 'calendar',
'id' => $id,
'name' => $name,
], $this->invokePrivate($this->provider, 'generateCalendarParameter', [$id, $name]));
], $this->invokePrivate($this->provider, 'generateLegacyCalendarParameter', [$id, $name]));
}
public function dataGenerateGroupParameter() {