Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(shares): Don't notify users that "Unshared" a calendar
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Aug 27, 2024
commit 5e861e64908697214a3746c73a66bab176006635
28 changes: 25 additions & 3 deletions lib/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function onTouchCalendarObject(string $action, array $calendarData, array
'hasTime' => $hasTime,
]);

$users = $this->getUsersForShares($shares, $owner);
$users = $this->getUsersForShares($shares, $owner, $calendarData['id']);

foreach ($users as $user) {
if ($user === $currentUser) {
Expand Down Expand Up @@ -210,7 +210,7 @@ protected function getObjectNameAndType(array $objectData) {
* @param string $owner
* @return string[]
*/
protected function getUsersForShares(array $shares, string $owner): array {
protected function getUsersForShares(array $shares, string $owner, int $calendarId): array {
$users = [$owner];
$groups = [];
foreach ($shares as $share) {
Expand All @@ -222,18 +222,40 @@ protected function getUsersForShares(array $shares, string $owner): array {
}
}

$groupAddedUsers = false;
if (!empty($groups)) {
foreach ($groups as $gid) {
$group = $this->groupManager->get($gid);
if ($group instanceof IGroup) {
foreach ($group->getUsers() as $user) {
$groupAddedUsers = true;
$users[] = $user->getUID();
}
}
}
}

return array_unique($users);
$users = array_unique($users);

if (!$groupAddedUsers) {
return $users;
}

/** @var \OCA\DAV\CalDAV\Sharing\Service $service */
$service = \OCP\Server::get(\OCA\DAV\CalDAV\Sharing\Service::class);
$unshares = $service->getUnshares($calendarId);
$usersToRemove = [];
foreach ($unshares as $unshare) {

$prinical = explode('/', $unshare['principaluri']);
if ($prinical[1] === 'users') {
$usersToRemove[] = $prinical[2];
}
}

$users = array_diff($users, $usersToRemove);

return $users;
}

/**
Expand Down