From b3c79272609c8cd6d8245f6653b2645180635214 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 14 Sep 2021 19:30:21 +0200 Subject: [PATCH] Show warning on the share settings when the File Shares app is disabled Closes #3706 Signed-off-by: Thomas Citharel --- apps/settings/lib/Settings/Admin/Sharing.php | 13 +- .../templates/settings/admin/sharing.php | 281 +++++++++--------- .../tests/Settings/Admin/SharingTest.php | 30 +- 3 files changed, 173 insertions(+), 151 deletions(-) diff --git a/apps/settings/lib/Settings/Admin/Sharing.php b/apps/settings/lib/Settings/Admin/Sharing.php index 85d3e4d8d40a6..24be9f1426ac6 100644 --- a/apps/settings/lib/Settings/Admin/Sharing.php +++ b/apps/settings/lib/Settings/Admin/Sharing.php @@ -12,6 +12,7 @@ * @author Roeland Jago Douma * @author Sascha Wiswedel * @author Vincent Petry + * @author Thomas Citharel * * @license GNU AGPL version 3 or any later version * @@ -31,7 +32,7 @@ */ namespace OCA\Settings\Settings\Admin; -use OC\Share\Share; +use OCP\App\IAppManager; use OCP\AppFramework\Http\TemplateResponse; use OCP\Constants; use OCP\IConfig; @@ -50,13 +51,14 @@ class Sharing implements ISettings { /** @var IManager */ private $shareManager; - /** - * @param IConfig $config - */ - public function __construct(IConfig $config, IL10N $l, IManager $shareManager) { + /** @var IAppManager */ + private $appManager; + + public function __construct(IConfig $config, IL10N $l, IManager $shareManager, IAppManager $appManager) { $this->config = $config; $this->l = $l; $this->shareManager = $shareManager; + $this->appManager = $appManager; } /** @@ -72,6 +74,7 @@ public function getForm() { $parameters = [ // Built-In Sharing + 'sharingAppEnabled' => $this->appManager->isEnabledForUser('files_sharing'), 'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'), 'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'), 'allowLinksExcludeGroups' => $linksExcludeGroupsList, diff --git a/apps/settings/templates/settings/admin/sharing.php b/apps/settings/templates/settings/admin/sharing.php index 75ad6f76d2346..62be48dc99d4a 100644 --- a/apps/settings/templates/settings/admin/sharing.php +++ b/apps/settings/templates/settings/admin/sharing.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2016 Arthur Schiwon * * @author Arthur Schiwon + * @author Thomas Citharel * * @license GNU AGPL version 3 or any later version * @@ -28,234 +29,240 @@

t('Sharing'));?>

- -

t('As admin you can fine-tune the sharing behavior. Please see the documentation for more information.'));?>

-

- +

t('You need to enable the File sharing App.')); ?>

+ +
+ +

t('As admin you can fine-tune the sharing behavior. Please see the documentation for more information.'));?>

+

+ /> -
-

+
+

-

- /> -
-

-

t('Set default expiration date for shares'));?>
+

+

- t('Expire after') . ' '); ?> - ' /> - t('day(s)')); ?> - t('Expire after') . ' '); ?> + ' /> + t('day(s)')); ?> + /> -
-

+
+

-

- /> -
-

-

t('Set default expiration date for shares to other servers'));?>
+

+

- t('Expire after'). ' '); ?> - ' /> - t('day(s)')); ?> - t('Expire after'). ' '); ?> + ' /> + t('day(s)')); ?> + /> -
-

+
+

-

"> - /> -
-

+
+

-

- /> -
- t('Allow public uploads'));?>
+ /> -
- t('Always ask for a password'));?>
+ /> -
+
- /> -
+
-

-

- t('Expire after'). ' '); ?> - ' /> - t('day(s)')); ?> - t('Expire after'). ' '); ?> + ' /> + t('day(s)')); ?> + /> -
-

-

t('Enforce expiration date'));?>
+

+

-

- t('Exclude groups from creating link shares:'));?> -

-

+ t('Exclude groups from creating link shares:'));?> +

+

- -

- +

+ /> -
-

-

t('Allow resharing'));?>
+

+

- /> -
-

-

t('Allow sharing with groups'));?>
+

+

- /> -
-

-

t('Restrict users to only share with users in their groups'));?>
+

+

- /> -
-

-

t('Exclude groups from sharing'));?>
+

+

- -
- t('These groups will still be able to receive shares, but not to initiate them.')); ?> -

+ +
+ t('These groups will still be able to receive shares, but not to initiate them.')); ?> +

-

"> - /> -
-

+
+

-

- /> -
-

+
+

-

- /> -
-

-

t('Allow username autocompletion to users based on phone number integration'));?>
+

