diff options
Diffstat (limited to 'apps/dav/lib/caldav/birthdayservice.php')
-rw-r--r-- | apps/dav/lib/caldav/birthdayservice.php | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/apps/dav/lib/caldav/birthdayservice.php b/apps/dav/lib/caldav/birthdayservice.php index 7fca4dc8c64..31897130ca7 100644 --- a/apps/dav/lib/caldav/birthdayservice.php +++ b/apps/dav/lib/caldav/birthdayservice.php @@ -23,6 +23,7 @@ namespace OCA\DAV\CalDAV; use Exception; use OCA\DAV\CardDAV\CardDavBackend; +use OCA\DAV\DAV\GroupPrincipalBackend; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Reader; @@ -30,15 +31,20 @@ class BirthdayService { const BIRTHDAY_CALENDAR_URI = 'contact_birthdays'; + /** @var GroupPrincipalBackend */ + private $principalBackend; + /** * BirthdayService constructor. * * @param CalDavBackend $calDavBackEnd * @param CardDavBackend $cardDavBackEnd + * @param GroupPrincipalBackend $principalBackend */ - public function __construct($calDavBackEnd, $cardDavBackEnd) { + public function __construct($calDavBackEnd, $cardDavBackEnd, $principalBackend) { $this->calDavBackEnd = $calDavBackEnd; $this->cardDavBackEnd = $cardDavBackEnd; + $this->principalBackend = $principalBackend; } /** @@ -48,14 +54,7 @@ class BirthdayService { */ public function onCardChanged($addressBookId, $cardUri, $cardData) { - $shares = $this->cardDavBackEnd->getShares($addressBookId); - // TODO: resolve group shares - $shares = array_filter($shares, function($share) { - return !$share['{http://owncloud.org/ns}group-share']; - }); - $targetPrincipals = array_map(function($share) { - return $share['{http://owncloud.org/ns}principal']; - }, $shares); + $targetPrincipals = $this->getAllAffectedPrincipals($addressBookId); $book = $this->cardDavBackEnd->getAddressBookById($addressBookId); $targetPrincipals[] = $book['principaluri']; @@ -85,15 +84,7 @@ class BirthdayService { * @param string $cardUri */ public function onCardDeleted($addressBookId, $cardUri) { - $shares = $this->cardDavBackEnd->getShares($addressBookId); - // TODO: resolve group shares - $shares = array_filter($shares, function($share) { - return !$share['{http://owncloud.org/ns}group-share']; - }); - $targetPrincipals = array_map(function($share) { - return $share['href']; - }, $shares); - + $targetPrincipals = $this->getAllAffectedPrincipals($addressBookId); $book = $this->cardDavBackEnd->getAddressBookById($addressBookId); $targetPrincipals[] = $book['principaluri']; foreach ($targetPrincipals as $principalUri) { @@ -207,4 +198,24 @@ class BirthdayService { return false; } + /** + * @param $addressBookId + * @return mixed + */ + protected function getAllAffectedPrincipals($addressBookId) { + $targetPrincipals = []; + $shares = $this->cardDavBackEnd->getShares($addressBookId); + foreach ($shares as $share) { + if ($share['{http://owncloud.org/ns}group-share']) { + $users = $this->principalBackend->getGroupMemberSet($share['{http://owncloud.org/ns}principal']); + foreach ($users as $user) { + $targetPrincipals[] = $user['uri']; + } + } else { + $targetPrincipals[] = $share['{http://owncloud.org/ns}principal']; + } + } + return array_values(array_unique($targetPrincipals, SORT_STRING)); + } + } |