diff --git a/apps/files_sharing/lib/Controller/Share20OcsController.php b/apps/files_sharing/lib/Controller/Share20OcsController.php index 810533a9bdfa..0ac2c451f426 100644 --- a/apps/files_sharing/lib/Controller/Share20OcsController.php +++ b/apps/files_sharing/lib/Controller/Share20OcsController.php @@ -379,12 +379,12 @@ public function createShare() { $shareWith = $this->request->getParam('shareWith', null); - $autoAccept = false; - $globalAutoAcceptValue = $this->config->getAppValue('core', 'shareapi_auto_accept_share', 'yes'); - if ($globalAutoAcceptValue === 'yes') { - $autoAccept = $this->config->getUserValue($shareWith, 'files_sharing', 'auto_accept_share', $globalAutoAcceptValue) === 'yes'; - } + $globalAutoAccept = $this->config->getAppValue('core', 'shareapi_auto_accept_share', 'yes') === 'yes'; if ($shareType === Share::SHARE_TYPE_USER) { + $userAutoAccept = false; + if ($globalAutoAccept) { + $userAutoAccept = $this->config->getUserValue($shareWith, 'files_sharing', 'auto_accept_share', 'yes') === 'yes'; + } // Valid user is required to share if ($shareWith === null || !$this->userManager->userExists($shareWith)) { $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); @@ -392,7 +392,7 @@ public function createShare() { } $share->setSharedWith($shareWith); $share->setPermissions($permissions); - if ($autoAccept) { + if ($userAutoAccept) { $share->setState(Share::STATE_ACCEPTED); } else { $share->setState(Share::STATE_PENDING); @@ -413,7 +413,7 @@ public function createShare() { } $share->setSharedWith($shareWith); $share->setPermissions($permissions); - if ($autoAccept) { + if ($globalAutoAccept) { $share->setState(Share::STATE_ACCEPTED); } else { $share->setState(Share::STATE_PENDING); @@ -501,6 +501,21 @@ public function createShare() { try { $share = $this->shareManager->createShare($share); + /** + * If auto accept enabled by admin and it is a group share, + * create sub-share for auto accept disabled users in pending state. + */ + if ($share->getShareType() === Share::SHARE_TYPE_GROUP && $globalAutoAccept) { + $subShare = $share; + $group = $this->groupManager->get($share->getSharedWith()); + foreach ($group->getUsers() as $user) { + $userAutoAccept = $this->config->getUserValue($user->getUID(), 'files_sharing', 'auto_accept_share', 'yes') === 'yes'; + if (!$userAutoAccept) { + $subShare->setState(Share::STATE_PENDING); + $this->shareManager->updateShareForRecipient($subShare, $user->getUID()); + } + } + } } catch (GenericShareException $e) { $code = $e->getCode() === 0 ? 403 : $e->getCode(); $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); diff --git a/apps/files_sharing/tests/Controller/Share20OcsControllerTest.php b/apps/files_sharing/tests/Controller/Share20OcsControllerTest.php index e374c1f583c2..5732b7ddfd21 100644 --- a/apps/files_sharing/tests/Controller/Share20OcsControllerTest.php +++ b/apps/files_sharing/tests/Controller/Share20OcsControllerTest.php @@ -200,6 +200,7 @@ private function getGroupMock(array $attrs) { if (isset($attrs['displayname'])) { $groupMock->method('getDisplayName')->willReturn($attrs['displayname']); } + $groupMock->method('getUsers')->willReturn([]); return $groupMock; } diff --git a/tests/acceptance/features/webUISharingAcceptShares/acceptShares.feature b/tests/acceptance/features/webUISharingAcceptShares/acceptShares.feature index f3568141b7f0..964dd8ddcecc 100644 --- a/tests/acceptance/features/webUISharingAcceptShares/acceptShares.feature +++ b/tests/acceptance/features/webUISharingAcceptShares/acceptShares.feature @@ -238,7 +238,6 @@ Feature: accept/decline shares coming from internal users Then folder "simple-folder-renamed" should be in state "" in the shared-with-you page on the webUI And folder "simple-folder-renamed" should be listed in the files page on the webUI - @issue-34705 Scenario: User-based accepting is disabled while global is enabled Given the setting "Automatically accept new incoming local user shares" in the section "Sharing" has been enabled And user "user1" has logged in using the webUI @@ -247,14 +246,11 @@ Feature: accept/decline shares coming from internal users And user "user2" shares folder "/simple-folder" with group "grp1" using the sharing API And user "user2" shares file "/testimage.jpg" with user "user1" using the sharing API And the user browses to the files page - Then folder "simple-folder (2)" should be listed on the webUI - #Then folder "simple-folder (2)" should not be listed on the webUI + Then folder "simple-folder (2)" should not be listed on the webUI And file "testimage (2).jpg" should not be listed on the webUI - And folder "simple-folder (2)" should be listed in the shared-with-you page on the webUI - #But folder "simple-folder" should be listed in the shared-with-you page on the webUI + But folder "simple-folder" should be listed in the shared-with-you page on the webUI And file "testimage.jpg" should be listed in the shared-with-you page on the webUI - And folder "simple-folder (2)" should be in state "" in the shared-with-you page on the webUI - #And folder "simple-folder" should be in state "Pending" in the shared-with-you page on the webUI + And folder "simple-folder" should be in state "Pending" in the shared-with-you page on the webUI And file "testimage.jpg" should be in state "Pending" in the shared-with-you page on the webUI Scenario: User-based accepting is enabled while global is enabled