Merge branch 'master' of git://gitorious.org/owncloud/owncloud into oracle-support

This commit is contained in:
Jörn Friedrich Dreyer 2012-08-25 00:06:20 +02:00
commit fd5af9aff4
12 changed files with 215 additions and 149 deletions

View File

@ -45,11 +45,11 @@ class OC_Connector_Sabre_CalDAV_CalendarObject extends Sabre_CalDAV_CalendarObje
$uid = OC_Calendar_Calendar::extractUserID($this->getOwner()); $uid = OC_Calendar_Calendar::extractUserID($this->getOwner());
if($uid != OCP\USER::getUser()) { if($uid != OCP\USER::getUser()) {
$sharedAddressbook = OCP\Share::getItemSharedWithBySource('calendar', $this->$calendarInfo['id']); $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $this->$calendarInfo['id']);
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_READ)) { if ($sharedCalendar && ($sharedCalendar['permissions'] & OCP\Share::PERMISSION_READ)) {
$readprincipal = 'principals/' . OCP\USER::getUser(); $readprincipal = 'principals/' . OCP\USER::getUser();
} }
if ($sharedAddressbook && ($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_UPDATE)) { if ($sharedCalendar && ($sharedCalendar['permissions'] & OCP\Share::PERMISSION_UPDATE)) {
$writeprincipal = 'principals/' . OCP\USER::getUser(); $writeprincipal = 'principals/' . OCP\USER::getUser();
} }
} }

View File

