From f9bbfad3e561c52cd3a7a9002ed9708a87237dc5 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 17 Oct 2013 16:45:11 +0200 Subject: Fix sharing error message - id -> file name fixe #2827 --- lib/public/share.php | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/public/share.php b/lib/public/share.php index 1b6f5d05f10..814c02499f3 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); } -- cgit v1.2.3 From 9d1b425b62af0dc56af473d853d39182a7597a6c Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Oct 2013 12:25:48 +0200 Subject: Correct indentation for default language. --- lib/private/l10n.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 3e84c306dc2..38efa88388d 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -447,11 +447,11 @@ class OC_L10N implements \OCP\IL10N { } } - $default_language = OC_Config::getValue('default_language', false); + $default_language = OC_Config::getValue('default_language', false); - if($default_language !== false) { - return $default_language; - } + if($default_language !== false) { + return $default_language; + } if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $accepted_languages = preg_split('/,\s*/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])); -- cgit v1.2.3 From 207f6d55ce5047e43f7250ef30b14525dee6bd65 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Oct 2013 12:39:12 +0200 Subject: Fix coding style for else. --- lib/private/l10n.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 38efa88388d..99481404f62 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -438,8 +438,7 @@ class OC_L10N implements \OCP\IL10N { if(is_array($app)) { $available = $app; $lang_exists = array_search($lang, $available) !== false; - } - else { + } else { $lang_exists = self::languageExists($app, $lang); } if($lang_exists) { @@ -457,8 +456,7 @@ class OC_L10N implements \OCP\IL10N { $accepted_languages = preg_split('/,\s*/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])); if(is_array($app)) { $available = $app; - } - else{ + } else { $available = self::findAvailableLanguages($app); } foreach($accepted_languages as $i) { -- cgit v1.2.3 From 4c76dd38719f28d6c995047e2ac6154ec20c2ad5 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Oct 2013 12:56:51 +0200 Subject: Better variable names. --- lib/private/l10n.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 99481404f62..9f89f0d03e3 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -453,27 +453,27 @@ class OC_L10N implements \OCP\IL10N { } if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { - $accepted_languages = preg_split('/,\s*/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])); if(is_array($app)) { $available = $app; } else { $available = self::findAvailableLanguages($app); } - foreach($accepted_languages as $i) { - $temp = explode(';', $i); - $temp[0] = str_replace('-', '_', $temp[0]); - if( ($key = array_search($temp[0], $available)) !== false) { + $preferences = preg_split('/,\s*/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])); + foreach($preferences as $preference) { + list($prefered_language) = explode(';', $preference); + $prefered_language = str_replace('-', '_', $prefered_language); + if( ($key = array_search($prefered_language, $available)) !== false) { if (is_null($app)) { self::$language = $available[$key]; } return $available[$key]; } - foreach($available as $l) { - if ( $temp[0] == substr($l, 0, 2) ) { + foreach($available as $available_language) { + if ($prefered_language == substr($available_language, 0, 2)) { if (is_null($app)) { - self::$language = $l; + self::$language = $available_language; } - return $l; + return $available_language; } } } -- cgit v1.2.3 From c14b470ea24258b0402ad8ee783646d23c6693b9 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Oct 2013 15:38:22 +0200 Subject: Apply substring on the correct value. --- lib/private/l10n.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 9f89f0d03e3..62827312d32 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -469,7 +469,7 @@ class OC_L10N implements \OCP\IL10N { return $available[$key]; } foreach($available as $available_language) { - if ($prefered_language == substr($available_language, 0, 2)) { + if (substr($prefered_language, 0, 2) === $available_language) { if (is_null($app)) { self::$language = $available_language; } -- cgit v1.2.3 From daf93c45165ac2c73fc1f0d6af513b8c3e497691 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Oct 2013 15:38:54 +0200 Subject: Sort, so 'de' is preferred over 'de_DE' when performing non-exact matching. --- lib/private/l10n.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 62827312d32..9392cfac05b 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -458,6 +458,10 @@ class OC_L10N implements \OCP\IL10N { } else { $available = self::findAvailableLanguages($app); } + + // E.g. make sure that 'de' is before 'de_DE'. + sort($available); + $preferences = preg_split('/,\s*/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])); foreach($preferences as $preference) { list($prefered_language) = explode(';', $preference); -- cgit v1.2.3 From 06f2ae082eb6fc04b1c6680bd2f35ca1c2032d59 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 23 Oct 2013 15:39:50 +0200 Subject: Have to also strtolower() on available language name. Otherwise no match. --- lib/private/l10n.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 9392cfac05b..0125dca92ee 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -466,11 +466,13 @@ class OC_L10N implements \OCP\IL10N { foreach($preferences as $preference) { list($prefered_language) = explode(';', $preference); $prefered_language = str_replace('-', '_', $prefered_language); - if( ($key = array_search($prefered_language, $available)) !== false) { - if (is_null($app)) { - self::$language = $available[$key]; + foreach($available as $available_language) { + if ($prefered_language === strtolower($available_language)) { + if (is_null($app)) { + self::$language = $available_language; + } + return $available_language; } - return $available[$key]; } foreach($available as $available_language) { if (substr($prefered_language, 0, 2) === $available_language) { -- cgit v1.2.3 From 1317b7c03dbbd98165ef29b50aa26bb1dd283cba Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Wed, 23 Oct 2013 18:39:37 +0200 Subject: 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(-) (limited to 'lib') diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index 68f6f3ba76f..340e0939445 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 0dacc17d3a5..be02c056357 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 281cccaaef8..352ad4d4ca8 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 = '