From 3d42e402c5f1956bc72ac5accc268f519d66c3e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 29 Oct 2013 23:07:27 +0100 Subject: [PATCH 01/10] http header OCS-ApiRequest: true is required in case of session based OCS API calls --- lib/private/api.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/private/api.php b/lib/private/api.php index 26091657b31..0576f3e3f93 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -250,7 +250,8 @@ class OC_API { // reuse existing login $loggedIn = OC_User::isLoggedIn(); - if ($loggedIn === true) { + $ocsApiRequest = isset($_SERVER['OCS_APIREQUEST']) ? $_SERVER['OCS_APIREQUEST'] === 'true' : false; + if ($loggedIn === true && $ocsApiRequest) { return OC_User::getUser(); } From b65b7965ae18cbad09b8feda512f85354dd77bf0 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 30 Oct 2013 15:39:55 +0100 Subject: [PATCH 02/10] fix failing preview test on master --- tests/lib/preview.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/lib/preview.php b/tests/lib/preview.php index d0cdd2c44fb..353b66fd6d6 100644 --- a/tests/lib/preview.php +++ b/tests/lib/preview.php @@ -134,13 +134,11 @@ class Preview extends \PHPUnit_Framework_TestCase { } private function initFS() { - if(\OC\Files\Filesystem::getView()){ - $user = \OC_User::getUser(); - }else{ - $user=uniqid(); - \OC_User::setUserId($user); - \OC\Files\Filesystem::init($user, '/'.$user.'/files'); - } + // create a new user with his own filesystem view + // this gets called by each test in this test class + $user=uniqid(); + \OC_User::setUserId($user); + \OC\Files\Filesystem::init($user, '/'.$user.'/files'); \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/'); From 68e88b6e4048d36ec9bcd426d437be1b3d5e7519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 30 Oct 2013 15:48:38 +0100 Subject: [PATCH 03/10] count correct array, then using 1000 as MAX_SQL_CHUNK_SIZE works as expected --- apps/files_sharing/lib/cache.php | 80 +++++++++++++++++--------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 123268e240a..6b66edcacc5 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -228,69 +228,73 @@ class Shared_Cache extends Cache { */ public function search($pattern) { + $where = '`name` LIKE ? AND '; + // normalize pattern - $pattern = $this->normalize($pattern); + $value = $this->normalize($pattern); - $ids = $this->getAll(); + return $this->searchWithWhere($where, $value); - $files = array(); - - // divide into 1k chunks - $chunks = array_chunk($ids, 1000); - - foreach ($chunks as $chunk) { - $placeholders = join(',', array_fill(0, count($chunk), '?')); - - $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, - `encrypted`, `unencrypted_size`, `etag` - FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `fileid` IN (' . $placeholders . ')'; - - $result = \OC_DB::executeAudited($sql, array_merge(array($pattern), $chunk)); - - while ($row = $result->fetchRow()) { - if (substr($row['path'], 0, 6)==='files/') { - $row['path'] = substr($row['path'],6); // remove 'files/' from path as it's relative to '/Shared' - } - $row['mimetype'] = $this->getMimetype($row['mimetype']); - $row['mimepart'] = $this->getMimetype($row['mimepart']); - $files[] = $row; - } - } - return $files; } /** * search for files by mimetype * - * @param string $part1 - * @param string $part2 + * @param string $mimetype * @return array */ public function searchByMime($mimetype) { + if (strpos($mimetype, '/')) { - $where = '`mimetype` = ?'; + $where = '`mimetype` = ? AND '; } else { - $where = '`mimepart` = ?'; + $where = '`mimepart` = ? AND '; } - $mimetype = $this->getMimetypeId($mimetype); + + $value = $this->getMimetypeId($mimetype); + + return $this->searchWithWhere($where, $value); + + } + + /** + * The maximum number of placeholders that can be used in an SQL query. + * Value MUST be <= 1000 for oracle: + * see ORA-01795 maximum number of expressions in a list is 1000 + * FIXME we should get this from doctrine as other DBs allow a lot more placeholders + */ + const MAX_SQL_CHUNK_SIZE = 1000; + + /** + * search for files with a custom where clause and value + * the $wherevalue will be array_merge()d with the file id chunks + * + * @param string $sqlwhere + * @param string $wherevalue + * @return array + */ + private function searchWithWhere($sqlwhere, $wherevalue, $chunksize = self::MAX_SQL_CHUNK_SIZE) { + $ids = $this->getAll(); $files = array(); - // divide into 1k chunks - $chunks = array_chunk($ids, 1000); + // divide into chunks + $chunks = array_chunk($ids, $chunksize); foreach ($chunks as $chunk) { - $placeholders = join(',', array_fill(0, count($ids), '?')); + $placeholders = join(',', array_fill(0, count($chunk), '?')); $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag` - FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `fileid` IN (' . $placeholders . ')'; + FROM `*PREFIX*filecache` WHERE ' . $sqlwhere . ' `fileid` IN (' . $placeholders . ')'; - $result = \OC_DB::executeAudited($sql, array_merge(array($mimetype), $chunk)); + $stmt = \OC_DB::prepare($sql); + + $result = $stmt->execute(array_merge(array($wherevalue), $chunk)); while ($row = $result->fetchRow()) { - if (substr($row['path'], 0, 6)==='files/') { - $row['path'] = substr($row['path'],6); // remove 'files/' from path as it's relative to '/Shared' + if (substr($row['path'], 0, 6) === 'files/') { + $row['path'] = substr($row['path'], 6); // remove 'files/' from path as it's relative to '/Shared' } $row['mimetype'] = $this->getMimetype($row['mimetype']); $row['mimepart'] = $this->getMimetype($row['mimepart']); From aeac3186ee52fcadf57b34fc307f5441041cb43d Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 30 Oct 2013 16:14:08 +0100 Subject: [PATCH 04/10] Fixed summary visibility check Now using the integer values to check whether to show the summary parts instead of trying to parse the html code. --- apps/files/js/filelist.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index c33a06bbdc3..02dfa16a224 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -593,18 +593,19 @@ var FileList={ var fileSize = ''+humanFileSize(totalSize)+''; } - $('#fileList').append(''+info+''+fileSize+''); + var $summary = $(''+info+''+fileSize+''); + $('#fileList').append($summary); - var $dirInfo = $('.summary .dirinfo'); - var $fileInfo = $('.summary .fileinfo'); - var $connector = $('.summary .connector'); + var $dirInfo = $summary.find('.dirinfo'); + var $fileInfo = $summary.find('.fileinfo'); + var $connector = $summary.find('.connector'); // Show only what's necessary, e.g.: no files: don't show "0 files" - if ($dirInfo.html().charAt(0) === "0") { + if (totalDirs === 0) { $dirInfo.hide(); $connector.hide(); } - if ($fileInfo.html().charAt(0) === "0") { + if (totalFiles === 0) { $fileInfo.hide(); $connector.hide(); } From 4c7082bf1ddd45824fd0f68fbdbb761d3e39a5ee Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 30 Oct 2013 17:03:53 +0100 Subject: [PATCH 05/10] allow to share a file/folder as public link also if one of it parents was already shared as link --- core/js/share.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/js/share.js b/core/js/share.js index c53fa4110b5..411f0d23c36 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -56,7 +56,7 @@ OC.Share={ var path = dir; // Search for possible parent folders that are shared while (path != last) { - if (path == data['path']) { + if (path == data['path'] && !data['link']) { var actions = $('.fileactions .action[data-action="Share"]'); $.each(actions, function(index, action) { var img = $(action).find('img'); @@ -244,7 +244,9 @@ OC.Share={ if (data.shares) { $.each(data.shares, function(index, share) { if (share.share_type == OC.Share.SHARE_TYPE_LINK) { - OC.Share.showLink(share.token, share.share_with, itemSource); + if ( !('file_target' in share) ) { + OC.Share.showLink(share.token, share.share_with, itemSource); + } } else { if (share.collection) { OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.mail_send, share.collection); From 19eeb618ff5332c7b6b1efad7350c1a8c2851bd4 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 30 Oct 2013 17:55:41 +0100 Subject: [PATCH 06/10] Prevent closing the create dropdown when right clicking in Firefox Firefox sends a click event on the document when right clicking which makes pasting with right click into the field impossible. Fixes #5498 --- apps/files/js/file-upload.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 95c0723f254..8c56f1cb364 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -465,7 +465,11 @@ $(document).ready(function() { crumb.text(text); } - $(document).click(function() { + $(document).click(function(ev) { + // do not close when clicking in the dropdown + if ($(ev.target).closest('#new').length){ + return; + } $('#new>ul').hide(); $('#new').removeClass('active'); if ($('#new .error').length > 0) { From e3b13b13c96bcdcf63f51a5d1234fd64f7cce702 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 30 Oct 2013 18:23:48 +0100 Subject: [PATCH 07/10] Changed log level labels in log level dropdown --- settings/templates/admin.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/settings/templates/admin.php b/settings/templates/admin.php index a5724bf3b17..2d9c3ff4f58 100644 --- a/settings/templates/admin.php +++ b/settings/templates/admin.php @@ -4,6 +4,13 @@ * See the COPYING-README file. */ $levels = array('Debug', 'Info', 'Warning', 'Error', 'Fatal'); +$levelLabels = array( + $l->t( 'Everything (fatal errors, warnings, info, debug)' ), + $l->t( 'Info, warnings, errors and fatal' ), + $l->t( 'Warnings, errors and fatal' ), + $l->t( 'Errors and fatal' ), + $l->t( 'Fatal only' ), +); ?>

t('Log'));?>

