diff options
author | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-08-07 15:20:57 -0400 |
---|---|---|
committer | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-08-07 15:20:57 -0400 |
commit | 5d521d7c7c8f8e796a3ddc81e1e4430238ba5451 (patch) | |
tree | 4a6cac924a71eed163e481823b29a8614abbf21c | |
parent | fbdd65bf7b4cb5572e38099a840d48a9644f52e3 (diff) | |
download | nextcloud-server-5d521d7c7c8f8e796a3ddc81e1e4430238ba5451.tar.gz nextcloud-server-5d521d7c7c8f8e796a3ddc81e1e4430238ba5451.zip |
Sharing dropdown changes: show users that have a parent folder shared with them and add the ability to change permissions
-rw-r--r-- | apps/files_publiclink/lib_public.php | 4 | ||||
-rw-r--r-- | apps/files_sharing/ajax/getitem.php | 17 | ||||
-rw-r--r-- | apps/files_sharing/ajax/setpermissions.php | 12 | ||||
-rw-r--r-- | apps/files_sharing/js/share.js | 68 |
4 files changed, 78 insertions, 23 deletions
diff --git a/apps/files_publiclink/lib_public.php b/apps/files_publiclink/lib_public.php index 21286fe4ff2..0ecf909720e 100644 --- a/apps/files_publiclink/lib_public.php +++ b/apps/files_publiclink/lib_public.php @@ -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']; + } } /** diff --git a/apps/files_sharing/ajax/getitem.php b/apps/files_sharing/ajax/getitem.php index 580b6ca5585..3a3be404a30 100644 --- a/apps/files_sharing/ajax/getitem.php +++ b/apps/files_sharing/ajax/getitem.php @@ -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); + ?>
\ No newline at end of file diff --git a/apps/files_sharing/ajax/setpermissions.php b/apps/files_sharing/ajax/setpermissions.php new file mode 100644 index 00000000000..8e0bac0b06f --- /dev/null +++ b/apps/files_sharing/ajax/setpermissions.php @@ -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); + +?>
\ No newline at end of file diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index 5538073d0fb..0b97010c4f1 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -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(); - }); } |