@ -77,6 +77,10 @@ FileActions={
parent.children('a.name').append('<span class="fileactions" />'); parent.children('a.name').append('<span class="fileactions" />');
var defaultAction=FileActions.getDefault(FileActions.getCurrentMimeType(),FileActions.getCurrentType(), FileActions.getCurrentPermissions()); var defaultAction=FileActions.getDefault(FileActions.getCurrentMimeType(),FileActions.getCurrentType(), FileActions.getCurrentPermissions());
for(name in actions){ for(name in actions){
// NOTE: Temporary fix to prevent rename action in root of Shared directory
if (name == 'Rename' && $('#dir').val() == '/Shared') {
continue;
}
if((name=='Download' || actions[name]!=defaultAction) && name!='Delete'){ if((name=='Download' || actions[name]!=defaultAction) && name!='Delete'){
var img=FileActions.icons[name]; var img=FileActions.icons[name];
if(img.call){ if(img.call){

View File

@ -9,7 +9,7 @@
$name = str_replace('%2F','/', $name); $name = str_replace('%2F','/', $name);
$directory = str_replace('+','%20',urlencode($file['directory'])); $directory = str_replace('+','%20',urlencode($file['directory']));
$directory = str_replace('%2F','/', $directory); ?> $directory = str_replace('%2F','/', $directory); ?>
<tr data-file="<?php echo $name;?>" data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>" data-mime="<?php echo $file['mimetype']?>" data-size='<?php echo $file['size'];?>' data-permissions='<?php echo $file['permissions']; ?>'> <tr data-id="<?php echo $file['id']; ?>" data-file="<?php echo $name;?>" data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>" data-mime="<?php echo $file['mimetype']?>" data-size='<?php echo $file['size'];?>' data-permissions='<?php echo $file['permissions']; ?>'>
<td class="filename svg" style="background-image:url(<?php if($file['type'] == 'dir') echo OCP\mimetype_icon('dir'); else echo OCP\mimetype_icon($file['mimetype']); ?>)"> <td class="filename svg" style="background-image:url(<?php if($file['type'] == 'dir') echo OCP\mimetype_icon('dir'); else echo OCP\mimetype_icon($file['mimetype']); ?>)">
<?php if(!isset($_['readonly']) || !$_['readonly']) { ?><input type="checkbox" /><?php } ?> <?php if(!isset($_['readonly']) || !$_['readonly']) { ?><input type="checkbox" /><?php } ?>
<a class="name" href="<?php if($file['type'] == 'dir') echo $_['baseURL'].$directory.'/'.$name; else echo $_['downloadURL'].$directory.'/'.$name; ?>" title=""> <a class="name" href="<?php if($file['type'] == 'dir') echo $_['baseURL'].$directory.'/'.$name; else echo $_['downloadURL'].$directory.'/'.$name; ?>" title="">

View File

@ -2,7 +2,7 @@ $(document).ready(function() {
if (typeof FileActions !== 'undefined') { if (typeof FileActions !== 'undefined') {
OC.Share.loadIcons('file'); OC.Share.loadIcons('file');
FileActions.register('all', 'Share', FileActions.PERMISSION_SHARE, function(filename) { FileActions.register('all', 'Share', FileActions.PERMISSION_READ, function(filename) {
// Return the correct sharing icon // Return the correct sharing icon
if (scanFiles.scanning) { return; } // workaround to prevent additional http request block scanning feedback if (scanFiles.scanning) { return; } // workaround to prevent additional http request block scanning feedback
if ($('#dir').val() == '/') { if ($('#dir').val() == '/') {
@ -36,27 +36,27 @@ $(document).ready(function() {
} else { } else {
var item = $('#dir').val() + '/' + filename; var item = $('#dir').val() + '/' + filename;
} }
if ($('tr').filterAttr('data-file', filename).data('type') == 'dir') { var tr = $('tr').filterAttr('data-file', filename);
if ($(tr).data('type') == 'dir') {
var itemType = 'folder'; var itemType = 'folder';
var possiblePermissions = OC.Share.PERMISSION_CREATE | OC.Share.PERMISSION_UPDATE | OC.Share.PERMISSION_DELETE | OC.Share.PERMISSION_SHARE;
} else { } else {
var itemType = 'file'; var itemType = 'file';
var possiblePermissions = OC.Share.PERMISSION_UPDATE | OC.Share.PERMISSION_DELETE | OC.Share.PERMISSION_SHARE;
} }
var appendTo = $('tr').filterAttr('data-file', filename).find('td.filename'); var possiblePermissions = $(tr).data('permissions');
var appendTo = $(tr).find('td.filename');
// Check if drop down is already visible for a different file // Check if drop down is already visible for a different file
if (OC.Share.droppedDown) { if (OC.Share.droppedDown) {
if (item != $('#dropdown').data('item')) { if (item != $('#dropdown').data('item')) {
OC.Share.hideDropDown(function () { OC.Share.hideDropDown(function () {
$('tr').filterAttr('data-file', filename).addClass('mouseOver'); $(tr).addClass('mouseOver');
OC.Share.showDropDown(itemType, item, appendTo, true, possiblePermissions); OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, true, possiblePermissions);
}); });
} else { } else {
OC.Share.hideDropDown(); OC.Share.hideDropDown();
} }
} else { } else {
$('tr').filterAttr('data-file',filename).addClass('mouseOver'); $(tr).addClass('mouseOver');
OC.Share.showDropDown(itemType, item, appendTo, true, possiblePermissions); OC.Share.showDropDown(itemType, $(tr).data('id'), appendTo, true, possiblePermissions);
} }
}); });
} }

View File

@ -26,30 +26,40 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
const FORMAT_FILE_APP_ROOT = 2; const FORMAT_FILE_APP_ROOT = 2;
const FORMAT_OPENDIR = 3; const FORMAT_OPENDIR = 3;
public function isValidSource($item, $uid) { private $path;
if (OC_Filesystem::file_exists($item)) {
public function isValidSource($itemSource, $uidOwner) {
$path = OC_FileCache::getPath($itemSource, $uidOwner);
if (OC_Filesystem::file_exists($path)) {
$this->path = $path;
return true; return true;
} }
return false; return false;
} }
public function getFilePath($item, $uid) { public function getFilePath($itemSource, $uidOwner) {
return $item; if (isset($this->path)) {
$path = $this->path;
$this->path = null;
return $path;
}
return false;
} }
public function generateTarget($item, $uid, $exclude = null) { public function generateTarget($itemSource, $shareWith, $exclude = null) {
// TODO Make sure target path doesn't exist already // TODO Make sure target path doesn't exist already
return $item; return $itemSource;
} }
public function formatItems($items, $format, $parameters = null) { public function formatItems($items, $format, $parameters = null) {
if ($format == self::FORMAT_SHARED_STORAGE) { if ($format == self::FORMAT_SHARED_STORAGE) {
// Only 1 item should come through for this format call // Only 1 item should come through for this format call
return array('path' => $items[key($items)]['file_source'], 'permissions' => $items[key($items)]['permissions']); return array('path' => $items[key($items)]['path'], 'permissions' => $items[key($items)]['permissions']);
} else if ($format == self::FORMAT_FILE_APP) { } else if ($format == self::FORMAT_FILE_APP) {
$files = array(); $files = array();
foreach ($items as $item) { foreach ($items as $item) {
$file = array(); $file = array();
$file['id'] = $item['file_source'];
$file['path'] = $item['file_target']; $file['path'] = $item['file_target'];
$file['name'] = basename($item['file_target']); $file['name'] = basename($item['file_target']);
$file['ctime'] = $item['ctime']; $file['ctime'] = $item['ctime'];
@ -77,7 +87,7 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
} }
$size += $item['size']; $size += $item['size'];
} }
return array(0 => array('name' => 'Shared', 'mtime' => $mtime, 'mimetype' => 'httpd/unix-directory', 'size' => $size, 'writable' => false, 'type' => 'dir', 'directory' => '', 'permissions' => OCP\Share::PERMISSION_READ)); return array(0 => array('id' => -1, 'name' => 'Shared', 'mtime' => $mtime, 'mimetype' => 'httpd/unix-directory', 'size' => $size, 'writable' => false, 'type' => 'dir', 'directory' => '', 'permissions' => OCP\Share::PERMISSION_READ));
} else if ($format == self::FORMAT_OPENDIR) { } else if ($format == self::FORMAT_OPENDIR) {
$files = array(); $files = array();
foreach ($items as $item) { foreach ($items as $item) {

View File

@ -24,7 +24,7 @@ class OC_Share_Backend_Folder extends OC_Share_Backend_File {
public function formatItems($items, $format, $parameters = null) { public function formatItems($items, $format, $parameters = null) {
if ($format == self::FORMAT_SHARED_STORAGE) { if ($format == self::FORMAT_SHARED_STORAGE) {
// Only 1 item should come through for this format call // Only 1 item should come through for this format call
return array('path' => $items[key($items)]['file_source'], 'permissions' => $items[key($items)]['permissions']); return array('path' => $items[key($items)]['path'], 'permissions' => $items[key($items)]['permissions']);
} else if ($format == self::FORMAT_FILE_APP && isset($parameters['folder'])) { } else if ($format == self::FORMAT_FILE_APP && isset($parameters['folder'])) {
// Only 1 item should come through for this format call // Only 1 item should come through for this format call
$folder = $items[key($items)]; $folder = $items[key($items)];
@ -33,7 +33,7 @@ class OC_Share_Backend_Folder extends OC_Share_Backend_File {
} else { } else {
$mimetype_filter = ''; $mimetype_filter = '';
} }
$path = $folder['file_source'].substr($parameters['folder'], 7 + strlen($folder['file_target'])); $path = $folder['path'].substr($parameters['folder'], 7 + strlen($folder['file_target']));
$files = OC_FileCache::getFolderContent($path, '', $mimetype_filter); $files = OC_FileCache::getFolderContent($path, '', $mimetype_filter);
foreach ($files as &$file) { foreach ($files as &$file) {
$file['directory'] = $parameters['folder']; $file['directory'] = $parameters['folder'];

View File

@ -312,21 +312,32 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
} }
public function rename($path1, $path2) { public function rename($path1, $path2) {
if ($oldSource = $this->getSourcePath($path1)) { // Renaming/moving is only allowed within shared folders
$root1 = substr($path1, 0, strpos($path1, '/')); $pos1 = strpos($path1, '/', 1);
$root2 = substr($path2, 0, strpos($path2, '/')); $pos2 = strpos($path2, '/', 1);
// Moving/renaming is only allowed within the same shared folder if ($pos1 !== false && $pos2 !== false && ($oldSource = $this->getSourcePath($path1))) {
if ($root1 == $root2) { $newSource = $this->getSourcePath(dirname($path2)).'/'.basename($path2);
$storage = OC_Filesystem::getStorage($oldSource); if (dirname($path1) == dirname($path2)) {
$newSource = substr($oldSource, 0, strpos($oldSource, $root1)).$path2; // Rename the file if UPDATE permission is granted
if (dirname($path1) == dirname($path2)) { if ($this->isUpdatable($path1)) {
// Rename the file if UPDATE permission is granted $storage = OC_Filesystem::getStorage($oldSource);
if ($this->isUpdatable($path1)) { return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
}
} else {
// Move the file if DELETE and CREATE permissions are granted
if ($this->isDeletable($path1) && $this->isCreatable(dirname($path2))) {
// Get the root shared folder
$folder1 = substr($path1, 0, $pos1);
$folder2 = substr($path2, 0, $pos2);
// Copy and unlink the file if it exists in a different shared folder
if ($folder1 != $folder2) {
if ($this->copy($path1, $path2)) {
return $this->unlink($path1);
}
} else {
$storage = OC_Filesystem::getStorage($oldSource);
return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource)); return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
} }
// Move the file if DELETE and CREATE permissions are granted
} else if ($this->isDeletable($path1) && $this->isCreatable(dirname($path2))) {
return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
} }
} }
} }
@ -335,12 +346,12 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
public function copy($path1, $path2) { public function copy($path1, $path2) {
// Copy the file if CREATE permission is granted // Copy the file if CREATE permission is granted
if (($source = $this->getSourcePath($path1)) && $this->isCreatable(dirname($path2))) { if ($this->isCreatable(dirname($path2))) {
$source = $this->fopen($path1, 'r'); $source = $this->fopen($path1, 'r');
$target = $this->fopen($path2, 'w'); $target = $this->fopen($path2, 'w');
return OC_Helper::streamCopy($source, $target); return OC_Helper::streamCopy($source, $target);
} }
return true; return false;
} }
public function fopen($path, $mode) { public function fopen($path, $mode) {

View File

@ -56,9 +56,13 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
} }
break; break;
case 'getItem': case 'getItem':
if (isset($_GET['itemType']) && isset($_GET['itemSource']) && isset($_GET['checkShares'])) { if (isset($_GET['itemType']) && isset($_GET['itemSource']) && isset($_GET['checkReshare']) && isset($_GET['checkShares'])) {
$reshare = OCP\Share::getItemSharedWithBySource($_GET['itemType'], $_GET['itemSource'], OCP\Share::FORMAT_NONE, null, true); if ($_GET['checkReshare'] == 'true') {
if ($_GET['checkShares'] == "true") { $reshare = OCP\Share::getItemSharedWithBySource($_GET['itemType'], $_GET['itemSource'], OCP\Share::FORMAT_NONE, null, true);
} else {
$reshare = false;
}
if ($_GET['checkShares'] == 'true') {
$shares = OCP\Share::getItemShared($_GET['itemType'], $_GET['itemSource']); $shares = OCP\Share::getItemShared($_GET['itemType'], $_GET['itemSource']);
} else { } else {
$shares = false; $shares = false;

View File

@ -2,10 +2,11 @@
This file is licensed under the Affero General Public License version 3 or later. This file is licensed under the Affero General Public License version 3 or later.
See the COPYING-README file. */ See the COPYING-README file. */
#dropdown { display:block; position:absolute; z-index:500; width:16em; right:0; margin-right:7em; background:#eee; padding:1em; #dropdown { display:block; position:absolute; z-index:500; width:19em; right:0; margin-right:7em; background:#eee; padding:1em;
-moz-box-shadow:0 1px 1px #777; -webkit-box-shadow:0 1px 1px #777; box-shadow:0 1px 1px #777; -moz-box-shadow:0 1px 1px #777; -webkit-box-shadow:0 1px 1px #777; box-shadow:0 1px 1px #777;
-moz-border-radius-bottomleft:1em; -webkit-border-bottom-left-radius:1em; border-bottom-left-radius:1em; -moz-border-radius-bottomleft:1em; -webkit-border-bottom-left-radius:1em; border-bottom-left-radius:1em;
-moz-border-radius-bottomright:1em; -webkit-border-bottom-right-radius:1em; border-bottom-right-radius:1em; } -moz-border-radius-bottomright:1em; -webkit-border-bottom-right-radius:1em; border-bottom-right-radius:1em; }
.reshare { padding-left:0.5em; }
#shareWithList { padding:0.5em; list-style-type: none; } #shareWithList { padding:0.5em; list-style-type: none; }
#shareWithList li { padding-top:0.1em; } #shareWithList li { padding-top:0.1em; }
#dropdown label { font-weight:normal; } #dropdown label { font-weight:normal; }

View File

@ -30,14 +30,57 @@ OC.Share={
} }
}); });
}, },
updateIcon:function(itemType, itemSource) {
if (itemType == 'file' || itemType == 'folder') {
var filename = $('tr').filterAttr('data-id', String(itemSource)).data('file');
if ($('#dir').val() == '/') {
itemSource = $('#dir').val() + filename;
} else {
itemSource = $('#dir').val() + '/' + filename;
}
}
var shares = false;
$.each(OC.Share.itemShares, function(index) {
if (OC.Share.itemShares[index].length > 0) {
shares = true;
return;
}
});
if (shares) {
$('a.share[data-item="'+itemSource+'"]').css('background', 'url('+OC.imagePath('core', 'actions/shared')+') no-repeat center');
if (typeof OC.Share.statuses[itemSource] === 'undefined') {
OC.Share.statuses[itemSource] = false;
}
} else {
if (itemType != 'file' && itemType != 'folder') {
$('a.share[data-item="'+itemSource+'"]').css('background', 'url('+OC.imagePath('core', 'actions/share')+') no-repeat center');
}
delete OC.Share.statuses[itemSource];
}
},
loadItem:function(itemType, itemSource) { loadItem:function(itemType, itemSource) {
var data = ''; var data = '';
if (typeof OC.Share.statuses[itemSource] === 'undefined') { var checkReshare = true;
// Switch file sources to path to check if status is set
if (itemType == 'file' || itemType == 'folder') {
var filename = $('tr').filterAttr('data-id', String(itemSource)).data('file');
if ($('#dir').val() == '/') {
var item = $('#dir').val() + filename;
} else {
var item = $('#dir').val() + '/' + filename;
}
if (item.substring(0, 8) != '/Shared/') {
checkReshare = false;
}
} else {
var item = itemSource;
}
if (typeof OC.Share.statuses[item] === 'undefined') {
checkShares = false; checkShares = false;
} else { } else {
checkShares = true; checkShares = true;
} }
$.ajax({type: 'GET', url: OC.filePath('core', 'ajax', 'share.php'), data: { fetch: 'getItem', itemType: itemType, itemSource: itemSource, checkShares: checkShares }, async: false, success: function(result) { $.ajax({type: 'GET', url: OC.filePath('core', 'ajax', 'share.php'), data: { fetch: 'getItem', itemType: itemType, itemSource: itemSource, checkReshare: checkReshare, checkShares: checkShares }, async: false, success: function(result) {
if (result && result.status === 'success') { if (result && result.status === 'success') {
data = result.data; data = result.data;
} else { } else {
@ -80,71 +123,79 @@ OC.Share={
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) {
if (data.reshare.share_type == OC.Share.SHARE_TYPE_GROUP) { 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; html += '<span class="reshare">Shared with you and the group '+data.reshare.share_with+' by '+data.reshare.uid_owner+'</span>';
} else { } else {
html += 'Shared with you by '+data.reshare.uid_owner; html += '<span class="reshare">Shared with you by '+data.reshare.uid_owner+'</span>';
} }
html += '<br />'; html += '<br />';
} }
html += '<input id="shareWith" type="text" placeholder="Share with" style="width:90%;"/>'; if (possiblePermissions & OC.Share.PERMISSION_SHARE) {
html += '<ul id="shareWithList">'; html += '<input id="shareWith" type="text" placeholder="Share with" style="width:90%;"/>';
html += '</ul>'; html += '<ul id="shareWithList">';
if (privateLink) { html += '</ul>';
html += '<div id="privateLink">'; if (privateLink) {
html += '<input type="checkbox" name="privateLinkCheckbox" id="privateLinkCheckbox" value="1" /><label for="privateLinkCheckbox">Share with private link</label>'; html += '<div id="privateLink">';
html += '<br />'; html += '<input type="checkbox" name="privateLinkCheckbox" id="privateLinkCheckbox" value="1" /><label for="privateLinkCheckbox">Share with private link</label>';
html += '<input id="privateLinkText" style="display:none; width:90%;" readonly="readonly" />'; html += '<br />';
html += '<input id="privateLinkText" style="display:none; width:90%;" readonly="readonly" />';
html += '</div>';
}
html += '</div>'; html += '</div>';
} $(html).appendTo(appendTo);
html += '</div>'; // Reset item shares
$(html).appendTo(appendTo); OC.Share.itemShares = [];
// Reset item shares if (data.shares) {
OC.Share.itemShares = []; $.each(data.shares, function(index, share) {
if (data.shares) { if (share.share_type == OC.Share.SHARE_TYPE_PRIVATE_LINK) {
$.each(data.shares, function(index, share) { OC.Share.showPrivateLink(item, share.share_with);
if (share.share_type == OC.Share.SHARE_TYPE_PRIVATE_LINK) {
OC.Share.showPrivateLink(item, share.share_with);
} else {
OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions);
}
});
}
$('#shareWith').autocomplete({minLength: 2, source: function(search, response) {
// if (cache[search.term]) {
// response(cache[search.term]);
// } else {
$.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWith', search: search.term, itemShares: OC.Share.itemShares }, function(result) {
if (result.status == 'success' && result.data.length > 0) {
response(result.data);
} else { } else {
// Suggest sharing via email if valid email address OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions);
var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
if (pattern.test(search.term)) {
response([{label: 'Share via email: '+search.term, value: {shareType: OC.Share.SHARE_TYPE_EMAIL, shareWith: search.term}}]);
} else {
response(['No people found']);
}
} }
}); });
// } }
}, $('#shareWith').autocomplete({minLength: 2, source: function(search, response) {
focus: function(event, focused) { // if (cache[search.term]) {
event.preventDefault(); // response(cache[search.term]);
}, // } else {
select: function(event, selected) { $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWith', search: search.term, itemShares: OC.Share.itemShares }, function(result) {
var shareType = selected.item.value.shareType; if (result.status == 'success' && result.data.length > 0) {
var shareWith = selected.item.value.shareWith; response(result.data);
$(this).val(shareWith); } else {
// Default permissions are Read and Share // Suggest sharing via email if valid email address
var permissions = OC.Share.PERMISSION_READ | OC.Share.PERMISSION_SHARE; var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
OC.Share.share($('#dropdown').data('item-type'), $('#dropdown').data('item-source'), shareType, shareWith, permissions, function() { if (pattern.test(search.term)) {
OC.Share.addShareWith(shareType, shareWith, permissions, possiblePermissions); response([{label: 'Share via email: '+search.term, value: {shareType: OC.Share.SHARE_TYPE_EMAIL, shareWith: search.term}}]);
$('#shareWith').val(''); } else {
response(['No people found']);
}
}
});
// }
},
focus: function(event, focused) {
event.preventDefault();
},
select: function(event, selected) {
var itemType = $('#dropdown').data('item-type');
var itemSource = $('#dropdown').data('item-source');
var shareType = selected.item.value.shareType;
var shareWith = selected.item.value.shareWith;
$(this).val(shareWith);
// Default permissions are Read and Share
var permissions = OC.Share.PERMISSION_READ | OC.Share.PERMISSION_SHARE;
OC.Share.share(itemType, itemSource, shareType, shareWith, permissions, function() {
OC.Share.addShareWith(shareType, shareWith, permissions, possiblePermissions);
$('#shareWith').val('');
OC.Share.updateIcon(itemType, itemSource);
});
return false;
}
}); });
return false; } else {
html += '<input id="shareWith" type="text" placeholder="Resharing is not allowed" style="width:90%;" disabled="disabled"/>';
html += '</div>';
$(html).appendTo(appendTo);
} }
});
$('#dropdown').show('blind', function() { $('#dropdown').show('blind', function() {
OC.Share.droppedDown = true; OC.Share.droppedDown = true;
}); });
@ -306,12 +357,15 @@ $(document).ready(function() {
$('.unshare').live('click', function() { $('.unshare').live('click', function() {
var li = $(this).parent(); var li = $(this).parent();
var itemType = $('#dropdown').data('item-type');
var itemSource = $('#dropdown').data('item-source');
var shareType = $(li).data('share-type'); var shareType = $(li).data('share-type');
var shareWith = $(li).data('share-with'); var shareWith = $(li).data('share-with');
OC.Share.unshare($('#dropdown').data('item-type'), $('#dropdown').data('item-source'), shareType, shareWith, function() { OC.Share.unshare(itemType, itemSource, shareType, shareWith, function() {
$(li).remove(); $(li).remove();
var index = OC.Share.itemShares[shareType].indexOf(shareWith); var index = OC.Share.itemShares[shareType].indexOf(shareWith);
OC.Share.itemShares[shareType].splice(index, 1); OC.Share.itemShares[shareType].splice(index, 1);
OC.Share.updateIcon(itemType, itemSource);
}); });
}); });

View File

@ -58,7 +58,7 @@ class OC_FileCache_Cached{
if($parent==-1){ if($parent==-1){
return array(); return array();
} }
$query=OC_DB::prepare('SELECT path,name,ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE parent=? AND (mimetype LIKE ? OR mimetype = ?)'); $query=OC_DB::prepare('SELECT id,path,name,ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE parent=? AND (mimetype LIKE ? OR mimetype = ?)');
$result=$query->execute(array($parent, $mimetype_filter.'%', 'httpd/unix-directory'))->fetchAll(); $result=$query->execute(array($parent, $mimetype_filter.'%', 'httpd/unix-directory'))->fetchAll();
if(is_array($result)){ if(is_array($result)){
return $result; return $result;

View File

@ -237,8 +237,16 @@ class Share {
// Continue scanning into child folders // Continue scanning into child folders
array_push($files, $children); array_push($files, $children);
} else { } else {
// Check file extension for an equivalent item type to convert to
$extension = strtolower(substr($itemSource, strrpos($itemSource, '.') + 1));
foreach (self::$backends as $type => $backend) {
if (isset($backend->dependsOn) && $backend->dependsOn == 'file' && isset($backend->supportedFileExtensions) && in_array($extension, $backend->supportedFileExtensions)) {
$itemType = $type;
break;
}
}
// Pass on to put() to check if this item should be converted, the item won't be inserted into the database unless it can be converted // Pass on to put() to check if this item should be converted, the item won't be inserted into the database unless it can be converted
self::put('file', $name, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder); self::put($itemType, $name, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder);
} }
} }
return true; return true;
@ -425,7 +433,7 @@ class Share {
} else { } else {
$fileDependent = false; $fileDependent = false;
$root = ''; $root = '';
if ($includeCollections && !isset($item) && $collectionTypes = self::getCollectionItemTypes($itemType)) { if ($includeCollections && !isset($item) && ($collectionTypes = self::getCollectionItemTypes($itemType))) {
// If includeCollections is true, find collections of this item type, e.g. a music album contains songs // If includeCollections is true, find collections of this item type, e.g. a music album contains songs
$itemTypes = array_merge(array($itemType), $collectionTypes); $itemTypes = array_merge(array($itemType), $collectionTypes);
$placeholders = join(',', array_fill(0, count($itemTypes), '?')); $placeholders = join(',', array_fill(0, count($itemTypes), '?'));
@ -481,12 +489,11 @@ class Share {
if (isset($uidOwner) || $itemShareWithBySource) { if (isset($uidOwner) || $itemShareWithBySource) {
// If item type is a file, file source needs to be checked in case the item was converted // If item type is a file, file source needs to be checked in case the item was converted
if ($itemType == 'file' || $itemType == 'folder') { if ($itemType == 'file' || $itemType == 'folder') {
$where .= " AND path = ?"; $where .= ' AND file_source = ?';
$queryArgs[] = $root.$item; $column = 'file_source';
} else { } else {
$where .= " AND item_source = ?"; $where .= " AND item_source = ?";
$column = 'item_source'; $column = 'item_source';
$queryArgs[] = $item;
} }
} else { } else {
if ($itemType == 'file' || $itemType == 'folder') { if ($itemType == 'file' || $itemType == 'folder') {
@ -494,8 +501,8 @@ class Share {
} else { } else {
$where .= " AND item_target = ?"; $where .= " AND item_target = ?";
} }
$queryArgs[] = $item;
} }
$queryArgs[] = $item;
if ($includeCollections && $collectionTypes = self::getCollectionItemTypes($itemType)) { if ($includeCollections && $collectionTypes = self::getCollectionItemTypes($itemType)) {
// TODO Bart - this doesn't work with only one argument // TODO Bart - this doesn't work with only one argument
// $placeholders = join(',', array_fill(0, count($collectionTypes), '?')); // $placeholders = join(',', array_fill(0, count($collectionTypes), '?'));
@ -519,23 +526,23 @@ class Share {
// TODO Optimize selects // TODO Optimize selects
if ($format == self::FORMAT_STATUSES) { if ($format == self::FORMAT_STATUSES) {
if ($itemType == 'file' || $itemType == 'folder') { if ($itemType == 'file' || $itemType == 'folder') {
$select = '*PREFIX*share.id, item_type, *PREFIX*share.parent, share_type, *PREFIX*fscache.path as file_source'; $select = '*PREFIX*share.id, item_type, *PREFIX*share.parent, share_type, file_source, path';
} else { } else {
$select = 'id, item_type, item_source, parent, share_type'; $select = 'id, item_type, item_source, parent, share_type';
} }
} else { } else {
if (isset($uidOwner)) { if (isset($uidOwner)) {
if ($itemType == 'file' || $itemType == 'folder') { if ($itemType == 'file' || $itemType == 'folder') {
$select = '*PREFIX*share.id, item_type, *PREFIX*fscache.path as file_source, *PREFIX*share.parent, share_type, share_with, permissions, stime'; $select = '*PREFIX*share.id, item_type, *PREFIX*share.parent, share_type, share_with, file_source, path, permissions, stime';
} else { } else {
$select = 'id, item_type, item_source, parent, share_type, share_with, permissions, stime, file_source'; $select = 'id, item_type, item_source, parent, share_type, share_with, permissions, stime, file_source';
} }
} else { } else {
if ($fileDependent) { if ($fileDependent) {
if (($itemType == 'file' || $itemType == 'folder') && $format == \OC_Share_Backend_File::FORMAT_FILE_APP || $format == \OC_Share_Backend_File::FORMAT_FILE_APP_ROOT) { 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'; $select = '*PREFIX*share.id, item_type, *PREFIX*share.parent, share_type, share_with, file_source, path, file_target, permissions, name, ctime, mtime, mimetype, size, encrypted, versioned, writable';
} else { } else {
$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'; $select = '*PREFIX*share.id, item_type, item_source, item_target, *PREFIX*share.parent, share_type, share_with, uid_owner, file_source, path, file_target, permissions, stime';
} }
} else { } else {
$select = '*'; $select = '*';
@ -580,11 +587,11 @@ class Share {
} }
} }
// Remove root from file source paths if retrieving own shared items // Remove root from file source paths if retrieving own shared items
if (isset($uidOwner) && isset($row['file_source'])) { if (isset($uidOwner) && isset($row['path'])) {
if (isset($row['parent'])) { if (isset($row['parent'])) {
$row['file_source'] = '/Shared/'.basename($row['file_source']); $row['path'] = '/Shared/'.basename($row['path']);
} else { } else {
$row['file_source'] = substr($row['file_source'], $root); $row['path'] = substr($row['path'], $root);
} }
} }
$items[$row['id']] = $row; $items[$row['id']] = $row;
@ -601,7 +608,7 @@ class Share {
} }
} }
// Check if this is a collection of the requested item type // Check if this is a collection of the requested item type
if ($includeCollections && $row['item_type'] != $itemType && $collectionBackend = self::getBackend($row['item_type']) && $collectionBackend instanceof Share_Backend_Collection) { if ($includeCollections && $row['item_type'] != $itemType && ($collectionBackend = self::getBackend($row['item_type'])) && $collectionBackend instanceof Share_Backend_Collection) {
$row['collection'] = array('item_type' => $itemType, $column => $row[$column]); $row['collection'] = array('item_type' => $itemType, $column => $row[$column]);
// Fetch all of the children sources // Fetch all of the children sources
$children = $collectionBackend->getChildren($row[$column]); $children = $collectionBackend->getChildren($row[$column]);
@ -636,6 +643,10 @@ class Share {
return $items; return $items;
} else if ($format == self::FORMAT_STATUSES) { } else if ($format == self::FORMAT_STATUSES) {
$statuses = array(); $statuses = array();
// Switch column to path for files and folders, used for determining statuses inside of folders
if ($itemType == 'file' || $itemType == 'folder') {
$column = 'path';
}
foreach ($items as $item) { foreach ($items as $item) {
if ($item['share_type'] == self::SHARE_TYPE_PRIVATE_LINK) { if ($item['share_type'] == self::SHARE_TYPE_PRIVATE_LINK) {
$statuses[$item[$column]] = true; $statuses[$item[$column]] = true;
@ -664,20 +675,6 @@ class Share {
* @return bool Returns true on success or false on failure * @return bool Returns true on success or false on failure
*/ */
private static function put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder = null) { private static function put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder = null) {
// Check file extension for an equivalent item type to convert to
if ($itemType == 'file') {
$extension = strtolower(substr($itemSource, strrpos($itemSource, '.') + 1));
foreach (self::$backends as $type => $backend) {
if (isset($backend->dependsOn) && $backend->dependsOn == 'file' && isset($backend->supportedFileExtensions) && in_array($extension, $backend->supportedFileExtensions)) {
$itemType = $type;
break;
}
}
// Exit if this is being called for a file inside a folder, and no equivalent item type is found
if (isset($parentFolder) && $itemType == 'file') {
return false;
}
}
$backend = self::getBackend($itemType); $backend = self::getBackend($itemType);
// Check if this is a reshare // Check if this is a reshare
if ($checkReshare = self::getItemSharedWithBySource($itemType, $itemSource, self::FORMAT_NONE, null, true)) { if ($checkReshare = self::getItemSharedWithBySource($itemType, $itemSource, self::FORMAT_NONE, null, true)) {
@ -686,24 +683,6 @@ class Share {
$message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is the original sharer'; $message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is the original sharer';
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
throw new \Exception($message); throw new \Exception($message);
// Check if attempting to share back to group TODO Check unique user target
} else if ($shareType == self::SHARE_TYPE_GROUP && $checkReshare['share_with'] == $shareWith['group']) {
$message = 'Sharing '.$itemSource.' failed, because the item was orignally shared with the group '.$shareWith['group'];
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
throw new \Exception($message);
// Check if attempting to share back a group share to a member of the same group
} else if (($checkReshare['share_type'] == self::SHARE_TYPE_GROUP || $checkReshare['share_type'] == self::$shareTypeGroupUserUnique) && $shareType == self::SHARE_TYPE_USER) {
if ($checkReshare['share_type'] == self::$shareTypeGroupUserUnique) {
$query = \OC_DB::prepare('SELECT share_with FROM *PREFIX*share WHERE id = ?');
$group = $query->execute(array($checkReshare['parent']))->fetchOne();
} else {
$group = $checkReshare['share_with'];
}
if (\OC_Group::inGroup($shareWith, $group)) {
$message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is a member of the original group share';
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
throw new \Exception($message);
}
} }
// Check if share permissions is granted // Check if share permissions is granted
if ((int)$checkReshare['permissions'] & self::PERMISSION_SHARE) { if ((int)$checkReshare['permissions'] & self::PERMISSION_SHARE) {
@ -734,9 +713,12 @@ class Share {
} }
$parent = null; $parent = null;
if ($backend instanceof Share_Backend_File_Dependent) { if ($backend instanceof Share_Backend_File_Dependent) {
// NOTE Apps should start using the file cache ids in their tables
$filePath = $backend->getFilePath($itemSource, $uidOwner); $filePath = $backend->getFilePath($itemSource, $uidOwner);
$fileSource = \OC_FileCache::getId($filePath); if ($itemType == 'file' && $itemType == 'folder') {
$fileSource = $itemSource;
} else {
$fileSource = \OC_FileCache::getId($filePath);
}
if ($fileSource == -1) { if ($fileSource == -1) {
$message = 'Sharing '.$itemSource.' failed, because the file could not be found in the file cache'; $message = 'Sharing '.$itemSource.' failed, because the file could not be found in the file cache';
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);