[Pkg-owncloud-commits] [owncloud] 71/118: Backport of #15025
David Prévot
taffit at moszumanska.debian.org
Fri Mar 27 22:13:14 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch stable8
in repository owncloud.
commit 9d0ea7fa11ec81bca602b1bd08f1de4e2aa6d58c
Author: Roeland Jago Douma <roeland at famdouma.nl>
Date: Thu Mar 19 10:07:17 2015 +0100
Backport of #15025
When the expiration date is enforced respect this
- Make sure that we do not allow removing of the expiration date when this
is enforced in the settings.
- Added unit test
---
apps/files_sharing/tests/api.php | 18 ++++++++++++++++++
lib/private/share/share.php | 10 +++++++++-
tests/lib/share/share.php | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php
index 278e713..232fcf2 100644
--- a/apps/files_sharing/tests/api.php
+++ b/apps/files_sharing/tests/api.php
@@ -1008,6 +1008,24 @@ class Test_Files_Sharing_Api extends TestCase {
$this->assertTrue(is_array($updatedLinkShare));
$this->assertEquals($dateWithinRange->format('Y-m-d') . ' 00:00:00', $updatedLinkShare['expiration']);
+
+ // Try to remove expire date
+ $params = array();
+ $params['id'] = $linkShare['id'];
+ $params['_put'] = ['expireDate' => ''];
+
+ $result = \OCA\Files_Sharing\API\Local::updateShare($params);
+
+ $this->assertFalse($result->succeeded());
+
+ $items = \OCP\Share::getItemShared('file', $linkShare['file_source']);
+
+ $updatedLinkShare = reset($items);
+
+ // date shouldn't be changed
+ $this->assertTrue(is_array($updatedLinkShare));
+ $this->assertEquals($dateWithinRange->format('Y-m-d') . ' 00:00:00', $updatedLinkShare['expiration']);
+
// cleanup
$config->setAppValue('core', 'shareapi_default_expire_date', 'no');
$config->setAppValue('core', 'shareapi_enforce_expire_date', 'no');
diff --git a/lib/private/share/share.php b/lib/private/share/share.php
index 9af5672..229dbc5 100644
--- a/lib/private/share/share.php
+++ b/lib/private/share/share.php
@@ -1097,9 +1097,17 @@ class Share extends \OC\Share\Constants {
*/
public static function setExpirationDate($itemType, $itemSource, $date, $shareTime = null) {
$user = \OC_User::getUser();
+ $l = \OC::$server->getL10N('lib');
if ($date == '') {
- $date = null;
+ if (\OCP\Util::isDefaultExpireDateEnforced()) {
+ $warning = 'Cannot clear expiration date. Shares are required to have an expiration date.';
+ $warning_t = $l->t('Cannot clear expiration date. Shares are required to have an expiration date.');
+ \OCP\Util::writeLog('OCP\Share', $warning, \OCP\Util::WARN);
+ throw new \Exception($warning_t);
+ } else {
+ $date = null;
+ }
} else {
$date = self::validateExpireDate($date, $shareTime, $itemType, $itemSource);
}
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index 1ef62dc..42bb829 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -1051,6 +1051,41 @@ class Test_Share extends \Test\TestCase {
),
);
}
+
+ /**
+ * Ensure that we do not allow removing a an expiration date from a link share if this
+ * is enforced by the settings.
+ */
+ public function testClearExpireDateWhileEnforced() {
+ OC_User::setUserId($this->user1);
+
+ \OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'yes');
+ \OC_Appconfig::setValue('core', 'shareapi_expire_after_n_days', '2');
+ \OC_Appconfig::setValue('core', 'shareapi_enforce_expire_date', 'yes');
+
+ $token = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ);
+ $this->assertInternalType(
+ 'string',
+ $token,
+ 'Failed asserting that user 1 successfully shared text.txt as link with token.'
+ );
+
+ $setExpireDateFailed = false;
+ try {
+ $this->assertTrue(
+ OCP\Share::setExpirationDate('test', 'test.txt', '', ''),
+ 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.'
+ );
+ } catch (\Exception $e) {
+ $setExpireDateFailed = true;
+ }
+
+ $this->assertTrue($setExpireDateFailed);
+
+ \OC_Appconfig::deleteKey('core', 'shareapi_default_expire_date');
+ \OC_Appconfig::deleteKey('core', 'shareapi_expire_after_n_days');
+ \OC_Appconfig::deleteKey('core', 'shareapi_enforce_expire_date');
+ }
}
class DummyShareClass extends \OC\Share\Share {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list