From 2c03c7c96f2205176c44c3d324dadefe654bd6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Tue, 16 Jan 2018 19:06:28 +0100 Subject: [PATCH 1/9] Add switch to disable password enforcement in upload-only shares Base for share 2.0 --- core/js/config.php | 2 ++ core/js/shareconfigmodel.js | 1 + core/js/sharedialoglinkshareview.js | 3 ++- lib/private/Share20/Manager.php | 17 +++++++++++++---- settings/Panels/Admin/FileSharing.php | 1 + settings/templates/panels/admin/filesharing.php | 4 ++++ 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/core/js/config.php b/core/js/config.php index 3536f239eb70..965995d05a93 100644 --- a/core/js/config.php +++ b/core/js/config.php @@ -66,6 +66,7 @@ $value = $config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'); $enforceDefaultExpireDate = ($value === 'yes') ? true : false; } +$disableEnforceLinkPasswordForUploadOnly = $config->getAppValue('core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no') === 'yes'; $outgoingServer2serverShareEnabled = $config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; $countOfDataLocation = 0; @@ -164,6 +165,7 @@ 'defaultExpireDate' => $defaultExpireDate, 'defaultExpireDateEnforced' => $enforceDefaultExpireDate, 'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(), + 'disableEnforceLinkPasswordForUploadOnly' => $disableEnforceLinkPasswordForUploadOnly, 'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(), 'resharingAllowed' => \OCP\Share::isResharingAllowed(), 'remoteShareAllowed' => $outgoingServer2serverShareEnabled, diff --git a/core/js/shareconfigmodel.js b/core/js/shareconfigmodel.js index ec328804ea60..585bbbb7b0d0 100644 --- a/core/js/shareconfigmodel.js +++ b/core/js/shareconfigmodel.js @@ -22,6 +22,7 @@ defaults: { publicUploadEnabled: false, enforcePasswordForPublicLink: oc_appconfig.core.enforcePasswordForPublicLink, + disableEnforceLinkPasswordForUploadOnly: oc_appconfig.core.disableEnforceLinkPasswordForUploadOnly, isDefaultExpireDateEnforced: oc_appconfig.core.defaultExpireDateEnforced === true, isDefaultExpireDateEnabled: oc_appconfig.core.defaultExpireDateEnabled === true, isRemoteShareAllowed: oc_appconfig.core.remoteShareAllowed, diff --git a/core/js/sharedialoglinkshareview.js b/core/js/sharedialoglinkshareview.js index 6828eb377901..ceefb8815f5c 100644 --- a/core/js/sharedialoglinkshareview.js +++ b/core/js/sharedialoglinkshareview.js @@ -146,6 +146,7 @@ if (this.configModel.get('enforcePasswordForPublicLink') && !password + && (this.model.get('permissions') !== OC.PERMISSION_CREATE || !this.configModel.get('disableEnforceLinkPasswordForUploadOnly')) && (this.model.isNew() || !this.model.get('encryptedPassword')) ) { $password.addClass('error'); @@ -221,7 +222,7 @@ this.$el.html(this.template({ cid: this.cid, passwordPlaceholder: isPasswordSet ? PASSWORD_PLACEHOLDER_STARS : PASSWORD_PLACEHOLDER_MESSAGE, - isPasswordRequired: this.configModel.get('enforcePasswordForPublicLink'), + isPasswordRequired: this.configModel.get('enforcePasswordForPublicLink') && (this.model.get('permissions') !== OC.PERMISSION_CREATE || !this.configModel.get('disableEnforceLinkPasswordForUploadOnly')), namePlaceholder: t('core', 'Name'), name: this.model.get('name'), isPasswordSet: isPasswordSet, diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 2855717e84ed..42083bf66b79 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -147,10 +147,10 @@ private function splitFullId($id) { * @param string $password * @throws \Exception */ - protected function verifyPassword($password) { + protected function verifyPassword($password, $permissions) { if ($password === null) { // No password is set, check if this is allowed. - if ($this->shareApiLinkEnforcePassword()) { + if ($this->shareApiLinkEnforcePassword() && ($permissions !== \OCP\CONSTANTS::PERMISSION_CREATE || !$this->shareApiLinkEnforcePasswordDisabledForUploads())) { throw new \InvalidArgumentException('Passwords are enforced for link shares'); } @@ -585,7 +585,7 @@ public function createShare(\OCP\Share\IShare $share) { $this->validateExpirationDate($share); //Verify the password - $this->verifyPassword($share->getPassword()); + $this->verifyPassword($share->getPassword(), $share->getPermissions()); // If a password is set. Hash it! if ($share->getPassword() !== null) { @@ -699,7 +699,7 @@ public function updateShare(\OCP\Share\IShare $share) { // Password updated. if ($share->getPassword() !== $originalShare->getPassword()) { //Verify the password - $this->verifyPassword($share->getPassword()); + $this->verifyPassword($share->getPassword(), $share->getPermissions()); // If a password is set. Hash it! if ($share->getPassword() !== null) { @@ -1259,6 +1259,15 @@ public function shareApiLinkEnforcePassword() { return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; } + /** + * Is password enforced for upload-only shares? + * + * @return bool + */ + public function shareApiLinkEnforcePasswordDisabledForUploads() { + return $this->config->getAppValue('core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no') === 'yes'; + } + /** * Is default expire date enabled * diff --git a/settings/Panels/Admin/FileSharing.php b/settings/Panels/Admin/FileSharing.php index 0cb8ae771355..bb0e33a1e36c 100644 --- a/settings/Panels/Admin/FileSharing.php +++ b/settings/Panels/Admin/FileSharing.php @@ -53,6 +53,7 @@ public function getPanel() { $template->assign('allowLinks', $this->config->getAppValue('core', 'shareapi_allow_links', 'yes')); $template->assign('allowPublicUpload', $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes')); $template->assign('enforceLinkPassword', $this->helper->isPublicLinkPasswordRequired()); + $template->assign('disableEnforceLinkPasswordForUploadOnly', $this->config->getAppValue('core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no')); $template->assign('shareDefaultExpireDateSet', $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no')); $template->assign('allowPublicMailNotification', $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no')); $template->assign('allowSocialShare', $this->config->getAppValue('core', 'shareapi_allow_social_share', 'yes')); diff --git a/settings/templates/panels/admin/filesharing.php b/settings/templates/panels/admin/filesharing.php index 9202aa3d236d..0f7036f48792 100644 --- a/settings/templates/panels/admin/filesharing.php +++ b/settings/templates/panels/admin/filesharing.php @@ -27,6 +27,10 @@ value="1" />
+ /> +
+ />
From 51a8ccc60eba99219d324d70974691b224ebb5ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Wed, 17 Jan 2018 10:59:44 +0100 Subject: [PATCH 2/9] Add method to the interface and verify the password again when the permissions change empty password from upload-only share might not be adecuate if the share changes to a read-only share --- lib/private/Share20/Manager.php | 3 ++- lib/public/Share/IManager.php | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 42083bf66b79..aa24e592befb 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -697,7 +697,8 @@ public function updateShare(\OCP\Share\IShare $share) { $this->linkCreateChecks($share); // Password updated. - if ($share->getPassword() !== $originalShare->getPassword()) { + if ($share->getPassword() !== $originalShare->getPassword() || + $share->getPermissions() !== $originalShare->getPermissions()) { //Verify the password $this->verifyPassword($share->getPassword(), $share->getPermissions()); diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php index d9df3f3930f1..c531287d4529 100644 --- a/lib/public/Share/IManager.php +++ b/lib/public/Share/IManager.php @@ -116,7 +116,7 @@ public function getSharesBy($userId, $shareType, $path = null, $reshares = false /** * Get shares shared with $userId for specified share types. * Filter by $node if provided - * + * * @param string $userId * @param int[] $shareTypes - ref \OC\Share\Constants[] * @param Node|null $node @@ -236,6 +236,14 @@ public function shareApiAllowLinks(); */ public function shareApiLinkEnforcePassword(); + /** + * Is password enforced for upload-only shares? + * + * @return bool true -> password isn't enforce for upload-only share, false otherwise + * @since 10.0.6 + */ + public function shareApiLinkEnforcePasswordDisabledForUploads(); + /** * Is default expire date enabled * From ae23ca2a9ea8c34f0b69c47ecb38805909e86268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Wed, 17 Jan 2018 12:26:16 +0100 Subject: [PATCH 3/9] Remove password requirement mark in the dialog --- core/js/sharedialoglinkshareview.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/js/sharedialoglinkshareview.js b/core/js/sharedialoglinkshareview.js index ceefb8815f5c..0e58197b2eeb 100644 --- a/core/js/sharedialoglinkshareview.js +++ b/core/js/sharedialoglinkshareview.js @@ -40,7 +40,7 @@ '' + '{{/if}}' + '' + @@ -101,7 +101,7 @@ _getPermissions: function() { var permissions = this.$('input[name="publicPermissions"]:checked').val(); - return (permissions) ? permissions : OC.PERMISSION_READ; + return (permissions) ? parseInt(permissions, 10) : OC.PERMISSION_READ; }, _save: function () { @@ -146,7 +146,7 @@ if (this.configModel.get('enforcePasswordForPublicLink') && !password - && (this.model.get('permissions') !== OC.PERMISSION_CREATE || !this.configModel.get('disableEnforceLinkPasswordForUploadOnly')) + && (this._getPermissions() !== OC.PERMISSION_CREATE || !this.configModel.get('disableEnforceLinkPasswordForUploadOnly')) && (this.model.isNew() || !this.model.get('encryptedPassword')) ) { $password.addClass('error'); @@ -222,7 +222,6 @@ this.$el.html(this.template({ cid: this.cid, passwordPlaceholder: isPasswordSet ? PASSWORD_PLACEHOLDER_STARS : PASSWORD_PLACEHOLDER_MESSAGE, - isPasswordRequired: this.configModel.get('enforcePasswordForPublicLink') && (this.model.get('permissions') !== OC.PERMISSION_CREATE || !this.configModel.get('disableEnforceLinkPasswordForUploadOnly')), namePlaceholder: t('core', 'Name'), name: this.model.get('name'), isPasswordSet: isPasswordSet, From 36d2ac3484c23f72a009d7093536210e8646efb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Wed, 17 Jan 2018 13:56:49 +0100 Subject: [PATCH 4/9] Adjust tests --- .../specs/sharedialoglinkshareviewSpec.js | 20 +++------- tests/lib/Share20/ManagerTest.php | 40 +++++++++++++++---- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/core/js/tests/specs/sharedialoglinkshareviewSpec.js b/core/js/tests/specs/sharedialoglinkshareviewSpec.js index 2fbf2c29d58a..95fa017c07f9 100644 --- a/core/js/tests/specs/sharedialoglinkshareviewSpec.js +++ b/core/js/tests/specs/sharedialoglinkshareviewSpec.js @@ -230,16 +230,6 @@ describe('OC.Share.ShareDialogLinkShareView', function() { expect(view.$('.linkPassText').val()).toEqual(''); expect(view.$('.linkPassText').attr('placeholder')).toEqual(PASSWORD_PLACEHOLDER_STARS); }); - it('renders required indicator when password is enforced', function() { - configModel.set('enforcePasswordForPublicLink', true); - view.render(); - expect(view.$('.linkPass .required-indicator').length).toEqual(1); - }); - it('does not render required indicator when password not enforced', function() { - configModel.set('enforcePasswordForPublicLink', false); - view.render(); - expect(view.$('.linkPass .required-indicator').length).toEqual(0); - }); }); }); @@ -271,7 +261,7 @@ describe('OC.Share.ShareDialogLinkShareView', function() { name: 'first link', expireDate: '', password: 'newpassword', - permissions: OC.PERMISSION_READ.toString(), + permissions: OC.PERMISSION_READ, shareType: OC.Share.SHARE_TYPE_LINK }); }); @@ -284,7 +274,7 @@ describe('OC.Share.ShareDialogLinkShareView', function() { expect(saveStub.getCall(0).args[0]).toEqual({ name: 'first link', expireDate: '', - permissions: OC.PERMISSION_READ.toString(), + permissions: OC.PERMISSION_READ, shareType: OC.Share.SHARE_TYPE_LINK }); }); @@ -367,8 +357,8 @@ describe('OC.Share.ShareDialogLinkShareView', function() { beforeEach(function() { publicUploadConfigStub = sinon.stub(configModel, 'isPublicUploadEnabled'); }); - afterEach(function() { - publicUploadConfigStub.restore(); + afterEach(function() { + publicUploadConfigStub.restore(); }); var dataProvider = [ @@ -379,7 +369,7 @@ describe('OC.Share.ShareDialogLinkShareView', function() { ]; function testPermissions(globalEnabled, expectedPerms) { - expectedPerms = expectedPerms.toString(); + expectedPerms = expectedPerms; it('sets permissions to ' + expectedPerms + ' if global enabled is ' + globalEnabled + ' and corresponding radiobutton is checked', function() { diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 1a2513eb12fb..d89e6b5a450b 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -522,23 +522,48 @@ public function testGetExpiredShareById() { public function testVerifyPasswordNullButEnforced() { $this->config->method('getAppValue')->will($this->returnValueMap([ ['core', 'shareapi_enforce_links_password', 'no', 'yes'], + ['core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no', 'no'], ])); - $this->invokePrivate($this->manager, 'verifyPassword', [null]); + $this->invokePrivate($this->manager, 'verifyPassword', [null, \OCP\Constants::PERMISSION_READ]); } public function testVerifyPasswordNull() { $this->config->method('getAppValue')->will($this->returnValueMap([ - ['core', 'shareapi_enforce_links_password', 'no', 'no'], + ['core', 'shareapi_enforce_links_password', 'no', 'no'], + ['core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no', 'no'], ])); - $result = $this->invokePrivate($this->manager, 'verifyPassword', [null]); + $result = $this->invokePrivate($this->manager, 'verifyPassword', [null, \OCP\Constants::PERMISSION_READ]); $this->assertNull($result); } + public function testVerifyPasswordNullEnforcedDisableForWriteOnly() { + $this->config->method('getAppValue')->will($this->returnValueMap([ + ['core', 'shareapi_enforce_links_password', 'no', 'yes'], + ['core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no', 'yes'], + ])); + + $this->invokePrivate($this->manager, 'verifyPassword', [null, \OCP\Constants::PERMISSION_CREATE]); + } + + /** + * @expectedException InvalidArgumentException + * @expectedExceptionMessage Passwords are enforced for link shares + */ + public function testVerifyPasswordNullEnforcedDisableForWriteOnlyButReadOnly() { + $this->config->method('getAppValue')->will($this->returnValueMap([ + ['core', 'shareapi_enforce_links_password', 'no', 'yes'], + ['core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no', 'yes'], + ])); + + $this->invokePrivate($this->manager, 'verifyPassword', [null, \OCP\Constants::PERMISSION_READ]); + } + public function testVerifyPasswordHook() { $this->config->method('getAppValue')->will($this->returnValueMap([ - ['core', 'shareapi_enforce_links_password', 'no', 'no'], + ['core', 'shareapi_enforce_links_password', 'no', 'no'], + ['core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no', 'no'], ])); $hookListner = $this->getMockBuilder('Dummy')->setMethods(['listner'])->getMock(); @@ -552,7 +577,7 @@ public function testVerifyPasswordHook() { 'message' => '' ]); - $result = $this->invokePrivate($this->manager, 'verifyPassword', ['password']); + $result = $this->invokePrivate($this->manager, 'verifyPassword', ['password', \OCP\Constants::PERMISSION_READ]); $this->assertNull($result); } @@ -562,12 +587,13 @@ public function testVerifyPasswordHook() { */ public function testVerifyPasswordHookFails() { $this->config->method('getAppValue')->will($this->returnValueMap([ - ['core', 'shareapi_enforce_links_password', 'no', 'no'], + ['core', 'shareapi_enforce_links_password', 'no', 'no'], + ['core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no', 'no'], ])); $dummy = new DummyPassword(); \OCP\Util::connectHook('\OC\Share', 'verifyPassword', $dummy, 'listner'); - $this->invokePrivate($this->manager, 'verifyPassword', ['password']); + $this->invokePrivate($this->manager, 'verifyPassword', ['password', \OCP\Constants::PERMISSION_READ]); } public function createShare($id, $type, $path, $sharedWith, $sharedBy, $shareOwner, From 48bcb64b47dab580c2ce21beae68a94d0a802329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Mon, 22 Jan 2018 15:20:08 +0100 Subject: [PATCH 5/9] Changed to use 3 options --- core/js/config.php | 8 ++- core/js/shareconfigmodel.js | 4 +- core/js/sharedialoglinkshareview.js | 18 ++++- lib/private/Share20/Manager.php | 68 +++++++++++++----- lib/public/Share/IManager.php | 25 ++++++- settings/Panels/Admin/FileSharing.php | 5 +- .../templates/panels/admin/filesharing.php | 16 +++-- tests/lib/Share20/ManagerTest.php | 69 +++++++++++-------- 8 files changed, 152 insertions(+), 61 deletions(-) diff --git a/core/js/config.php b/core/js/config.php index 965995d05a93..7b9b9bedd78a 100644 --- a/core/js/config.php +++ b/core/js/config.php @@ -66,7 +66,9 @@ $value = $config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'); $enforceDefaultExpireDate = ($value === 'yes') ? true : false; } -$disableEnforceLinkPasswordForUploadOnly = $config->getAppValue('core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no') === 'yes'; +$enforceLinkPasswordReadOnly = $config->getAppValue('core', 'shareapi_enforce_links_password_read_only', 'no') === 'yes'; +$enforceLinkPasswordReadWrite = $config->getAppValue('core', 'shareapi_enforce_links_password_read_write', 'no') === 'yes'; +$enforceLinkPasswordWriteOnly = $config->getAppValue('core', 'shareapi_enforce_links_password_write_only', 'no') === 'yes'; $outgoingServer2serverShareEnabled = $config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; $countOfDataLocation = 0; @@ -165,7 +167,9 @@ 'defaultExpireDate' => $defaultExpireDate, 'defaultExpireDateEnforced' => $enforceDefaultExpireDate, 'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(), - 'disableEnforceLinkPasswordForUploadOnly' => $disableEnforceLinkPasswordForUploadOnly, + 'enforceLinkPasswordReadOnly' => $enforceLinkPasswordReadOnly, + 'enforceLinkPasswordReadWrite' => $enforceLinkPasswordReadWrite, + 'enforceLinkPasswordWriteOnly' => $enforceLinkPasswordWriteOnly, 'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(), 'resharingAllowed' => \OCP\Share::isResharingAllowed(), 'remoteShareAllowed' => $outgoingServer2serverShareEnabled, diff --git a/core/js/shareconfigmodel.js b/core/js/shareconfigmodel.js index 585bbbb7b0d0..8c2f9d8a09b7 100644 --- a/core/js/shareconfigmodel.js +++ b/core/js/shareconfigmodel.js @@ -22,7 +22,9 @@ defaults: { publicUploadEnabled: false, enforcePasswordForPublicLink: oc_appconfig.core.enforcePasswordForPublicLink, - disableEnforceLinkPasswordForUploadOnly: oc_appconfig.core.disableEnforceLinkPasswordForUploadOnly, + enforceLinkPasswordReadOnly: oc_appconfig.core.enforceLinkPasswordReadOnly, + enforceLinkPasswordReadWrite: oc_appconfig.core.enforceLinkPasswordReadWrite, + enforceLinkPasswordWriteOnly: oc_appconfig.core.enforceLinkPasswordWriteOnly, isDefaultExpireDateEnforced: oc_appconfig.core.defaultExpireDateEnforced === true, isDefaultExpireDateEnabled: oc_appconfig.core.defaultExpireDateEnabled === true, isRemoteShareAllowed: oc_appconfig.core.remoteShareAllowed, diff --git a/core/js/sharedialoglinkshareview.js b/core/js/sharedialoglinkshareview.js index 0e58197b2eeb..6211b2dec477 100644 --- a/core/js/sharedialoglinkshareview.js +++ b/core/js/sharedialoglinkshareview.js @@ -104,6 +104,19 @@ return (permissions) ? parseInt(permissions, 10) : OC.PERMISSION_READ; }, + _shouldRequirePassword: function() { + // matching passwordMustBeEnforced from server side + var permissions = this._getPermissions(); + var roEnforcement = permissions === OC.PERMISSION_READ && this.configModel.get('enforceLinkPasswordReadOnly'); + var woEnforcement = permissions === OC.PERMISSION_CREATE && this.configModel.get('enforceLinkPasswordWriteOnly'); + var rwEnforcement = (permissions !== OC.PERMISSION_READ && permissions !== OC.PERMISSION_CREATE) && this.configModel.get('enforceLinkPasswordReadWrite'); + if (roEnforcement || woEnforcement || rwEnforcement) { + return true; + } else { + return false; + } + }, + _save: function () { var deferred = $.Deferred(); var $el = this.$el; @@ -144,9 +157,8 @@ var validates = true; validates &= this.expirationView.validate(); - if (this.configModel.get('enforcePasswordForPublicLink') - && !password - && (this._getPermissions() !== OC.PERMISSION_CREATE || !this.configModel.get('disableEnforceLinkPasswordForUploadOnly')) + if (!password + && this._shouldRequirePassword() && (this.model.isNew() || !this.model.get('encryptedPassword')) ) { $password.addClass('error'); diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index aa24e592befb..0aa6a7f148cc 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -147,16 +147,7 @@ private function splitFullId($id) { * @param string $password * @throws \Exception */ - protected function verifyPassword($password, $permissions) { - if ($password === null) { - // No password is set, check if this is allowed. - if ($this->shareApiLinkEnforcePassword() && ($permissions !== \OCP\CONSTANTS::PERMISSION_CREATE || !$this->shareApiLinkEnforcePasswordDisabledForUploads())) { - throw new \InvalidArgumentException('Passwords are enforced for link shares'); - } - - return; - } - + protected function verifyPassword($password) { // Let others verify the password $accepted = true; $message = ''; @@ -176,6 +167,23 @@ protected function verifyPassword($password, $permissions) { ); } + /** + * Check if a password must be enforced if the shared has those permissions + * @param int $permissions \OCP\Constants::PERMISSION_* ("|" can be use for sets of permissions) + * @return bool true if the password must be enforced, false otherwise + */ + protected function passwordMustBeEnforced($permissions) { + $roEnforcement = $permissions === \OCP\Constants::PERMISSION_READ && $this->shareApiLinkEnforcePasswordReadOnly(); + $woEnforcement = $permissions === \OCP\Constants::PERMISSION_CREATE && $this->shareApiLinkEnforcePasswordWriteOnly(); + // use read & write enforcement for the rest of the cases + $rwEnforcement = ($permissions !== \OCP\Constants::PERMISSION_READ && $permissions !== \OCP\Constants::PERMISSION_CREATE) && $this->shareApiLinkEnforcePasswordReadWrite(); + if ($roEnforcement || $woEnforcement || $rwEnforcement) { + return true; + } else { + return false; + } + } + /** * Check for generic requirements before creating a share * @@ -585,7 +593,11 @@ public function createShare(\OCP\Share\IShare $share) { $this->validateExpirationDate($share); //Verify the password - $this->verifyPassword($share->getPassword(), $share->getPermissions()); + if ($this->passwordMustBeEnforced($share->getPermissions()) && $share->getPassword() === null) { + throw new \InvalidArgumentException('Passwords are enforced for link shares'); + } else { + $this->verifyPassword($share->getPassword()); + } // If a password is set. Hash it! if ($share->getPassword() !== null) { @@ -700,7 +712,11 @@ public function updateShare(\OCP\Share\IShare $share) { if ($share->getPassword() !== $originalShare->getPassword() || $share->getPermissions() !== $originalShare->getPermissions()) { //Verify the password - $this->verifyPassword($share->getPassword(), $share->getPermissions()); + if ($this->passwordMustBeEnforced($share->getPermissions()) && $share->getPassword() === null) { + throw new \InvalidArgumentException('Passwords are enforced for link shares'); + } else { + $this->verifyPassword($share->getPassword(), $share->getPermissions()); + } // If a password is set. Hash it! if ($share->getPassword() !== null) { @@ -1252,21 +1268,39 @@ public function shareApiAllowLinks() { } /** - * Is password on public link requires + * Is password on public link requires (fallback to shareApiLinkEnforcePasswordReadOnly) * * @return bool */ public function shareApiLinkEnforcePassword() { - return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; + return $this->shareApiLinkEnforcePasswordReadOnly(); + } + + /** + * Is password enforced for read-only shares? + * + * @return bool + */ + public function shareApiLinkEnforcePasswordReadOnly() { + return $this->config->getAppValue('core', 'shareapi_enforce_links_password_read_only', 'no') === 'yes'; + } + + /** + * Is password enforced for read & write shares? + * + * @return bool + */ + public function shareApiLinkEnforcePasswordReadWrite() { + return $this->config->getAppValue('core', 'shareapi_enforce_links_password_read_write', 'no') === 'yes'; } /** - * Is password enforced for upload-only shares? + * Is password enforced for write-only shares? * * @return bool */ - public function shareApiLinkEnforcePasswordDisabledForUploads() { - return $this->config->getAppValue('core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no') === 'yes'; + public function shareApiLinkEnforcePasswordWriteOnly() { + return $this->config->getAppValue('core', 'shareapi_enforce_links_password_write_only', 'no') === 'yes'; } /** diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php index c531287d4529..10a6af12a7c9 100644 --- a/lib/public/Share/IManager.php +++ b/lib/public/Share/IManager.php @@ -230,19 +230,38 @@ public function shareApiAllowLinks(); /** * Is password on public link requires + * NOTE: This method is deprecated and will fallback to the "shareApiLinkEnforcePasswordReadOnly" * * @return bool * @since 9.0.0 + * @see IManager::shareApiLinkEnforcePasswordReadOnly() + * @deprecated */ public function shareApiLinkEnforcePassword(); /** - * Is password enforced for upload-only shares? + * Is password enforced for read-only shares? * - * @return bool true -> password isn't enforce for upload-only share, false otherwise + * @return bool true if password is enforced, false otherwise * @since 10.0.6 */ - public function shareApiLinkEnforcePasswordDisabledForUploads(); + public function shareApiLinkEnforcePasswordReadOnly(); + + /** + * Is password enforced for read & write shares? + * + * @return bool true if password is enforced, false otherwise + * @since 10.0.6 + */ + public function shareApiLinkEnforcePasswordReadWrite(); + + /** + * Is password enforced for write-only shares? + * + * @return bool true if password is enforced, false otherwise + * @since 10.0.6 + */ + public function shareApiLinkEnforcePasswordWriteOnly(); /** * Is default expire date enabled diff --git a/settings/Panels/Admin/FileSharing.php b/settings/Panels/Admin/FileSharing.php index bb0e33a1e36c..ccbf538c5baf 100644 --- a/settings/Panels/Admin/FileSharing.php +++ b/settings/Panels/Admin/FileSharing.php @@ -52,8 +52,9 @@ public function getPanel() { $template->assign('shareAPIEnabled', $this->config->getAppValue('core', 'shareapi_enabled', 'yes')); $template->assign('allowLinks', $this->config->getAppValue('core', 'shareapi_allow_links', 'yes')); $template->assign('allowPublicUpload', $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes')); - $template->assign('enforceLinkPassword', $this->helper->isPublicLinkPasswordRequired()); - $template->assign('disableEnforceLinkPasswordForUploadOnly', $this->config->getAppValue('core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no')); + $template->assign('enforceLinkPasswordReadOnly', $this->config->getAppValue('core', 'shareapi_enforce_links_password_read_only', 'no')); + $template->assign('enforceLinkPasswordReadWrite', $this->config->getAppValue('core', 'shareapi_enforce_links_password_read_write', 'no')); + $template->assign('enforceLinkPasswordWriteOnly', $this->config->getAppValue('core', 'shareapi_enforce_links_password_write_only', 'no')); $template->assign('shareDefaultExpireDateSet', $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no')); $template->assign('allowPublicMailNotification', $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no')); $template->assign('allowSocialShare', $this->config->getAppValue('core', 'shareapi_allow_social_share', 'yes')); diff --git a/settings/templates/panels/admin/filesharing.php b/settings/templates/panels/admin/filesharing.php index 0f7036f48792..10b5a35c4fcd 100644 --- a/settings/templates/panels/admin/filesharing.php +++ b/settings/templates/panels/admin/filesharing.php @@ -23,13 +23,17 @@ value="1" />
- /> -
+ /> +
- /> -
+ /> +
+ + /> +
/> diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index d89e6b5a450b..f7b558d4b46c 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -515,49 +515,64 @@ public function testGetExpiredShareById() { $manager->getShareById('default:42'); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Passwords are enforced for link shares - */ - public function testVerifyPasswordNullButEnforced() { + public function testPasswordMustBeEnforcedForReadOnly() { $this->config->method('getAppValue')->will($this->returnValueMap([ - ['core', 'shareapi_enforce_links_password', 'no', 'yes'], - ['core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no', 'no'], + ['core', 'shareapi_enforce_links_password_read_only', 'no', 'yes'], + ['core', 'shareapi_enforce_links_password_read_write', 'no', 'yes'], + ['core', 'shareapi_enforce_links_password_write_only', 'no', 'yes'], ])); - $this->invokePrivate($this->manager, 'verifyPassword', [null, \OCP\Constants::PERMISSION_READ]); + $this->assertTrue($this->invokePrivate($this->manager, 'passwordMustBeEnforced', [\OCP\Constants::PERMISSION_READ])); } - public function testVerifyPasswordNull() { + public function testPasswordMustBeEnforcedForReadWrite() { $this->config->method('getAppValue')->will($this->returnValueMap([ - ['core', 'shareapi_enforce_links_password', 'no', 'no'], - ['core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no', 'no'], + ['core', 'shareapi_enforce_links_password_read_only', 'no', 'yes'], + ['core', 'shareapi_enforce_links_password_read_write', 'no', 'yes'], + ['core', 'shareapi_enforce_links_password_write_only', 'no', 'yes'], ])); - $result = $this->invokePrivate($this->manager, 'verifyPassword', [null, \OCP\Constants::PERMISSION_READ]); - $this->assertNull($result); + $this->assertTrue($this->invokePrivate($this->manager, 'passwordMustBeEnforced', [\OCP\Constants::PERMISSION_ALL])); } - public function testVerifyPasswordNullEnforcedDisableForWriteOnly() { + public function testPasswordMustBeEnforcedForWriteOnly() { $this->config->method('getAppValue')->will($this->returnValueMap([ - ['core', 'shareapi_enforce_links_password', 'no', 'yes'], - ['core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no', 'yes'], + ['core', 'shareapi_enforce_links_password_read_only', 'no', 'yes'], + ['core', 'shareapi_enforce_links_password_read_write', 'no', 'yes'], + ['core', 'shareapi_enforce_links_password_write_only', 'no', 'yes'], ])); - $this->invokePrivate($this->manager, 'verifyPassword', [null, \OCP\Constants::PERMISSION_CREATE]); + $this->assertTrue($this->invokePrivate($this->manager, 'passwordMustBeEnforced', [\OCP\Constants::PERMISSION_CREATE])); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Passwords are enforced for link shares - */ - public function testVerifyPasswordNullEnforcedDisableForWriteOnlyButReadOnly() { + public function testPasswordMustBeEnforcedForReadOnlyNotEnforced() { + $this->config->method('getAppValue')->will($this->returnValueMap([ + ['core', 'shareapi_enforce_links_password_read_only', 'no', 'no'], + ['core', 'shareapi_enforce_links_password_read_write', 'no', 'yes'], + ['core', 'shareapi_enforce_links_password_write_only', 'no', 'yes'], + ])); + + $this->assertFalse($this->invokePrivate($this->manager, 'passwordMustBeEnforced', [\OCP\Constants::PERMISSION_READ])); + } + + public function testPasswordMustBeEnforcedForReadWrite() { + $this->config->method('getAppValue')->will($this->returnValueMap([ + ['core', 'shareapi_enforce_links_password_read_only', 'no', 'yes'], + ['core', 'shareapi_enforce_links_password_read_write', 'no', 'no'], + ['core', 'shareapi_enforce_links_password_write_only', 'no', 'yes'], + ])); + + $this->assertFalse($this->invokePrivate($this->manager, 'passwordMustBeEnforced', [\OCP\Constants::PERMISSION_ALL])); + } + + public function testPasswordMustBeEnforcedForWriteOnly() { $this->config->method('getAppValue')->will($this->returnValueMap([ - ['core', 'shareapi_enforce_links_password', 'no', 'yes'], - ['core', 'shareapi_disable_enforce_links_password_for_upload_only', 'no', 'yes'], + ['core', 'shareapi_enforce_links_password_read_only', 'no', 'yes'], + ['core', 'shareapi_enforce_links_password_read_write', 'no', 'yes'], + ['core', 'shareapi_enforce_links_password_write_only', 'no', 'no'], ])); - $this->invokePrivate($this->manager, 'verifyPassword', [null, \OCP\Constants::PERMISSION_READ]); + $this->assertFalse($this->invokePrivate($this->manager, 'passwordMustBeEnforced', [\OCP\Constants::PERMISSION_CREATE])); } public function testVerifyPasswordHook() { @@ -577,7 +592,7 @@ public function testVerifyPasswordHook() { 'message' => '' ]); - $result = $this->invokePrivate($this->manager, 'verifyPassword', ['password', \OCP\Constants::PERMISSION_READ]); + $result = $this->invokePrivate($this->manager, 'verifyPassword', ['password']); $this->assertNull($result); } @@ -593,7 +608,7 @@ public function testVerifyPasswordHookFails() { $dummy = new DummyPassword(); \OCP\Util::connectHook('\OC\Share', 'verifyPassword', $dummy, 'listner'); - $this->invokePrivate($this->manager, 'verifyPassword', ['password', \OCP\Constants::PERMISSION_READ]); + $this->invokePrivate($this->manager, 'verifyPassword', ['password']); } public function createShare($id, $type, $path, $sharedWith, $sharedBy, $shareOwner, From c1983ae2672a7bee758fa7230b7264b2be0743f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Tue, 23 Jan 2018 13:47:45 +0100 Subject: [PATCH 6/9] Adjust tests --- apps/files_sharing/tests/ApiTest.php | 4 +-- .../specs/sharedialoglinkshareviewSpec.js | 35 +++++++++++++++++-- tests/lib/Share20/ManagerTest.php | 4 +-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php index 9de5206cf02f..d2617dc8710d 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -302,7 +302,7 @@ public function testCreateShareLinkPublicUpload() { function testEnfoceLinkPassword() { $appConfig = \OC::$server->getAppConfig(); - $appConfig->setValue('core', 'shareapi_enforce_links_password', 'yes'); + $appConfig->setValue('core', 'shareapi_enforce_links_password_read_only', 'yes'); // don't allow to share link without a password $data['path'] = $this->folder; @@ -361,7 +361,7 @@ function testEnfoceLinkPassword() { $result = $ocs->deleteShare($data['id']); $this->assertTrue($result->succeeded()); - $appConfig->setValue('core', 'shareapi_enforce_links_password', 'no'); + $appConfig->setValue('core', 'shareapi_enforce_links_password_read_only', 'no'); } /** diff --git a/core/js/tests/specs/sharedialoglinkshareviewSpec.js b/core/js/tests/specs/sharedialoglinkshareviewSpec.js index 95fa017c07f9..7c44a3525672 100644 --- a/core/js/tests/specs/sharedialoglinkshareviewSpec.js +++ b/core/js/tests/specs/sharedialoglinkshareviewSpec.js @@ -238,6 +238,7 @@ describe('OC.Share.ShareDialogLinkShareView', function() { var sendMailStub; var sendMailDeferred; var isMailEnabledStub; + var isPublicUploadEnabledStub; beforeEach(function() { saveStub = sinon.stub(OC.Share.ShareModel.prototype, 'save'); @@ -251,6 +252,9 @@ describe('OC.Share.ShareDialogLinkShareView', function() { sendMailStub.restore(); isMailEnabledStub.restore(); sendMailDeferred = null; + if (isPublicUploadEnabledStub) { + isPublicUploadEnabledStub.restore(); + } }); it('reads values from the fields and saves', function() { @@ -342,8 +346,35 @@ describe('OC.Share.ShareDialogLinkShareView', function() { expect(view.$('.error-message-global').hasClass('hidden')).toEqual(false); expect(view.$('.error-message-global').text()).toEqual('Some error'); }); - it('displays inline error when password enforced but missing', function() { - configModel.set('enforcePasswordForPublicLink', true); + it('displays inline error when password enforced for read-only but missing', function() { + isPublicUploadEnabledStub = sinon.stub(configModel, 'isPublicUploadEnabled').returns(true); + configModel.set('enforceLinkPasswordReadOnly', true); + view.render(); + view.$('#sharingDialogAllowPublicRead-' + view.cid).prop('checked', true) + var handler = sinon.stub(); + view.on('saved', handler); + view._save(); + expect(handler.notCalled).toEqual(true); + + expect(view.$('.linkPassText').next('.error-message').hasClass('hidden')).toEqual(false); + }); + it('displays inline error when password enforced for read & write but missing', function() { + isPublicUploadEnabledStub = sinon.stub(configModel, 'isPublicUploadEnabled').returns(true); + configModel.set('enforceLinkPasswordReadWrite', true); + view.render(); + view.$('#sharingDialogAllowPublicReadWrite-' + view.cid).prop('checked', true) + var handler = sinon.stub(); + view.on('saved', handler); + view._save(); + expect(handler.notCalled).toEqual(true); + + expect(view.$('.linkPassText').next('.error-message').hasClass('hidden')).toEqual(false); + }); + it('displays inline error when password enforced for write-only but missing', function() { + isPublicUploadEnabledStub = sinon.stub(configModel, 'isPublicUploadEnabled').returns(true); + configModel.set('enforceLinkPasswordWriteOnly', true); + view.render(); + view.$('#sharingDialogAllowPublicUpload-' + view.cid).prop('checked', true) var handler = sinon.stub(); view.on('saved', handler); view._save(); diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index f7b558d4b46c..67878706061f 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -555,7 +555,7 @@ public function testPasswordMustBeEnforcedForReadOnlyNotEnforced() { $this->assertFalse($this->invokePrivate($this->manager, 'passwordMustBeEnforced', [\OCP\Constants::PERMISSION_READ])); } - public function testPasswordMustBeEnforcedForReadWrite() { + public function testPasswordMustBeEnforcedForReadWriteNotEnforced() { $this->config->method('getAppValue')->will($this->returnValueMap([ ['core', 'shareapi_enforce_links_password_read_only', 'no', 'yes'], ['core', 'shareapi_enforce_links_password_read_write', 'no', 'no'], @@ -565,7 +565,7 @@ public function testPasswordMustBeEnforcedForReadWrite() { $this->assertFalse($this->invokePrivate($this->manager, 'passwordMustBeEnforced', [\OCP\Constants::PERMISSION_ALL])); } - public function testPasswordMustBeEnforcedForWriteOnly() { + public function testPasswordMustBeEnforcedForWriteOnlyNotEnforced() { $this->config->method('getAppValue')->will($this->returnValueMap([ ['core', 'shareapi_enforce_links_password_read_only', 'no', 'yes'], ['core', 'shareapi_enforce_links_password_read_write', 'no', 'yes'], From 78a12b1259dc254ce2685be9e6db35a1d22b53b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Tue, 23 Jan 2018 14:30:48 +0100 Subject: [PATCH 7/9] Add migration for the configuration key --- core/Migrations/Version20180123131835.php | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 core/Migrations/Version20180123131835.php diff --git a/core/Migrations/Version20180123131835.php b/core/Migrations/Version20180123131835.php new file mode 100644 index 000000000000..69c384b2cd83 --- /dev/null +++ b/core/Migrations/Version20180123131835.php @@ -0,0 +1,26 @@ +getConfig(); + $enforceLinks = $config->getAppValue('core', 'shareapi_enforce_links_password', null); + if ($enforceLinks !== null) { + $config->setAppValue('core', 'shareapi_enforce_links_password_read_only', $enforceLinks); + $config->setAppValue('core', 'shareapi_enforce_links_password_read_write', $enforceLinks); + $config->setAppValue('core', 'shareapi_enforce_links_password_write_only', $enforceLinks); + } + $config->deleteAppValue('core', 'shareapi_enforce_links_password'); + } +} From 5f58c45b51c64add8bf974e20de94e69b510ab81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Tue, 23 Jan 2018 16:50:58 +0100 Subject: [PATCH 8/9] Deprecate and remove isPublicLinkPasswordRequired --- core/js/config.php | 1 - core/js/shareconfigmodel.js | 1 - core/js/tests/specs/sharedialogexpirationviewSpec.js | 5 ++--- core/js/tests/specs/sharedialogshareelistview.js | 3 --- core/js/tests/specs/sharedialogviewSpec.js | 3 --- lib/private/legacy/util.php | 8 ++++++-- lib/public/Util.php | 4 ++++ settings/Panels/Helper.php | 4 ---- 8 files changed, 12 insertions(+), 17 deletions(-) diff --git a/core/js/config.php b/core/js/config.php index 7b9b9bedd78a..279aa4668067 100644 --- a/core/js/config.php +++ b/core/js/config.php @@ -166,7 +166,6 @@ 'defaultExpireDateEnabled' => $defaultExpireDateEnabled, 'defaultExpireDate' => $defaultExpireDate, 'defaultExpireDateEnforced' => $enforceDefaultExpireDate, - 'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(), 'enforceLinkPasswordReadOnly' => $enforceLinkPasswordReadOnly, 'enforceLinkPasswordReadWrite' => $enforceLinkPasswordReadWrite, 'enforceLinkPasswordWriteOnly' => $enforceLinkPasswordWriteOnly, diff --git a/core/js/shareconfigmodel.js b/core/js/shareconfigmodel.js index 8c2f9d8a09b7..c728efeda2c5 100644 --- a/core/js/shareconfigmodel.js +++ b/core/js/shareconfigmodel.js @@ -21,7 +21,6 @@ var ShareConfigModel = OC.Backbone.Model.extend({ defaults: { publicUploadEnabled: false, - enforcePasswordForPublicLink: oc_appconfig.core.enforcePasswordForPublicLink, enforceLinkPasswordReadOnly: oc_appconfig.core.enforceLinkPasswordReadOnly, enforceLinkPasswordReadWrite: oc_appconfig.core.enforceLinkPasswordReadWrite, enforceLinkPasswordWriteOnly: oc_appconfig.core.enforceLinkPasswordWriteOnly, diff --git a/core/js/tests/specs/sharedialogexpirationviewSpec.js b/core/js/tests/specs/sharedialogexpirationviewSpec.js index ce67ff657890..fb04abee4533 100644 --- a/core/js/tests/specs/sharedialogexpirationviewSpec.js +++ b/core/js/tests/specs/sharedialogexpirationviewSpec.js @@ -67,8 +67,8 @@ describe('OC.Share.ShareDialogExpirationView', function() { }); view.render(); }); - afterEach(function() { - tooltipStub.restore(); + afterEach(function() { + tooltipStub.restore(); view.remove(); }); @@ -128,7 +128,6 @@ describe('OC.Share.ShareDialogExpirationView', function() { setDefaultsStub = sinon.stub($.datepicker, 'setDefaults'); configModel.set({ - enforcePasswordForPublicLink: false, isDefaultExpireDateEnabled: false, isDefaultExpireDateEnforced: false, defaultExpireDate: 7 diff --git a/core/js/tests/specs/sharedialogshareelistview.js b/core/js/tests/specs/sharedialogshareelistview.js index fb2f3e4ff958..52a83d3a49ac 100644 --- a/core/js/tests/specs/sharedialogshareelistview.js +++ b/core/js/tests/specs/sharedialogshareelistview.js @@ -32,7 +32,6 @@ describe('OC.Share.ShareDialogShareeListView', function () { beforeEach(function () { /* jshint camelcase:false */ oldAppConfig = _.extend({}, oc_appconfig.core); - oc_appconfig.core.enforcePasswordForPublicLink = false; $('#testArea').append(''); @@ -59,9 +58,7 @@ describe('OC.Share.ShareDialogShareeListView', function () { }); configModel = new OC.Share.ShareConfigModel({ - enforcePasswordForPublicLink: false, isResharingAllowed: true, - enforcePasswordForPublicLink: false, isDefaultExpireDateEnabled: false, isDefaultExpireDateEnforced: false, defaultExpireDate: 7 diff --git a/core/js/tests/specs/sharedialogviewSpec.js b/core/js/tests/specs/sharedialogviewSpec.js index 248308cc2e22..3a4596496f7a 100644 --- a/core/js/tests/specs/sharedialogviewSpec.js +++ b/core/js/tests/specs/sharedialogviewSpec.js @@ -44,7 +44,6 @@ describe('OC.Share.ShareDialogView', function() { $container = $('#shareContainer'); /* jshint camelcase:false */ oldAppConfig = _.extend({}, oc_appconfig.core); - oc_appconfig.core.enforcePasswordForPublicLink = false; fetchStub = sinon.stub(OC.Share.ShareItemModel.prototype, 'fetch'); @@ -65,9 +64,7 @@ describe('OC.Share.ShareDialogView', function() { permissions: 31 }; configModel = new OC.Share.ShareConfigModel({ - enforcePasswordForPublicLink: false, isResharingAllowed: true, - enforcePasswordForPublicLink: false, isDefaultExpireDateEnabled: false, isDefaultExpireDateEnforced: false, defaultExpireDate: 7 diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index 9ce32863648d..ea2424905b15 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -304,13 +304,17 @@ function ($mountPoint, $storage) use ($user) { } /** - * check if a password is required for each public link + * check if a password is required for each public link. + * This is deprecated due to not reflecting all the possibilities now. Falling back to + * enforce password for read-only links. Note that read & write or write-only options won't + * be considered here * * @return boolean + * @deprecated */ public static function isPublicLinkPasswordRequired() { $appConfig = \OC::$server->getAppConfig(); - $enforcePassword = $appConfig->getValue('core', 'shareapi_enforce_links_password', 'no'); + $enforcePassword = $appConfig->getValue('core', 'shareapi_enforce_links_password_read_only', 'no'); return ($enforcePassword === 'yes') ? true : false; } diff --git a/lib/public/Util.php b/lib/public/Util.php index 3f1cc165983f..ce80c844f213 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -679,8 +679,12 @@ public static function naturalSortCompare($a, $b) { /** * check if a password is required for each public link + * This is deprecated due to not reflecting all the possibilities now. Falling back to + * enforce password for read-only links. Note that read & write or write-only options won't + * be considered here * @return boolean * @since 7.0.0 + * @deprecated */ public static function isPublicLinkPasswordRequired() { return \OC_Util::isPublicLinkPasswordRequired(); diff --git a/settings/Panels/Helper.php b/settings/Panels/Helper.php index cff4c4dd5d1f..e23340413476 100644 --- a/settings/Panels/Helper.php +++ b/settings/Panels/Helper.php @@ -35,10 +35,6 @@ public function getAdminForms() { return \OC_App::getForms('admin'); } - public function isPublicLinkPasswordRequired() { - return \OCP\Util::isPublicLinkPasswordRequired(); - } - public function shareWithGroupMembersOnly() { return \OC\Share\Share::shareWithGroupMembersOnly(); } From 4363ad0c244346e2fb93b47fda99a6533c4dd207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Tue, 30 Jan 2018 14:21:15 +0100 Subject: [PATCH 9/9] Change "since" tags --- lib/public/Share/IManager.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php index 10a6af12a7c9..2e71f80a3f98 100644 --- a/lib/public/Share/IManager.php +++ b/lib/public/Share/IManager.php @@ -243,7 +243,7 @@ public function shareApiLinkEnforcePassword(); * Is password enforced for read-only shares? * * @return bool true if password is enforced, false otherwise - * @since 10.0.6 + * @since 10.0.8 */ public function shareApiLinkEnforcePasswordReadOnly(); @@ -251,7 +251,7 @@ public function shareApiLinkEnforcePasswordReadOnly(); * Is password enforced for read & write shares? * * @return bool true if password is enforced, false otherwise - * @since 10.0.6 + * @since 10.0.8 */ public function shareApiLinkEnforcePasswordReadWrite(); @@ -259,7 +259,7 @@ public function shareApiLinkEnforcePasswordReadWrite(); * Is password enforced for write-only shares? * * @return bool true if password is enforced, false otherwise - * @since 10.0.6 + * @since 10.0.8 */ public function shareApiLinkEnforcePasswordWriteOnly();