Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
61 changes: 31 additions & 30 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ 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'] ?: '0',
];

$this->addOwnerPrincipal($addressBooks[$row['id']]);
Expand All @@ -176,7 +176,7 @@ 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'])
Expand All @@ -194,7 +194,7 @@ 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.
Expand All @@ -212,13 +212,13 @@ 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'] ?: '0',
'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'],
$readOnlyPropertyName => $readOnly,
];
Expand All @@ -234,21 +234,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'] ?: '0',
];

$this->addOwnerPrincipal($addressBooks[$row['id']]);
Expand Down Expand Up @@ -289,13 +289,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'] ?: '0',
];

$this->addOwnerPrincipal($addressBook);
Expand Down Expand Up @@ -323,13 +323,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'] ?: '0',
];

$this->addOwnerPrincipal($addressBook);
Expand Down Expand Up @@ -383,7 +383,7 @@ function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) {
$query->set($key, $query->createNamedParameter($value));
}
$query->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId)))
->execute();
->execute();

$this->addChange($addressBookId, "", 2);

Expand Down Expand Up @@ -622,7 +622,7 @@ 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.');
Expand Down Expand Up @@ -800,22 +800,22 @@ function deleteCard($addressBookId, $cardUri) {
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)) return null;

$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;
}

Expand Down Expand Up @@ -906,9 +906,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 = array()) {
Expand Down Expand Up @@ -943,7 +943,7 @@ public function search($addressBookId, $pattern, $searchProperties, $options = a
$matches = $result->fetchAll();
$result->closeCursor();
$matches = array_map(function ($match) {
return (int) $match['cardid'];
return (int)$match['cardid'];
}, $matches);

$query = $this->db->getQueryBuilder();
Expand Down Expand Up @@ -990,8 +990,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();
Expand All @@ -1015,8 +1015,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();
Expand Down Expand Up @@ -1094,7 +1094,7 @@ protected function updateProperties($addressBookId, $cardUri, $vCardSerialized)
* @return VCard
*/
protected function readCard($cardData) {
return Reader::read($cardData);
return Reader::read($cardData);
}

/**
Expand Down Expand Up @@ -1137,6 +1137,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
Expand Down
40 changes: 24 additions & 16 deletions apps/federatedfilesharing/lib/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ public function prepare(INotification $notification, string $languageCode): INot

$params = $notification->getSubjectParameters();
if ($params[0] !== $params[1] && $params[1] !== null) {
$remoteInitiator = $this->createRemoteUser($params[0]);
$remoteOwner = $this->createRemoteUser($params[1]);
$params[3] = $remoteInitiator['name'] . '@' . $remoteInitiator['server'];
$params[4] = $remoteOwner['name'] . '@' . $remoteOwner['server'];

$notification->setParsedSubject(
$l->t('You received "%3$s" as a remote share from %4$s (%1$s) (on behalf of %5$s (%2$s))', $params)
);

$initiator = $params[0];
$initiatorDisplay = isset($params[3]) ? $params[3] : null;
$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})'),
[
Expand All @@ -119,17 +119,18 @@ 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' => $remoteInitiator,
'behalf' => $remoteOwner,
]
);
} else {
$remoteOwner = $this->createRemoteUser($params[0]);
$params[3] = $remoteOwner['name'] . '@' . $remoteOwner['server'];

$notification->setParsedSubject(
$l->t('You received "%3$s" as a remote share from %4$s (%1$s)', $params)
);

$owner = $params[0];
$ownerDisplay = isset($params[3]) ? $params[3] : null;

$notification->setRichSubject(
$l->t('You received {share} as a remote share from {user}'),
Expand All @@ -139,7 +140,7 @@ public function prepare(INotification $notification, string $languageCode): INot
'id' => $notification->getObjectId(),
'name' => $params[2],
],
'user' => $this->createRemoteUser($owner, $ownerDisplay),
'user' => $remoteOwner,
]
);
}
Expand All @@ -149,14 +150,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;
}
Expand Down Expand Up @@ -203,7 +204,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) {
Expand All @@ -213,17 +214,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 {
return $this->getDisplayNameFromContact($user . '@http://' . $server);
} catch (\OutOfBoundsException $e) {
}

try {
$this->getDisplayNameFromContact($user . '@https://' . $server);
return $this->getDisplayNameFromContact($user . '@https://' . $server);
} catch (\OutOfBoundsException $e) {
}

Expand Down
17 changes: 4 additions & 13 deletions apps/federatedfilesharing/lib/ocm/CloudFederationProviderFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function shareReceived(ICloudFederationShare $share) {
->setAffectedUser($shareWith)
->setObject('remote_share', (int)$shareId, $name);
\OC::$server->getActivityManager()->publish($event);
$this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $sharedBy, $owner);
$this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name);
} else {
$groupMembers = $this->groupManager->get($shareWith)->getUsers();
foreach ($groupMembers as $user) {
Expand All @@ -267,7 +267,7 @@ public function shareReceived(ICloudFederationShare $share) {
->setAffectedUser($user->getUID())
->setObject('remote_share', (int)$shareId, $name);
\OC::$server->getActivityManager()->publish($event);
$this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $sharedBy, $owner);
$this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name);
}
}
return $shareId;
Expand Down Expand Up @@ -335,22 +335,13 @@ private function mapShareTypeToNextcloud($shareType) {
return $result;
}

/**
* notify user about new federated share
*
* @param $shareWith
* @param $shareId
* @param $ownerFederatedId
* @param $sharedByFederatedId
* @param $name
*/
private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $sharedBy, $owner) {
private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name): void {
$notification = $this->notificationManager->createNotification();
$notification->setApp('files_sharing')
->setUser($shareWith)
->setDateTime(new \DateTime())
->setObject('remote_share', $shareId)
->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/'), $sharedBy, $owner]);
->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]);

$declineAction = $notification->createAction();
$declineAction->setLabel('decline')
Expand Down