|
11 | 11 | use OCA\Activity\BackgroundJob\RemoteActivity;
|
12 | 12 | use OCA\Activity\Extension\Files;
|
13 | 13 | use OCA\Activity\Extension\Files_Sharing;
|
| 14 | +use OCA\Circles\CirclesManager; |
| 15 | +use OCA\Circles\Model\Member; |
14 | 16 | use OCP\Activity\IManager;
|
15 | 17 | use OCP\Constants;
|
16 | 18 | use OCP\Files\Config\IUserMountCache;
|
@@ -60,7 +62,8 @@ public function __construct(
|
60 | 62 | protected IUserMountCache $userMountCache,
|
61 | 63 | protected IConfig $config,
|
62 | 64 | protected NotificationGenerator $notificationGenerator,
|
63 |
| - protected ITagManager $tagManager |
| 65 | + protected ITagManager $tagManager, |
| 66 | + protected ?CirclesManager $teamManager, |
64 | 67 | ) {
|
65 | 68 | }
|
66 | 69 |
|
@@ -664,6 +667,16 @@ public function share($share) {
|
664 | 667 | (int)$share->getId()
|
665 | 668 | );
|
666 | 669 | break;
|
| 670 | + case IShare::TYPE_CIRCLE: |
| 671 | + $this->shareWithTeam( |
| 672 | + $share->getSharedWith(), |
| 673 | + $share->getNodeId(), |
| 674 | + $share->getNodeType(), |
| 675 | + $share->getTarget(), |
| 676 | + (int)$share->getId(), |
| 677 | + $share->getSharedBy(), |
| 678 | + ); |
| 679 | + break; |
667 | 680 | case IShare::TYPE_LINK:
|
668 | 681 | $this->shareByLink(
|
669 | 682 | $share->getNodeId(),
|
@@ -726,7 +739,8 @@ protected function shareWithGroup($shareWith, $fileSource, $itemType, $fileTarge
|
726 | 739 | $offset = 0;
|
727 | 740 | $users = $group->searchUsers('', self::USER_BATCH_SIZE, $offset);
|
728 | 741 | while (!empty($users)) {
|
729 |
| - $this->addNotificationsForGroupUsers($users, 'shared_with_by', $fileSource, $itemType, $fileTarget, $shareId); |
| 742 | + $users = array_map(fn (IUser $user) => $user->getUID(), $users); |
| 743 | + $this->addNotificationsForUsers($users, 'shared_with_by', $fileSource, $itemType, $fileTarget, $shareId); |
730 | 744 | $offset += self::USER_BATCH_SIZE;
|
731 | 745 | $users = $group->searchUsers('', self::USER_BATCH_SIZE, $offset);
|
732 | 746 | }
|
@@ -758,6 +772,42 @@ protected function shareByLink($fileSource, $itemType, $linkOwner) {
|
758 | 772 | );
|
759 | 773 | }
|
760 | 774 |
|
| 775 | + /** |
| 776 | + * Sharing a file or folder with a team |
| 777 | + * |
| 778 | + * @param string $shareWith |
| 779 | + * @param int $fileSource File ID that is being shared |
| 780 | + * @param string $itemType File type that is being shared (file or folder) |
| 781 | + * @param string $fileTarget File path |
| 782 | + * @param int $shareId The Share ID of this share |
| 783 | + */ |
| 784 | + protected function shareWithTeam(string $shareWith, int $fileSource, string $itemType, string $fileTarget, int $shareId, string $sharer): void { |
| 785 | + if ($this->teamManager === null) { |
| 786 | + return; |
| 787 | + } |
| 788 | + |
| 789 | + try { |
| 790 | + $this->teamManager->startSuperSession(); |
| 791 | + $team = $this->teamManager->getCircle($shareWith); |
| 792 | + $members = $team->getInheritedMembers(); |
| 793 | + $members = array_filter($members, fn ($member) => $member->getUserType() === Member::TYPE_USER); |
| 794 | + $users = array_map(fn ($member) => $member->getUserId(), $members); |
| 795 | + } catch (\Throwable $e) { |
| 796 | + $this->logger->debug('Fetching team members for share activity failed', ['exception' => $e]); |
| 797 | + // error in teams app - setting users list to empty |
| 798 | + $users = []; |
| 799 | + } |
| 800 | + |
| 801 | + // Activity for user performing the share |
| 802 | + $this->shareNotificationForSharer('shared_team_self', $shareWith, $fileSource, $itemType); |
| 803 | + // Activity for original owner of the file (re-sharing) |
| 804 | + if ($this->currentUser->getUID() !== null) { |
| 805 | + $this->shareNotificationForOriginalOwners($this->currentUser->getUID(), 're-shared_team_by', $shareWith, $fileSource, $itemType); |
| 806 | + } |
| 807 | + // Activity for all affected users |
| 808 | + $this->addNotificationsForUsers($users, 'shared_with_by', $fileSource, $itemType, $fileTarget, $shareId); |
| 809 | + } |
| 810 | + |
761 | 811 | /**
|
762 | 812 | * Manage unsharing events
|
763 | 813 | *
|
@@ -878,9 +928,11 @@ protected function unshareFromGroup(IShare $share) {
|
878 | 928 |
|
879 | 929 | $offset = 0;
|
880 | 930 | $users = $group->searchUsers('', self::USER_BATCH_SIZE, $offset);
|
| 931 | + $users = array_map(fn (IUser $user) => $user->getUID(), $users); |
881 | 932 | $shouldFlush = $this->startActivityTransaction();
|
882 | 933 | while (!empty($users)) {
|
883 |
| - $this->addNotificationsForGroupUsers($users, $actionUser, $share->getNodeId(), $share->getNodeType(), $share->getTarget(), (int) $share->getId()); |
| 934 | + $userIds = array_map(fn (IUser $user) => $user->getUID(), $users); |
| 935 | + $this->addNotificationsForUsers($userIds, $actionUser, $share->getNodeId(), $share->getNodeType(), $share->getTarget(), (int)$share->getId()); |
884 | 936 | $offset += self::USER_BATCH_SIZE;
|
885 | 937 | $users = $group->searchUsers('', self::USER_BATCH_SIZE, $offset);
|
886 | 938 | }
|
@@ -940,18 +992,18 @@ protected function unshareLink(IShare $share) {
|
940 | 992 | }
|
941 | 993 |
|
942 | 994 | /**
|
943 |
| - * @param IUser[] $usersInGroup |
| 995 | + * @param string[] $usersIds |
944 | 996 | * @param string $actionUser
|
945 | 997 | * @param int $fileSource File ID that is being shared
|
946 | 998 | * @param string $itemType File type that is being shared (file or folder)
|
947 | 999 | * @param string $fileTarget File path
|
948 | 1000 | * @param int $shareId The Share ID of this share
|
949 | 1001 | */
|
950 |
| - protected function addNotificationsForGroupUsers(array $usersInGroup, $actionUser, $fileSource, $itemType, $fileTarget, $shareId) { |
| 1002 | + protected function addNotificationsForUsers(array $usersIds, $actionUser, $fileSource, $itemType, $fileTarget, $shareId) { |
951 | 1003 | $affectedUsers = [];
|
952 | 1004 |
|
953 |
| - foreach ($usersInGroup as $user) { |
954 |
| - $affectedUsers[$user->getUID()] = $fileTarget; |
| 1005 | + foreach ($usersIds as $user) { |
| 1006 | + $affectedUsers[$user] = $fileTarget; |
955 | 1007 | }
|
956 | 1008 |
|
957 | 1009 | // Remove the triggering user, we already managed his notifications
|
|
0 commit comments