-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix display of remote users in incoming share notifications #22062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
b79e34c
04521c6
ac3d8d1
79027c8
a0ee4b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,13 +159,13 @@ public function getAddressBooksForUser($principalUri) { | |
| $result = $query->execute(); | ||
| while ($row = $result->fetch()) { | ||
| $addressBooks[$row['id']] = [ | ||
| 'id' => $row['id'], | ||
| 'id' => $row['id'], | ||
| 'uri' => $row['uri'], | ||
| 'principaluri' => $this->convertPrincipal($row['principaluri'], false), | ||
| '{DAV:}displayname' => $row['displayname'], | ||
| '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], | ||
| '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], | ||
| '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', | ||
| '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', | ||
| ]; | ||
|
|
||
| $this->addOwnerPrincipal($addressBooks[$row['id']]); | ||
|
|
@@ -179,7 +179,7 @@ public function getAddressBooksForUser($principalUri) { | |
| $principals = array_map(function ($principal) { | ||
| return urldecode($principal); | ||
| }, $principals); | ||
| $principals[]= $principalUri; | ||
| $principals[] = $principalUri; | ||
|
|
||
| $query = $this->db->getQueryBuilder(); | ||
| $result = $query->select(['a.id', 'a.uri', 'a.displayname', 'a.principaluri', 'a.description', 'a.synctoken', 's.access']) | ||
|
|
@@ -197,7 +197,7 @@ public function getAddressBooksForUser($principalUri) { | |
| continue; | ||
| } | ||
|
|
||
| $readOnly = (int) $row['access'] === Backend::ACCESS_READ; | ||
| $readOnly = (int)$row['access'] === Backend::ACCESS_READ; | ||
| if (isset($addressBooks[$row['id']])) { | ||
| if ($readOnly) { | ||
| // New share can not have more permissions then the old one. | ||
|
|
@@ -215,13 +215,13 @@ public function getAddressBooksForUser($principalUri) { | |
| $displayName = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; | ||
|
|
||
| $addressBooks[$row['id']] = [ | ||
| 'id' => $row['id'], | ||
| 'id' => $row['id'], | ||
| 'uri' => $uri, | ||
| 'principaluri' => $principalUriOriginal, | ||
| '{DAV:}displayname' => $displayName, | ||
| '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], | ||
| '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], | ||
| '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', | ||
| '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', | ||
nickvergessen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'], | ||
| $readOnlyPropertyName => $readOnly, | ||
| ]; | ||
|
|
@@ -237,21 +237,21 @@ public function getUsersOwnAddressBooks($principalUri) { | |
| $principalUri = $this->convertPrincipal($principalUri, true); | ||
| $query = $this->db->getQueryBuilder(); | ||
| $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken']) | ||
| ->from('addressbooks') | ||
| ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); | ||
| ->from('addressbooks') | ||
| ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); | ||
|
|
||
| $addressBooks = []; | ||
|
|
||
| $result = $query->execute(); | ||
| while ($row = $result->fetch()) { | ||
| $addressBooks[$row['id']] = [ | ||
| 'id' => $row['id'], | ||
| 'id' => $row['id'], | ||
| 'uri' => $row['uri'], | ||
| 'principaluri' => $this->convertPrincipal($row['principaluri'], false), | ||
| '{DAV:}displayname' => $row['displayname'], | ||
| '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], | ||
| '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], | ||
| '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', | ||
| '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', | ||
nickvergessen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ]; | ||
|
|
||
| $this->addOwnerPrincipal($addressBooks[$row['id']]); | ||
|
|
@@ -292,13 +292,13 @@ public function getAddressBookById($addressBookId) { | |
| } | ||
|
|
||
| $addressBook = [ | ||
| 'id' => $row['id'], | ||
| 'id' => $row['id'], | ||
| 'uri' => $row['uri'], | ||
| 'principaluri' => $row['principaluri'], | ||
| '{DAV:}displayname' => $row['displayname'], | ||
| '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], | ||
| '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], | ||
| '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', | ||
| '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', | ||
nickvergessen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ]; | ||
|
|
||
| $this->addOwnerPrincipal($addressBook); | ||
|
|
@@ -326,13 +326,13 @@ public function getAddressBooksByUri($principal, $addressBookUri) { | |
| } | ||
|
|
||
| $addressBook = [ | ||
| 'id' => $row['id'], | ||
| 'id' => $row['id'], | ||
| 'uri' => $row['uri'], | ||
| 'principaluri' => $row['principaluri'], | ||
| '{DAV:}displayname' => $row['displayname'], | ||
| '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'], | ||
| '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], | ||
| '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', | ||
| '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', | ||
nickvergessen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ]; | ||
|
|
||
| $this->addOwnerPrincipal($addressBook); | ||
|
|
@@ -367,7 +367,7 @@ public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatc | |
| */ | ||
| $propPatch->handle($supportedProperties, function ($mutations) use ($addressBookId) { | ||
| $updates = []; | ||
| foreach ($mutations as $property=>$newValue) { | ||
| foreach ($mutations as $property => $newValue) { | ||
| switch ($property) { | ||
| case '{DAV:}displayname': | ||
| $updates['displayname'] = $newValue; | ||
|
|
@@ -380,11 +380,11 @@ public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatc | |
| $query = $this->db->getQueryBuilder(); | ||
| $query->update('addressbooks'); | ||
|
|
||
| foreach ($updates as $key=>$value) { | ||
| foreach ($updates as $key => $value) { | ||
| $query->set($key, $query->createNamedParameter($value)); | ||
| } | ||
| $query->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId))) | ||
| ->execute(); | ||
| ->execute(); | ||
|
|
||
| $this->addChange($addressBookId, "", 2); | ||
|
|
||
|
|
@@ -410,7 +410,7 @@ public function createAddressBook($principalUri, $url, array $properties) { | |
| 'synctoken' => 1 | ||
| ]; | ||
|
|
||
| foreach ($properties as $property=>$newValue) { | ||
| foreach ($properties as $property => $newValue) { | ||
| switch ($property) { | ||
| case '{DAV:}displayname': | ||
| $values['displayname'] = $newValue; | ||
|
|
@@ -636,7 +636,7 @@ public function createCard($addressBookId, $cardUri, $cardData) { | |
| ->andWhere($q->expr()->eq('uid', $q->createNamedParameter($uid))) | ||
| ->setMaxResults(1); | ||
| $result = $q->execute(); | ||
| $count = (bool) $result->fetchColumn(); | ||
| $count = (bool)$result->fetchColumn(); | ||
| $result->closeCursor(); | ||
| if ($count) { | ||
| throw new \Sabre\DAV\Exception\BadRequest('VCard object with uid already exists in this addressbook collection.'); | ||
|
|
@@ -825,7 +825,7 @@ public function deleteCard($addressBookId, $cardUri) { | |
| public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit = null) { | ||
| // Current synctoken | ||
| $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*addressbooks` WHERE `id` = ?'); | ||
| $stmt->execute([ $addressBookId ]); | ||
| $stmt->execute([$addressBookId]); | ||
| $currentToken = $stmt->fetchColumn(0); | ||
|
|
||
| if (is_null($currentToken)) { | ||
|
|
@@ -834,14 +834,14 @@ public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, | |
|
|
||
| $result = [ | ||
| 'syncToken' => $currentToken, | ||
| 'added' => [], | ||
| 'modified' => [], | ||
| 'deleted' => [], | ||
| 'added' => [], | ||
| 'modified' => [], | ||
| 'deleted' => [], | ||
| ]; | ||
|
|
||
| if ($syncToken) { | ||
| $query = "SELECT `uri`, `operation` FROM `*PREFIX*addressbookchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `addressbookid` = ? ORDER BY `synctoken`"; | ||
| if ($limit>0) { | ||
| if ($limit > 0) { | ||
| $query .= " LIMIT " . (int)$limit; | ||
| } | ||
|
|
||
|
|
@@ -909,7 +909,7 @@ protected function addChange($addressBookId, $objectUri, $operation) { | |
| * @param bool $modified | ||
| * @return string | ||
| */ | ||
| private function readBlob($cardData, &$modified=false) { | ||
| private function readBlob($cardData, &$modified = false) { | ||
| if (is_resource($cardData)) { | ||
| $cardData = stream_get_contents($cardData); | ||
| } | ||
|
|
@@ -957,9 +957,9 @@ public function updateShares(IShareable $shareable, $add, $remove) { | |
| * @param string $pattern which should match within the $searchProperties | ||
| * @param array $searchProperties defines the properties within the query pattern should match | ||
| * @param array $options = array() to define the search behavior | ||
| * - 'escape_like_param' - If set to false wildcards _ and % are not escaped, otherwise they are | ||
| * - 'limit' - Set a numeric limit for the search results | ||
| * - 'offset' - Set the offset for the limited search results | ||
| * - 'escape_like_param' - If set to false wildcards _ and % are not escaped, otherwise they are | ||
| * - 'limit' - Set a numeric limit for the search results | ||
| * - 'offset' - Set the offset for the limited search results | ||
| * @return array an array of contacts which are arrays of key-value-pairs | ||
| */ | ||
| public function search($addressBookId, $pattern, $searchProperties, $options = []) { | ||
|
|
@@ -974,8 +974,9 @@ public function search($addressBookId, $pattern, $searchProperties, $options = [ | |
| continue; | ||
| } | ||
|
|
||
| if ($property === 'CLOUD' && preg_match('/[^a-zA-Z0-9 _.@\-\']/', $pattern) === 1) { | ||
| // There can be no chars in cloud ids which are not valid for user ids | ||
| if ($property === 'CLOUD' && preg_match('/[^a-zA-Z0-9 :_.@\/\-\']/', $pattern) === 1) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. D'oh! |
||
| // There can be no chars in cloud ids which are not valid for user ids plus :/ | ||
| // worst case: CA61590A-BBBC-423E-84AF-E6DF01455A53@https://my.nxt/srv/ | ||
| continue; | ||
| } | ||
| } | ||
|
|
@@ -1012,7 +1013,7 @@ public function search($addressBookId, $pattern, $searchProperties, $options = [ | |
| $matches = $result->fetchAll(); | ||
| $result->closeCursor(); | ||
| $matches = array_map(function ($match) { | ||
| return (int) $match['cardid']; | ||
| return (int)$match['cardid']; | ||
| }, $matches); | ||
|
|
||
| $query = $this->db->getQueryBuilder(); | ||
|
|
@@ -1063,8 +1064,8 @@ public function collectCardProperties($bookId, $name) { | |
| public function getCardUri($id) { | ||
| $query = $this->db->getQueryBuilder(); | ||
| $query->select('uri')->from($this->dbCardsTable) | ||
| ->where($query->expr()->eq('id', $query->createParameter('id'))) | ||
| ->setParameter('id', $id); | ||
| ->where($query->expr()->eq('id', $query->createParameter('id'))) | ||
| ->setParameter('id', $id); | ||
|
|
||
| $result = $query->execute(); | ||
| $uri = $result->fetch(); | ||
|
|
@@ -1088,8 +1089,8 @@ public function getContact($addressBookId, $uri) { | |
| $result = []; | ||
| $query = $this->db->getQueryBuilder(); | ||
| $query->select('*')->from($this->dbCardsTable) | ||
| ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) | ||
| ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))); | ||
| ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) | ||
| ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))); | ||
| $queryResult = $query->execute(); | ||
| $contact = $queryResult->fetch(); | ||
| $queryResult->closeCursor(); | ||
|
|
@@ -1174,7 +1175,7 @@ protected function updateProperties($addressBookId, $cardUri, $vCardSerialized) | |
| * @return VCard | ||
| */ | ||
| protected function readCard($cardData) { | ||
| return Reader::read($cardData); | ||
| return Reader::read($cardData); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -1217,6 +1218,7 @@ protected function getCardId($addressBookId, $uri) { | |
|
|
||
| /** | ||
| * For shared address books the sharee is set in the ACL of the address book | ||
| * | ||
| * @param $addressBookId | ||
| * @param $acl | ||
| * @return array | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,9 +107,7 @@ public function prepare(INotification $notification, string $languageCode): INot | |
| ); | ||
|
|
||
| $initiator = $params[0]; | ||
| $initiatorDisplay = isset($params[3]) ? $params[3] : null; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then we can revert the change where this was added?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some details (formating, error information) are still in place. |
||
| $owner = $params[1]; | ||
| $ownerDisplay = isset($params[4]) ? $params[4] : null; | ||
|
|
||
| $notification->setRichSubject( | ||
| $l->t('You received {share} as a remote share from {user} (on behalf of {behalf})'), | ||
|
|
@@ -119,8 +117,8 @@ public function prepare(INotification $notification, string $languageCode): INot | |
| 'id' => $notification->getObjectId(), | ||
| 'name' => $params[2], | ||
| ], | ||
| 'user' => $this->createRemoteUser($initiator, $initiatorDisplay), | ||
| 'behalf' => $this->createRemoteUser($owner, $ownerDisplay), | ||
| 'user' => $this->createRemoteUser($initiator), | ||
| 'behalf' => $this->createRemoteUser($owner), | ||
| ] | ||
| ); | ||
| } else { | ||
|
|
@@ -129,7 +127,6 @@ public function prepare(INotification $notification, string $languageCode): INot | |
| ); | ||
|
|
||
| $owner = $params[0]; | ||
| $ownerDisplay = isset($params[3]) ? $params[3] : null; | ||
|
|
||
| $notification->setRichSubject( | ||
| $l->t('You received {share} as a remote share from {user}'), | ||
|
|
@@ -139,7 +136,7 @@ public function prepare(INotification $notification, string $languageCode): INot | |
| 'id' => $notification->getObjectId(), | ||
| 'name' => $params[2], | ||
| ], | ||
| 'user' => $this->createRemoteUser($owner, $ownerDisplay), | ||
| 'user' => $this->createRemoteUser($owner), | ||
| ] | ||
| ); | ||
| } | ||
|
|
@@ -149,14 +146,14 @@ public function prepare(INotification $notification, string $languageCode): INot | |
| switch ($action->getLabel()) { | ||
| case 'accept': | ||
| $action->setParsedLabel( | ||
| (string) $l->t('Accept') | ||
| (string)$l->t('Accept') | ||
| ) | ||
| ->setPrimary(true); | ||
| ->setPrimary(true); | ||
| break; | ||
|
|
||
| case 'decline': | ||
| $action->setParsedLabel( | ||
| (string) $l->t('Decline') | ||
| (string)$l->t('Decline') | ||
| ); | ||
| break; | ||
| } | ||
|
|
@@ -203,7 +200,7 @@ protected function createRemoteUser($cloudId, $displayName = null) { | |
| * @param ICloudId $cloudId | ||
| * @return string | ||
| */ | ||
| protected function getDisplayName(ICloudId $cloudId) { | ||
| protected function getDisplayName(ICloudId $cloudId): string { | ||
| $server = $cloudId->getRemote(); | ||
| $user = $cloudId->getUser(); | ||
| if (strpos($server, 'http://') === 0) { | ||
|
|
@@ -213,17 +210,24 @@ protected function getDisplayName(ICloudId $cloudId) { | |
| } | ||
|
|
||
| try { | ||
| // contains protocol in the ID | ||
| return $this->getDisplayNameFromContact($cloudId->getId()); | ||
| } catch (\OutOfBoundsException $e) { | ||
| } | ||
|
|
||
| try { | ||
| $this->getDisplayNameFromContact($user . '@http://' . $server); | ||
| // does not include protocol, as stored in addressbooks | ||
| return $this->getDisplayNameFromContact($cloudId->getDisplayId()); | ||
| } catch (\OutOfBoundsException $e) { | ||
| } | ||
|
|
||
| try { | ||
| $this->getDisplayNameFromContact($user . '@https://' . $server); | ||
| return $this->getDisplayNameFromContact($user . '@http://' . $server); | ||
| } catch (\OutOfBoundsException $e) { | ||
| } | ||
|
|
||
| try { | ||
| return $this->getDisplayNameFromContact($user . '@https://' . $server); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https first? :)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't touch the order. can switch. actually i do wonder whether there is a valid use case for those two fall backs? |
||
| } catch (\OutOfBoundsException $e) { | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.