Reimplement links support for sharing and add password protection option
This commit is contained in:
parent
0ad16e84c5
commit
2aac6f02a0
|
@ -26,8 +26,12 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
|
||||||
case 'share':
|
case 'share':
|
||||||
if (isset($_POST['shareType']) && isset($_POST['shareWith']) && isset($_POST['permissions'])) {
|
if (isset($_POST['shareType']) && isset($_POST['shareWith']) && isset($_POST['permissions'])) {
|
||||||
try {
|
try {
|
||||||
OCP\Share::shareItem($_POST['itemType'], $_POST['itemSource'], (int)$_POST['shareType'], $_POST['shareWith'], $_POST['permissions']);
|
if ((int)$_POST['shareType'] === OCP\Share::SHARE_TYPE_LINK && $_POST['shareWith'] == '') {
|
||||||
// TODO May need to return private link
|
$shareWith = null;
|
||||||
|
} else {
|
||||||
|
$shareWith = $_POST['shareWith'];
|
||||||
|
}
|
||||||
|
OCP\Share::shareItem($_POST['itemType'], $_POST['itemSource'], (int)$_POST['shareType'], $shareWith, $_POST['permissions']);
|
||||||
OC_JSON::success();
|
OC_JSON::success();
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
OC_JSON::error(array('data' => array('message' => $exception->getMessage())));
|
OC_JSON::error(array('data' => array('message' => $exception->getMessage())));
|
||||||
|
@ -36,7 +40,12 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
|
||||||
break;
|
break;
|
||||||
case 'unshare':
|
case 'unshare':
|
||||||
if (isset($_POST['shareType']) && isset($_POST['shareWith'])) {
|
if (isset($_POST['shareType']) && isset($_POST['shareWith'])) {
|
||||||
$return = OCP\Share::unshare($_POST['itemType'], $_POST['itemSource'], $_POST['shareType'], $_POST['shareWith']);
|
if ((int)$_POST['shareType'] === OCP\Share::SHARE_TYPE_LINK && $_POST['shareWith'] == '') {
|
||||||
|
$shareWith = null;
|
||||||
|
} else {
|
||||||
|
$shareWith = $_POST['shareWith'];
|
||||||
|
}
|
||||||
|
$return = OCP\Share::unshare($_POST['itemType'], $_POST['itemSource'], $_POST['shareType'], $shareWith);
|
||||||
($return) ? OC_JSON::success() : OC_JSON::error();
|
($return) ? OC_JSON::success() : OC_JSON::error();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -15,4 +15,4 @@ a.showCruds { display:inline; opacity:.5; }
|
||||||
a.showCruds:hover { opacity:1; }
|
a.showCruds:hover { opacity:1; }
|
||||||
a.unshare { float:right; display:inline; padding:.3em 0 0 .3em !important; opacity:.5; }
|
a.unshare { float:right; display:inline; padding:.3em 0 0 .3em !important; opacity:.5; }
|
||||||
a.unshare:hover { opacity:1; }
|
a.unshare:hover { opacity:1; }
|
||||||
#privateLink { border-top:1px solid #ddd; padding-top:0.5em; }
|
#link { border-top:1px solid #ddd; padding-top:0.5em; }
|
109
core/js/share.js
109
core/js/share.js
|
@ -1,7 +1,7 @@
|
||||||
OC.Share={
|
OC.Share={
|
||||||
SHARE_TYPE_USER:0,
|
SHARE_TYPE_USER:0,
|
||||||
SHARE_TYPE_GROUP:1,
|
SHARE_TYPE_GROUP:1,
|
||||||
SHARE_TYPE_PRIVATE_LINK:3,
|
SHARE_TYPE_LINK:3,
|
||||||
SHARE_TYPE_EMAIL:4,
|
SHARE_TYPE_EMAIL:4,
|
||||||
PERMISSION_CREATE:4,
|
PERMISSION_CREATE:4,
|
||||||
PERMISSION_READ:1,
|
PERMISSION_READ:1,
|
||||||
|
@ -118,7 +118,7 @@ OC.Share={
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
showDropDown:function(itemType, itemSource, appendTo, privateLink, possiblePermissions) {
|
showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions) {
|
||||||
var data = OC.Share.loadItem(itemType, itemSource);
|
var data = OC.Share.loadItem(itemType, itemSource);
|
||||||
var html = '<div id="dropdown" class="drop" data-item-type="'+itemType+'" data-item-source="'+itemSource+'">';
|
var html = '<div id="dropdown" class="drop" data-item-type="'+itemType+'" data-item-source="'+itemSource+'">';
|
||||||
if (data.reshare) {
|
if (data.reshare) {
|
||||||
|
@ -133,11 +133,14 @@ OC.Share={
|
||||||
html += '<input id="shareWith" type="text" placeholder="Share with" style="width:90%;"/>';
|
html += '<input id="shareWith" type="text" placeholder="Share with" style="width:90%;"/>';
|
||||||
html += '<ul id="shareWithList">';
|
html += '<ul id="shareWithList">';
|
||||||
html += '</ul>';
|
html += '</ul>';
|
||||||
if (privateLink) {
|
if (link) {
|
||||||
html += '<div id="privateLink">';
|
html += '<div id="link">';
|
||||||
html += '<input type="checkbox" name="privateLinkCheckbox" id="privateLinkCheckbox" value="1" /><label for="privateLinkCheckbox">Share with private link</label>';
|
html += '<input type="checkbox" name="linkCheckbox" id="linkCheckbox" value="1" /><label for="linkCheckbox">Share with link</label>';
|
||||||
|
// TODO Change to lock/unlock icon?
|
||||||
|
html += '<a href="#" id="showPassword" style="display:none;"><img class="svg" alt="Password protect" src="'+OC.imagePath('core', 'actions/triangle-n')+'"/></a>';
|
||||||
html += '<br />';
|
html += '<br />';
|
||||||
html += '<input id="privateLinkText" style="display:none; width:90%;" readonly="readonly" />';
|
html += '<input id="linkText" style="display:none; width:90%;" readonly="readonly" />';
|
||||||
|
html += '<input id="linkPassText" type="password" placeholder="Password" style="display:none; width:90%;" />';
|
||||||
html += '</div>';
|
html += '</div>';
|
||||||
}
|
}
|
||||||
html += '</div>';
|
html += '</div>';
|
||||||
|
@ -146,8 +149,8 @@ OC.Share={
|
||||||
OC.Share.itemShares = [];
|
OC.Share.itemShares = [];
|
||||||
if (data.shares) {
|
if (data.shares) {
|
||||||
$.each(data.shares, function(index, share) {
|
$.each(data.shares, function(index, share) {
|
||||||
if (share.share_type == OC.Share.SHARE_TYPE_PRIVATE_LINK) {
|
if (share.share_type == OC.Share.SHARE_TYPE_LINK) {
|
||||||
OC.Share.showPrivateLink(item, share.share_with);
|
OC.Share.showLink(itemSource, share.share_with);
|
||||||
} else {
|
} else {
|
||||||
OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions);
|
OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions);
|
||||||
}
|
}
|
||||||
|
@ -264,36 +267,22 @@ OC.Share={
|
||||||
$(html).appendTo('#shareWithList');
|
$(html).appendTo('#shareWithList');
|
||||||
|
|
||||||
},
|
},
|
||||||
showPrivateLink:function(item, token) {
|
showLink:function(itemSource, password) {
|
||||||
$('#privateLinkCheckbox').attr('checked', true);
|
$('#linkCheckbox').attr('checked', true);
|
||||||
var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&token='+token;
|
var filename = $('tr').filterAttr('data-id', String(itemSource)).data('file');
|
||||||
if (token.indexOf('&path=') == -1) {
|
if ($('#dir').val() == '/') {
|
||||||
link += '&file=' + encodeURIComponent(item).replace(/%2F/g, '/');
|
var file = $('#dir').val() + filename;
|
||||||
} else {
|
} else {
|
||||||
// Disable checkbox if inside a shared parent folder
|
var file = $('#dir').val() + '/' + filename;
|
||||||
$('#privateLinkCheckbox').attr('disabled', 'true');
|
|
||||||
}
|
}
|
||||||
$('#privateLinkText').val(link);
|
file = '/'+OC.currentUser+'/files'+file;
|
||||||
$('#privateLinkText').show('blind', function() {
|
var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&file='+file;
|
||||||
$('#privateLinkText').after('<br id="emailBreak" />');
|
$('#linkText').val(link);
|
||||||
$('#email').show();
|
$('#linkText').show('blind');
|
||||||
$('#emailButton').show();
|
$('#showPassword').show();
|
||||||
});
|
|
||||||
},
|
},
|
||||||
hidePrivateLink:function() {
|
hideLink:function() {
|
||||||
$('#privateLinkText').hide('blind');
|
$('#linkText').hide('blind');
|
||||||
$('#emailBreak').remove();
|
|
||||||
$('#email').hide();
|
|
||||||
$('#emailButton').hide();
|
|
||||||
},
|
|
||||||
emailPrivateLink:function() {
|
|
||||||
var link = $('#privateLinkText').val();
|
|
||||||
var file = link.substr(link.lastIndexOf('/') + 1).replace(/%20/g, ' ');
|
|
||||||
$.post(OC.filePath('files_sharing', 'ajax', 'email.php'), { toaddress: $('#email').val(), link: link, file: file } );
|
|
||||||
$('#email').css('font-weight', 'bold');
|
|
||||||
$('#email').animate({ fontWeight: 'normal' }, 2000, function() {
|
|
||||||
$(this).val('');
|
|
||||||
}).val('Email sent');
|
|
||||||
},
|
},
|
||||||
dirname:function(path) {
|
dirname:function(path) {
|
||||||
return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
|
return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
|
||||||
|
@ -308,21 +297,21 @@ $(document).ready(function() {
|
||||||
var itemType = $(this).data('item-type');
|
var itemType = $(this).data('item-type');
|
||||||
var itemSource = $(this).data('item');
|
var itemSource = $(this).data('item');
|
||||||
var appendTo = $(this).parent().parent();
|
var appendTo = $(this).parent().parent();
|
||||||
var privateLink = false;
|
var link = false;
|
||||||
var possiblePermissions = $(this).data('possible-permissions');
|
var possiblePermissions = $(this).data('possible-permissions');
|
||||||
if ($(this).data('private-link') !== undefined && $(this).data('private-link') == true) {
|
if ($(this).data('link') !== undefined && $(this).data('link') == true) {
|
||||||
privateLink = true;
|
link = true;
|
||||||
}
|
}
|
||||||
if (OC.Share.droppedDown) {
|
if (OC.Share.droppedDown) {
|
||||||
if (itemSource != $('#dropdown').data('item')) {
|
if (itemSource != $('#dropdown').data('item')) {
|
||||||
OC.Share.hideDropDown(function () {
|
OC.Share.hideDropDown(function () {
|
||||||
OC.Share.showDropDown(itemType, itemSource, appendTo, privateLink, possiblePermissions);
|
OC.Share.showDropDown(itemType, itemSource, appendTo, link, possiblePermissions);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
OC.Share.hideDropDown();
|
OC.Share.hideDropDown();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
OC.Share.showDropDown(itemType, itemSource, appendTo, privateLink, possiblePermissions);
|
OC.Share.showDropDown(itemType, itemSource, appendTo, link, possiblePermissions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -396,35 +385,43 @@ $(document).ready(function() {
|
||||||
OC.Share.setPermissions($('#dropdown').data('item-type'), $('#dropdown').data('item-source'), $(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() {
|
$('#linkCheckbox').live('change', function() {
|
||||||
var itemType = $('#dropdown').data('item-type');
|
var itemType = $('#dropdown').data('item-type');
|
||||||
var item = $('#dropdown').data('item');
|
var itemSource = $('#dropdown').data('item-source');
|
||||||
if (this.checked) {
|
if (this.checked) {
|
||||||
// Create a private link
|
// Create a link
|
||||||
OC.Share.share(itemType, item, OC.Share.SHARE_TYPE_PRIVATE_LINK, 0, 0, function(token) {
|
OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.Share.PERMISSION_READ, function() {
|
||||||
OC.Share.showPrivateLink(item, 'foo');
|
OC.Share.showLink(itemSource);
|
||||||
// Change icon
|
// TODO Change icon
|
||||||
OC.Share.icons[item] = OC.imagePath('core', 'actions/public');
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Delete private link
|
// Delete private link
|
||||||
OC.Share.unshare(item, 'public', function() {
|
OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', function() {
|
||||||
OC.Share.hidePrivateLink();
|
OC.Share.hideLink();
|
||||||
// Change icon
|
|
||||||
if (OC.Share.itemUsers || OC.Share.itemGroups) {
|
|
||||||
OC.Share.icons[item] = OC.imagePath('core', 'actions/shared');
|
|
||||||
} else {
|
|
||||||
OC.Share.icons[item] = OC.imagePath('core', 'actions/share');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#privateLinkText').live('click', function() {
|
$('#linkText').live('click', function() {
|
||||||
$(this).focus();
|
$(this).focus();
|
||||||
$(this).select();
|
$(this).select();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#showPassword').live('click', function() {
|
||||||
|
$('#linkText').after('<br />');
|
||||||
|
$('#linkPassText').toggle('blind');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#linkPassText').live('keyup', function(event) {
|
||||||
|
if (event.keyCode == 13) {
|
||||||
|
var itemType = $('#dropdown').data('item-type');
|
||||||
|
var itemSource = $('#dropdown').data('item-source');
|
||||||
|
// TODO Do this internally
|
||||||
|
OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '');
|
||||||
|
OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $(this).val(), OC.Share.PERMISSION_READ);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$('#emailPrivateLink').live('submit', function() {
|
$('#emailPrivateLink').live('submit', function() {
|
||||||
OC.Share.emailPrivateLink();
|
OC.Share.emailPrivateLink();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue