-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
display displayname on federated shares #35915
Changes from all commits
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 | ||||
---|---|---|---|---|---|---|
|
@@ -55,10 +55,13 @@ | |||||
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 @@ public function shareReceived(ICloudFederationShare $share) { | |||||
$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 @@ private function mapShareTypeToNextcloud($shareType) { | |||||
return $result; | ||||||
} | ||||||
|
||||||
private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name): void { | ||||||
private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $displayName): void { | ||||||
Check notice Code scanning / Psalm MissingParamType
Parameter $shareId has no provided type
Check notice Code scanning / Psalm MissingParamType
Parameter $ownerFederatedId has no provided type
Check notice Code scanning / Psalm MissingParamType
Parameter $sharedByFederatedId has no provided type
Check notice Code scanning / Psalm MissingParamType
Parameter $name has no provided type
Check notice Code scanning / Psalm MissingParamType
Parameter $displayName has no provided type
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.
Suggested change
And might as well type all parameters, this is a private function. |
||||||
$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 @@ private function unshare($id, array $notification) { | |||||
->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 @@ private function unshare($id, array $notification) { | |||||
$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 @@ private function isS2SEnabled($incoming = false) { | |||||
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); | ||||||
|
||||||
} | ||||||
} |
Check notice
Code scanning / Psalm
MissingParamType