diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php index 5bc18ad4e873..3cfa87343b91 100644 --- a/apps/federatedfilesharing/lib/FederatedShareProvider.php +++ b/apps/federatedfilesharing/lib/FederatedShareProvider.php @@ -1065,11 +1065,15 @@ protected function getAccepted($remote, $shareWith) { 'auto_accept_trusted', 'no' ); + if ($globalAutoAcceptValue !== 'yes') { + return false; + } $autoAccept = $this->config->getUserValue( $shareWith, 'federatedfilesharing', 'auto_accept_share_trusted', - $globalAutoAcceptValue); + $globalAutoAcceptValue + ); if ($autoAccept !== 'yes') { return false; } diff --git a/apps/federatedfilesharing/lib/Panels/AdminPanel.php b/apps/federatedfilesharing/lib/Panels/AdminPanel.php index 4691292dfe08..238e615a2f26 100644 --- a/apps/federatedfilesharing/lib/Panels/AdminPanel.php +++ b/apps/federatedfilesharing/lib/Panels/AdminPanel.php @@ -57,7 +57,7 @@ public function getPanel() { $tmpl->assign('incomingServer2serverShareEnabled', $this->shareProvider->isIncomingServer2serverShareEnabled()); $tmpl->assign( 'autoAcceptTrusted', - $this->config->getAppValue('federatedfilesharing', 'auto_accept_trusted', 'no') + $this->config->getAppValue('federatedfilesharing', 'auto_accept_trusted', 'no') === 'yes' ); return $tmpl; } diff --git a/apps/federatedfilesharing/lib/Panels/SharingPersonalPanel.php b/apps/federatedfilesharing/lib/Panels/SharingPersonalPanel.php index 93c8b5941241..20a4146280c6 100644 --- a/apps/federatedfilesharing/lib/Panels/SharingPersonalPanel.php +++ b/apps/federatedfilesharing/lib/Panels/SharingPersonalPanel.php @@ -46,17 +46,29 @@ public function __construct(IConfig $config, IUserSession $userSession) { * @return TemplateResponse | Template */ public function getPanel() { + $tmpl = new Template('federatedfilesharing', 'settings-personal-sharing'); + $showEmptyTemplate = true; + $globalAutoAcceptShareEnabled = $this->config->getAppValue( + 'federatedfilesharing', + 'auto_accept_trusted', + 'no' + ); $autoAcceptShareEnabled = $this->config->getUserValue( $this->userSession->getUser()->getUID(), 'federatedfilesharing', 'auto_accept_share_trusted', - 'yes' - ); - $tmpl = new Template('federatedfilesharing', 'settings-personal-sharing'); - $tmpl->assign( - 'userAutoAcceptShareTrustedEnabled', - $autoAcceptShareEnabled + $globalAutoAcceptShareEnabled ); + if ($globalAutoAcceptShareEnabled === 'yes') { + $showEmptyTemplate = false; + $tmpl->assign( + 'userAutoAcceptShareTrustedEnabled', + $autoAcceptShareEnabled + ); + } + if ($showEmptyTemplate) { + return new Template('federatedfilesharing', 'settings-personal-sharing-empty'); + } return $tmpl; } diff --git a/apps/federatedfilesharing/templates/settings-personal-sharing-empty.php b/apps/federatedfilesharing/templates/settings-personal-sharing-empty.php new file mode 100644 index 000000000000..5331e2a8323e --- /dev/null +++ b/apps/federatedfilesharing/templates/settings-personal-sharing-empty.php @@ -0,0 +1,28 @@ + + * + * @copyright Copyright (c) 2019, ownCloud GmbH + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +/** @var \OCP\IL10N $l */ +?> + +
+

t('Federated Cloud Sharing'));?>

+

t('Nothing to configure.')); ?>

+
\ No newline at end of file diff --git a/apps/federatedfilesharing/templates/settings-personal-sharing.php b/apps/federatedfilesharing/templates/settings-personal-sharing.php index 252ab44d3b36..023fa2d8fa57 100644 --- a/apps/federatedfilesharing/templates/settings-personal-sharing.php +++ b/apps/federatedfilesharing/templates/settings-personal-sharing.php @@ -21,16 +21,20 @@ /** @var array $_ */ /** @var \OCP\IL10N $l */ + script('federatedfilesharing', 'settings-personal-sharing'); ?>

