diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2023-06-28 09:27:55 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2023-06-28 09:28:03 -0100 |
commit | d2efd0e03cb0f30b748b86c324fc574e603334aa (patch) | |
tree | 573612743cd7e60ad8f14b1426ef7735cdae7617 /apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php | |
parent | 266436b76788d14e061bbe1f013bc052edc8041f (diff) | |
download | nextcloud-server-d2efd0e03cb0f30b748b86c324fc574e603334aa.tar.gz nextcloud-server-d2efd0e03cb0f30b748b86c324fc574e603334aa.zip |
displayname on federated shares
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php')
-rw-r--r-- | apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php index 370ef8dc32a..5e2cafe0ce0 100644 --- a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php +++ b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php @@ -55,10 +55,13 @@ use OCP\ILogger; use OCP\IURLGenerator; use OCP\IUserManager; use OCP\Notification\IManager as INotificationManager; +use OCP\Server; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager; use OCP\Share\IShare; use OCP\Util; +use Psr\Container\ContainerExceptionInterface; +use Psr\Log\LoggerInterface; class CloudFederationProviderFiles implements ICloudFederationProvider { @@ -250,26 +253,29 @@ class CloudFederationProviderFiles implements ICloudFederationProvider { $this->externalShareManager->addShare($remote, $token, '', $name, $owner, $shareType,false, $shareWith, $remoteId); $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); + // get DisplayName about the owner of the share + $ownerDisplayName = $this->getUserDisplayName($ownerFederatedId); + if ($shareType === IShare::TYPE_USER) { $event = $this->activityManager->generateEvent(); $event->setApp('files_sharing') ->setType('remote_share') - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/'), $ownerDisplayName]) ->setAffectedUser($shareWith) ->setObject('remote_share', $shareId, $name); \OC::$server->getActivityManager()->publish($event); - $this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name); + $this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName); } else { $groupMembers = $this->groupManager->get($shareWith)->getUsers(); foreach ($groupMembers as $user) { $event = $this->activityManager->generateEvent(); $event->setApp('files_sharing') ->setType('remote_share') - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/'), $ownerDisplayName]) ->setAffectedUser($user->getUID()) ->setObject('remote_share', $shareId, $name); \OC::$server->getActivityManager()->publish($event); - $this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name); + $this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName); } } return $shareId; @@ -335,13 +341,13 @@ class CloudFederationProviderFiles implements ICloudFederationProvider { return $result; } - private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name): void { + private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $displayName): 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, '/')]); + ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/'), $displayName]); $declineAction = $notification->createAction(); $declineAction->setLabel('decline') @@ -579,6 +585,8 @@ class CloudFederationProviderFiles implements ICloudFederationProvider { ->where($qb->expr()->eq('parent', $qb->createNamedParameter((int)$share['id']))); $qb->execute(); + $ownerDisplayName = $this->getUserDisplayName($owner->getId()); + if ((int)$share['share_type'] === IShare::TYPE_USER) { if ($share['accepted']) { $path = trim($mountpoint, '/'); @@ -594,7 +602,7 @@ class CloudFederationProviderFiles implements ICloudFederationProvider { $event = $this->activityManager->generateEvent(); $event->setApp('files_sharing') ->setType('remote_share') - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path]) + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path, $ownerDisplayName]) ->setAffectedUser($user) ->setObject('remote_share', (int)$share['id'], $path); \OC::$server->getActivityManager()->publish($event); @@ -824,4 +832,25 @@ class CloudFederationProviderFiles implements ICloudFederationProvider { public function getSupportedShareTypes() { return ['user', 'group']; } + + + public function getUserDisplayName(string $userId): string { + // check if gss is enabled and available + if (!$this->appManager->isInstalled('globalsiteselector') + || !class_exists('\OCA\GlobalSiteSelector\Service\SlaveService')) { + return ''; + } + + try { + $slaveService = Server::get(\OCA\GlobalSiteSelector\Service\SlaveService::class); + } catch (\Throwable $e) { + Server::get(LoggerInterface::class)->error( + $e->getMessage(), + ['exception' => $e] + ); + return ''; + } + + return $slaveService->getUserDisplayName($this->cloudIdManager->removeProtocolFromUrl($userId), false); + } } |