From 34b7e1dac8dc43c2878e5fcb0620ea71bc3492ce Mon Sep 17 00:00:00 2001 From: Chris Fritsche Date: Wed, 23 Sep 2020 12:24:44 +0200 Subject: [PATCH 1/2] Move code for getting affected users to separate function This is only preparation for implementing notifications for group members in case of moving, renaming and sharing which is currently missing. This doesn't include any changes to the logic. Signed-off-by: Chris Fritsche Signed-off-by: Frieder Schrempf --- lib/FilesHooks.php | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/FilesHooks.php b/lib/FilesHooks.php index db42a7660..69dcea123 100755 --- a/lib/FilesHooks.php +++ b/lib/FilesHooks.php @@ -233,18 +233,7 @@ protected function addNotificationsForFileAction($filePath, $activityType, $subj $this->generateRemoteActivity($accessList['remotes'], $activityType, time(), $this->currentUser->getCloudId(), $accessList['ownerPath']); } - if ($this->config->getSystemValueBool('activity_use_cached_mountpoints', false)) { - $mountsForFile = $this->userMountCache->getMountsForFileId($fileId); - $affectedUserIds = array_map(function (ICachedMountInfo $mount) { - return $mount->getUser()->getUID(); - }, $mountsForFile); - $affectedPaths = array_map(function (ICachedMountFileInfo $mount) { - return $this->getVisiblePath($mount->getPath()); - }, $mountsForFile); - $affectedUsers = array_combine($affectedUserIds, $affectedPaths); - } else { - $affectedUsers = $accessList['users']; - } + $affectedUsers = $this->getAffectedUsers($accessList['users'], $fileId); [$filteredEmailUsers, $filteredNotificationUsers] = $this->getFileChangeActivitySettings($fileId, array_keys($affectedUsers)); @@ -1197,4 +1186,26 @@ protected function addNotificationsForUser($user, $subject, $subjectParams, $fil $this->activityData->storeMail($event, $latestSend); } } + + /** + * Gets an array of the users that should be notified for a path + * + * @param $defaultUsers + * @param $fileId + * @return array|mixed + */ + protected function getAffectedUsers($defaultUsers, $fileId) { + if ($this->config->getSystemValueBool('activity_use_cached_mountpoints', false)) { + $mountsForFile = $this->userMountCache->getMountsForFileId($fileId); + $affectedUserIds = array_map(function (ICachedMountInfo $mount) { + return $mount->getUser()->getUID(); + }, $mountsForFile); + $affectedPaths = array_map(function (ICachedMountFileInfo $mount) { + return $this->getVisiblePath($mount->getPath()); + }, $mountsForFile); + return array_combine($affectedUserIds, $affectedPaths); + } + + return $defaultUsers; + } } From cacdb3d61e48e0ac5991d25fc45f6014899d8704 Mon Sep 17 00:00:00 2001 From: Chris Fritsche Date: Wed, 23 Sep 2020 12:24:44 +0200 Subject: [PATCH 2/2] Implement notifications for group members in case of moving/renaming Signed-off-by: Chris Fritsche Signed-off-by: Frieder Schrempf --- lib/FilesHooks.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/FilesHooks.php b/lib/FilesHooks.php index 69dcea123..0739b68c8 100755 --- a/lib/FilesHooks.php +++ b/lib/FilesHooks.php @@ -350,6 +350,7 @@ public function fileMove($oldPath, $newPath) { return; } $this->oldAccessList = $this->getUserPathsFromPath($this->oldParentPath, $this->oldParentOwner); + $this->oldAccessList['users'] = $this->getAffectedUsers($this->oldAccessList['users'], $this->oldParentId); } @@ -409,7 +410,7 @@ protected function fileRenaming($oldPath, $newPath) { } $this->generateRemoteActivity($renameRemotes, Files::TYPE_FILE_CHANGED, time(), $this->currentUser->getCloudId()); - $affectedUsers = $accessList['users']; + $affectedUsers = $this->getAffectedUsers($accessList['users'], $fileId); [$filteredEmailUsers, $filteredNotificationUsers] = $this->getFileChangeActivitySettings($fileId, array_keys($affectedUsers)); foreach ($affectedUsers as $user => $path) { @@ -456,7 +457,7 @@ protected function fileMoving($oldPath, $newPath) { return; } $accessList = $this->getUserPathsFromPath($parentPath, $parentOwner); - $affectedUsers = $accessList['users']; + $affectedUsers = $this->getAffectedUsers($accessList['users'], $fileId); $oldUsers = $this->oldAccessList['users']; $beforeUsers = array_keys($oldUsers);