diff options
author | Jörn Friedrich Dreyer <jfd@butonic.de> | 2012-11-26 07:42:53 -0800 |
---|---|---|
committer | Jörn Friedrich Dreyer <jfd@butonic.de> | 2012-11-26 07:42:53 -0800 |
commit | 71e8755d318eb9a415b15f5775506ecf8a8d134f (patch) | |
tree | a9778edb2956902e8211b7f556ebb6f468e39fd5 /core | |
parent | 588bbd2c9f36761a8bf6f0b736d3042940c6fa18 (diff) | |
parent | 995b5c073922afd5d4fae00cad7e1bfc87c0ac73 (diff) | |
download | nextcloud-server-71e8755d318eb9a415b15f5775506ecf8a8d134f.tar.gz nextcloud-server-71e8755d318eb9a415b15f5775506ecf8a8d134f.zip |
Merge pull request #380 from butonic/feature_share_link_with_token
Feature share link with token
Diffstat (limited to 'core')
-rw-r--r-- | core/ajax/share.php | 14 | ||||
-rw-r--r-- | core/js/share.js | 28 |
2 files changed, 27 insertions, 15 deletions
diff --git a/core/ajax/share.php b/core/ajax/share.php index efe01dff886..41832a3c659 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -28,13 +28,19 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo case 'share': if (isset($_POST['shareType']) && isset($_POST['shareWith']) && isset($_POST['permissions'])) { try { - if ((int)$_POST['shareType'] === OCP\Share::SHARE_TYPE_LINK && $_POST['shareWith'] == '') { + $shareType = (int)$_POST['shareType']; + $shareWith = $_POST['shareWith']; + if ($shareType === OCP\Share::SHARE_TYPE_LINK && $shareWith == '') { $shareWith = null; + } + + $token = OCP\Share::shareItem($_POST['itemType'], $_POST['itemSource'], $shareType, $shareWith, $_POST['permissions']); + + if (is_string($token)) { + OC_JSON::success(array('data' => array('token' => $token))); } else { - $shareWith = $_POST['shareWith']; + OC_JSON::success(); } - OCP\Share::shareItem($_POST['itemType'], $_POST['itemSource'], (int)$_POST['shareType'], $shareWith, $_POST['permissions']); - OC_JSON::success(); } catch (Exception $exception) { OC_JSON::error(array('data' => array('message' => $exception->getMessage()))); } diff --git a/core/js/share.js b/core/js/share.js index 8fcea84af88..0f71ae22419 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -179,7 +179,7 @@ OC.Share={ if (data.shares) { $.each(data.shares, function(index, share) { if (share.share_type == OC.Share.SHARE_TYPE_LINK) { - OC.Share.showLink(itemSource, share.share_with); + OC.Share.showLink(share.token, share.share_with, itemSource); } else { if (share.collection) { OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions, share.collection); @@ -323,18 +323,24 @@ OC.Share={ $('#expiration').show(); } }, - showLink:function(itemSource, password) { + showLink:function(token, password, itemSource) { OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = true; $('#linkCheckbox').attr('checked', true); - var filename = $('tr').filterAttr('data-id', String(itemSource)).data('file'); - var type = $('tr').filterAttr('data-id', String(itemSource)).data('type'); - if ($('#dir').val() == '/') { - var file = $('#dir').val() + filename; + if (! token) { + //fallback to pre token link + var filename = $('tr').filterAttr('data-id', String(itemSource)).data('file'); + var type = $('tr').filterAttr('data-id', String(itemSource)).data('type'); + if ($('#dir').val() == '/') { + var file = $('#dir').val() + filename; + } else { + var file = $('#dir').val() + '/' + filename; + } + file = '/'+OC.currentUser+'/files'+file; + var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&'+type+'='+encodeURIComponent(file); } else { - var file = $('#dir').val() + '/' + filename; + //TODO add path param when showing a link to file in a subfolder of a public link share + var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&t='+token; } - file = '/'+OC.currentUser+'/files'+file; - var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&'+type+'='+encodeURIComponent(file); $('#linkText').val(link); $('#linkText').show('blind'); $('#showPassword').show(); @@ -480,8 +486,8 @@ $(document).ready(function() { var itemSource = $('#dropdown').data('item-source'); if (this.checked) { // Create a link - OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ, function() { - OC.Share.showLink(itemSource); + OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ, function(data) { + OC.Share.showLink(data.token, null, itemSource); OC.Share.updateIcon(itemType, itemSource); }); } else { |