diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php index 6d8e2dd8d8..d7bc169bf4 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -37,6 +37,7 @@ use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSException; use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\AppFramework\OCS\OCSNotFoundException; +use OCP\IConfig; use OCP\IL10N; use OCP\IRequest; @@ -105,6 +106,7 @@ class ApiTest extends TestCase { ->will($this->returnCallback(function($text, $parameters = []) { return vsprintf($text, $parameters); })); + $config = $this->createMock(IConfig::class); return new ShareAPIController( self::APP_NAME, @@ -115,7 +117,8 @@ class ApiTest extends TestCase { \OC::$server->getRootFolder(), \OC::$server->getURLGenerator(), $userId, - $l + $l, + $config ); } diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index c438dac252..a475474e3c 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -31,6 +31,7 @@ use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\Storage; +use OCP\IConfig; use OCP\IL10N; use OCA\Files_Sharing\Controller\ShareAPIController; use OCP\Files\NotFoundException; @@ -84,6 +85,9 @@ class ShareAPIControllerTest extends TestCase { /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */ private $l; + /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ + private $config; + protected function setUp() { $this->shareManager = $this->createMock(IManager::class); $this->shareManager @@ -102,6 +106,7 @@ class ShareAPIControllerTest extends TestCase { ->will($this->returnCallback(function($text, $parameters = []) { return vsprintf($text, $parameters); })); + $this->config = $this->createMock(IConfig::class); $this->ocs = new ShareAPIController( $this->appName, @@ -112,7 +117,8 @@ class ShareAPIControllerTest extends TestCase { $this->rootFolder, $this->urlGenerator, $this->currentUser, - $this->l + $this->l, + $this->config ); } @@ -131,6 +137,7 @@ class ShareAPIControllerTest extends TestCase { $this->urlGenerator, $this->currentUser, $this->l, + $this->config ])->setMethods(['formatShare']) ->getMock(); } @@ -439,6 +446,7 @@ class ShareAPIControllerTest extends TestCase { $this->urlGenerator, $this->currentUser, $this->l, + $this->config ])->setMethods(['canAccessShare']) ->getMock(); @@ -707,6 +715,7 @@ class ShareAPIControllerTest extends TestCase { $this->urlGenerator, $this->currentUser, $this->l, + $this->config ])->setMethods(['formatShare']) ->getMock(); @@ -804,6 +813,7 @@ class ShareAPIControllerTest extends TestCase { $this->urlGenerator, $this->currentUser, $this->l, + $this->config ])->setMethods(['formatShare']) ->getMock(); @@ -1119,6 +1129,7 @@ class ShareAPIControllerTest extends TestCase { $this->urlGenerator, $this->currentUser, $this->l, + $this->config ])->setMethods(['formatShare']) ->getMock(); diff --git a/lib/private/Settings/Admin/Sharing.php b/lib/private/Settings/Admin/Sharing.php index 7b60efdc67..dfc0b11478 100644 --- a/lib/private/Settings/Admin/Sharing.php +++ b/lib/private/Settings/Admin/Sharing.php @@ -57,7 +57,37 @@ class Sharing implements ISettings { $excludeGroupsList = !is_null(json_decode($excludedGroups)) ? implode('|', json_decode($excludedGroups, true)) : ''; - $permList = [ + $parameters = [ + // Built-In Sharing + 'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'), + 'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'), + 'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'), + 'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'), + 'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'), + 'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(), + 'onlyShareWithGroupMembers' => Share::shareWithGroupMembersOnly(), + 'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'), + 'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'), + 'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'), + 'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'), + 'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes', + 'shareExcludedGroupsList' => $excludeGroupsList, + 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null), + 'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'), + 'shareApiDefaultPermissions' => $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL), + 'shareApiDefaultPermissionsCheckboxes' => $this->getSharePermissionList(), + ]; + + return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, ''); + } + + /** + * get share permission list for template + * + * @return array + */ + private function getSharePermissionList() { + return [ [ 'id' => 'cancreate', 'label' => $this->l->t('Create'), @@ -79,29 +109,6 @@ class Sharing implements ISettings { 'value' => Constants::PERMISSION_SHARE ], ]; - - $parameters = [ - // Built-In Sharing - 'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'), - 'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'), - 'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'), - 'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'), - 'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'), - 'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(), - 'onlyShareWithGroupMembers' => Share::shareWithGroupMembersOnly(), - 'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'), - 'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'), - 'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'), - 'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'), - 'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes', - 'shareExcludedGroupsList' => $excludeGroupsList, - 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null), - 'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'), - 'shareApiDefaultPermissions' => $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL), - 'shareApiDefaultPermissionsCheckboxes' => $permList, - ]; - - return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, ''); } /** diff --git a/tests/lib/Settings/Admin/SharingTest.php b/tests/lib/Settings/Admin/SharingTest.php index ee60979b96..79065fb8d2 100644 --- a/tests/lib/Settings/Admin/SharingTest.php +++ b/tests/lib/Settings/Admin/SharingTest.php @@ -25,6 +25,7 @@ namespace Test\Settings\Admin; use OC\Settings\Admin\Sharing; use OCP\AppFramework\Http\TemplateResponse; +use OCP\Constants; use OCP\IConfig; use OCP\IL10N; use Test\TestCase; @@ -114,6 +115,11 @@ class SharingTest extends TestCase { ->method('getAppValue') ->with('core', 'shareapi_enable_link_password_by_default', 'no') ->willReturn('yes'); + $this->config + ->expects($this->at(13)) + ->method('getAppValue') + ->with('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL) + ->willReturn(Constants::PERMISSION_ALL); $expected = new TemplateResponse( 'settings', @@ -133,7 +139,9 @@ class SharingTest extends TestCase { 'shareExcludeGroups' => false, 'shareExcludedGroupsList' => '', 'publicShareDisclaimerText' => 'Lorem ipsum', - 'enableLinkPasswordByDefault' => 'yes' + 'enableLinkPasswordByDefault' => 'yes', + 'shareApiDefaultPermissions' => Constants::PERMISSION_ALL, + 'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', []) ], '' ); @@ -207,6 +215,12 @@ class SharingTest extends TestCase { ->method('getAppValue') ->with('core', 'shareapi_enable_link_password_by_default', 'no') ->willReturn('yes'); + $this->config + ->expects($this->at(13)) + ->method('getAppValue') + ->with('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL) + ->willReturn(Constants::PERMISSION_ALL); + $expected = new TemplateResponse( 'settings', @@ -226,7 +240,9 @@ class SharingTest extends TestCase { 'shareExcludeGroups' => true, 'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers', 'publicShareDisclaimerText' => 'Lorem ipsum', - 'enableLinkPasswordByDefault' => 'yes' + 'enableLinkPasswordByDefault' => 'yes', + 'shareApiDefaultPermissions' => Constants::PERMISSION_ALL, + 'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', []) ], '' );