From 1a60aa2b6a15ae68a2a6998a72580c171b88f719 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 18 Sep 2013 11:49:02 +0200 Subject: [PATCH 1/4] only remember password if the user changes the permissions, otherwise the user disabled the password protection --- lib/public/share.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/public/share.php b/lib/public/share.php index 9ab956d84b..91c5c477c8 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -106,22 +106,22 @@ class Share { } return false; } - + /** * @brief Prepare a path to be passed to DB as file_target * @return string Prepared path */ public static function prepFileTarget( $path ) { - + // Paths in DB are stored with leading slashes, so add one if necessary if ( substr( $path, 0, 1 ) !== '/' ) { - + $path = '/' . $path; - + } - + return $path; - + } /** @@ -256,7 +256,7 @@ class Share { return self::getItems($itemType, $itemTarget, self::$shareTypeUserAndGroups, \OC_User::getUser(), null, $format, $parameters, 1, $includeCollections); } - + /** * @brief Get the item of item type shared with the current user by source * @param string Item type @@ -450,6 +450,7 @@ class Share { $uidOwner, self::FORMAT_NONE, null, 1)) { // remember old token $oldToken = $checkExists['token']; + $oldPermissions = $checkExists['permissions']; //delete the old share self::delete($checkExists['id']); } @@ -460,8 +461,11 @@ class Share { $hasher = new \PasswordHash(8, $forcePortable); $shareWith = $hasher->HashPassword($shareWith.\OC_Config::getValue('passwordsalt', '')); } else { - // reuse the already set password - $shareWith = $checkExists['share_with']; + // reuse the already set password, but only if we change permissions + // otherwise the user disabled the password protection + if ($checkExists && (int)$permissions !== $oldPermissions) { + $shareWith = $checkExists['share_with']; + } } // Generate token From 944e9b8c69c4b78f7afbc6153d35cd50da060b09 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 20 Sep 2013 12:40:21 +0200 Subject: [PATCH 2/4] make sure that both $permissions and $oldPermissions have the same type --- lib/public/share.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/public/share.php b/lib/public/share.php index 91c5c477c8..91b0ef6dc6 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -463,7 +463,7 @@ class Share { } else { // reuse the already set password, but only if we change permissions // otherwise the user disabled the password protection - if ($checkExists && (int)$permissions !== $oldPermissions) { + if ($checkExists && (int)$permissions !== (int)$oldPermissions) { $shareWith = $checkExists['share_with']; } } From 12b4e7920148e1cf586fa96fafe7fee33a12523b Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 20 Sep 2013 13:11:05 +0200 Subject: [PATCH 3/4] calculate correct permissions while toggle the password protection --- core/js/share.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/js/share.js b/core/js/share.js index 5d34faf8a5..f0fc4136e6 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -603,7 +603,17 @@ $(document).ready(function() { if (!$('#showPassword').is(':checked') ) { var itemType = $('#dropdown').data('item-type'); var itemSource = $('#dropdown').data('item-source'); - OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ); + var allowPublicUpload = $('#sharingDialogAllowPublicUpload').is(':checked'); + + // Calculate permissions + if (allowPublicUpload) { + permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ; + } else { + permissions = OC.PERMISSION_READ; + } + + + OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', permissions); } else { $('#linkPassText').focus(); } From 71e129f295996a65e2e7d73c5e6a964ba9f8bebf Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 20 Sep 2013 15:47:33 +0200 Subject: [PATCH 4/4] initialize variable --- core/js/share.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/js/share.js b/core/js/share.js index f0fc4136e6..094b0be929 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -604,6 +604,7 @@ $(document).ready(function() { var itemType = $('#dropdown').data('item-type'); var itemSource = $('#dropdown').data('item-source'); var allowPublicUpload = $('#sharingDialogAllowPublicUpload').is(':checked'); + var permissions = 0; // Calculate permissions if (allowPublicUpload) {