Sharing dropdown changes: show users that have a parent folder shared with them and add the ability to change permissions
This commit is contained in:
parent
fbdd65bf7b
commit
5d521d7c7c
4 changed files with 78 additions and 23 deletions
|
@ -57,7 +57,9 @@ class OC_PublicLink{
|
|||
public static function getLink($path) {
|
||||
$query=OC_DB::prepare("SELECT token FROM *PREFIX*publiclink WHERE user=? AND path=? LIMIT 1");
|
||||
$result=$query->execute(array(OC_User::getUser(),$path))->fetchAll();
|
||||
return $result[0]['token'];
|
||||
if(count($result)>0){
|
||||
return $result[0]['token'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,6 +4,19 @@ $RUNTIME_NOAPPS = true;
|
|||
require_once('../../../lib/base.php');
|
||||
require_once('../lib_share.php');
|
||||
|
||||
$source = "/".OC_User::getUser()."/files".$_GET['source'];
|
||||
echo json_encode(OC_Share::getMySharedItem($source));
|
||||
$userDirectory = "/".OC_User::getUser()."/files";
|
||||
$source = $userDirectory.$_GET['source'];
|
||||
$users = OC_Share::getMySharedItem($source);
|
||||
$source = dirname($source);
|
||||
while ($source != "" && $source != "/" && $source != "." && $source != $userDirectory) {
|
||||
$parentUsers = array();
|
||||
$values = array_values(OC_Share::getMySharedItem($source));
|
||||
for ($i = 0; $i < count($values); $i++) {
|
||||
$parentUsers[basename($source)."-".$i] = $values[$i];
|
||||
}
|
||||
$users = array_merge($users, $parentUsers);
|
||||
$source = dirname($source);
|
||||
}
|
||||
echo json_encode($users);
|
||||
|
||||
?>
|
12
apps/files_sharing/ajax/setpermissions.php
Normal file
12
apps/files_sharing/ajax/setpermissions.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
$RUNTIME_NOAPPS = true;
|
||||
|
||||
require_once('../../../lib/base.php');
|
||||
require_once('../lib_share.php');
|
||||
|
||||
$source = "/".OC_User::getUser()."/files".$_GET['source'];
|
||||
$uid_shared_with = $_GET['uid_shared_with'];
|
||||
$permissions = $_GET['permissions'];
|
||||
OC_Share::setPermissions($source, $uid_shared_with, $permissions);
|
||||
|
||||
?>
|
|
@ -1,10 +1,12 @@
|
|||
$(document).ready(function() {
|
||||
$(this).click(function() {
|
||||
if ($('#dropdown').is(':visible')) {
|
||||
$('#dropdown').hide('blind', function() {
|
||||
$('#dropdown').remove();
|
||||
$('tr').removeClass('mouseOver');
|
||||
});
|
||||
$(this).click(function(event) {
|
||||
if ($(event.target).parents().index($('#dropdown')) == -1) {
|
||||
if ($('#dropdown').is(':visible')) {
|
||||
$('#dropdown').hide('blind', function() {
|
||||
$('#dropdown').remove();
|
||||
$('tr').removeClass('mouseOver');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
FileActions.register('all', 'Share', OC.imagePath('core', 'actions/share'), function(filename) {
|
||||
|
@ -35,13 +37,29 @@ $(document).ready(function() {
|
|||
});
|
||||
});
|
||||
$('.permissions').live('change', function() {
|
||||
// TODO Modify item ajax call
|
||||
var permissions;
|
||||
if (this.checked) {
|
||||
permissions = 1;
|
||||
} else {
|
||||
permissions = 0;
|
||||
}
|
||||
var source = $('#dropdown').data('file');
|
||||
var uid_shared_with = $(this).parent().data('uid_shared_with');
|
||||
var data = 'source='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with)+'&permissions='+encodeURIComponent(permissions);
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: OC.linkTo('files_sharing','ajax/setpermissions.php'),
|
||||
cache: false,
|
||||
data: data
|
||||
});
|
||||
});
|
||||
$('.unshare').live('click', function(event) {
|
||||
// TODO Fix unshare
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
var source = $('#dropdown').data('file');
|
||||
var uid_shared_with = $(this).data('uid_shared_with');
|
||||
var data='source='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with);
|
||||
var uid_shared_with = $(this).parent().data('uid_shared_with');
|
||||
var data = 'source='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with);
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: OC.linkTo('files_sharing','ajax/unshare.php'),
|
||||
|
@ -84,13 +102,16 @@ $(document).ready(function() {
|
|||
});
|
||||
}
|
||||
});
|
||||
$('#link').live('click', function() {
|
||||
$(this).focus();
|
||||
$(this).select();
|
||||
});
|
||||
});
|
||||
|
||||
function createShareDropdown(filenames, files) {
|
||||
var html = "<div id='dropdown' data-file='"+files+"'>";
|
||||
html += "<div id='private'>";
|
||||
html += "<input placeholder='User or Group' id='uid_shared_with' />";
|
||||
html += "<input type='checkbox' name='permissions' id='permissions' value='1' /><label for='permissions'>can edit</label>";
|
||||
html += "<div id='shared_list'></div>";
|
||||
html += "</div>";
|
||||
html += "<div id='public'>";
|
||||
|
@ -105,13 +126,23 @@ function createShareDropdown(filenames, files) {
|
|||
if (users) {
|
||||
var list = "<ul>";
|
||||
$.each(users, function(index, row) {
|
||||
list += "<li>";
|
||||
list += row.uid_shared_with;
|
||||
list += "<input type='checkbox' name='permissions' data-uid_shared_with='"+row.uid_shared_with+"' /><label>can edit</label>";
|
||||
list += "<a href='' title='Unshare' class='unshare' data-uid_shared_with='"+row.uid_shared_with+"'><img src='"+OC.imagePath('core','actions/delete')+"'/></a>";
|
||||
list += "</li>";
|
||||
if (row.permissions > 0) {
|
||||
$('share_private_permissions').prop('checked', true);
|
||||
if (typeof(index) == 'string') {
|
||||
// TODO typeof not always working, group together users that have parent folders shared with them
|
||||
list += "<li>disabled";
|
||||
list += index;
|
||||
list += row.uid_shared_with;
|
||||
list += "</li>";
|
||||
} else {
|
||||
list += "<li data-uid_shared_with='"+row.uid_shared_with+"'>";
|
||||
list += row.uid_shared_with;
|
||||
var checked;
|
||||
if (row.permissions > 0) {
|
||||
checked = "checked='checked'";
|
||||
}
|
||||
list += "<input type='checkbox' name='permissions' id='"+index+"' class='permissions' "+checked+" /><label for='"+index+"'>can edit</label>";
|
||||
list += "<a href='' title='Unshare' class='unshare' data-uid_shared_with='"+row.uid_shared_with+"'><img class='svg' src='"+OC.imagePath('core','actions/delete')+"'/></a>";
|
||||
list += "</li>";
|
||||
|
||||
}
|
||||
});
|
||||
list += "</ul>";
|
||||
|
@ -127,7 +158,4 @@ function createShareDropdown(filenames, files) {
|
|||
}
|
||||
});
|
||||
$('#dropdown').show('blind');
|
||||
$('#dropdown').click(function(event) {
|
||||
event.stopPropagation();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue