Skip to content

Commit 8593edd

Browse files
authored
Merge pull request #13430 from nextcloud/bugfix/13331/respect-classification-of-calendar-events-in-activity-stream
Respect classification of calendar events in activity stream
2 parents 1c5e43f + 9f2d144 commit 8593edd

File tree

6 files changed

+147
-3
lines changed

6 files changed

+147
-3
lines changed

apps/dav/appinfo/info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<step>OCA\DAV\Migration\CalDAVRemoveEmptyValue</step>
3232
<step>OCA\DAV\Migration\BuildCalendarSearchIndex</step>
3333
<step>OCA\DAV\Migration\RefreshWebcalJobRegistrar</step>
34+
<step>OCA\DAV\Migration\RemoveClassifiedEventActivity</step>
3435
</post-migration>
3536
<live-migration>
3637
<step>OCA\DAV\Migration\ChunkCleanup</step>

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
'OCA\\DAV\\Migration\\ChunkCleanup' => $baseDir . '/../lib/Migration/ChunkCleanup.php',
158158
'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => $baseDir . '/../lib/Migration/FixBirthdayCalendarComponent.php',
159159
'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => $baseDir . '/../lib/Migration/RefreshWebcalJobRegistrar.php',
160+
'OCA\\DAV\\Migration\\RemoveClassifiedEventActivity' => $baseDir . '/../lib/Migration/RemoveClassifiedEventActivity.php',
160161
'OCA\\DAV\\Migration\\Version1004Date20170825134824' => $baseDir . '/../lib/Migration/Version1004Date20170825134824.php',
161162
'OCA\\DAV\\Migration\\Version1004Date20170919104507' => $baseDir . '/../lib/Migration/Version1004Date20170919104507.php',
162163
'OCA\\DAV\\Migration\\Version1004Date20170924124212' => $baseDir . '/../lib/Migration/Version1004Date20170924124212.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class ComposerStaticInitDAV
172172
'OCA\\DAV\\Migration\\ChunkCleanup' => __DIR__ . '/..' . '/../lib/Migration/ChunkCleanup.php',
173173
'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => __DIR__ . '/..' . '/../lib/Migration/FixBirthdayCalendarComponent.php',
174174
'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => __DIR__ . '/..' . '/../lib/Migration/RefreshWebcalJobRegistrar.php',
175+
'OCA\\DAV\\Migration\\RemoveClassifiedEventActivity' => __DIR__ . '/..' . '/../lib/Migration/RemoveClassifiedEventActivity.php',
175176
'OCA\\DAV\\Migration\\Version1004Date20170825134824' => __DIR__ . '/..' . '/../lib/Migration/Version1004Date20170825134824.php',
176177
'OCA\\DAV\\Migration\\Version1004Date20170919104507' => __DIR__ . '/..' . '/../lib/Migration/Version1004Date20170919104507.php',
177178
'OCA\\DAV\\Migration\\Version1004Date20170924124212' => __DIR__ . '/..' . '/../lib/Migration/Version1004Date20170924124212.php',

apps/dav/lib/CalDAV/Activity/Backend.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
use OCA\DAV\CalDAV\Activity\Provider\Calendar;
2929
use OCA\DAV\CalDAV\Activity\Provider\Event;
30+
use OCA\DAV\CalDAV\CalDavBackend;
3031
use OCP\Activity\IEvent;
3132
use OCP\Activity\IManager as IActivityManager;
3233
use OCP\IGroup;
@@ -415,6 +416,7 @@ public function onTouchCalendarObject($action, array $calendarData, array $share
415416
$currentUser = $owner;
416417
}
417418

419+
$classification = $objectData['classification'] ?? CalDavBackend::CLASSIFICATION_PUBLIC;
418420
$object = $this->getObjectNameAndType($objectData);
419421
$action = $action . '_' . $object['type'];
420422