+

- t('If autocompletion "same group" and "phone number integration" are enabled a match in either is enough to show the user.'));?>
-

-


+

+

- /> -
-

+
+

-

- + /> - - -
- -

+

-

t('Default share permissions'));?>

- -

- - + /> - - -

+ + +

+
+
diff --git a/apps/settings/tests/Settings/Admin/SharingTest.php b/apps/settings/tests/Settings/Admin/SharingTest.php index ff25c7174986b..c90429f6dd848 100644 --- a/apps/settings/tests/Settings/Admin/SharingTest.php +++ b/apps/settings/tests/Settings/Admin/SharingTest.php @@ -32,11 +32,13 @@ namespace OCA\Settings\Tests\Settings\Admin; use OCA\Settings\Settings\Admin\Sharing; +use OCP\App\IAppManager; use OCP\AppFramework\Http\TemplateResponse; use OCP\Constants; use OCP\IConfig; use OCP\IL10N; use OCP\Share\IManager; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class SharingTest extends TestCase { @@ -44,10 +46,12 @@ class SharingTest extends TestCase { private $admin; /** @var IConfig */ private $config; - /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IL10N|MockObject */ private $l10n; - /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IManager|MockObject */ private $shareManager; + /** @var IAppManager|MockObject */ + private $appManager; protected function setUp(): void { parent::setUp(); @@ -55,15 +59,17 @@ protected function setUp(): void { $this->l10n = $this->getMockBuilder(IL10N::class)->getMock(); $this->shareManager = $this->getMockBuilder(IManager::class)->getMock(); + $this->appManager = $this->getMockBuilder(IAppManager::class)->getMock(); $this->admin = new Sharing( $this->config, $this->l10n, - $this->shareManager + $this->shareManager, + $this->appManager ); } - public function testGetFormWithoutExcludedGroups() { + public function testGetFormWithoutExcludedGroups(): void { $this->config ->method('getAppValue') ->willReturnMap([ @@ -94,10 +100,13 @@ public function testGetFormWithoutExcludedGroups() { $this->shareManager->method('shareWithGroupMembersOnly') ->willReturn(false); + $this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(false); + $expected = new TemplateResponse( 'settings', 'settings/admin/sharing', [ + 'sharingAppEnabled' => false, 'allowGroupSharing' => 'yes', 'allowLinks' => 'yes', 'allowPublicUpload' => 'yes', @@ -117,7 +126,7 @@ public function testGetFormWithoutExcludedGroups() { 'publicShareDisclaimerText' => 'Lorem ipsum', 'enableLinkPasswordByDefault' => 'yes', 'shareApiDefaultPermissions' => Constants::PERMISSION_ALL, - 'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', []), + 'shareApiDefaultPermissionsCheckboxes' => self::invokePrivate($this->admin, 'getSharePermissionList', []), 'shareDefaultInternalExpireDateSet' => 'no', 'shareInternalExpireAfterNDays' => '7', 'shareInternalEnforceExpireDate' => 'no', @@ -132,7 +141,7 @@ public function testGetFormWithoutExcludedGroups() { $this->assertEquals($expected, $this->admin->getForm()); } - public function testGetFormWithExcludedGroups() { + public function testGetFormWithExcludedGroups(): void { $this->config ->method('getAppValue') ->willReturnMap([ @@ -163,10 +172,13 @@ public function testGetFormWithExcludedGroups() { $this->shareManager->method('shareWithGroupMembersOnly') ->willReturn(false); + $this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(true); + $expected = new TemplateResponse( 'settings', 'settings/admin/sharing', [ + 'sharingAppEnabled' => true, 'allowGroupSharing' => 'yes', 'allowLinks' => 'yes', 'allowPublicUpload' => 'yes', @@ -186,7 +198,7 @@ public function testGetFormWithExcludedGroups() { 'publicShareDisclaimerText' => 'Lorem ipsum', 'enableLinkPasswordByDefault' => 'yes', 'shareApiDefaultPermissions' => Constants::PERMISSION_ALL, - 'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', []), + 'shareApiDefaultPermissionsCheckboxes' => self::invokePrivate($this->admin, 'getSharePermissionList', []), 'shareDefaultInternalExpireDateSet' => 'no', 'shareInternalExpireAfterNDays' => '7', 'shareInternalEnforceExpireDate' => 'no', @@ -201,11 +213,11 @@ public function testGetFormWithExcludedGroups() { $this->assertEquals($expected, $this->admin->getForm()); } - public function testGetSection() { + public function testGetSection(): void { $this->assertSame('sharing', $this->admin->getSection()); } - public function testGetPriority() { + public function testGetPriority(): void { $this->assertSame(0, $this->admin->getPriority()); } }