-
Notifications
You must be signed in to change notification settings - Fork 68
feat: Add sharing activity for teams #1754
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 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 |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ | |
| use OCA\Activity\BackgroundJob\RemoteActivity; | ||
| use OCA\Activity\Extension\Files; | ||
| use OCA\Activity\Extension\Files_Sharing; | ||
| use OCA\Circles\CirclesManager; | ||
| use OCA\Circles\Model\Member; | ||
| use OCP\Activity\IManager; | ||
| use OCP\Constants; | ||
| use OCP\Files\Config\IUserMountCache; | ||
|
|
@@ -60,7 +62,8 @@ public function __construct( | |
| protected IUserMountCache $userMountCache, | ||
| protected IConfig $config, | ||
| protected NotificationGenerator $notificationGenerator, | ||
| protected ITagManager $tagManager | ||
| protected ITagManager $tagManager, | ||
| protected ?CirclesManager $teamManager, | ||
| ) { | ||
| } | ||
|
|
||
|
|
@@ -664,6 +667,16 @@ public function share($share) { | |
| (int)$share->getId() | ||
| ); | ||
| break; | ||
| case IShare::TYPE_CIRCLE: | ||
| $this->shareWithTeam( | ||
| $share->getSharedWith(), | ||
| $share->getNodeId(), | ||
| $share->getNodeType(), | ||
| $share->getTarget(), | ||
| (int)$share->getId(), | ||
| $share->getSharedBy(), | ||
| ); | ||
| break; | ||
| case IShare::TYPE_LINK: | ||
| $this->shareByLink( | ||
| $share->getNodeId(), | ||
|
|
@@ -726,7 +739,8 @@ protected function shareWithGroup($shareWith, $fileSource, $itemType, $fileTarge | |
| $offset = 0; | ||
| $users = $group->searchUsers('', self::USER_BATCH_SIZE, $offset); | ||
| while (!empty($users)) { | ||
| $this->addNotificationsForGroupUsers($users, 'shared_with_by', $fileSource, $itemType, $fileTarget, $shareId); | ||
| $userIds = array_map(fn (IUser $user) => $user->getUID(), $users); | ||
| $this->addNotificationsForUsers($userIds, 'shared_with_by', $fileSource, $itemType, $fileTarget, $shareId); | ||
| $offset += self::USER_BATCH_SIZE; | ||
| $users = $group->searchUsers('', self::USER_BATCH_SIZE, $offset); | ||
| } | ||
|
|
@@ -758,6 +772,42 @@ protected function shareByLink($fileSource, $itemType, $linkOwner) { | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Sharing a file or folder with a team | ||
| * | ||
| * @param string $shareWith | ||
| * @param int $fileSource File ID that is being shared | ||
| * @param string $itemType File type that is being shared (file or folder) | ||
| * @param string $fileTarget File path | ||
| * @param int $shareId The Share ID of this share | ||
| */ | ||
| protected function shareWithTeam(string $shareWith, int $fileSource, string $itemType, string $fileTarget, int $shareId, string $sharer): void { | ||
| if ($this->teamManager === null) { | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| $this->teamManager->startSuperSession(); | ||
| $team = $this->teamManager->getCircle($shareWith); | ||
| $members = $team->getInheritedMembers(); | ||
| $members = array_filter($members, fn ($member) => $member->getUserType() === Member::TYPE_USER); | ||
| $userIds = array_map(fn ($member) => $member->getUserId(), $members); | ||
| } catch (\Throwable $e) { | ||
| $this->logger->debug('Fetching team members for share activity failed', ['exception' => $e]); | ||
| // error in teams app - setting users list to empty | ||
| $userIds = []; | ||
| } | ||
|
|
||
| // Activity for user performing the share | ||
| $this->shareNotificationForSharer('shared_team_self', $shareWith, $fileSource, $itemType); | ||
| // Activity for original owner of the file (re-sharing) | ||
| if ($this->currentUser->getUID() !== null) { | ||
| $this->shareNotificationForOriginalOwners($this->currentUser->getUID(), 're-shared_team_by', $shareWith, $fileSource, $itemType); | ||
| } | ||
| // Activity for all affected users | ||
| $this->addNotificationsForUsers($userIds, 'shared_with_by', $fileSource, $itemType, $fileTarget, $shareId); | ||
| } | ||
|
|
||
| /** | ||
| * Manage unsharing events | ||
| * | ||
|
|
@@ -878,9 +928,11 @@ protected function unshareFromGroup(IShare $share) { | |
|
|
||
| $offset = 0; | ||
| $users = $group->searchUsers('', self::USER_BATCH_SIZE, $offset); | ||
| $users = array_map(fn (IUser $user) => $user->getUID(), $users); | ||
| $shouldFlush = $this->startActivityTransaction(); | ||
| while (!empty($users)) { | ||
| $this->addNotificationsForGroupUsers($users, $actionUser, $share->getNodeId(), $share->getNodeType(), $share->getTarget(), (int)$share->getId()); | ||
| $userIds = array_map(fn (IUser $user) => $user->getUID(), $users); | ||
|
Comment on lines
+931
to
+934
Contributor
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. $users contains string[] after line 931, then you try to convert to string again.
Contributor
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. Oh seems like a rebase issue or similar, line 931 should be removed...
Contributor
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. (or remove 934 to keep the activity transaction as short as possible) |
||
| $this->addNotificationsForUsers($userIds, $actionUser, $share->getNodeId(), $share->getNodeType(), $share->getTarget(), (int)$share->getId()); | ||
| $offset += self::USER_BATCH_SIZE; | ||
| $users = $group->searchUsers('', self::USER_BATCH_SIZE, $offset); | ||
| } | ||
|
|
@@ -940,18 +992,18 @@ protected function unshareLink(IShare $share) { | |
| } | ||
|
|
||
| /** | ||
| * @param IUser[] $usersInGroup | ||
| * @param string[] $usersIds | ||
| * @param string $actionUser | ||
| * @param int $fileSource File ID that is being shared | ||
| * @param string $itemType File type that is being shared (file or folder) | ||
| * @param string $fileTarget File path | ||
| * @param int $shareId The Share ID of this share | ||
| */ | ||
| protected function addNotificationsForGroupUsers(array $usersInGroup, $actionUser, $fileSource, $itemType, $fileTarget, $shareId) { | ||
| protected function addNotificationsForUsers(array $usersIds, $actionUser, $fileSource, $itemType, $fileTarget, $shareId) { | ||
| $affectedUsers = []; | ||
|
|
||
| foreach ($usersInGroup as $user) { | ||
| $affectedUsers[$user->getUID()] = $fileTarget; | ||
| foreach ($usersIds as $user) { | ||
| $affectedUsers[$user] = $fileTarget; | ||
| } | ||
|
|
||
| // Remove the triggering user, we already managed his notifications | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.