@@ -434,6 +436,11 @@ public function onTouchCalendarObject($action, array $calendarData, array $share
434436
$users[] = $owner;
435437

436438
foreach ($users as $user) {
439+
if ($classification === CalDavBackend::CLASSIFICATION_PRIVATE && $user !== $owner) {
440+
// Private events are only shown to the owner
441+
continue;
442+
}
443+
437444
$event->setAffectedUser($user)
438445
->setSubject(
439446
$user === $currentUser ? $action . '_self' : $action,
@@ -446,7 +453,8 @@ public function onTouchCalendarObject($action, array $calendarData, array $share
446453
],
447454
'object' => [
448455
'id' => $object['id'],
449-
'name' => $object['name'],
456+
'name' => $classification === CalDavBackend::CLASSIFICATION_CONFIDENTIAL && $user !== $owner ? 'Busy' : $object['name'],
457+
'classified' => $classification === CalDavBackend::CLASSIFICATION_CONFIDENTIAL && $user !== $owner,
450458
],
451459
]
452460
);

apps/dav/lib/CalDAV/Activity/Provider/Event.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
namespace OCA\DAV\CalDAV\Activity\Provider;
2525

26+
use OCA\DAV\CalDAV\CalDavBackend;
2627
use OCP\Activity\IEvent;
2728
use OCP\Activity\IEventMerger;
2829
use OCP\Activity\IManager;
@@ -131,14 +132,14 @@ protected function getParameters(IEvent $event) {
131132
return [
132133
'actor' => $this->generateUserParameter($parameters['actor']),
133134
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
134-
'event' => $this->generateObjectParameter($parameters['object']),
135+
'event' => $this->generateClassifiedObjectParameter($parameters['object']),
135136
];
136137
case self::SUBJECT_OBJECT_ADD . '_event_self':
137138
case self::SUBJECT_OBJECT_DELETE . '_event_self':
138139
case self::SUBJECT_OBJECT_UPDATE . '_event_self':
139140
return [
140141
'calendar' => $this->generateCalendarParameter($parameters['calendar'], $this->l),
141-
'event' => $this->generateObjectParameter($parameters['object']),
142+
'event' => $this->generateClassifiedObjectParameter($parameters['object']),
142143
];
143144
}
144145
}
@@ -168,4 +169,12 @@ protected function getParameters(IEvent $event) {
168169

169170
throw new \InvalidArgumentException();
170171
}
172+
173+
private function generateClassifiedObjectParameter(array $eventData) {
174+
$parameter = $this->generateObjectParameter($eventData);
175+
if ($eventData['classified']) {
176+
$parameter['name'] = $this->l->t('Busy');
177+
}
178+
return $parameter;
179+
}
171180
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com>
5+
*
6+
* @license GNU AGPL version 3 or any later version
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
namespace OCA\DAV\Migration;
24+
25+
use OCA\DAV\CalDAV\CalDavBackend;
26+
use OCP\IDBConnection;
27+
use OCP\Migration\IOutput;
28+
use OCP\Migration\IRepairStep;
29+
30+
class RemoveClassifiedEventActivity implements IRepairStep {
31+
32+
/** @var IDBConnection */
33+
private $connection;
34+
35+
public function __construct(IDBConnection $connection) {
36+
$this->connection = $connection;
37+
}
38+
39+
/**
40+
* @inheritdoc
41+
*/
42+
public function getName() {
43+
return 'Remove activity entries of private events';
44+
}
45+
46+
/**
47+
* @inheritdoc
48+
*/
49+
public function run(IOutput $output) {
50+
if (!$this->connection->tableExists('activity')) {
51+
return;
52+
}
53+
54+
$deletedEvents = $this->removePrivateEventActivity();
55+
$deletedEvents += $this->removeConfidentialUncensoredEventActivity();
56+
57+
$output->info("Removed $deletedEvents activity entries");
58+
}
59+
60+
protected function removePrivateEventActivity(): int {
61+
$deletedEvents = 0;
62+
63+
$delete = $this->connection->getQueryBuilder();
64+
$delete->delete('activity')
65+
->where($delete->expr()->neq('affecteduser', $delete->createParameter('owner')))
66+
->andWhere($delete->expr()->eq('object_type', $delete->createParameter('type')))
67+
->andWhere($delete->expr()->eq('object_id', $delete->createParameter('calendar_id')))
68+
->andWhere($delete->expr()->like('subjectparams', $delete->createParameter('event_uid')));
69+
70+
$query = $this->connection->getQueryBuilder();
71+
$query->select('c.principaluri', 'o.calendarid', 'o.uid')
72+
->from('calendarobjects', 'o')
73+
->leftJoin('o', 'calendars', 'c', $query->expr()->eq('c.id', 'o.calendarid'))
74+
->where($query->expr()->eq('o.classification', $query->createNamedParameter(CalDavBackend::CLASSIFICATION_PRIVATE)));
75+
$result = $query->execute();
76+
77+
while ($row = $result->fetch()) {
78+
$delete->setParameter('owner', $this->getPrincipal($row['principaluri']))
79+
->setParameter('type', 'calendar')
80+
->setParameter('calendar_id', $row['calendarid'])
81+
->setParameter('event_uid', '%' . $this->connection->escapeLikeParameter('{"id":"' . $row['uid'] . '"') . '%');
82+
$deletedEvents += $delete->execute();
83+
}
84+
$result->closeCursor();
85+
86+
return $deletedEvents;
87+
}
88+
89+
protected function removeConfidentialUncensoredEventActivity(): int {
90+
$deletedEvents = 0;
91+
92+
$delete = $this->connection->getQueryBuilder();
93+
$delete->delete('activity')
94+
->where($delete->expr()->neq('affecteduser', $delete->createParameter('owner')))
95+
->andWhere($delete->expr()->eq('object_type', $delete->createParameter('type')))
96+
->andWhere($delete->expr()->eq('object_id', $delete->createParameter('calendar_id')))
97+
->andWhere($delete->expr()->like('subjectparams', $delete->createParameter('event_uid')))
98+
->andWhere($delete->expr()->notLike('subjectparams', $delete->createParameter('filtered_name')));
99+
100+
$query = $this->connection->getQueryBuilder();
101+
$query->select('c.principaluri', 'o.calendarid', 'o.uid')
102+
->from('calendarobjects', 'o')
103+
->leftJoin('o', 'calendars', 'c', $query->expr()->eq('c.id', 'o.calendarid'))
104+
->where($query->expr()->eq('o.classification', $query->createNamedParameter(CalDavBackend::CLASSIFICATION_CONFIDENTIAL)));
105+
$result = $query->execute();
106+
107+
while ($row = $result->fetch()) {
108+
$delete->setParameter('owner', $this->getPrincipal($row['principaluri']))
109+
->setParameter('type', 'calendar')
110+
->setParameter('calendar_id', $row['calendarid'])
111+
->setParameter('event_uid', '%' . $this->connection->escapeLikeParameter('{"id":"' . $row['uid'] . '"') . '%')
112+
->setParameter('filtered_name', '%' . $this->connection->escapeLikeParameter('{"id":"' . $row['uid'] . '","name":"Busy"') . '%');
113+
$deletedEvents += $delete->execute();
114+
}
115+
$result->closeCursor();
116+
117+
return $deletedEvents;
118+
}
119+
120+
protected function getPrincipal(string $principalUri): string {
121+
$uri = explode('/', $principalUri);
122+
return $uri[2];
123+
}
124+
}

0 commit comments

Comments
 (0)