diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-05-19 20:52:25 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-05-19 20:52:25 +0200 |
commit | 51a6764f3180a258dc17a6744929866aeddb8779 (patch) | |
tree | 78452f7027ab7b71d48f1aedc736cd9617430ce8 /apps/files_sharing | |
parent | 2c483fdca21fc32bf6ef8eaf5835e8e4614acd3a (diff) | |
parent | b6d2d6329d99c47fa8a01a7a8db7f8f2de6b9f74 (diff) | |
download | nextcloud-server-51a6764f3180a258dc17a6744929866aeddb8779.tar.gz nextcloud-server-51a6764f3180a258dc17a6744929866aeddb8779.zip |
Merge branch 'master' into cleanup-list-code
Conflicts:
apps/files_sharing/ajax/list.php
Diffstat (limited to 'apps/files_sharing')
24 files changed, 480 insertions, 183 deletions
diff --git a/apps/files_sharing/ajax/list.php b/apps/files_sharing/ajax/list.php index c31b3a0e06f..93964c5ed5b 100644 --- a/apps/files_sharing/ajax/list.php +++ b/apps/files_sharing/ajax/list.php @@ -40,6 +40,9 @@ if (isset($_GET['dir'])) { $relativePath = $_GET['dir']; } +$sortAttribute = isset( $_GET['sort'] ) ? $_GET['sort'] : 'name'; +$sortDirection = isset( $_GET['sortdirection'] ) ? ($_GET['sortdirection'] === 'desc') : false; + $data = \OCA\Files_Sharing\Helper::setupFromToken($token, $relativePath, $password); $linkItem = $data['linkItem']; @@ -56,7 +59,7 @@ if (!\OC\Files\Filesystem::is_dir($dir . '/')) { $data = array(); // make filelist -$files = \OCA\Files\Helper::getFiles($dir); +$files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection); $formattedFiles = array(); foreach ($files as $file) { @@ -80,4 +83,4 @@ if (OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes') === 'n $data['permissions'] = $permissions; -OCP\JSON::success(array('data' => $data));
\ No newline at end of file +OCP\JSON::success(array('data' => $data)); diff --git a/apps/files_sharing/ajax/publicpreview.php b/apps/files_sharing/ajax/publicpreview.php index 6ba47e5b3a6..0b2af7a6e59 100644 --- a/apps/files_sharing/ajax/publicpreview.php +++ b/apps/files_sharing/ajax/publicpreview.php @@ -15,6 +15,7 @@ $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36'; $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36'; $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; $token = array_key_exists('t', $_GET) ? (string) $_GET['t'] : ''; +$keepAspect = array_key_exists('a', $_GET) ? true : false; if($token === ''){ \OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); @@ -69,6 +70,10 @@ if(substr($path, 0, 1) === '/') { $path = substr($path, 1); } +if ($keepAspect === true) { + $maxY = $maxX; +} + if($maxX === 0 || $maxY === 0) { \OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); @@ -83,8 +88,9 @@ try{ $preview->setMaxX($maxX); $preview->setMaxY($maxY); $preview->setScalingUp($scalingUp); + $preview->setKeepAspect($keepAspect); - $preview->show(); + $preview->showPreview(); } catch (\Exception $e) { \OC_Response::setStatus(\OC_Response::STATUS_INTERNAL_SERVER_ERROR); \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG); diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php index 06e454b7d77..7c2834dc9c2 100644 --- a/apps/files_sharing/appinfo/routes.php +++ b/apps/files_sharing/appinfo/routes.php @@ -1,9 +1,9 @@ <?php /** @var $this \OCP\Route\IRouter */ -$this->create('core_ajax_public_preview', '/publicpreview.png')->action( -function() { - require_once __DIR__ . '/../ajax/publicpreview.php'; -}); +$this->create('core_ajax_public_preview', '/publicpreview')->action( + function() { + require_once __DIR__ . '/../ajax/publicpreview.php'; + }); // OCS API diff --git a/apps/files_sharing/css/public.css b/apps/files_sharing/css/public.css index 67d84701946..70897af9eb9 100644 --- a/apps/files_sharing/css/public.css +++ b/apps/files_sharing/css/public.css @@ -1,7 +1,3 @@ -#controls { - left: 0; -} - #preview { background: #fff; text-align: center; diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index ae2412f6a3b..d3d4479215e 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -8,77 +8,164 @@ * */ -/* global OC, FileActions, FileList, Files */ +/* global FileActions, Files */ +/* global dragOptions, folderDropOptions */ +OCA.Sharing = {}; +if (!OCA.Files) { + OCA.Files = {}; +} +OCA.Sharing.PublicApp = { + _initialized: false, -$(document).ready(function() { + initialize: function($el) { + if (this._initialized) { + return; + } + this._initialized = true; + // file list mode ? + if ($el.find('#filestable')) { + this.fileList = new OCA.Files.FileList( + $el, + { + scrollContainer: $(window), + dragOptions: dragOptions, + folderDropOptions: folderDropOptions + } + ); + this.files = OCA.Files.Files; + this.files.initialize(); + } - if (typeof FileActions !== 'undefined') { var mimetype = $('#mimetype').val(); - // Show file preview if previewer is available, images are already handled by the template - if (mimetype.substr(0, mimetype.indexOf('/')) != 'image' && $('.publicpreview').length === 0) { - // Trigger default action if not download TODO - var action = FileActions.getDefault(mimetype, 'file', OC.PERMISSION_READ); - if (typeof action !== 'undefined') { - action($('#filename').val()); + + if (typeof FileActions !== 'undefined') { + // Show file preview if previewer is available, images are already handled by the template + if (mimetype.substr(0, mimetype.indexOf('/')) !== 'image' && $('.publicpreview').length === 0) { + // Trigger default action if not download TODO + var action = FileActions.getDefault(mimetype, 'file', OC.PERMISSION_READ); + if (typeof action !== 'undefined') { + action($('#filename').val()); + } } } - } - // override since the format is different - Files.getDownloadUrl = function(filename, dir) { - if ($.isArray(filename)) { - filename = JSON.stringify(filename); + // dynamically load image previews + if (mimetype.substr(0, mimetype.indexOf('/')) === 'image' ) { + + var params = { + x: $(document).width() * window.devicePixelRatio, + a: 'true', + file: encodeURIComponent($('#dir').val() + $('#filename').val()), + t: $('#sharingToken').val() + }; + + var img = $('<img class="publicpreview">'); + img.attr('src', OC.filePath('files_sharing', 'ajax', 'publicpreview.php') + '?' + OC.buildQueryString(params)); + img.appendTo('#imgframe'); } - var path = dir || FileList.getCurrentDirectory(); - var params = { - service: 'files', - t: $('#sharingToken').val(), - path: path, - files: filename, - download: null - }; - return OC.filePath('', '', 'public.php') + '?' + OC.buildQueryString(params); - }; - Files.getAjaxUrl = function(action, params) { - params = params || {}; - params.t = $('#sharingToken').val(); - return OC.filePath('files_sharing', 'ajax', action + '.php') + '?' + OC.buildQueryString(params); - }; + if (this.fileList) { + // TODO: move this to a separate PublicFileList class that extends OCA.Files.FileList (+ unit tests) + this.fileList.getDownloadUrl = function(filename, dir) { + if ($.isArray(filename)) { + filename = JSON.stringify(filename); + } + var path = dir || FileList.getCurrentDirectory(); + var params = { + service: 'files', + t: $('#sharingToken').val(), + path: path, + files: filename, + download: null + }; + return OC.filePath('', '', 'public.php') + '?' + OC.buildQueryString(params); + }; - FileList.linkTo = function(dir) { - var params = { - service: 'files', - t: $('#sharingToken').val(), - dir: dir - }; - return OC.filePath('', '', 'public.php') + '?' + OC.buildQueryString(params); - }; + this.fileList.getAjaxUrl = function(action, params) { + params = params || {}; + params.t = $('#sharingToken').val(); + return OC.filePath('files_sharing', 'ajax', action + '.php') + '?' + OC.buildQueryString(params); + }; - Files.generatePreviewUrl = function(urlSpec) { - urlSpec.t = $('#dirToken').val(); - return OC.generateUrl('/apps/files_sharing/ajax/publicpreview.php?') + $.param(urlSpec); - }; + this.fileList.linkTo = function(dir) { + var params = { + service: 'files', + t: $('#sharingToken').val(), + dir: dir + }; + return OC.filePath('', '', 'public.php') + '?' + OC.buildQueryString(params); + }; - var file_upload_start = $('#file_upload_start'); - file_upload_start.on('fileuploadadd', function(e, data) { - var fileDirectory = ''; - if(typeof data.files[0].relativePath !== 'undefined') { - fileDirectory = data.files[0].relativePath; + this.fileList.generatePreviewUrl = function(urlSpec) { + urlSpec.t = $('#dirToken').val(); + return OC.generateUrl('/apps/files_sharing/ajax/publicpreview.php?') + $.param(urlSpec); + }; + + var file_upload_start = $('#file_upload_start'); + file_upload_start.on('fileuploadadd', function(e, data) { + var fileDirectory = ''; + if(typeof data.files[0].relativePath !== 'undefined') { + fileDirectory = data.files[0].relativePath; + } + + // Add custom data to the upload handler + data.formData = { + requesttoken: $('#publicUploadRequestToken').val(), + dirToken: $('#dirToken').val(), + subdir: $('input#dir').val(), + file_directory: fileDirectory + }; + }); + + this.fileActions = _.extend({}, OCA.Files.FileActions); + this.fileActions.registerDefaultActions(this.fileList); + delete this.fileActions.actions.all.Share; + this.fileList.setFileActions(this.fileActions); + + this.fileList.changeDirectory($('#dir').val() || '/', false, true); + + // URL history handling + this.fileList.$el.on('changeDirectory', _.bind(this._onDirectoryChanged, this)); + OC.Util.History.addOnPopStateHandler(_.bind(this._onUrlChanged, this)); } - // Add custom data to the upload handler - data.formData = { - requesttoken: $('#publicUploadRequestToken').val(), - dirToken: $('#dirToken').val(), - subdir: $('input#dir').val(), - file_directory: fileDirectory - }; - }); + $(document).on('click', '#directLink', function() { + $(this).focus(); + $(this).select(); + }); + + // legacy + window.FileList = this.fileList; + }, - $(document).on('click', '#directLink', function() { - $(this).focus(); - $(this).select(); - }); + _onDirectoryChanged: function(e) { + OC.Util.History.pushState({ + service: 'files', + t: $('#sharingToken').val(), + // arghhhh, why is this not called "dir" !? + path: e.dir + }); + }, + _onUrlChanged: function(params) { + this.fileList.changeDirectory(params.path || params.dir, false, true); + } +}; + +$(document).ready(function() { + var App = OCA.Sharing.PublicApp; + App.initialize($('#preview')); + + // HACK: for oc-dialogs previews that depends on Files: + Files.lazyLoadPreview = function(path, mime, ready, width, height, etag) { + return App.fileList.lazyLoadPreview({ + path: path, + mime: mime, + callback: ready, + width: width, + height: height, + etag: etag + }); + }; }); + diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index 3c7c9239a6c..973c63c5d7e 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -8,15 +8,15 @@ * */ -/* global OC, t, FileList, FileActions */ +/* global FileList, FileActions */ $(document).ready(function() { - var disableSharing = $('#disableSharing').data('status'), - sharesLoaded = false; + var sharesLoaded = false; - if (typeof OC.Share !== 'undefined' && typeof FileActions !== 'undefined' && !disableSharing) { - var oldCreateRow = FileList._createRow; - FileList._createRow = function(fileData) { + if (typeof OC.Share !== 'undefined' && typeof FileActions !== 'undefined') { + // TODO: make a separate class for this or a hook or jQuery event ? + var oldCreateRow = OCA.Files.FileList.prototype._createRow; + OCA.Files.FileList.prototype._createRow = function(fileData) { var tr = oldCreateRow.apply(this, arguments); if (fileData.shareOwner) { tr.attr('data-share-owner', fileData.shareOwner); @@ -25,14 +25,16 @@ $(document).ready(function() { }; $('#fileList').on('fileActionsReady',function(){ - - var allShared = $('#fileList').find('[data-share-owner] [data-Action="Share"]'); + var $fileList = $(this); + var allShared = $fileList.find('[data-share-owner] [data-Action="Share"]'); allShared.addClass('permanent'); allShared.find('span').text(function(){ var $owner = $(this).closest('tr').attr('data-share-owner'); return ' ' + t('files_sharing', 'Shared by {owner}', {owner: $owner}); }); + // FIXME: these calls are also working on hard-coded + // list selectors... if (!sharesLoaded){ OC.Share.loadIcons('file'); // assume that we got all shares, so switching directories diff --git a/apps/files_sharing/l10n/ast.php b/apps/files_sharing/l10n/ast.php index d90df88723f..fa3704ea6ba 100644 --- a/apps/files_sharing/l10n/ast.php +++ b/apps/files_sharing/l10n/ast.php @@ -1,7 +1,17 @@ <?php $TRANSLATIONS = array( "Shared by {owner}" => "Compartíu por {owner}", +"This share is password-protected" => "Esta compartición tien contraseña protexida", +"The password is wrong. Try again." => "La contraseña ye incorreuta. Inténtalo otra vegada.", "Password" => "Contraseña", -"Download" => "Baxar" +"Sorry, this link doesn’t seem to work anymore." => "Sentímoslo, esti enllaz paez que yá nun furrula.", +"Reasons might be:" => "Les razones pueden ser: ", +"the item was removed" => "desanicióse l'elementu", +"the link expired" => "l'enllaz caducó", +"sharing is disabled" => "compartir ta desactiváu", +"For more info, please ask the person who sent this link." => "Pa más información, entrúga-y a la persona qu'unvió esti enllaz", +"Download" => "Baxar", +"Download %s" => "Descargar %s", +"Direct link" => "Enllaz direutu" ); $PLURAL_FORMS = "nplurals=2; plural=(n != 1);"; diff --git a/apps/files_sharing/l10n/eu.php b/apps/files_sharing/l10n/eu.php index 03c2f844a14..8be7bcb2a4b 100644 --- a/apps/files_sharing/l10n/eu.php +++ b/apps/files_sharing/l10n/eu.php @@ -11,6 +11,7 @@ $TRANSLATIONS = array( "sharing is disabled" => "elkarbanatzea ez dago gaituta", "For more info, please ask the person who sent this link." => "Informazio gehiagorako, mesedez eskatu lotura hau bidali zuen pertsonari", "Download" => "Deskargatu", +"Download %s" => "Deskargatu %s", "Direct link" => "Lotura zuzena" ); $PLURAL_FORMS = "nplurals=2; plural=(n != 1);"; diff --git a/apps/files_sharing/l10n/fa.php b/apps/files_sharing/l10n/fa.php index 1176401f1a3..fb6a4bc8709 100644 --- a/apps/files_sharing/l10n/fa.php +++ b/apps/files_sharing/l10n/fa.php @@ -1,8 +1,17 @@ <?php $TRANSLATIONS = array( "Shared by {owner}" => "اشتراک گذارنده {owner}", +"This share is password-protected" => "این اشتراک توسط رمز عبور محافظت می شود", "The password is wrong. Try again." => "رمزعبور اشتباه می باشد. دوباره امتحان کنید.", "Password" => "گذرواژه", -"Download" => "دانلود" +"Sorry, this link doesn’t seem to work anymore." => "متاسفانه این پیوند دیگر کار نمی کند", +"Reasons might be:" => "ممکن است به این دلایل باشد:", +"the item was removed" => "این مورد حذف شده است", +"the link expired" => "این پیوند منقضی شده است", +"sharing is disabled" => "قابلیت اشتراک گذاری غیرفعال است", +"For more info, please ask the person who sent this link." => "برای اطلاعات بیشتر، لطفا از شخصی که این پیوند را ارسال کرده سوال بفرمایید.", +"Download" => "دانلود", +"Download %s" => "دانلود %s", +"Direct link" => "پیوند مستقیم" ); $PLURAL_FORMS = "nplurals=1; plural=0;"; diff --git a/apps/files_sharing/l10n/km.php b/apps/files_sharing/l10n/km.php index db353c9cb74..75f5679d97a 100644 --- a/apps/files_sharing/l10n/km.php +++ b/apps/files_sharing/l10n/km.php @@ -1,6 +1,17 @@ <?php $TRANSLATIONS = array( +"Shared by {owner}" => "{owner} បានចែករំលែក", +"This share is password-protected" => "ការចែករំលែកនេះត្រូវបានការពារដោយពាក្យសម្ងាត់", +"The password is wrong. Try again." => "ពាក្យសម្ងាត់ខុសហើយ។ ព្យាយាមម្ដងទៀត។", "Password" => "ពាក្យសម្ងាត់", -"Download" => "ទាញយក" +"Sorry, this link doesn’t seem to work anymore." => "សូមទោស តំណនេះហាក់ដូចជាលែងដើរហើយ។", +"Reasons might be:" => "មូលហេតុអាចជា៖", +"the item was removed" => "របស់ត្រូវបានដកចេញ", +"the link expired" => "តំណផុតពេលកំណត់", +"sharing is disabled" => "មិនអនុញ្ញាតការចែករំលែក", +"For more info, please ask the person who sent this link." => "សម្រាប់ព័ត៌មានបន្ថែម សូមសួរអ្នកដែលផ្ញើតំណនេះ។", +"Download" => "ទាញយក", +"Download %s" => "ទាញយក %s", +"Direct link" => "តំណផ្ទាល់" ); $PLURAL_FORMS = "nplurals=1; plural=0;"; diff --git a/apps/files_sharing/l10n/ru.php b/apps/files_sharing/l10n/ru.php index 41c60d2ec8a..5920d79d9e5 100644 --- a/apps/files_sharing/l10n/ru.php +++ b/apps/files_sharing/l10n/ru.php @@ -11,6 +11,7 @@ $TRANSLATIONS = array( "sharing is disabled" => "общий доступ отключён", "For more info, please ask the person who sent this link." => "Пожалуйста, обратитесь к отправителю данной ссылки.", "Download" => "Скачать", +"Download %s" => "Скачать %s", "Direct link" => "Прямая ссылка" ); $PLURAL_FORMS = "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);"; diff --git a/apps/files_sharing/l10n/zh_CN.php b/apps/files_sharing/l10n/zh_CN.php index 3178b284058..5cc95b71af7 100644 --- a/apps/files_sharing/l10n/zh_CN.php +++ b/apps/files_sharing/l10n/zh_CN.php @@ -11,6 +11,7 @@ $TRANSLATIONS = array( "sharing is disabled" => "共享已禁用", "For more info, please ask the person who sent this link." => "欲知详情,请联系发给你链接的人。", "Download" => "下载", +"Download %s" => "下载 %s", "Direct link" => "直接链接" ); $PLURAL_FORMS = "nplurals=1; plural=0;"; diff --git a/apps/files_sharing/lib/api.php b/apps/files_sharing/lib/api.php index 438d3cc4ba3..21fd5d00a4c 100644 --- a/apps/files_sharing/lib/api.php +++ b/apps/files_sharing/lib/api.php @@ -25,7 +25,7 @@ namespace OCA\Files\Share; class Api { /** - * @brief get all shares + * get all shares * * @param array $params option 'file' to limit the result to a specific file/folder * @return \OC_OCS_Result share information @@ -60,7 +60,7 @@ class Api { } /** - * @brief get share information for a given share + * get share information for a given share * * @param array $params which contains a 'id' * @return \OC_OCS_Result share information @@ -76,7 +76,7 @@ class Api { } /** - * @brief collect all share information, either of a specific share or all + * collect all share information, either of a specific share or all * shares for a given path * @param array $params * @return \OC_OCS_Result @@ -130,7 +130,7 @@ class Api { } /** - * @brief add reshares to a array of shares + * add reshares to a array of shares * @param array $shares array of shares * @param int $itemSource item source ID * @return array new shares array which includes reshares @@ -161,7 +161,7 @@ class Api { } /** - * @brief get share from all files in a given folder (non-recursive) + * get share from all files in a given folder (non-recursive) * @param array $params contains 'path' to the folder * @return \OC_OCS_Result */ @@ -196,7 +196,7 @@ class Api { } /** - * @breif create a new share + * create a new share * @param array $params * @return \OC_OCS_Result */ @@ -313,7 +313,7 @@ class Api { } /** - * @brief update permissions for a share + * update permissions for a share * @param array $share information about the share * @param array $params contains 'permissions' * @return \OC_OCS_Result @@ -358,7 +358,7 @@ class Api { } /** - * @brief enable/disable public upload + * enable/disable public upload * @param array $share information about the share * @param array $params contains 'publicUpload' which can be 'yes' or 'no' * @return \OC_OCS_Result @@ -384,9 +384,9 @@ class Api { } /** - * @brief update password for public link share + * update password for public link share * @param array $share information about the share - * @param type $params 'password' + * @param array $params 'password' * @return \OC_OCS_Result */ private static function updatePassword($share, $params) { @@ -418,13 +418,18 @@ class Api { return new \OC_OCS_Result(null, 404, "share doesn't exists, can't change password"); } - $result = \OCP\Share::shareItem( - $itemType, - $itemSource, - \OCP\Share::SHARE_TYPE_LINK, - $shareWith, - $permissions - ); + try { + $result = \OCP\Share::shareItem( + $itemType, + $itemSource, + \OCP\Share::SHARE_TYPE_LINK, + $shareWith, + $permissions + ); + } catch (\Exception $e) { + return new \OC_OCS_Result(null, 403, $e->getMessage()); + } + if($result) { return new \OC_OCS_Result(); } @@ -433,7 +438,7 @@ class Api { } /** - * @brief unshare a file/folder + * unshare a file/folder * @param array $params contains the shareID 'id' which should be unshared * @return \OC_OCS_Result */ @@ -473,7 +478,7 @@ class Api { } /** - * @brief get file ID from a given path + * get file ID from a given path * @param string $path * @return string fileID or null */ @@ -490,7 +495,7 @@ class Api { } /** - * @brief get itemType + * get itemType * @param string $path * @return string type 'file', 'folder' or null of file/folder doesn't exists */ @@ -508,7 +513,7 @@ class Api { } /** - * @brief get some information from a given share + * get some information from a given share * @param int $shareID * @return array with: item_source, share_type, share_with, item_type, permissions */ diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 1f316301c47..9d83ed13b87 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -42,7 +42,7 @@ class Shared_Cache extends Cache { } /** - * @brief Get the source cache of a shared file or folder + * Get the source cache of a shared file or folder * @param string $target Shared target file path * @return \OC\Files\Cache\Cache */ @@ -80,7 +80,7 @@ class Shared_Cache extends Cache { /** * get the stored metadata of a file or folder * - * @param string /int $file + * @param string|int $file * @return array */ public function get($file) { @@ -424,7 +424,7 @@ class Shared_Cache extends Cache { * * @param int $id * @param string $pathEnd (optional) used internally for recursive calls - * @return string | null + * @return string|null */ public function getPathById($id, $pathEnd = '') { // direct shares are easy @@ -442,6 +442,9 @@ class Shared_Cache extends Cache { } } + /** + * @param integer $id + */ private function getShareById($id) { $item = \OCP\Share::getItemSharedWithBySource('file', $id); if ($item) { @@ -454,6 +457,9 @@ class Shared_Cache extends Cache { return null; } + /** + * @param integer $id + */ private function getParentInfo($id) { $sql = 'SELECT `parent`, `name` FROM `*PREFIX*filecache` WHERE `fileid` = ?'; $query = \OC_DB::prepare($sql); diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php index cc1f7d9ffdf..71b496ab944 100644 --- a/apps/files_sharing/lib/helper.php +++ b/apps/files_sharing/lib/helper.php @@ -79,7 +79,7 @@ class Helper { * @param array $linkItem link item array * @param string $password optional password * - * @return true if authorized, false otherwise + * @return boolean true if authorized, false otherwise */ public static function authenticate($linkItem, $password) { if ($password !== null) { @@ -125,9 +125,13 @@ class Helper { $ids = array(); - while ($path !== '' && $path !== '.' && $path !== '/') { + while ($path !== dirname($path)) { $info = $ownerView->getFileInfo($path); - $ids[] = $info['fileid']; + if ($info instanceof \OC\Files\FileInfo) { + $ids[] = $info['fileid']; + } else { + \OCP\Util::writeLog('sharing', 'No fileinfo available for: ' . $path, \OCP\Util::WARN); + } $path = dirname($path); } @@ -158,7 +162,7 @@ class Helper { } /** - * @brief Format a path to be relative to the /user/files/ directory + * Format a path to be relative to the /user/files/ directory * @param string $path the absolute path * @return string e.g. turns '/admin/files/test.txt' into 'test.txt' */ diff --git a/apps/files_sharing/lib/maintainer.php b/apps/files_sharing/lib/maintainer.php index bbb3268410e..f07c09e5aee 100644 --- a/apps/files_sharing/lib/maintainer.php +++ b/apps/files_sharing/lib/maintainer.php @@ -33,7 +33,7 @@ class Maintainer { * Keeps track of the "allow links" config setting * and removes all link shares if the config option is set to "no" * - * @param array with app, key, value as named values + * @param array $params array with app, key, value as named values */ static public function configChangeHook($params) { if($params['app'] === 'core' && $params['key'] === 'shareapi_allow_links' && $params['value'] === 'no') { diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php index c0c9e0c107e..af71786b104 100644 --- a/apps/files_sharing/lib/share/file.php +++ b/apps/files_sharing/lib/share/file.php @@ -33,10 +33,12 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { private $path; public function isValidSource($itemSource, $uidOwner) { - $query = \OC_DB::prepare('SELECT `name` FROM `*PREFIX*filecache` WHERE `fileid` = ?'); - $result = $query->execute(array($itemSource)); - if ($row = $result->fetchRow()) { - $this->path = $row['name']; + $path = \OC\Files\Filesystem::getPath($itemSource); + if ($path) { + // FIXME: attributes should not be set here, + // keeping this pattern for now to avoid unexpected + // regressions + $this->path = basename($path); return true; } return false; @@ -52,7 +54,7 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { } /** - * @brief create unique target + * create unique target * @param string $filePath * @param string $shareWith * @param string $exclude @@ -152,7 +154,7 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { } /** - * @brief resolve reshares to return the correct source item + * resolve reshares to return the correct source item * @param array $source * @return array source item */ @@ -181,8 +183,13 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { return $source; } + /** + * @param string $target + * @param string $mountPoint + * @param string $itemType + * @return array|false source item + */ public static function getSource($target, $mountPoint, $itemType) { - if ($itemType === 'folder') { $source = \OCP\Share::getItemSharedWith('folder', $mountPoint, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE); if ($source && $target !== '') { diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 4733dff3d14..4b69276d05a 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -36,7 +36,7 @@ class Shared extends \OC\Files\Storage\Common { } /** - * @breif get id of the mount point + * get id of the mount point * @return string */ public function getId() { @@ -44,7 +44,7 @@ class Shared extends \OC\Files\Storage\Common { } /** - * @breif get file cache of the shared item source + * get file cache of the shared item source * @return string */ public function getSourceId() { @@ -52,9 +52,8 @@ class Shared extends \OC\Files\Storage\Common { } /** - * @brief Get the source file path, permissions, and owner for a shared file - * @param string Shared target file path - * @param string $target + * Get the source file path, permissions, and owner for a shared file + * @param string $target Shared target file path * @return Returns array with the keys path, permissions, and owner or false if not found */ public function getFile($target) { @@ -76,9 +75,8 @@ class Shared extends \OC\Files\Storage\Common { } /** - * @brief Get the source file path for a shared file - * @param string Shared target file path - * @param string $target + * Get the source file path for a shared file + * @param string $target Shared target file path * @return string source file path or false if not found */ public function getSourcePath($target) { @@ -100,16 +98,17 @@ class Shared extends \OC\Files\Storage\Common { } /** - * @brief Get the permissions granted for a shared file - * @param string Shared target file path - * @return int CRUDS permissions granted or false if not found + * Get the permissions granted for a shared file + * @param string $target Shared target file path + * @return int CRUDS permissions granted */ public function getPermissions($target) { - $source = $this->getFile($target); - if ($source) { - return $source['permissions']; + $permissions = $this->share['permissions']; + // part file are always have delete permissions + if (pathinfo($target, PATHINFO_EXTENSION) === 'part') { + $permissions |= \OCP\PERMISSION_DELETE; } - return false; + return $permissions; } public function mkdir($path) { @@ -183,9 +182,6 @@ class Shared extends \OC\Files\Storage\Common { } public function isCreatable($path) { - if ($path == '') { - $path = $this->getMountPoint(); - } return ($this->getPermissions($path) & \OCP\PERMISSION_CREATE); } @@ -194,23 +190,14 @@ class Shared extends \OC\Files\Storage\Common { } public function isUpdatable($path) { - if ($path == '') { - $path = $this->getMountPoint(); - } return ($this->getPermissions($path) & \OCP\PERMISSION_UPDATE); } public function isDeletable($path) { - if ($path == '') { - $path = $this->getMountPoint(); - } return ($this->getPermissions($path) & \OCP\PERMISSION_DELETE); } public function isSharable($path) { - if ($path == '') { - $path = $this->getMountPoint(); - } return ($this->getPermissions($path) & \OCP\PERMISSION_SHARE); } @@ -276,7 +263,7 @@ class Shared extends \OC\Files\Storage\Common { } /** - * @brief Format a path to be relative to the /user/files/ directory + * Format a path to be relative to the /user/files/ directory * @param string $path the absolute path * @return string e.g. turns '/admin/files/test.txt' into '/test.txt' */ @@ -300,7 +287,7 @@ class Shared extends \OC\Files\Storage\Common { } /** - * @brief rename a shared folder/file + * rename a shared folder/file * @param string $sourcePath * @param string $targetPath * @return bool @@ -454,9 +441,6 @@ class Shared extends \OC\Files\Storage\Common { } public function free_space($path) { - if ($path == '') { - $path = $this->getMountPoint(); - } $source = $this->getSourcePath($path); if ($source) { list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source); @@ -497,7 +481,7 @@ class Shared extends \OC\Files\Storage\Common { } /** - * @brief return mount point of share, relative to data/user/files + * return mount point of share, relative to data/user/files * @return string */ public function getMountPoint() { @@ -505,7 +489,7 @@ class Shared extends \OC\Files\Storage\Common { } /** - * @brief get share type + * get share type * @return integer can be single user share (0) group share (1), unique group share name (2) */ private function getShareType() { @@ -517,7 +501,7 @@ class Shared extends \OC\Files\Storage\Common { } /** - * @brief does the group share already has a user specific unique name + * does the group share already has a user specific unique name * @return bool */ private function uniqueNameSet() { @@ -525,14 +509,14 @@ class Shared extends \OC\Files\Storage\Common { } /** - * @brief the share now uses a unique name of this user + * the share now uses a unique name of this user */ private function setUniqueName() { $this->share['unique_name'] = true; } /** - * @brief get share ID + * get share ID * @return integer unique share ID */ private function getShareId() { @@ -540,7 +524,7 @@ class Shared extends \OC\Files\Storage\Common { } /** - * @brief get the user who shared the file + * get the user who shared the file * @return string */ public function getSharedFrom() { @@ -548,7 +532,7 @@ class Shared extends \OC\Files\Storage\Common { } /** - * @brief return share type, can be "file" or "folder" + * return share type, can be "file" or "folder" * @return string */ public function getItemType() { diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php index f7c0a75aeeb..21d67caad9d 100644 --- a/apps/files_sharing/lib/updater.php +++ b/apps/files_sharing/lib/updater.php @@ -27,7 +27,7 @@ class Shared_Updater { static private $toRemove = array(); /** - * @brief walk up the users file tree and update the etags + * walk up the users file tree and update the etags * @param string $user * @param string $path */ @@ -38,14 +38,13 @@ class Shared_Updater { \OC\Files\Filesystem::initMountPoints($user); $view = new \OC\Files\View('/' . $user); if ($view->file_exists($path)) { - while ($path !== '/') { + while ($path !== dirname($path)) { $etag = $view->getETag($path); $view->putFileInfo($path, array('etag' => $etag)); $path = dirname($path); } } else { - error_log("error!" . 'can not update etags on ' . $path . ' for user ' . $user); - \OCP\Util::writeLog('files_sharing', 'can not update etags on ' . $path . ' for user ' . $user, \OCP\Util::ERROR); + \OCP\Util::writeLog('files_sharing', 'can not update etags on ' . $path . ' for user ' . $user . '. Path does not exists', \OCP\Util::DEBUG); } } @@ -55,6 +54,12 @@ class Shared_Updater { * @param string $target */ static public function correctFolders($target) { + + // ignore part files + if (pathinfo($target, PATHINFO_EXTENSION) === 'part') { + return false; + } + // Correct Shared folders of other users shared with $shares = \OCA\Files_Sharing\Helper::getSharesFromItem($target); @@ -73,7 +78,7 @@ class Shared_Updater { } /** - * @brief remove all shares for a given file if the file was deleted + * remove all shares for a given file if the file was deleted * * @param string $path */ diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index e17ffc48036..8a86cb3806a 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -149,11 +149,11 @@ if (isset($path)) { $freeSpace=OCP\Util::freeSpace($path); $uploadLimit=OCP\Util::uploadLimit(); - $folder = new OCP\Template('files', 'index', ''); + $folder = new OCP\Template('files', 'list', ''); $folder->assign('dir', $getPath); $folder->assign('dirToken', $linkItem['token']); $folder->assign('permissions', OCP\PERMISSION_READ); - $folder->assign('isPublic',true); + $folder->assign('isPublic', true); $folder->assign('publicUploadEnabled', 'no'); $folder->assign('files', $files); $folder->assign('uploadMaxFilesize', $maxUploadFilesize); @@ -162,7 +162,6 @@ if (isset($path)) { $folder->assign('uploadLimit', $uploadLimit); // PHP upload limit $folder->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true))); $folder->assign('usedSpacePercent', 0); - $folder->assign('disableSharing', true); $folder->assign('trash', false); $tmpl->assign('folder', $folder->fetchPage()); $allowZip = OCP\Config::getSystemValue('allowZipDownload', true); diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index f3c75134a5f..9471752b6b5 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -30,7 +30,6 @@ <?php else: ?> <?php if (substr($_['mimetype'], 0, strpos($_['mimetype'], '/')) == 'image'): ?> <div id="imgframe"> - <img src="<?php p($_['downloadURL']); ?>" alt="" /> </div> <?php elseif (substr($_['mimetype'], 0, strpos($_['mimetype'], '/')) == 'video'): ?> <div id="imgframe"> diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php index b2f05d10ac6..dc07c6fc620 100644 --- a/apps/files_sharing/tests/api.php +++ b/apps/files_sharing/tests/api.php @@ -29,10 +29,14 @@ use OCA\Files\Share; */ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { + const TEST_FOLDER_NAME = '/folder_share_api_test'; + + private static $tempStorage; + function setUp() { parent::setUp(); - $this->folder = '/folder_share_api_test'; + $this->folder = self::TEST_FOLDER_NAME; $this->subfolder = '/subfolder_share_api_test'; $this->subsubfolder = '/subsubfolder_share_api_test'; @@ -51,6 +55,8 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { $this->view->unlink($this->filename); $this->view->deleteAll($this->folder); + self::$tempStorage = null; + parent::tearDown(); } @@ -107,11 +113,65 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { $fileinfo = $this->view->getFileInfo($this->folder); \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null); + } + + function testEnfoceLinkPassword() { + + $appConfig = \OC::$server->getAppConfig(); + $appConfig->setValue('core', 'shareapi_enforce_links_password', 'yes'); + + // don't allow to share link without a password + $_POST['path'] = $this->folder; + $_POST['shareType'] = \OCP\Share::SHARE_TYPE_LINK; + + + $result = Share\Api::createShare(array()); + $this->assertFalse($result->succeeded()); + + + // don't allow to share link without a empty password + $_POST['path'] = $this->folder; + $_POST['shareType'] = \OCP\Share::SHARE_TYPE_LINK; + $_POST['password'] = ''; + + $result = Share\Api::createShare(array()); + $this->assertFalse($result->succeeded()); + + // share with password should succeed + $_POST['path'] = $this->folder; + $_POST['shareType'] = \OCP\Share::SHARE_TYPE_LINK; + $_POST['password'] = 'foo'; + $result = Share\Api::createShare(array()); + $this->assertTrue($result->succeeded()); + + $data = $result->getData(); + // setting new password should succeed + $params = array(); + $params['id'] = $data['id']; + $params['_put'] = array(); + $params['_put']['password'] = 'bar'; + $result = Share\Api::updateShare($params); + $this->assertTrue($result->succeeded()); + + // removing password should fail + $params = array(); + $params['id'] = $data['id']; + $params['_put'] = array(); + $params['_put']['password'] = ''; + + $result = Share\Api::updateShare($params); + $this->assertFalse($result->succeeded()); + + // cleanup + $fileinfo = $this->view->getFileInfo($this->folder); + \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null); + $appConfig->setValue('core', 'shareapi_enforce_links_password', 'no'); } + /** * @medium * @depends testCreateShare @@ -127,7 +187,7 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { $this->assertTrue($result->succeeded()); - // test should return two shares created from testCreateShare() + // test should return two shares created from testCreateShare() $this->assertTrue(count($result->getData()) === 1); \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, @@ -154,7 +214,7 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { $this->assertTrue($result->succeeded()); - // test should return one share created from testCreateShare() + // test should return one share created from testCreateShare() $this->assertTrue(count($result->getData()) === 2); \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, @@ -281,7 +341,7 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { $this->assertTrue($result->succeeded()); - // test should return one share within $this->folder + // test should return one share within $this->folder $this->assertTrue(count($result->getData()) === 1); \OCP\Share::unshare('file', $fileInfo1['fileid'], \OCP\Share::SHARE_TYPE_USER, @@ -292,7 +352,7 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { } /** - * @brief share a folder, than reshare a file within the shared folder and check if we construct the correct path + * share a folder, than reshare a file within the shared folder and check if we construct the correct path * @medium */ function testGetShareFromFolderReshares() { @@ -357,7 +417,7 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { } /** - * @brief reshare a sub folder and check if we get the correct path + * reshare a sub folder and check if we get the correct path * @medium */ function testGetShareFromSubFolderReShares() { @@ -410,7 +470,7 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { } /** - * @brief test re-re-share of folder if the path gets constructed correctly + * test re-re-share of folder if the path gets constructed correctly * @medium */ function testGetShareFromFolderReReShares() { @@ -478,7 +538,7 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { } /** - * @brief test multiple shared folder if the path gets constructed correctly + * test multiple shared folder if the path gets constructed correctly * @medium */ function testGetShareMultipleSharedFolder() { @@ -561,7 +621,7 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { } /** - * @brief test re-re-share of folder if the path gets constructed correctly + * test re-re-share of folder if the path gets constructed correctly * @medium */ function testGetShareFromFileReReShares() { @@ -638,7 +698,7 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { $result = Share\Api::getShare($params); $this->assertEquals(404, $result->getStatusCode()); - $meta = $result->getMeta(); + $meta = $result->getMeta(); $this->assertEquals('share doesn\'t exist', $meta['message']); } @@ -695,7 +755,7 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { $result = Share\Api::updateShare($params); - $meta = $result->getMeta(); + $meta = $result->getMeta(); $this->assertTrue($result->succeeded(), $meta['message']); $items = \OCP\Share::getItemShared('file', $userShare['file_source']); @@ -835,7 +895,7 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { } /** - * @brief test unshare of a reshared file + * test unshare of a reshared file */ function testDeleteReshare() { @@ -879,7 +939,7 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { } /** - * @brief share a folder which contains a share mount point, should be forbidden + * share a folder which contains a share mount point, should be forbidden */ public function testShareFolderWithAMountPoint() { // user 1 shares a folder with user2 @@ -929,6 +989,54 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { } /** + * Post init mount points hook for mounting simulated ext storage + */ + public static function initTestMountPointsHook($data) { + if ($data['user'] === \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1) { + \OC\Files\Filesystem::mount(self::$tempStorage, array(), '/' . \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1 . '/files' . self::TEST_FOLDER_NAME); + } + } + + /** + * Tests mounting a folder that is an external storage mount point. + */ + public function testShareStorageMountPoint() { + self::$tempStorage = new \OC\Files\Storage\Temporary(array()); + self::$tempStorage->file_put_contents('test.txt', 'abcdef'); + self::$tempStorage->getScanner()->scan(''); + + // needed because the sharing code sometimes switches the user internally and mounts the user's + // storages. In our case the temp storage isn't mounted automatically, so doing it in the post hook + // (similar to how ext storage works) + OCP\Util::connectHook('OC_Filesystem', 'post_initMountPoints', '\Test_Files_Sharing_Api', 'initTestMountPointsHook'); + + // logging in will auto-mount the temp storage for user1 as well + \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1); + + $fileInfo = $this->view->getFileInfo($this->folder); + + // user 1 shares the mount point folder with user2 + $result = \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, + \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31); + + $this->assertTrue($result); + + // user2: check that mount point name appears correctly + \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2); + + $view = new \OC\Files\View('/' . \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2 . '/files'); + + $this->assertTrue($view->file_exists($this->folder)); + $this->assertTrue($view->file_exists($this->folder . '/test.txt')); + + \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1); + + \OCP\Share::unshare('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, + \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2); + + \OC_Hook::clear('OC_Filesystem', 'post_initMountPoints', '\Test_Files_Sharing_Api', 'initTestMountPointsHook'); + } + /** * @expectedException \Exception */ public function testShareNonExisting() { @@ -951,4 +1059,57 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_LINK, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31); } + public function testDefaultExpireDate() { + \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1); + \OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'yes'); + \OC_Appconfig::setValue('core', 'shareapi_enforce_expire_date', 'yes'); + \OC_Appconfig::setValue('core', 'shareapi_expire_after_n_days', '2'); + + // default expire date is set to 2 days + // the time when the share was created is set to 3 days in the past + // user defined expire date is set to +2 days from now on + // -> link should be already expired by the default expire date but the user + // share should still exists. + $now = time(); + $dateFormat = 'Y-m-d H:i:s'; + $shareCreated = $now - 3 * 24 * 60 * 60; + $expireDate = date($dateFormat, $now + 2 * 24 * 60 * 60); + + $info = OC\Files\Filesystem::getFileInfo($this->filename); + $this->assertTrue($info instanceof \OC\Files\FileInfo); + + $result = \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_LINK, null, \OCP\PERMISSION_READ); + $this->assertTrue(is_string($result)); + + $result = \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31); + $this->assertTrue($result); + + $result = \OCP\Share::setExpirationDate('file', $info->getId() , $expireDate); + $this->assertTrue($result); + + //manipulate stime so that both shares are older then the default expire date + $statement = "UPDATE `*PREFIX*share` SET `stime` = ? WHERE `share_type` = ?"; + $query = \OCP\DB::prepare($statement); + $result = $query->execute(array($shareCreated, \OCP\Share::SHARE_TYPE_LINK)); + $this->assertSame(1, $result); + $statement = "UPDATE `*PREFIX*share` SET `stime` = ? WHERE `share_type` = ?"; + $query = \OCP\DB::prepare($statement); + $result = $query->execute(array($shareCreated, \OCP\Share::SHARE_TYPE_USER)); + $this->assertSame(1, $result); + + // now the link share should expire because of enforced default expire date + // the user share should still exist + $result = \OCP\Share::getItemShared('file', $info->getId()); + $this->assertTrue(is_array($result)); + $this->assertSame(1, count($result)); + $share = reset($result); + $this->assertSame(\OCP\Share::SHARE_TYPE_USER, $share['share_type']); + + //cleanup + $result = \OCP\Share::unshare('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2); + $this->assertTrue($result); + \OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'no'); + \OC_Appconfig::setValue('core', 'shareapi_enforce_expire_date', 'no'); + + } } diff --git a/apps/files_sharing/tests/base.php b/apps/files_sharing/tests/base.php index 495dca072c7..7cd36b9d419 100644 --- a/apps/files_sharing/tests/base.php +++ b/apps/files_sharing/tests/base.php @@ -39,7 +39,7 @@ abstract class Test_Files_Sharing_Base extends \PHPUnit_Framework_TestCase { public $filename; public $data; /** - * @var OC_FilesystemView + * @var OC\Files\View */ public $view; public $folder; @@ -68,7 +68,7 @@ abstract class Test_Files_Sharing_Base extends \PHPUnit_Framework_TestCase { self::loginHelper(self::TEST_FILES_SHARING_API_USER1); $this->data = 'foobar'; - $this->view = new \OC_FilesystemView('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); + $this->view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); // remember files_encryption state $this->stateFilesEncryption = \OC_App::isEnabled('files_encryption'); @@ -97,7 +97,7 @@ abstract class Test_Files_Sharing_Base extends \PHPUnit_Framework_TestCase { } /** - * @param $user + * @param string $user * @param bool $create * @param bool $password */ @@ -119,7 +119,7 @@ abstract class Test_Files_Sharing_Base extends \PHPUnit_Framework_TestCase { } /** - * @brief get some information from a given share + * get some information from a given share * @param int $shareID * @return array with: item_source, share_type, share_with, item_type, permissions */ diff --git a/apps/files_sharing/tests/cache.php b/apps/files_sharing/tests/cache.php index 1af73c558d5..c5408ba55e7 100644 --- a/apps/files_sharing/tests/cache.php +++ b/apps/files_sharing/tests/cache.php @@ -25,7 +25,7 @@ require_once __DIR__ . '/base.php'; class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base { /** - * @var OC_FilesystemView + * @var OC\Files\View */ public $user2View; @@ -230,7 +230,7 @@ class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base { } /** - * @brief verify if each value from the result matches the expected result + * verify if each value from the result matches the expected result * @param array $example array with the expected results * @param array $result array with the results */ |