t('Federated Cloud Sharing'));?>

- /> -
+ + + + + + +
+
\ No newline at end of file diff --git a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php index a4071707f728..b48d5316e7d6 100644 --- a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php +++ b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php @@ -939,9 +939,10 @@ public function dataTestGetAccepted() { [false, 'yes', 'yes', false, false], // autoaccept [false, 'yes', 'yes', true, true], - // userAutoAccept overrides globalAutoAccept + // users can override globalAutoAccept when globalAutoAccept enabled [false, 'yes', 'no', true, false], - [false, 'no', 'yes', true, true], + [false, 'no', 'yes', true, false], + [false, 'yes', 'yes', true, true], ]; } } diff --git a/apps/federatedfilesharing/tests/Panels/SharingPersonalPanelTest.php b/apps/federatedfilesharing/tests/Panels/SharingPersonalPanelTest.php index 68e182783e56..2ffdf0374d10 100644 --- a/apps/federatedfilesharing/tests/Panels/SharingPersonalPanelTest.php +++ b/apps/federatedfilesharing/tests/Panels/SharingPersonalPanelTest.php @@ -56,7 +56,20 @@ public function testGetPriority() { $this->assertEquals(40, $this->sharingPersonalPanel->getPriority()); } - public function testGetPanel() { + public function globalFederatedSharingConfigProvider() { + return [ + [['auto_accept_trusted' => 'yes'], '
'], + [['auto_accept_trusted' => 'no'], '

Nothing to configure.

'], + ]; + } + + /** + * @dataProvider globalFederatedSharingConfigProvider + * + * @param array $globalConfigs + * @param string $expectedString + */ + public function testGetPanel($globalConfigs, $expectedString) { $mockUser = $this->getMockBuilder(IUser::class) ->disableOriginalConstructor() ->getMock(); @@ -67,8 +80,12 @@ public function testGetPanel() { $this->userSession->expects($this->any()) ->method('getUser') ->willReturn($mockUser); - + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('federatedfilesharing', 'auto_accept_trusted', 'no') + ->willReturn($globalConfigs['auto_accept_trusted']); + $templateHtml = $this->sharingPersonalPanel->getPanel()->fetchPage(); - $this->assertContains('', $templateHtml); + $this->assertContains($expectedString, $templateHtml); } } diff --git a/apps/files_sharing/lib/Controller/Share20OcsController.php b/apps/files_sharing/lib/Controller/Share20OcsController.php index 4431d7e76f16..db6756a0ace5 100644 --- a/apps/files_sharing/lib/Controller/Share20OcsController.php +++ b/apps/files_sharing/lib/Controller/Share20OcsController.php @@ -378,8 +378,11 @@ public function createShare() { $shareWith = $this->request->getParam('shareWith', null); + $autoAccept = false; $globalAutoAcceptValue = $this->config->getAppValue('core', 'shareapi_auto_accept_share', 'yes'); - $autoAccept = $this->config->getUserValue($shareWith, 'files_sharing', 'auto_accept_share', $globalAutoAcceptValue) === 'yes'; + if ($globalAutoAcceptValue === 'yes') { + $autoAccept = $this->config->getUserValue($shareWith, 'files_sharing', 'auto_accept_share', $globalAutoAcceptValue) === 'yes'; + } if ($shareType === Share::SHARE_TYPE_USER) { // Valid user is required to share if ($shareWith === null || !$this->userManager->userExists($shareWith)) { diff --git a/apps/files_sharing/lib/Panels/Personal/PersonalPanel.php b/apps/files_sharing/lib/Panels/Personal/PersonalPanel.php index d2ee7868be39..86b117b9dfa3 100644 --- a/apps/files_sharing/lib/Panels/Personal/PersonalPanel.php +++ b/apps/files_sharing/lib/Panels/Personal/PersonalPanel.php @@ -46,17 +46,29 @@ public function __construct(IConfig $config, IUserSession $userSession) { * @return TemplateResponse | Template */ public function getPanel() { + $tmpl = new Template('files_sharing', 'settings-personal'); + $showEmptyTemplate = true; + $globalAutoAcceptShareEnabled = $this->config->getAppValue( + 'core', + 'shareapi_auto_accept_share', + 'yes' + ); $autoAcceptShareEnabled = $this->config->getUserValue( $this->userSession->getUser()->getUID(), 'files_sharing', 'auto_accept_share', - 'yes' - ); - $tmpl = new Template('files_sharing', 'settings-personal'); - $tmpl->assign( - 'userAutoAcceptShareEnabled', - $autoAcceptShareEnabled + $globalAutoAcceptShareEnabled ); + if ($globalAutoAcceptShareEnabled === 'yes') { + $showEmptyTemplate = false; + $tmpl->assign( + 'userAutoAcceptShareEnabled', + $autoAcceptShareEnabled + ); + } + if ($showEmptyTemplate) { + return new Template('files_sharing', 'settings-personal-empty'); + } return $tmpl; } diff --git a/apps/files_sharing/templates/settings-personal-empty.php b/apps/files_sharing/templates/settings-personal-empty.php new file mode 100644 index 000000000000..c0fa4eb35fba --- /dev/null +++ b/apps/files_sharing/templates/settings-personal-empty.php @@ -0,0 +1,28 @@ + + * + * @copyright Copyright (c) 2019, ownCloud GmbH + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +/** @var \OCP\IL10N $l */ +?> + +
+

t('Sharing'));?>

