diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-10-31 09:05:35 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-10-31 09:05:35 +0100 |
commit | 64bfd21ccd25231b86ba4c3b95993dc205c8ea3b (patch) | |
tree | f8427f09afca56da54433331caabbd5e9385d21b | |
parent | edafd29630f5866f10f331e69ba34cf26681782b (diff) | |
parent | 8f50d7680b0cb280a545685d26873a6c3d428aa3 (diff) | |
download | nextcloud-server-64bfd21ccd25231b86ba4c3b95993dc205c8ea3b.tar.gz nextcloud-server-64bfd21ccd25231b86ba4c3b95993dc205c8ea3b.zip |
Merge branch 'master' into fix_privatedata
-rw-r--r-- | apps/files/js/file-upload.js | 6 | ||||
-rw-r--r-- | apps/files/js/filelist.js | 13 | ||||
-rw-r--r-- | apps/files_sharing/lib/cache.php | 80 | ||||
-rw-r--r-- | core/js/share.js | 6 | ||||
-rw-r--r-- | lib/private/api.php | 3 | ||||
-rwxr-xr-x | lib/private/util.php | 2 | ||||
-rw-r--r-- | settings/templates/admin.php | 20 | ||||
-rw-r--r-- | tests/lib/preview.php | 12 |
8 files changed, 81 insertions, 61 deletions
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) { 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 = '<td class="filesize">'+humanFileSize(totalSize)+'</td>'; } - $('#fileList').append('<tr class="summary"><td><span class="info">'+info+'</span></td>'+fileSize+'<td></td></tr>'); + var $summary = $('<tr class="summary"><td><span class="info">'+info+'</span></td>'+fileSize+'<td></td></tr>'); + $('#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(); } 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']); 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); diff --git a/lib/private/api.php b/lib/private/api.php index 26091657b31..7e69a6a77d2 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['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false; + if ($loggedIn === true && $ocsApiRequest) { return OC_User::getUser(); } 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(); diff --git a/settings/templates/admin.php b/settings/templates/admin.php index a5724bf3b17..5413b700936 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 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' ), +); ?> <?php @@ -210,12 +217,13 @@ if (!$_['internetconnectionworking']) { <fieldset class="personalblock"> <h2><?php p($l->t('Log'));?></h2> <?php p($l->t('Log level'));?> <select name='loglevel' id='loglevel'> - <option value='<?php p($_['loglevel'])?>'><?php p($levels[$_['loglevel']])?></option> - <?php for ($i = 0; $i < 5; $i++): - if ($i !== $_['loglevel']):?> - <option value='<?php p($i)?>'><?php p($levels[$i])?></option> - <?php endif; -endfor;?> +<?php for ($i = 0; $i < 5; $i++): + $selected = ''; + if ($i == $_['loglevel']): + $selected = 'selected="selected"'; + endif; ?> + <option value='<?php p($i)?>' <?php p($selected) ?>><?php p($levelLabels[$i])?></option> +<?php endfor;?> </select> <table id="log" class="grid"> <?php foreach ($_['entries'] as $entry): ?> 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(), '/'); |