From f9bbfad3e561c52cd3a7a9002ed9708a87237dc5 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 17 Oct 2013 16:45:11 +0200 Subject: [PATCH 1/3] Fix sharing error message - id -> file name fixe #2827 --- lib/public/share.php | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/lib/public/share.php b/lib/public/share.php index 1b6f5d05f1..814c02499f 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -439,22 +439,31 @@ class Share { public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions) { $uidOwner = \OC_User::getUser(); $sharingPolicy = \OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global'); + + //retrieve name of file + $fileData = \OC\Files\Filesystem::getFileInfo(\OC\Files\Filesystem::getPath($itemSource)); + if(!is_null($fileData)) { + $itemSourceName = $fileData['name']; + } else { + $itemSourceName = $itemSource; + } + // Verify share type and sharing conditions are met if ($shareType === self::SHARE_TYPE_USER) { if ($shareWith == $uidOwner) { - $message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is the item owner'; + $message = 'Sharing '.$itemSourceName.' failed, because the user '.$shareWith.' is the item owner'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } if (!\OC_User::userExists($shareWith)) { - $message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' does not exist'; + $message = 'Sharing '.$itemSourceName.' failed, because the user '.$shareWith.' does not exist'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } if ($sharingPolicy == 'groups_only') { $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith)); if (empty($inGroup)) { - $message = 'Sharing '.$itemSource.' failed, because the user ' + $message = 'Sharing '.$itemSourceName.' failed, because the user ' .$shareWith.' is not a member of any groups that '.$uidOwner.' is a member of'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); @@ -467,19 +476,19 @@ class Share { // owner and is not a user share, this use case is for increasing // permissions for a specific user if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { - $message = 'Sharing '.$itemSource.' failed, because this item is already shared with '.$shareWith; + $message = 'Sharing '.$itemSourceName.' failed, because this item is already shared with '.$shareWith; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } } } else if ($shareType === self::SHARE_TYPE_GROUP) { if (!\OC_Group::groupExists($shareWith)) { - $message = 'Sharing '.$itemSource.' failed, because the group '.$shareWith.' does not exist'; + $message = 'Sharing '.$itemSourceName.' failed, because the group '.$shareWith.' does not exist'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } if ($sharingPolicy == 'groups_only' && !\OC_Group::inGroup($uidOwner, $shareWith)) { - $message = 'Sharing '.$itemSource.' failed, because ' + $message = 'Sharing '.$itemSourceName.' failed, because ' .$uidOwner.' is not a member of the group '.$shareWith; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); @@ -492,7 +501,7 @@ class Share { // owner and is not a group share, this use case is for increasing // permissions for a specific user if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { - $message = 'Sharing '.$itemSource.' failed, because this item is already shared with '.$shareWith; + $message = 'Sharing '.$itemSourceName.' failed, because this item is already shared with '.$shareWith; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } @@ -541,7 +550,7 @@ class Share { return false; } } - $message = 'Sharing '.$itemSource.' failed, because sharing with links is not allowed'; + $message = 'Sharing '.$itemSourceName.' failed, because sharing with links is not allowed'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); return false; @@ -1318,18 +1327,27 @@ class Share { private static function put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder = null, $token = null) { $backend = self::getBackend($itemType); + // Check if this is a reshare if ($checkReshare = self::getItemSharedWithBySource($itemType, $itemSource, self::FORMAT_NONE, null, true)) { + //retrieve name of file + $fileData = \OC\Files\Filesystem::getFileInfo(\OC\Files\Filesystem::getPath($itemSource)); + if(!is_null($fileData)) { + $itemSourceName = $fileData['name']; + } else { + $itemSourceName = $itemSource; + } + // Check if attempting to share back to owner if ($checkReshare['uid_owner'] == $shareWith && $shareType == self::SHARE_TYPE_USER) { - $message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is the original sharer'; + $message = 'Sharing '.$itemSourceName.' failed, because the user '.$shareWith.' is the original sharer'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } // Check if share permissions is granted if (self::isResharingAllowed() && (int)$checkReshare['permissions'] & PERMISSION_SHARE) { if (~(int)$checkReshare['permissions'] & $permissions) { - $message = 'Sharing '.$itemSource + $message = 'Sharing '.$itemSourceName .' failed, because the permissions exceed permissions granted to '.$uidOwner; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); @@ -1343,7 +1361,7 @@ class Share { $filePath = $checkReshare['file_target']; } } else { - $message = 'Sharing '.$itemSource.' failed, because resharing is not allowed'; + $message = 'Sharing '.$itemSourceName.' failed, because resharing is not allowed'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } From 1317b7c03dbbd98165ef29b50aa26bb1dd283cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 23 Oct 2013 18:39:37 +0200 Subject: [PATCH 2/3] pass the name of the item source from the browser to the server - no need to get the data via complicated db queries --- apps/files_sharing/js/share.js | 4 ++-- core/ajax/share.php | 3 ++- core/js/share.js | 24 +++++++++++++++---- lib/public/share.php | 44 ++++++++++++++++------------------ 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index 68f6f3ba76..340e093944 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -35,14 +35,14 @@ $(document).ready(function() { if ($(tr).data('id') != $('#dropdown').attr('data-item-source')) { OC.Share.hideDropDown(function () { $(tr).addClass('mouseOver'); - OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, true, possiblePermissions); + OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, true, possiblePermissions, filename); }); } else { OC.Share.hideDropDown(); } } else { $(tr).addClass('mouseOver'); - OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, true, possiblePermissions); + OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, true, possiblePermissions, filename); } }); } diff --git a/core/ajax/share.php b/core/ajax/share.php index 0dacc17d3a..be02c05635 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -41,7 +41,8 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo $_POST['itemSource'], $shareType, $shareWith, - $_POST['permissions'] + $_POST['permissions'], + $_POST['itemSourceName'] ); if (is_string($token)) { diff --git a/core/js/share.js b/core/js/share.js index 281cccaaef..352ad4d4ca 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -136,8 +136,17 @@ OC.Share={ return data; }, - share:function(itemType, itemSource, shareType, shareWith, permissions, callback) { - $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'share', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) { + share:function(itemType, itemSource, shareType, shareWith, permissions, itemSourceName, callback) { + $.post(OC.filePath('core', 'ajax', 'share.php'), + { + action: 'share', + itemType: itemType, + itemSource: itemSource, + shareType: shareType, + shareWith: shareWith, + permissions: permissions, + itemSourceName: itemSourceName + }, function (result) { if (result && result.status === 'success') { if (callback) { callback(result.data); @@ -170,9 +179,9 @@ OC.Share={ } }); }, - showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions) { + showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions, filename) { var data = OC.Share.loadItem(itemType, itemSource); - var html = '