+

t('Nothing to configure.')); ?>

+
\ No newline at end of file diff --git a/apps/files_sharing/templates/settings-personal.php b/apps/files_sharing/templates/settings-personal.php index 6f5b7dfdc334..a2a214b16acc 100644 --- a/apps/files_sharing/templates/settings-personal.php +++ b/apps/files_sharing/templates/settings-personal.php @@ -21,16 +21,20 @@ /** @var array $_ */ /** @var \OCP\IL10N $l */ + script('files_sharing', 'settings-personal'); ?>

t('Sharing'));?>

- /> -
+ + + + + + +
+ \ No newline at end of file diff --git a/apps/files_sharing/tests/Panels/Personal/PersonalPanelTest.php b/apps/files_sharing/tests/Panels/Personal/PersonalPanelTest.php index cbad02432c90..b958fa8786a0 100644 --- a/apps/files_sharing/tests/Panels/Personal/PersonalPanelTest.php +++ b/apps/files_sharing/tests/Panels/Personal/PersonalPanelTest.php @@ -56,7 +56,20 @@ public function testGetPriority() { $this->assertEquals(100, $this->personalPanel->getPriority()); } - public function testGetPanel() { + public function globalSharingConfigProvider() { + return [ + [['shareapi_auto_accept_share' => 'yes'], '
'], + [['shareapi_auto_accept_share' => 'no'], '

Nothing to configure.

'], + ]; + } + + /** + * @dataProvider globalSharingConfigProvider + * + * @param array $globalConfigs + * @param string $expectedString + */ + public function testGetPanel($globalConfigs, $expectedString) { $mockUser = $this->getMockBuilder(IUser::class) ->disableOriginalConstructor() ->getMock(); @@ -67,8 +80,12 @@ public function testGetPanel() { $this->userSession->expects($this->any()) ->method('getUser') ->willReturn($mockUser); + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('core', 'shareapi_auto_accept_share', 'yes') + ->willReturn($globalConfigs['shareapi_auto_accept_share']); $templateHtml = $this->personalPanel->getPanel()->fetchPage(); - $this->assertContains('', $templateHtml); + $this->assertContains($expectedString, $templateHtml); } } diff --git a/tests/acceptance/features/bootstrap/WebUIPersonalSharingSettingsContext.php b/tests/acceptance/features/bootstrap/WebUIPersonalSharingSettingsContext.php index 989f57c58ce3..10add8f008b4 100644 --- a/tests/acceptance/features/bootstrap/WebUIPersonalSharingSettingsContext.php +++ b/tests/acceptance/features/bootstrap/WebUIPersonalSharingSettingsContext.php @@ -80,4 +80,26 @@ public function switchAutoAcceptingFederatedShares($action) { $this->getSession(), $action ); } + + /** + * @Then User-based auto accepting checkbox should not be displayed on the personal sharing settings page in the webUI + * + * @return void + */ + public function autoAcceptingCheckboxShouldNotBeDisplayedOnThePersonalSharingSettingsPageInTheWebui() { + PHPUnit_Framework_Assert::assertFalse( + $this->personalSharingSettingsPage->isAutoAcceptLocalSharesCheckboxDisplayed() + ); + } + + /** + * @Then User-based auto accepting from trusted servers checkbox should not be displayed on the personal sharing settings page in the webUI + * + * @return void + */ + public function autoAcceptingFederatedCheckboxShouldNotBeDisplayedOnThePersonalSharingSettingsPageInTheWebui() { + PHPUnit_Framework_Assert::assertFalse( + $this->personalSharingSettingsPage->isAutoAcceptFederatedSharesCheckboxDisplayed() + ); + } } diff --git a/tests/acceptance/features/lib/PersonalSharingSettingsPage.php b/tests/acceptance/features/lib/PersonalSharingSettingsPage.php index ccf942b95ead..9b8d1f6117be 100644 --- a/tests/acceptance/features/lib/PersonalSharingSettingsPage.php +++ b/tests/acceptance/features/lib/PersonalSharingSettingsPage.php @@ -33,6 +33,8 @@ class PersonalSharingSettingsPage extends SharingSettingsPage { * @var string $path */ protected $path = '/index.php/settings/personal?sectionid=sharing'; + protected $personalSharingPanelDivXpath + = '//div[@id="OCA\Files_Sharing\Panels\Personal\PersonalPanel"]'; protected $autoAcceptLocalSharesCheckboxXpath = '//label[@for="userAutoAcceptShareInput"]'; protected $autoAcceptLocalSharesCheckboxXpathCheckboxId @@ -76,7 +78,7 @@ public function toggleAutoAcceptingFederatedShares(Session $session, $action) { /** * there is no reliable loading indicator on the personal sharing settings page, - * so just wait for the auto accept checkbox to be there and all Ajax calls to finish + * so just wait for files_sharing personal panel div to be there and all Ajax calls to finish * * @param Session $session * @param int $timeout_msec @@ -89,7 +91,33 @@ public function waitTillPageIsLoaded( ) { $this->waitForOutstandingAjaxCalls($session); $this->waitTillXpathIsVisible( - $this->autoAcceptLocalSharesCheckboxXpath, $timeout_msec + $this->personalSharingPanelDivXpath, $timeout_msec ); } + + /** + * Check if the auto accept local shares checkbox is shown in the webui + * + * @return boolean + */ + public function isAutoAcceptLocalSharesCheckboxDisplayed() { + $localAutoAcceptCheckbox = $this->find('xpath', $this->autoAcceptLocalSharesCheckboxXpath); + if ($localAutoAcceptCheckbox === null) { + return false; + } + return true; + } + + /** + * Check if the auto accept local shares checkbox is shown in the webui + * + * @return boolean + */ + public function isAutoAcceptFederatedSharesCheckboxDisplayed() { + $localAutoAcceptCheckbox = $this->find('xpath', $this->autoAcceptFederatedSharesCheckboxXpath); + if ($localAutoAcceptCheckbox === null) { + return false; + } + return true; + } } diff --git a/tests/acceptance/features/webUISharingAcceptShares/acceptShares.feature b/tests/acceptance/features/webUISharingAcceptShares/acceptShares.feature index 718c9f317f06..f3568141b7f0 100644 --- a/tests/acceptance/features/webUISharingAcceptShares/acceptShares.feature +++ b/tests/acceptance/features/webUISharingAcceptShares/acceptShares.feature @@ -257,47 +257,27 @@ Feature: accept/decline shares coming from internal users #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 - @issue-34708 @issue-34705 - Scenario: User-based accepting is enabled while global is disabled - Given the setting "Automatically accept new incoming local user shares" in the section "Sharing" has been disabled + Scenario: User-based accepting is enabled 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 And the user has browsed to the personal sharing settings page - When the user disables automatically accepting new incoming local shares - And the user enables automatically accepting new incoming local shares + When the user enables automatically accepting new incoming local shares 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 not be listed on the webUI - #Then folder "simple-folder (2)" should be listed on the webUI + Then folder "simple-folder (2)" should be listed on the webUI And file "testimage (2).jpg" should be listed on the webUI - And folder "simple-folder" should be listed in the shared-with-you page on the webUI - #And folder "simple-folder (2)" should be listed in the shared-with-you page on the webUI + And folder "simple-folder (2)" should be listed in the shared-with-you page on the webUI And file "testimage (2).jpg" should be listed 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 (2)" should be in state "" 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 file "testimage (2).jpg" should be in state "" in the shared-with-you page on the webUI - @issue-34705 - Scenario: Admin enables auto-accept setting again after user disabled personal auto-accept setting + Scenario: User-based accepting checkbox is not visible while global is disabled Given the setting "Automatically accept new incoming local user shares" in the section "Sharing" has been disabled And user "user1" has logged in using the webUI And the user has browsed to the personal sharing settings page - When the user disables automatically accepting new incoming local shares - And the administrator enables the setting "Automatically accept new incoming local user shares" in the section "Sharing" - 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 - 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 - 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 file "testimage.jpg" should be in state "Pending" in the shared-with-you page on the webUI + Then User-based auto accepting checkbox should not be displayed on the personal sharing settings page in the webUI - @issue-34705 Scenario: Admin disables auto-accept setting again after user enabled personal auto-accept setting 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 @@ -309,11 +289,8 @@ Feature: accept/decline shares coming from internal users 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 not be listed on the webUI - #Then folder "simple-folder (2)" should be listed on the webUI - And file "testimage (2).jpg" should be listed on the webUI + And file "testimage (2).jpg" should not be listed on the webUI And folder "simple-folder" should be listed in the shared-with-you page on the webUI - #And folder "simple-folder (2)" should be listed in the shared-with-you page on the webUI - And file "testimage (2).jpg" 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" should be in state "Pending" 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 file "testimage (2).jpg" should be in state "" 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 diff --git a/tests/acceptance/features/webUISharingExternal/federationSharing.feature b/tests/acceptance/features/webUISharingExternal/federationSharing.feature index f54400391f2f..d3a2b7580b95 100644 --- a/tests/acceptance/features/webUISharingExternal/federationSharing.feature +++ b/tests/acceptance/features/webUISharingExternal/federationSharing.feature @@ -92,8 +92,7 @@ Feature: Federation Sharing - sharing with users on other cloud storages Then user "user2" should see the following elements | /lorem%20(2).txt | - @issue-34708 - Scenario: User-based auto accepting is enabled while global is disabled + Scenario: User-based accepting from trusted server checkbox is not visible while global is disabled Given parameter "autoAddServers" of app "federation" has been set to "1" And user "user1" from server "REMOTE" has shared "simple-folder" with user "user1" from server "LOCAL" And user "user1" from server "LOCAL" has accepted the last pending share @@ -101,12 +100,7 @@ Feature: Federation Sharing - sharing with users on other cloud storages And parameter "auto_accept_trusted" of app "federatedfilesharing" has been set to "no" And parameter "autoAddServers" of app "federation" has been set to "0" And the user has browsed to the personal sharing settings page - #delete the following line when issue-34708 is fixed - When the user disables automatically accepting remote shares from trusted servers - And the user enables automatically accepting remote shares from trusted servers - And user "user1" from server "REMOTE" shares "/lorem.txt" with user "user1" from server "LOCAL" using the sharing API - Then user "user1" should see the following elements - | /lorem%20(2).txt | + Then User-based auto accepting from trusted servers checkbox should not be displayed on the personal sharing settings page in the webUI @skip @issue-34742 Scenario: User-based & global auto accepting is enabled but remote server is not trusted