t('Log level'));?> From aba7335d3fe66ab43198d6dbae598d6e89e61834 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 30 Oct 2013 18:39:21 +0100 Subject: [PATCH 08/10] Changed wording in log level dropdown --- settings/templates/admin.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/settings/templates/admin.php b/settings/templates/admin.php index 2d9c3ff4f58..5413b700936 100644 --- a/settings/templates/admin.php +++ b/settings/templates/admin.php @@ -5,11 +5,11 @@ */ $levels = array('Debug', 'Info', 'Warning', 'Error', 'Fatal'); $levelLabels = array( - $l->t( 'Everything (fatal errors, warnings, info, debug)' ), - $l->t( 'Info, warnings, errors and fatal' ), - $l->t( 'Warnings, errors and fatal' ), - $l->t( 'Errors and fatal' ), - $l->t( 'Fatal only' ), + $l->t( 'Everything (fatal issues, errors, warnings, info, debug)' ), + $l->t( 'Info, warnings, errors and fatal issues' ), + $l->t( 'Warnings, errors and fatal issues' ), + $l->t( 'Errors and fatal issues' ), + $l->t( 'Fatal issues only' ), ); ?> From cba12e009fd11591763198665e5845cc54f395da Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Wed, 30 Oct 2013 21:07:19 +0100 Subject: [PATCH 09/10] Added missing HTTP prefix to the $_SERVER variable --- lib/private/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/api.php b/lib/private/api.php index 0576f3e3f93..7e69a6a77d2 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -250,7 +250,7 @@ class OC_API { // reuse existing login $loggedIn = OC_User::isLoggedIn(); - $ocsApiRequest = isset($_SERVER['OCS_APIREQUEST']) ? $_SERVER['OCS_APIREQUEST'] === 'true' : false; + $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false; if ($loggedIn === true && $ocsApiRequest) { return OC_User::getUser(); } From 3f42c890be86fdeebbf9008ccac117cb4f292e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 30 Oct 2013 22:59:31 +0100 Subject: [PATCH 10/10] we should check if a user is logged in before we check for admin privilege --- lib/private/util.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/private/util.php b/lib/private/util.php index f63884c0f32..176eb4bc369 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -579,6 +579,7 @@ class OC_Util { * @return void */ public static function checkAdminUser() { + OC_Util::checkLoggedIn(); if( !OC_User::isAdminUser(OC_User::getUser())) { header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' )); exit(); @@ -611,6 +612,7 @@ class OC_Util { * @return array $groups where the current user is subadmin */ public static function checkSubAdminUser() { + OC_Util::checkLoggedIn(); if(!OC_SubAdmin::isSubAdmin(OC_User::getUser())) { header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' )); exit();