summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2012-08-20 20:00:29 -0400
committerMichael Gapczynski <mtgap@owncloud.com>2012-08-20 21:22:22 -0400
commit09e851a9c4751db6225130bdb6290e65308f8c76 (patch)
treebac3ec01003c49a65b3a8ce7b8bf06e1a11317d7
parent49229da0e12ed950288ca5c44bbaf4e7b85e3542 (diff)
downloadnextcloud-server-09e851a9c4751db6225130bdb6290e65308f8c76.tar.gz
nextcloud-server-09e851a9c4751db6225130bdb6290e65308f8c76.zip
Fix share ajax calls to use itemName/itemSource, show who shared a file with you
-rw-r--r--core/ajax/share.php22
-rw-r--r--core/js/share.js68
-rw-r--r--lib/public/share.php2
3 files changed, 53 insertions, 39 deletions
diff --git a/core/ajax/share.php b/core/ajax/share.php
index 4ff12af9eb9..9376f18e8ad 100644
--- a/core/ajax/share.php
+++ b/core/ajax/share.php
@@ -21,12 +21,12 @@
require_once '../../lib/base.php';
OC_JSON::checkLoggedIn();
-if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['item'])) {
+if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSource'])) {
switch ($_POST['action']) {
case 'share':
- if (isset($_POST['shareType']) && isset($_POST['shareWith']) && isset($_POST['permissions'])) {
+ if (isset($_POST['itemName']) && isset($_POST['shareType']) && isset($_POST['shareWith']) && isset($_POST['permissions'])) {
try {
- OCP\Share::shareItem($_POST['itemType'], $_POST['item'], $_POST['item'], (int)$_POST['shareType'], $_POST['shareWith'], $_POST['permissions']);
+ OCP\Share::shareItem($_POST['itemType'], $_POST['itemName'], $_POST['itemSource'], (int)$_POST['shareType'], $_POST['shareWith'], $_POST['permissions']);
// TODO May need to return private link
OC_JSON::success();
} catch (Exception $exception) {
@@ -36,13 +36,13 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['item']
break;
case 'unshare':
if (isset($_POST['shareType']) && isset($_POST['shareWith'])) {
- $return = OCP\Share::unshare($_POST['itemType'], $_POST['item'], $_POST['shareType'], $_POST['shareWith']);
+ $return = OCP\Share::unshare($_POST['itemType'], $_POST['itemSource'], $_POST['shareType'], $_POST['shareWith']);
($return) ? OC_JSON::success() : OC_JSON::error();
}
break;
case 'setPermissions':
if (isset($_POST['shareType']) && isset($_POST['shareWith']) && isset($_POST['permissions'])) {
- $return = OCP\Share::setPermissions($_POST['itemType'], $_POST['item'], $_POST['shareType'], $_POST['shareWith'], $_POST['permissions']);
+ $return = OCP\Share::setPermissions($_POST['itemType'], $_POST['itemSource'], $_POST['shareType'], $_POST['shareWith'], $_POST['permissions']);
($return) ? OC_JSON::success() : OC_JSON::error();
}
break;
@@ -56,10 +56,14 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['item']
}
break;
case 'getItem':
- // TODO Check if the item was shared to the current user
- if (isset($_GET['itemType']) && isset($_GET['item'])) {
- $return = OCP\Share::getItemShared($_GET['itemType'], $_GET['item']);
- ($return) ? OC_JSON::success(array('data' => $return)) : OC_JSON::error();
+ if (isset($_GET['itemType']) && isset($_GET['itemName']) && isset($_GET['itemSource'])) {
+ $reshare = OCP\Share::getItemSharedWith($_GET['itemType'], $_GET['itemName'], OCP\Share::FORMAT_NONE, null, true);
+ if ($_GET['itemSource'] !== false) {
+ $shares = OCP\Share::getItemShared($_GET['itemType'], $_GET['itemSource']);
+ } else {
+ $shares = false;
+ }
+ OC_JSON::success(array('data' => array('reshare' => $reshare, 'shares' => $shares)));
}
break;
case 'getShareWith':
diff --git a/core/js/share.js b/core/js/share.js
index bd145eab41c..418d18f86b7 100644
--- a/core/js/share.js
+++ b/core/js/share.js
@@ -30,21 +30,22 @@ OC.Share={
}
});
},
- loadItem:function(itemType, item) {
+ loadItem:function(itemType, itemName, itemSource) {
var data = '';
- if (typeof OC.Share.statuses[item] !== 'undefined') {
- $.ajax({type: 'GET', url: OC.filePath('core', 'ajax', 'share.php'), data: { fetch: 'getItem', itemType: itemType, item: item }, async: false, success: function(result) {
- if (result && result.status === 'success') {
- data = result.data;
- } else {
- data = false;
- }
- }});
+ if (typeof OC.Share.statuses[itemName] === 'undefined') {
+ itemSource = false;
}
+ $.ajax({type: 'GET', url: OC.filePath('core', 'ajax', 'share.php'), data: { fetch: 'getItem', itemType: itemType, itemName: itemName, itemSource: itemSource }, async: false, success: function(result) {
+ if (result && result.status === 'success') {
+ data = result.data;
+ } else {
+ data = false;
+ }
+ }});
return data;
},
- share:function(itemType, item, shareType, shareWith, permissions, callback) {
- $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'share', itemType: itemType, item: item, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) {
+ share:function(itemType, itemName, itemSource, shareType, shareWith, permissions, callback) {
+ $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'share', itemType: itemType, itemName: itemName, itemSource: itemSource, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) {
if (result && result.status === 'success') {
if (callback) {
callback(result.data);
@@ -54,8 +55,8 @@ OC.Share={
}
});
},
- unshare:function(itemType, item, shareType, shareWith, callback) {
- $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'unshare', itemType: itemType, item: item, shareType: shareType, shareWith: shareWith }, function(result) {
+ unshare:function(itemType, itemSource, shareType, shareWith, callback) {
+ $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'unshare', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith }, function(result) {
if (result && result.status === 'success') {
if (callback) {
callback();
@@ -65,15 +66,24 @@ OC.Share={
}
});
},
- setPermissions:function(itemType, item, shareType, shareWith, permissions) {
- $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setPermissions', itemType: itemType, item: item, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) {
+ setPermissions:function(itemType, itemSource, shareType, shareWith, permissions) {
+ $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setPermissions', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) {
if (!result || result.status !== 'success') {
OC.dialogs.alert('Error', 'Error while changing permissions');
}
});
},
- showDropDown:function(itemType, item, appendTo, privateLink, possiblePermissions) {
- var html = '<div id="dropdown" class="drop" data-item-type="'+itemType+'" data-item="'+item+'">';
+ showDropDown:function(itemType, itemName, itemSource, appendTo, privateLink, possiblePermissions) {
+ var data = OC.Share.loadItem(itemType, itemName, itemSource);
+ var html = '<div id="dropdown" class="drop" data-item-type="'+itemType+'" data-item-name="'+itemName+'" data-item-source="'+itemSource+'">';
+ if (data.reshare) {
+ if (data.reshare.share_type == OC.Share.SHARE_TYPE_GROUP) {
+ html += 'Shared with you and the group '+data.reshare.share_with+' by '+data.reshare.uid_owner;
+ } else {
+ html += 'Shared with you by '+data.reshare.uid_owner;
+ }
+ html += '<br />';
+ }
html += '<input id="shareWith" type="text" placeholder="Share with" style="width:90%;"/>';
html += '<ul id="shareWithList">';
html += '</ul>';
@@ -88,9 +98,8 @@ OC.Share={
$(html).appendTo(appendTo);
// Reset item shares
OC.Share.itemShares = [];
- var data = OC.Share.loadItem(itemType, item);
- if (data) {
- $.each(data, function(index, share) {
+ if (data.shares) {
+ $.each(data.shares, function(index, share) {
if (share.share_type == OC.Share.SHARE_TYPE_PRIVATE_LINK) {
OC.Share.showPrivateLink(item, share.share_with);
} else {
@@ -127,7 +136,7 @@ OC.Share={
$(this).val(shareWith);
// Default permissions are Read and Share
var permissions = OC.Share.PERMISSION_READ | OC.Share.PERMISSION_SHARE;
- OC.Share.share($('#dropdown').data('item-type'), $('#dropdown').data('item'), shareType, shareWith, permissions, function() {
+ OC.Share.share($('#dropdown').data('item-type'), $('#dropdown').data('item-name'), $('#dropdown').data('item-source'), shareType, shareWith, permissions, function() {
OC.Share.addShareWith(shareType, shareWith, permissions, possiblePermissions);
$('#shareWith').val('');
});
@@ -242,9 +251,10 @@ $(document).ready(function() {
$('a.share').live('click', function(event) {
event.stopPropagation();
- if ($(this).data('item-type') !== undefined && $(this).data('item') !== undefined) {
+ if ($(this).data('item-type') !== undefined && $(this).data('item-name') !== undefined && $(this).data('item-source') !== undefined) {
var itemType = $(this).data('item-type');
- var item = $(this).data('item');
+ var itemName = $(this).data('item-name');
+ var itemSource = $(this).data('item-source');
var appendTo = $(this).parent().parent();
var privateLink = false;
var possiblePermissions = $(this).data('possible-permissions');
@@ -254,13 +264,13 @@ $(document).ready(function() {
if (OC.Share.droppedDown) {
if (item != $('#dropdown').data('item')) {
OC.Share.hideDropDown(function () {
- OC.Share.showDropDown(itemType, item, appendTo, privateLink, possiblePermissions);
+ OC.Share.showDropDown(itemType, itemName, itemSource, appendTo, privateLink, possiblePermissions);
});
} else {
OC.Share.hideDropDown();
}
} else {
- OC.Share.showDropDown(itemType, item, appendTo, privateLink, possiblePermissions);
+ OC.Share.showDropDown(itemType, itemName, itemSource, appendTo, privateLink, possiblePermissions);
}
}
});
@@ -306,14 +316,14 @@ $(document).ready(function() {
if (item != $('#dropdown').data('item')) {
OC.Share.hideDropDown(function () {
$('tr').filterAttr('data-file', filename).addClass('mouseOver');
- OC.Share.showDropDown(itemType, item, appendTo, true, possiblePermissions);
+ OC.Share.showDropDown(itemType, '/'+filename, item, appendTo, true, possiblePermissions);
});
} else {
OC.Share.hideDropDown();
}
} else {
$('tr').filterAttr('data-file',filename).addClass('mouseOver');
- OC.Share.showDropDown(itemType, item, appendTo, true, possiblePermissions);
+ OC.Share.showDropDown(itemType, '/'+filename, item, appendTo, true, possiblePermissions);
}
});
}
@@ -350,7 +360,7 @@ $(document).ready(function() {
var li = $(this).parent();
var shareType = $(li).data('share-type');
var shareWith = $(li).data('share-with');
- OC.Share.unshare($('#dropdown').data('item-type'), $('#dropdown').data('item'), shareType, shareWith, function() {
+ OC.Share.unshare($('#dropdown').data('item-type'), $('#dropdown').data('item-source'), shareType, shareWith, function() {
$(li).remove();
var index = OC.Share.itemShares[shareType].indexOf(shareWith);
OC.Share.itemShares[shareType].splice(index, 1);
@@ -381,7 +391,7 @@ $(document).ready(function() {
$(checkboxes).filter(':not(input[name="edit"])').filter(':checked').each(function(index, checkbox) {
permissions |= $(checkbox).data('permissions');
});
- OC.Share.setPermissions($('#dropdown').data('item-type'), $('#dropdown').data('item'), $(li).data('share-type'), $(li).data('share-with'), permissions);
+ OC.Share.setPermissions($('#dropdown').data('item-type'), $('#dropdown').data('item-source'), $(li).data('share-type'), $(li).data('share-with'), permissions);
});
$('#privateLinkCheckbox').live('change', function() {
diff --git a/lib/public/share.php b/lib/public/share.php
index c57016fb984..6d4749b1ac9 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -520,7 +520,7 @@ class Share {
if (($itemType == 'file' || $itemType == 'folder') && $format == \OC_Share_Backend_File::FORMAT_FILE_APP || $format == \OC_Share_Backend_File::FORMAT_FILE_APP_ROOT) {
$select = '*PREFIX*share.id, item_type, *PREFIX*share.parent, share_type, share_with, permissions, file_target, *PREFIX*fscache.id, path as file_source, name, ctime, mtime, mimetype, size, encrypted, versioned, writable';
} else {
- $select = '*PREFIX*share.id, item_type, item_source, item_target, *PREFIX*share.parent, share_type, share_with, permissions, stime, path as file_source, file_target';
+ $select = '*PREFIX*share.id, item_type, item_source, item_target, *PREFIX*share.parent, share_type, share_with, uid_owner, permissions, stime, path as file_source, file_target';
}
} else {
$select = '*';