Merge pull request #22062 from nextcloud/fix/noid/displayname-in-incoming-remote-share-notification

fix display of remote users in incoming share notifications
This commit is contained in:
blizzz 2020-08-04 16:26:41 +00:00 committed by GitHub
commit 7d2f5aff1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 65 deletions

View File

@ -165,7 +165,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
'{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']]);
@ -221,7 +221,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
'{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,
];
@ -251,7 +251,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
'{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']]);
@ -298,7 +298,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
'{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);
@ -332,7 +332,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
'{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);
@ -1018,8 +1018,9 @@ class CardDavBackend implements BackendInterface, SyncSupport {
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) {
// 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;
}
}
@ -1262,6 +1263,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
/**
* For shared address books the sharee is set in the ACL of the address book
*
* @param $addressBookId
* @param $acl
* @return array

View File

@ -102,15 +102,15 @@ class Notifier implements INotifier {
$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})'),
[
@ -119,17 +119,18 @@ class Notifier implements INotifier {
'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}'),
@ -139,7 +140,7 @@ class Notifier implements INotifier {
'id' => $notification->getObjectId(),
'name' => $params[2],
],
'user' => $this->createRemoteUser($owner, $ownerDisplay),
'user' => $remoteOwner,
]
);
}
@ -203,7 +204,7 @@ class Notifier implements INotifier {
* @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 +214,24 @@ class Notifier implements INotifier {
}
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);
} catch (\OutOfBoundsException $e) {
}

View File

@ -257,7 +257,7 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
->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) {
@ -268,7 +268,7 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
->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;
@ -334,22 +334,13 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
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')