Merge branch 'share_api'

Conflicts:
	apps/contacts/lib/vcard.php
	apps/files/index.php
	lib/files.php
This commit is contained in:
Michael Gapczynski 2012-08-19 22:29:01 -04:00
commit 82d81e8d39
68 changed files with 3605 additions and 431 deletions

View File

@ -10,6 +10,8 @@ OC::$CLASSPATH['OC_Calendar_Share'] = 'apps/calendar/lib/share.php';
OC::$CLASSPATH['OC_Search_Provider_Calendar'] = 'apps/calendar/lib/search.php';
OC::$CLASSPATH['OC_Calendar_Export'] = 'apps/calendar/lib/export.php';
OC::$CLASSPATH['OC_Calendar_Import'] = 'apps/calendar/lib/import.php';
OC::$CLASSPATH['OC_Share_Backend_Calendar'] = 'apps/calendar/lib/share/calendar.php';
OC::$CLASSPATH['OC_Share_Backend_Event'] = 'apps/calendar/lib/share/event.php';
//General Hooks
OCP\Util::connectHook('OC_User', 'post_createUser', 'OC_Calendar_Hooks', 'createUser');
OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser');
@ -34,3 +36,5 @@ OCP\App::addNavigationEntry( array(
'icon' => OCP\Util::imagePath( 'calendar', 'icon.svg' ),
'name' => $l->t('Calendar')));
OC_Search::registerProvider('OC_Search_Provider_Calendar');
OCP\Share::registerBackend('calendar', 'OC_Share_Backend_Calendar');
OCP\Share::registerBackend('event', 'OC_Share_Backend_Event');

View File

@ -173,7 +173,7 @@ Calendar_Import={
}
$(document).ready(function(){
if(typeof FileActions !== 'undefined'){
FileActions.register('text/calendar','importCalendar', '', Calendar_Import.Dialog.open);
FileActions.register('text/calendar','importCalendar', FileActions.PERMISSION_READ, '', Calendar_Import.Dialog.open);
FileActions.setDefault('text/calendar','importCalendar');
};
});

View File

@ -18,19 +18,16 @@ class OC_Calendar_Share{
* @return: array $return - information about calendars
*/
public static function allSharedwithuser($userid, $type, $active=null, $permission=null){
$group_where = self::group_sql(OC_Group::getUserGroups($userid));
$permission_where = self::permission_sql($permission);
if($type == self::CALENDAR){
$active_where = self::active_sql($active);
}else{
$active_where = '';
}
$stmt = OCP\DB::prepare("SELECT * FROM *PREFIX*calendar_share_" . $type . " WHERE ((share = ? AND sharetype = 'user') " . $group_where . ") AND owner <> ? " . $permission_where . " " . $active_where);
$result = $stmt->execute(array($userid, $userid));
$return = array();
while( $row = $result->fetchRow()){
$return[] = $row;
$format = OC_Share_Backend_Calendar::FORMAT_CALENDAR;
if ($type == self::EVENT) {
$format = OC_Share_Backend_Event::FORMAT_EVENT;
}
$return = OCP\Share::getItemsSharedWith($type,
$format,
array(
'active' => $active,
'permissions' => $permission,
));
return $return;
}
/**

View File

@ -0,0 +1,111 @@
<?php
/**
* ownCloud
*
* @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
* Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
class OC_Share_Backend_Calendar implements OCP\Share_Backend_Collection {
const FORMAT_CALENDAR = 1;
/**
* @brief Get the source of the item to be stored in the database
* @param string Item
* @param string Owner of the item
* @return mixed|array|false Source
*
* Return an array if the item is file dependent, the array needs two keys: 'item' and 'file'
* Return false if the item does not exist for the user
*
* The formatItems() function will translate the source returned back into the item
*/
public function isValidSource($itemSource, $uidOwner) {
$calendar = OC_Calendar_App::getCalendar( $itemSource );
if ($calendar || $calendar['userid'] != $uidOwner) {
return false;
}
return true;
}
/**
* @brief Get a unique name of the item for the specified user
* @param string Item
* @param string|false User the item is being shared with
* @param array|null List of similar item names already existing as shared items
* @return string Target name
*
* This function needs to verify that the user does not already have an item with this name.
* If it does generate a new name e.g. name_#
*/
public function generateTarget($itemSource, $shareWith, $exclude = null) {
$calendar = OC_Calendar_App::getCalendar( $itemSource );
$user_calendars = array();
foreach(OC_Contacts_Addressbook::all($uid) as $user_calendar) {
$user_calendars[] = $user_calendar['displayname'];
}
$name = $calendar['userid']."'s ".$calendar['displayname'];
$suffix = '';
while (in_array($name.$suffix, $user_calendars)) {
$suffix++;
}
return $name.$suffix;
}
/**
* @brief Converts the shared item sources back into the item in the specified format
* @param array Shared items
* @param int Format
* @return ?
*
* The items array is a 3-dimensional array with the item_source as the first key and the share id as the second key to an array with the share info.
* The key/value pairs included in the share info depend on the function originally called:
* If called by getItem(s)Shared: id, item_type, item, item_source, share_type, share_with, permissions, stime, file_source
* If called by getItem(s)SharedWith: id, item_type, item, item_source, item_target, share_type, share_with, permissions, stime, file_source, file_target
* This function allows the backend to control the output of shared items with custom formats.
* It is only called through calls to the public getItem(s)Shared(With) functions.
*/
public function formatItems($items, $format, $parameters = null) {
$calendars = array();
if ($format == self::FORMAT_CALENDAR) {
foreach ($items as $item) {
$calendar = OC_Calendar_App::getCalendar($item['item_source'], false);
// TODO: really check $parameters['permissions'] == 'rw'/'r'
if ($parameters['permissions'] == 'rw') {
continue; // TODO
}
$calendar['displaynamename'] = $item['item_target'];
$calendar['calendarid'] = $calendar['id'];
$calendar['owner'] = $calendar['userid'];
$calendars[] = $calendar;
}
}
return $calendars;
}
public function getChildren($itemSource) {
$query = OCP\DB::prepare('SELECT id FROM *PREFIX*calendar_objects WHERE calendarid = ?');
$result = $query->execute(array($itemSource));
$sources = array();
while ($object = $result->fetchRow()) {
$sources[] = $object['id'];
}
return $sources;
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
class OC_Share_Backend_Event implements OCP\Share_Backend {
const FORMAT_EVENT = 0;
private static $event;
public function isValidSource($itemSource, $uidOwner) {
self::$event = OC_Calendar_Object::find($itemSource);
if (self::$event) {
return true;
}
return false;
}
public function generateTarget($itemSource, $shareWith, $exclude = null) {
// TODO Get default calendar and check for conflicts
return self::$event['summary'];
}
public function formatItems($items, $format, $parameters = null) {
$events = array();
if ($format == self::FORMAT_EVENT) {
foreach ($items as $item) {
$event = OC_Calendar_Object::find($item['item_source']);
$event['summary'] = $item['item_target'];
$events[] = $event;
}
}
return $events;
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* ownCloud
*
* @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
class OC_Share_Backend_Calendar extends OCP\Share_Backend {
public function getSource($item, $uid) {
$query = OCP\DB::prepare('SELECT id FROM *PREFIX*calendar_calendars WHERE userid = ? AND displayname = ? LIMIT 1');
return $query->execute(array($uid, $item))->fetchAll();
}
public function generateTarget($item, $uid) {
}
public function getItems($sources) {
}
}
class OC_Share_Backend_Event extends OCP\Share_Backend {
}
?>

View File

@ -5,7 +5,7 @@
<label for="active_<?php echo $_['calendar']['id'] ?>"><?php echo $_['calendar']['displayname'] ?></label>
</td>
<td width="20px">
<a href="#" onclick="Calendar.UI.Share.dropdown('<?php echo OCP\USER::getUser() ?>', <?php echo $_['calendar']['id'] ?>);" title="<?php echo $l->t('Share Calendar') ?>" class="action"><img class="svg action" src="<?php echo (!$_['shared']) ? OCP\Util::imagePath('core', 'actions/share.svg') : OCP\Util::imagePath('core', 'actions/shared.svg') ?>"></a>
<a href="#" class="share" data-item-type="calendar" data-item="<?php echo $_['calendar']['id']; ?>" title="<?php echo $l->t('Share Calendar') ?>" class="action"><img class="svg action" src="<?php echo (!$_['shared']) ? OCP\Util::imagePath('core', 'actions/share.svg') : OCP\Util::imagePath('core', 'actions/shared.svg') ?>"></a>
</td>
<td width="20px">
<a href="#" onclick="Calendar.UI.showCalDAVUrl('<?php echo OCP\USER::getUser() ?>', '<?php echo rawurlencode(html_entity_decode($_['calendar']['uri'], ENT_QUOTES, 'UTF-8')) ?>');" title="<?php echo $l->t('CalDav Link') ?>" class="action"><img class="svg action" src="<?php echo OCP\Util::imagePath('core', 'actions/public.svg') ?>"></a>

View File

@ -3,6 +3,8 @@ OC::$CLASSPATH['OC_Contacts_App'] = 'apps/contacts/lib/app.php';
OC::$CLASSPATH['OC_Contacts_Addressbook'] = 'apps/contacts/lib/addressbook.php';
OC::$CLASSPATH['OC_Contacts_VCard'] = 'apps/contacts/lib/vcard.php';
OC::$CLASSPATH['OC_Contacts_Hooks'] = 'apps/contacts/lib/hooks.php';
OC::$CLASSPATH['OC_Share_Backend_Contact'] = 'apps/contacts/lib/share/contact.php';
OC::$CLASSPATH['OC_Share_Backend_Addressbook'] = 'apps/contacts/lib/share/addressbook.php';
OC::$CLASSPATH['OC_Connector_Sabre_CardDAV'] = 'apps/contacts/lib/connector_sabre.php';
OC::$CLASSPATH['Sabre_CardDAV_VCFExportPlugin'] = 'apps/contacts/lib/VCFExportPlugin.php';
OC::$CLASSPATH['OC_Search_Provider_Contacts'] = 'apps/contacts/lib/search.php';
@ -20,3 +22,6 @@ OCP\App::addNavigationEntry( array(
OCP\Util::addscript('contacts', 'loader');
OC_Search::registerProvider('OC_Search_Provider_Contacts');
OCP\Share::registerBackend('contact', 'OC_Share_Backend_Contact');
OCP\Share::registerBackend('addressbook', 'OC_Share_Backend_Addressbook', 'contact');

View File

@ -50,11 +50,12 @@ label:hover, dt:hover { color: #333; }
.float { float: left; }
.svg { border: inherit; background: inherit; }
.listactions { height: 1em; width:60px; float: left; clear: right; }
.add,.edit,.delete,.mail, .globe, .upload, .download, .cloud { cursor: pointer; width: 20px; height: 20px; margin: 0; float: left; position:relative; opacity: 0.1; }
.add,.edit,.delete,.mail, .globe, .upload, .download, .cloud, .share { cursor: pointer; width: 20px; height: 20px; margin: 0; float: left; position:relative; opacity: 0.1; }
.add:hover,.edit:hover,.delete:hover,.mail:hover, .globe:hover, .upload:hover, .download:hover .cloud:hover { opacity: 1.0 }
.add { background:url('%webroot%/core/img/actions/add.svg') no-repeat center; clear: both; }
.delete { background:url('%webroot%/core/img/actions/delete.svg') no-repeat center; }
.edit { background:url('%webroot%/core/img/actions/rename.svg') no-repeat center; }
.share { background:url('%webroot%/core/img/actions/share.svg') no-repeat center; }
.mail { background:url('%webroot%/core/img/actions/mail.svg') no-repeat center; }
.upload { background:url('%webroot%/core/img/actions/upload.svg') no-repeat center; }
.download { background:url('%webroot%/core/img/actions/download.svg') no-repeat center; }

View File

@ -78,9 +78,9 @@ Contacts_Import={
}
$(document).ready(function(){
if(typeof FileActions !== 'undefined'){
FileActions.register('text/vcard','importaddressbook', '', Contacts_Import.importdialog);
FileActions.register('text/vcard','importaddressbook', FileActions.PERMISSION_READ, '', Contacts_Import.importdialog);
FileActions.setDefault('text/vcard','importaddressbook');
FileActions.register('text/x-vcard','importaddressbook', '', Contacts_Import.importdialog);
FileActions.register('text/x-vcard','importaddressbook', FileActions.PERMISSION_READ, '', Contacts_Import.importdialog);
FileActions.setDefault('text/x-vcard','importaddressbook');
};
});

View File

@ -4,6 +4,7 @@ OC.Contacts.Settings = OC.Contacts.Settings || {
this.Addressbook.adrsettings = $('.addressbooks-settings').first();
this.Addressbook.adractions = $('#contacts-settings').find('div.actions');
console.log('actions: ' + this.Addressbook.adractions.length);
OC.Share.loadIcons('addressbook');
},
Addressbook:{
showActions:function(act) {

View File

@ -64,10 +64,10 @@ class OC_Contacts_Addressbook {
while( $row = $result->fetchRow()) {
$addressbooks[] = $row;
}
$addressbooks = array_merge($addressbooks, OCP\Share::getItemsSharedWith('addressbook', OC_Share_Backend_Addressbook::FORMAT_ADDRESSBOOKS));
if(!$active && !count($addressbooks)) {
self::addDefault($uid);
}
return $addressbooks;
}
@ -208,7 +208,12 @@ class OC_Contacts_Addressbook {
public static function edit($id,$name,$description) {
// Need these ones for checking uri
$addressbook = self::find($id);
if ($addressbook['userid'] != OCP\User::getUser()) {
$sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $id);
if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_UPDATE)) {
return false;
}
}
if(is_null($name)) {
$name = $addressbook['name'];
}
@ -270,6 +275,13 @@ class OC_Contacts_Addressbook {
* @return boolean
*/
public static function delete($id) {
$addressbook = self::find($id);
if ($addressbook['userid'] != OCP\User::getUser()) {
$sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $id);
if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_DELETE)) {
return false;
}
}
self::setActive($id, false);
try {
$stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?' );

View File

@ -37,21 +37,24 @@ class OC_Contacts_App {
)
)
);
}
else {
OCP\Util::writeLog('contacts',
'Addressbook('.$id.') is not from '.OCP\USER::getUser(),
OCP\Util::ERROR);
//throw new Exception('This is not your addressbook.');
OCP\JSON::error(
array(
'data' => array(
'message' => self::$l10n->t('This is not your addressbook.')
} else {
$sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $id, OC_Share_Backend_Addressbook::FORMAT_ADDRESSBOOKS);
if ($sharedAddressbook) {
return $sharedAddressbook;
} else {
OCP\Util::writeLog('contacts',
'Addressbook('.$id.') is not from '.OCP\USER::getUser(),
OCP\Util::ERROR);
//throw new Exception('This is not your addressbook.');
OCP\JSON::error(
array(
'data' => array(
'message' => self::$l10n->t('This is not your addressbook.')
)
)
)
);
);
}
}
exit();
}
return $addressbook;
}

View File

@ -0,0 +1,93 @@
<?php
/**
* Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
class OC_Share_Backend_Addressbook implements OCP\Share_Backend_Collection {
const FORMAT_ADDRESSBOOKS = 1;
/**
* @brief Get the source of the item to be stored in the database
* @param string Item
* @param string Owner of the item
* @return mixed|array|false Source
*
* Return an array if the item is file dependent, the array needs two keys: 'item' and 'file'
* Return false if the item does not exist for the user
*
* The formatItems() function will translate the source returned back into the item
*/
public function isValidSource($itemSource, $uidOwner) {
$addressbook = OC_Contacts_Addressbook::find( $itemSource );
if( $addressbook === false || $addressbook['userid'] != $uidOwner) {
return false;
}
return true;
}
/**
* @brief Get a unique name of the item for the specified user
* @param string Item
* @param string|false User the item is being shared with
* @param array|null List of similar item names already existing as shared items
* @return string Target name
*
* This function needs to verify that the user does not already have an item with this name.
* If it does generate a new name e.g. name_#
*/
public function generateTarget($itemSource, $shareWith, $exclude = null) {
$addressbook = OC_Contacts_Addressbook::find( $itemSource );
$user_addressbooks = array();
foreach(OC_Contacts_Addressbook::all($uid) as $user_addressbook) {
$user_addressbooks[] = $user_addressbook['displayname'];
}
$name = $addressbook['userid']."'s ".$addressbook['displayname'];
$suffix = '';
while (in_array($name.$suffix, $user_addressbooks)) {
$suffix++;
}
return $name.$suffix;
}
/**
* @brief Converts the shared item sources back into the item in the specified format
* @param array Shared items
* @param int Format
* @return ?
*
* The items array is a 3-dimensional array with the item_source as the first key and the share id as the second key to an array with the share info.
* The key/value pairs included in the share info depend on the function originally called:
* If called by getItem(s)Shared: id, item_type, item, item_source, share_type, share_with, permissions, stime, file_source
* If called by getItem(s)SharedWith: id, item_type, item, item_source, item_target, share_type, share_with, permissions, stime, file_source, file_target
* This function allows the backend to control the output of shared items with custom formats.
* It is only called through calls to the public getItem(s)Shared(With) functions.
*/
public function formatItems($items, $format, $parameters = null) {
$addressbooks = array();
if ($format == self::FORMAT_ADDRESSBOOKS) {
foreach ($items as $item) {
$addressbook = OC_Contacts_Addressbook::find($item['item_source']);
if ($addressbook) {
$addressbook['displayname'] = $item['item_target'];
$addressbooks[] = $addressbook;
}
}
}
return $addressbooks;
}
public function getChildren($itemSource) {
$query = OCP\DB::prepare('SELECT id FROM *PREFIX*contacts_cards WHERE addressbookid = ?');
$result = $query->execute(array($itemSource));
$sources = array();
while ($contact = $result->fetchRow()) {
$sources[] = $contact['id'];
}
return $sources;
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* ownCloud
*
* @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
class OC_Share_Backend_Contact implements OCP\Share_Backend {
const FORMAT_CONTACT = 0;
private static $contact;
public function isValidSource($itemSource, $uidOwner) {
self::$contact = OC_Contacts_VCard::find($itemSource);
if (self::$contact) {
return true;
}
return false;
}
public function generateTarget($itemSource, $shareWith, $exclude = null) {
// TODO Get default addressbook and check for conflicts
return self::$contact['fullname'];
}
public function formatItems($items, $format, $parameters = null) {
$contacts = array();
if ($format == self::FORMAT_CONTACT) {
foreach ($items as $item) {
$contact = OC_Contacts_VCard::find($item['item_source']);
$contact['fullname'] = $item['item_target'];
$contacts[] = $contact;
}
}
return $contacts;
}
}

View File

@ -293,12 +293,17 @@ class OC_Contacts_VCard{
OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::add. No vCard supplied', OCP\Util::ERROR);
return null;
};
$addressbook = OC_Contacts_Addressbook::find($aid);
if ($addressbook['userid'] != OCP\User::getUser()) {
$sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $aid);
if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_CREATE)) {
return false;
}
}
if(!$isChecked) {
OC_Contacts_App::loadCategoriesFromVCard($card);
self::updateValuesFromAdd($aid, $card);
}
$card->setString('VERSION', '3.0');
// Add product ID is missing.
$prodid = trim($card->getAsString('PRODID'));
@ -357,6 +362,17 @@ class OC_Contacts_VCard{
foreach($objects as $object) {
$vcard = OC_VObject::parse($object[1]);
if(!is_null($vcard)) {
$oldcard = self::find($object[0]);
if (!$oldcard) {
return false;
}
$addressbook = OC_Contacts_Addressbook::find($oldcard['addressbookid']);
if ($addressbook['userid'] != OCP\User::getUser()) {
$sharedContact = OCP\Share::getItemSharedWithBySource('contact', $object[0], OCP\Share::FORMAT_NONE, null, true);
if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_UPDATE)) {
return false;
}
}
$vcard->setString('REV', $now->format(DateTime::W3C));
$data = $vcard->serialize();
try {
@ -378,11 +394,20 @@ class OC_Contacts_VCard{
*/
public static function edit($id, OC_VObject $card){
$oldcard = self::find($id);
if (!$oldcard) {
return false;
}
if(is_null($card)) {
return false;
}
// NOTE: Owner checks are being made in the ajax files, which should be done inside the lib files to prevent any redundancies with sharing checks
$addressbook = OC_Contacts_Addressbook::find($oldcard['addressbookid']);
if ($addressbook['userid'] != OCP\User::getUser()) {
$sharedContact = OCP\Share::getItemSharedWithBySource('contact', $id, OCP\Share::FORMAT_NONE, null, true);
if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_UPDATE)) {
return false;
}
}
OC_Contacts_App::loadCategoriesFromVCard($card);
$fn = $card->getAsString('FN');
@ -431,6 +456,17 @@ class OC_Contacts_VCard{
* @return boolean
*/
public static function delete($id){
$card = self::find($id);
if (!$card) {
return false;
}
$addressbook = OC_Contacts_Addressbook::find($card['addressbookid']);
if ($addressbook['userid'] != OCP\User::getUser()) {
$sharedContact = OCP\Share::getItemSharedWithBySource('contact', $id, OCP\Share::FORMAT_NONE, null, true);
if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) {
return false;
}
}
OC_Hook::emit('OC_Contacts_VCard', 'pre_deleteVCard', array('aid' => null, 'id' => $id, 'uri' => null));
$stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE id = ?' );
try {
@ -451,6 +487,18 @@ class OC_Contacts_VCard{
* @return boolean
*/
public static function deleteFromDAVData($aid,$uri){
$addressbook = OC_Contacts_Addressbook::find($aid);
if ($addressbook['userid'] != OCP\User::getUser()) {
$query = OCP\DB::prepare( 'SELECT id FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri = ?' );
$id = $query->execute(array($aid, $uri))->fetchOne();
if (!$id) {
return false;
}
$sharedContact = OCP\Share::getItemSharedWithBySource('contact', $id, OCP\Share::FORMAT_NONE, null, true);
if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) {
return false;
}
}
OC_Hook::emit('OC_Contacts_VCard', 'pre_deleteVCard', array('aid' => $aid, 'id' => null, 'uri' => $uri));
$stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri=?' );
try {
@ -594,7 +642,27 @@ class OC_Contacts_VCard{
*/
public static function moveToAddressBook($aid, $id, $isAddressbook = false) {
OC_Contacts_App::getAddressbook($aid); // check for user ownership.
$addressbook = OC_Contacts_Addressbook::find($aid);
if ($addressbook['userid'] != OCP\User::getUser()) {
$sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $aid);
if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_CREATE)) {
return false;
}
}
if(is_array($id)) {
foreach ($id as $index => $cardId) {
$card = self::find($cardId);
if (!$card) {
unset($id[$index]);
}
$oldAddressbook = OC_Contacts_Addressbook::find($card['addressbookid']);
if ($oldAddressbook['userid'] != OCP\User::getUser()) {
$sharedContact = OCP\Share::getItemSharedWithBySource('contact', $cardId, OCP\Share::FORMAT_NONE, null, true);
if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) {
unset($id[$index]);
}
}
}
$id_sql = join(',', array_fill(0, count($id), '?'));
$prep = 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id IN ('.$id_sql.')';
try {
@ -613,6 +681,17 @@ class OC_Contacts_VCard{
if($isAddressbook) {
$stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE addressbookid = ?' );
} else {
$card = self::find($id);
if (!$card) {
return false;
}
$oldAddressbook = OC_Contacts_Addressbook::find($card['addressbookid']);
if ($oldAddressbook['userid'] != OCP\User::getUser()) {
$sharedContact = OCP\Share::getItemSharedWithBySource('contact', $id, OCP\Share::FORMAT_NONE, null, true);
if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) {
return false;
}
}
$stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id = ?' );
}
try {

View File

@ -22,6 +22,9 @@
<td class="action">
<a class="svg action cloud" title="<?php echo $l->t('Show read-only VCF link'); ?>"></a>
</td>
<td class="action">
<a class="svg action share" data-item-type="addressbook" data-item="<?php echo $addressbook['id'] ?>" title="<?php echo $l->t("Share"); ?>"></a>
</td>
<td class="action">
<a class="svg action download" title="<?php echo $l->t('Download'); ?>"
href="<?php echo OCP\Util::linkToAbsolute('contacts', 'export.php'); ?>?bookid=<?php echo $addressbook['id'] ?>"></a>

View File

@ -93,7 +93,7 @@ $tmpl = new OCP\Template( 'files', 'index', 'user' );
$tmpl->assign( 'fileList', $list->fetchPage(), false );
$tmpl->assign( 'breadcrumb', $breadcrumbNav->fetchPage(), false );
$tmpl->assign( 'dir', OC_Filesystem::normalizePath($dir));
$tmpl->assign( 'readonly', !OC_Filesystem::is_writable($dir.'/'));
$tmpl->assign( 'isCreatable', OC_Filesystem::isCreatable($dir.'/'));
$tmpl->assign( 'files', $files );
$tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize);
$tmpl->assign( 'uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));

View File

@ -1,19 +1,28 @@
FileActions={
PERMISSION_CREATE:4,
PERMISSION_READ:1,
PERMISSION_UPDATE:2,
PERMISSION_DELETE:8,
PERMISSION_SHARE:16,
actions:{},
defaults:{},
icons:{},
currentFile:null,
register:function(mime,name,icon,action){
register:function(mime,name,permissions,icon,action){
if(!FileActions.actions[mime]){
FileActions.actions[mime]={};
}
FileActions.actions[mime][name]=action;
if (!FileActions.actions[mime][name]) {
FileActions.actions[mime][name] = {};
}
FileActions.actions[mime][name]['action'] = action;
FileActions.actions[mime][name]['permissions'] = permissions;
FileActions.icons[name]=icon;
},
setDefault:function(mime,name){
FileActions.defaults[mime]=name;
},
get:function(mime,type){
get:function(mime,type,permissions){
var actions={};
if(FileActions.actions.all){
actions=$.extend( actions, FileActions.actions.all )
@ -32,9 +41,15 @@ FileActions={
actions=$.extend( actions, FileActions.actions[type] )
}
}
return actions;
var filteredActions = {};
$.each(actions, function(name, action) {
if (action.permissions & permissions) {
filteredActions[name] = action.action;
}
});
return filteredActions;
},
getDefault:function(mime,type){
getDefault:function(mime,type,permissions){
if(mime){
var mimePart=mime.substr(0,mime.indexOf('/'));
}
@ -48,22 +63,20 @@ FileActions={
}else{
name=FileActions.defaults.all;
}
var actions=this.get(mime,type);
var actions=this.get(mime,type,permissions);
return actions[name];
},
display:function(parent, filename, type){
display:function(parent){
FileActions.currentFile=parent;
$('#fileList span.fileactions, #fileList td.date a.action').remove();
var actions=FileActions.get(FileActions.getCurrentMimeType(),FileActions.getCurrentType());
var actions=FileActions.get(FileActions.getCurrentMimeType(),FileActions.getCurrentType(), FileActions.getCurrentPermissions());
var file=FileActions.getCurrentFile();
if($('tr').filterAttr('data-file',file).data('renaming')){
return;
}
parent.children('a.name').append('<span class="fileactions" />');
var defaultAction=FileActions.getDefault(FileActions.getCurrentMimeType(),FileActions.getCurrentType());
var defaultAction=FileActions.getDefault(FileActions.getCurrentMimeType(),FileActions.getCurrentType(), FileActions.getCurrentPermissions());
for(name in actions){
// no rename and share action for the 'Shared' dir
if((name=='Rename' || name =='Share') && type=='dir' && filename=='Shared') { continue; }
if((name=='Download' || actions[name]!=defaultAction) && name!='Delete'){
var img=FileActions.icons[name];
if(img.call){
@ -86,16 +99,12 @@ FileActions={
parent.find('a.name>span.fileactions').append(element);
}
}
if(actions['Delete'] && (type!='dir' || filename != 'Shared')){ // no delete action for the 'Shared' dir
if(actions['Delete']){
var img=FileActions.icons['Delete'];
if(img.call){
img=img(file);
}
if ($('#dir').val().indexOf('Shared') != -1) {
var html='<a href="#" original-title="' + t('files', 'Unshare') + '" class="action delete" style="display:none" />';
} else {
var html='<a href="#" original-title="' + t('files', 'Delete') + '" class="action delete" style="display:none" />';
}
var html='<a href="#" original-title="' + t('files', 'Delete') + '" class="action delete" style="display:none" />';
var element=$(html);
if(img){
element.append($('<img src="'+img+'"/>'));
@ -131,6 +140,9 @@ FileActions={
},
getCurrentType:function(){
return FileActions.currentFile.parent().attr('data-type');
},
getCurrentPermissions:function() {
return FileActions.currentFile.parent().data('permissions');
}
}
@ -140,12 +152,12 @@ $(document).ready(function(){
} else {
var downloadScope = 'file';
}
FileActions.register(downloadScope,'Download',function(){return OC.imagePath('core','actions/download')},function(filename){
FileActions.register(downloadScope,'Download', FileActions.PERMISSION_READ, function(){return OC.imagePath('core','actions/download')},function(filename){
window.location=OC.filePath('files', 'ajax', 'download.php') + encodeURIComponent('?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent($('#dir').val()));
});
});
FileActions.register('all','Delete',function(){return OC.imagePath('core','actions/delete')},function(filename){
FileActions.register('all','Delete', FileActions.PERMISSION_DELETE, function(){return OC.imagePath('core','actions/delete')},function(filename){
if(Files.cancelUpload(filename)) {
if(filename.substr){
filename=[filename];
@ -163,11 +175,11 @@ FileActions.register('all','Delete',function(){return OC.imagePath('core','actio
$('.tipsy').remove();
});
FileActions.register('all','Rename',function(){return OC.imagePath('core','actions/rename')},function(filename){
FileActions.register('all','Rename', FileActions.PERMISSION_UPDATE, function(){return OC.imagePath('core','actions/rename')},function(filename){
FileList.rename(filename);
});
FileActions.register('dir','Open','',function(filename){
FileActions.register('dir','Open', FileActions.PERMISSION_READ, '', function(filename){
window.location=OC.linkTo('files', 'index.php') + '&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename);
});

View File

@ -56,7 +56,7 @@ $(document).ready(function() {
// Sets the file-action buttons behaviour :
$('tr').live('mouseenter',function(event) {
FileActions.display($(this).children('td.filename'), $(this).attr('data-file'), $(this).attr('data-type'));
FileActions.display($(this).children('td.filename'));
});
$('tr').live('mouseleave',function(event) {
FileActions.hide();
@ -106,7 +106,8 @@ $(document).ready(function() {
if(!renaming && !FileList.isLoading(filename)){
var mime=$(this).parent().parent().data('mime');
var type=$(this).parent().parent().data('type');
var action=FileActions.getDefault(mime,type);
var permissions = $(this).parent().parent().data('permissions');
var action=FileActions.getDefault(mime,type, permissions);
if(action){
action(filename);
}
@ -462,14 +463,18 @@ $(document).ready(function() {
$.post(
OC.filePath('files','ajax','newfile.php'),
{dir:$('#dir').val(),filename:name,content:" \n"},
function(data){
var date=new Date();
FileList.addFile(name,0,date);
var tr=$('tr').filterAttr('data-file',name);
tr.data('mime','text/plain');
getMimeIcon('text/plain',function(path){
tr.find('td.filename').attr('style','background-image:url('+path+')');
});
function(result){
if (result.status == 'success') {
var date=new Date();
FileList.addFile(name,0,date);
var tr=$('tr').filterAttr('data-file',name);
tr.data('mime','text/plain');
getMimeIcon('text/plain',function(path){
tr.find('td.filename').attr('style','background-image:url('+path+')');
});
} else {
OC.dialogs.alert(result.data.message, 'Error');
}
}
);
break;
@ -477,9 +482,13 @@ $(document).ready(function() {
$.post(
OC.filePath('files','ajax','newfolder.php'),
{dir:$('#dir').val(),foldername:name},
function(data){
var date=new Date();
FileList.addDir(name,0,date);
function(result){
if (result.status == 'success') {
var date=new Date();
FileList.addDir(name,0,date);
} else {
OC.dialogs.alert(result.data.message, 'Error');
}
}
);
break;

38
apps/files/share.php Executable file
View File

@ -0,0 +1,38 @@
<?php
/**
* ownCloud
*
* @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
class OC_Share_Backend_Files extends OCP\Share_Backend {
public function getSource($item, $uid) {
return $item;
}
}
class OC_Share_Backend_Folders extends OC_Share_Backend_Files {
public function share($
public function getDirectoryContent($folder) {
}
}
?>

View File

@ -1,8 +1,8 @@
<!--[if IE 8]><style>input[type="checkbox"]{padding:0;}table td{position:static !important;}</style><![endif]-->
<div id="controls">
<?php echo($_['breadcrumb']); ?>
<?php if (!isset($_['readonly']) || !$_['readonly']):?>
<div class="actions <?php if (isset($_['files']) and ! $_['readonly'] and count($_['files'])==0):?>emptyfolder<?php endif; ?>">
<?php if ($_['isCreatable']):?>
<div class="actions <?php if (isset($_['files']) and count($_['files'])==0):?>emptyfolder<?php endif; ?>">
<div id='new' class='button'>
<a><?php echo $l->t('New');?></a>
<ul class="popup popupTop">
@ -35,7 +35,7 @@
</div>
<div id='notification'></div>
<?php if (isset($_['files']) and ! $_['readonly'] and count($_['files'])==0):?>
<?php if (isset($_['files']) and $_['isCreatable'] and count($_['files'])==0):?>
<div id="emptyfolder"><?php echo $l->t('Nothing in here. Upload something!')?></div>
<?php endif; ?>
@ -43,7 +43,7 @@
<thead>
<tr>
<th id='headerName'>
<?php if(!isset($_['readonly']) || !$_['readonly']) { ?><input type="checkbox" id="select_all" /><?php } ?>
<input type="checkbox" id="select_all" />
<span class='name'><?php echo $l->t( 'Name' ); ?></span>
<span class='selectedActions'>
<!-- <a href="" class="share"><img class='svg' alt="Share" src="<?php echo OCP\image_path("core", "actions/share.svg"); ?>" /> <?php echo $l->t('Share')?></a> -->
@ -56,7 +56,7 @@
<th id="headerDate"><span id="modified"><?php echo $l->t( 'Modified' ); ?></span><span class="selectedActions"><a href="" class="delete"><?php echo $l->t('Delete')?> <img class="svg" alt="<?php echo $l->t('Delete')?>" src="<?php echo OCP\image_path("core", "actions/delete.svg"); ?>" /></a></span></th>
</tr>
</thead>
<tbody id="fileList" data-readonly="<?php echo $_['readonly'];?>">
<tbody id="fileList">
<?php echo($_['fileList']); ?>
</tbody>
</table>

View File

@ -1,5 +1,4 @@
<?php foreach($_['files'] as $file):
$write = ($file['writable']) ? 'true' : 'false';
$simple_file_size = OCP\simple_file_size($file['size']);
$simple_size_color = intval(200-$file['size']/(1024*1024)*2); // the bigger the file, the darker the shade of grey; megabytes*2
if($simple_size_color<0) $simple_size_color = 0;
@ -10,7 +9,7 @@
$name = str_replace('%2F','/', $name);
$directory = str_replace('+','%20',urlencode($file['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-write='<?php echo $write;?>'>
<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']; ?>'>
<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 } ?>
<a class="name" href="<?php if($file['type'] == 'dir') echo $_['baseURL'].$directory.'/'.$name; else echo $_['downloadURL'].$directory.'/'.$name; ?>" title="">

View File

@ -7,11 +7,11 @@
$(document).ready(function() {
if(typeof FileActions!=='undefined'){
FileActions.register('application/zip','Open','',function(filename){
FileActions.register('application/zip','Open', FileActions.PERMISSION_READ, '',function(filename){
window.location=OC.linkTo('files', 'index.php')+'&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename);
});
FileActions.setDefault('application/zip','Open');
FileActions.register('application/x-gzip','Open','',function(filename){
FileActions.register('application/x-gzip','Open', FileActions.PERMISSION_READ, '',function(filename){
window.location=OC.linkTo('files', 'index.php')+'&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename);
});
FileActions.setDefault('application/x-gzip','Open');

View File

@ -89,10 +89,10 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{
return $this->archive->fileExists($path.'/')?'dir':'file';
}
}
public function is_readable($path){
public function isReadable($path){
return is_readable($this->path);
}
public function is_writable($path){
public function isUpdatable($path){
return is_writable($this->path);
}
public function file_exists($path){

View File

@ -134,12 +134,12 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common {
return false;
}
public function is_readable($path) {
public function isReadable($path) {
// TODO Check acl and determine who grantee is
return true;
}
public function is_writable($path) {
public function isUpdatable($path) {
// TODO Check acl and determine who grantee is
return true;
}

View File

@ -125,11 +125,11 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
return false;
}
public function is_readable($path) {
public function isReadable($path) {
return $this->file_exists($path);
}
public function is_writable($path) {
public function isUpdatable($path) {
return $this->file_exists($path);
}

View File

@ -0,0 +1,71 @@
<?php
require_once 'dropbox.php';
// $oauth = new Dropbox_OAuth_Curl('526ar3qlrtzmv65', '3bbn0wo5lzgpjty');
$dropbox = new OC_Filestorage_Dropbox(array('app_key' => '526ar3qlrtzmv65', 'app_secret' => '3bbn0wo5lzgpjty', 'token' => 'a3ben02jb1y538a', 'token_secret' => 'x60h3fsky21r1b0'));
$dropbox->rename('/652072main_2012-2897_full (1).jpg', '/test.jpg');
// $dropbox->test();
// print_r($dropbox->mkdir('Again'));
// GET&https%3A%2F%2Fapi.dropbox.com%2F1%2Fmetadata%2Fdropbox%2FownCloud&list%3D0%26
// uzpi8oo2rbax1po
// th9uoso3xxny3ca
//Step 3: Acquiring access tokens Array ( [token] => 37my637p88ng967 [token_secret] => t49fmgp3omucnnr )
//The user is authenticated You should really save the oauth tokens somewhere, so the first steps will no longer be needed Array ( [token] => 37my637p88ng967 [token_secret] => t49fmgp3omucnnr )
// For convenience, definitely not required
// header('Content-Type: text/plain');
// // We need to start a session
// session_start();
// There are multiple steps in this workflow, we keep a 'state number' here
// if (isset($_SESSION['state'])) {
// $state = 2;
// } else {
// $state = 1;
// }
//
// switch($state) {
//
// /* In this phase we grab the initial request tokens
// and redirect the user to the 'authorize' page hosted
// on dropbox */
// case 1 :
// echo "Step 1: Acquire request tokens\n";
// $tokens = $oauth->getRequestToken();
// print_r($tokens);
//
// // Note that if you want the user to automatically redirect back, you can
// // add the 'callback' argument to getAuthorizeUrl.
// echo "Step 2: You must now redirect the user to:\n";
// echo $oauth->getAuthorizeUrl() . "\n";
// $_SESSION['state'] = 2;
// $_SESSION['oauth_tokens'] = $tokens;
// die();
//
// /* In this phase, the user just came back from authorizing
// and we're going to fetch the real access tokens */
// case 2 :
// echo "Step 3: Acquiring access tokens\n";
// $oauth->setToken($_SESSION['oauth_tokens']);
// $tokens = $oauth->getAccessToken();
// print_r($tokens);
// $_SESSION['state'] = 3;
// $_SESSION['oauth_tokens'] = $tokens;
// // There is no break here, intentional
//
// /* This part gets called if the authentication process
// already succeeded. We can use our stored tokens and the api
// should work. Store these tokens somewhere, like a database */
// case 3 :
// echo "The user is authenticated\n";
// echo "You should really save the oauth tokens somewhere, so the first steps will no longer be needed\n";
// print_r($_SESSION['oauth_tokens']);
// $oauth->setToken($_SESSION['oauth_tokens']);
// break;
//
// }
?>

View File

@ -284,11 +284,11 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
return false;
}
public function is_readable($path) {
public function isReadable($path) {
return true;
}
public function is_writable($path) {
public function isUpdatable($path) {
if ($path == '' || $path == '/') {
return true;
} else if ($entry = $this->getResource($path)) {

View File

@ -0,0 +1,8 @@
<?php
require_once 'google.php';
// $drive = new OC_Filestorage_Google(array('token' => '4/7nZMlRLlAEeXdY0AeH-eHNCL0YaK', 'token_secret' => 'NqO5VMGUVkwFtOYqHsex4257'));
// $drive = new OC_Filestorage_Google(array('token' => '1/4Xo84YtTxL2MkQst-Ti3nqF1Isy70NUHDRk-BwsLMf4', 'token_secret' => 'jYnyJ_4-ITNxlX9f9RDNoRW-'));
// var_export($drive->getFeed('https://docs.google.com/feeds/metadata/default', 'GET'));

View File

@ -32,11 +32,11 @@ abstract class OC_FileStorage_StreamWrapper extends OC_Filestorage_Common{
return filetype($this->constructUrl($path));
}
public function is_readable($path){
public function isReadable($path){
return true;//not properly supported
}
public function is_writable($path){
public function isUpdatable($path){
return true;//not properly supported
}

View File

@ -353,11 +353,11 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
}
public function is_readable($path){
public function isReadable($path){
return true;
}
public function is_writable($path){
public function isUpdatable($path){
return true;
}

View File

@ -104,11 +104,11 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
}
}
public function is_readable($path){
public function isReadable($path){
return true;//not properly supported
}
public function is_writable($path){
public function isUpdatable($path){
return true;//not properly supported
}

View File

@ -0,0 +1,7 @@
<?php
require_once 'files_external/lib/config.php';
echo "<pre>";
print_r(OC_Mount_Config::getSystemMountPoints());
echo "</pre>";
// OC_Mount_Config::addMountPoint('Photos', 'OC_Filestorage_SWIFT', array('host' => 'gapinthecloud.com', 'user' => 'Gap', 'token' => '23423afdasFJEW22', 'secure' => 'true', 'root' => ''), OC_Mount_Config::MOUNT_TYPE_GROUP, 'admin', false);
?>

View File

@ -1,6 +1,6 @@
$(document).ready(function() {
if(typeof FileActions!=='undefined'){
FileActions.register('image','View','',function(filename){
FileActions.register('image','View', FileActions.PERMISSION_READ, '',function(filename){
viewImage($('#dir').val(),filename);
});
FileActions.setDefault('image','View');

View File

@ -40,7 +40,7 @@ $(document).ready(function(){
if(location.href.indexOf("files")!=-1) {
PDFJS.workerSrc = OC.filePath('files_pdfviewer','js','pdfjs/build/pdf.js');
if(typeof FileActions!=='undefined'){
FileActions.register('application/pdf','Edit','',function(filename){
FileActions.register('application/pdf','Edit', FileActions.PERMISSION_READ, '',function(filename){
showPDFviewer($('#dir').val(),filename);
});
FileActions.setDefault('application/pdf','Edit');

View File

@ -1,6 +1,8 @@
<?php
OC::$CLASSPATH['OC_Share'] = "apps/files_sharing/lib_share.php";
OC::$CLASSPATH['OC_Share_Backend_File'] = "apps/files_sharing/lib/share/file.php";
OC::$CLASSPATH['OC_Share_Backend_Folder'] = 'apps/files_sharing/lib/share/folder.php';
OC::$CLASSPATH['OC_Filestorage_Shared'] = "apps/files_sharing/sharedstorage.php";
OCP\App::registerAdmin('files_sharing', 'settings');
@ -17,8 +19,10 @@ OCP\Util::connectHook('OC_User', 'post_removeFromGroup', 'OC_Share', 'removeFrom
$dir = isset($_GET['dir']) ? $_GET['dir'] : '/';
if ($dir != '/Shared' || OCP\Config::getAppValue('files_sharing', 'resharing', 'yes') == 'yes') {
OCP\Util::addscript("files_sharing", "share");
OCP\Util::addScript('core', 'share');
}
OCP\Util::addscript("3rdparty", "chosen/chosen.jquery.min");
OCP\Util::addStyle( 'files_sharing', 'sharing' );
OCP\Util::addStyle("3rdparty", "chosen/chosen");
OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');

View File

@ -2,14 +2,16 @@
This file is licensed under the Affero General Public License version 3 or later.
See the COPYING-README file. */
#dropdown { display:block; position:absolute; z-index:100; width:16em; right:0; margin-right:7em; background:#eee; padding:1em;
#dropdown { display:block; position:absolute; z-index:500; width:16em; 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-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; }
#sharedWithList { padding:0.5em; list-style-type: none; }
#privateLink { border-top:1px solid #ddd; padding-top:0.5em; }
a.unshare { float:right; display:inline; margin:0 .5em; padding:.3em .3em 0 .3em !important; opacity:.5; }
#shareWithList { padding:0.5em; list-style-type: none; }
#shareWithList li { padding-top:0.1em; }
#dropdown label { font-weight:normal; }
#dropdown input[type="checkbox"] { margin:0 0.2em 0 0.5em; }
a.showCruds { display:inline; opacity:.5; }
a.showCruds:hover { opacity:1; }
a.unshare { float:right; display:inline; padding:.3em 0 0 .3em !important; opacity:.5; }
a.unshare:hover { opacity:1; }
#share_with { width: 16em; }
#privateLink label, .edit { font-weight:normal; }
#share_with_chzn { display: block; }
#privateLink { border-top:1px solid #ddd; padding-top:0.5em; }

View File

@ -0,0 +1,91 @@
<?php
/**
* ownCloud
*
* @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
const FORMAT_SHARED_STORAGE = 0;
const FORMAT_FILE_APP = 1;
const FORMAT_FILE_APP_ROOT = 2;
const FORMAT_OPENDIR = 3;
public function isValidSource($item, $uid) {
if (OC_Filesystem::file_exists($item)) {
return true;
}
return false;
}
public function getFilePath($item, $uid) {
return $item;
}
public function generateTarget($item, $uid, $exclude = null) {
// TODO Make sure target path doesn't exist already
return $item;
}
public function formatItems($items, $format, $parameters = null) {
if ($format == self::FORMAT_SHARED_STORAGE) {
// Only 1 item should come through for this format call
return array('path' => $items[key($items)]['file_source'], 'permissions' => $items[key($items)]['permissions']);
} else if ($format == self::FORMAT_FILE_APP) {
$files = array();
foreach ($items as $item) {
$file = array();
$file['path'] = $item['file_target'];
$file['name'] = basename($item['file_target']);
$file['ctime'] = $item['ctime'];
$file['mtime'] = $item['mtime'];
$file['mimetype'] = $item['mimetype'];
$file['size'] = $item['size'];
$file['encrypted'] = $item['encrypted'];
$file['versioned'] = $item['versioned'];
$file['directory'] = $parameters['folder'];
$file['type'] = ($item['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file';
$file['permissions'] = $item['permissions'];
if ($file['type'] == 'file') {
// Remove Create permission if type is file
$file['permissions'] &= ~OCP\Share::PERMISSION_CREATE;
}
$files[] = $file;
}
return $files;
} else if ($format == self::FORMAT_FILE_APP_ROOT) {
$mtime = 0;
$size = 0;
foreach ($items as $item) {
if ($item['mtime'] > $mtime) {
$mtime = $item['mtime'];
}
$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));
} else if ($format == self::FORMAT_OPENDIR) {
$files = array();
foreach ($items as $item) {
$files[] = basename($item['file_target']);
}
return $files;
}
return array();
}
}

View File

@ -0,0 +1,61 @@
<?php
/**
* ownCloud
*
* @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
class OC_Share_Backend_Folder extends OC_Share_Backend_File {
public function formatItems($items, $format, $parameters = null) {
if ($format == self::FORMAT_SHARED_STORAGE) {
// Only 1 item should come through for this format call
return array('path' => $items[key($items)]['file_source'], 'permissions' => $items[key($items)]['permissions']);
} else if ($format == self::FORMAT_FILE_APP && isset($parameters['folder'])) {
// Only 1 item should come through for this format call
$folder = $items[key($items)];
if (isset($parameters['mimetype_filter'])) {
$mimetype_filter = $parameters['mimetype_filter'];
} else {
$mimetype_filter = '';
}
$path = $folder['file_source'].substr($parameters['folder'], 7 + strlen($folder['file_target']));
$files = OC_FileCache::getFolderContent($path, '', $mimetype_filter);
foreach ($files as &$file) {
$file['directory'] = $parameters['folder'];
$file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file';
$file['permissions'] = $folder['permissions'];
if ($file['type'] == 'file') {
// Remove Create permission if type is file
$file['permissions'] &= ~OCP\Share::PERMISSION_CREATE;
}
}
return $files;
}
return array();
}
public function getChildren($itemSource) {
$files = OC_FileCache::getFolderContent($itemSource);
$sources = array();
foreach ($files as $file) {
$sources[] = $file['path'];
}
return $sources;
}
}

View File

@ -3,7 +3,7 @@
* ownCloud
*
* @author Michael Gapczynski
* @copyright 2011 Michael Gapczynski GapczynskiM@gmail.com
* @copyright 2011 Michael Gapczynski mtgap@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@ -20,213 +20,217 @@
*
*/
require_once( 'lib_share.php' );
/**
* Convert target path to source path and pass the function call to the correct storage provider
*/
class OC_Filestorage_Shared extends OC_Filestorage_Common {
private $datadir;
private $sourcePaths = array();
private $sharedFolder;
private $files = array();
public function __construct($arguments) {
$this->datadir = $arguments['datadir'];
$this->datadir .= "/";
$this->sharedFolder = $arguments['sharedFolder'];
}
public function getInternalPath($path) {
/**
* @brief Get the source file path and the permissions granted for a shared file
* @param string Shared target file path
* @return Returns array with the keys path and permissions or false if not found
*/
private function getFile($target) {
$target = '/'.$target;
$target = rtrim($target, '/');
if (isset($this->files[$target])) {
return $this->files[$target];
} else {
$pos = strpos($target, '/', 1);
// Get shared folder name
if ($pos !== false) {
$folder = substr($target, 0, $pos);
if (isset($this->files[$folder])) {
$file = $this->files[$folder];
} else {
$file = OCP\Share::getItemSharedWith('folder', $folder, OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
}
if ($file) {
$this->files[$target]['path'] = $file['path'].substr($target, strlen($folder));
$this->files[$target]['permissions'] = $file['permissions'];
return $this->files[$target];
}
} else {
$file = OCP\Share::getItemSharedWith('file', $target, OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
if ($file) {
$this->files[$target] = $file;
return $this->files[$target];
}
}
OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, OCP\Util::ERROR);
return false;
}
}
/**
* @brief Get the source file path for a shared file
* @param string Shared target file path
* @return Returns source file path or false if not found
*/
private function getSourcePath($target) {
$file = $this->getFile($target);
if (isset($file['path'])) {
return $file['path'];
}
return false;
}
/**
* @brief Get the permissions granted for a shared file
* @param string Shared target file path
* @return Returns CRUDS permissions granted or false if not found
*/
private function getPermissions($target) {
$file = $this->getFile($target);
if (isset($file['permissions'])) {
return $file['permissions'];
}
return false;
}
/**
* @brief Get the internal path to pass to the storage filesystem call
* @param string Source file path
* @return Source file path with mount point stripped out
*/
private function getInternalPath($path) {
$mountPoint = OC_Filesystem::getMountPoint($path);
$internalPath = substr($path, strlen($mountPoint));
return $internalPath;
}
public function getSource($target) {
$target = $this->datadir.$target;
if (array_key_exists($target, $this->sourcePaths)) {
return $this->sourcePaths[$target];
} else {
$source = OC_Share::getSource($target);
$this->sourcePaths[$target] = $source;
return $source;
}
}
public function mkdir($path) {
if ($path == "" || $path == "/" || !$this->is_writable($path)) {
if ($path == '' || $path == '/' || !$this->isCreatable(dirname($path))) {
return false;
} else {
$source = $this->getSource($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
return $storage->mkdir($this->getInternalPath($source));
}
} else if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->mkdir($this->getInternalPath($source));
}
return false;
}
public function rmdir($path) {
// The folder will be removed from the database, but won't be deleted from the owner's filesystem
OC_Share::unshareFromMySelf($this->datadir.$path);
if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->rmdir($this->getInternalPath($source));
}
return false;
}
public function opendir($path) {
if ($path == "" || $path == "/") {
$path = $this->datadir.$path;
$sharedItems = OC_Share::getItemsInFolder($path);
$files = array();
foreach ($sharedItems as $item) {
// If item is in the root of the shared storage provider and the item exists add it to the fakedirs
if (dirname($item['target'])."/" == $path && $this->file_exists(basename($item['target']))) {
$files[] = basename($item['target']);
}
}
OC_FakeDirStream::$dirs['shared'.$path] = $files;
return opendir('fakedir://shared'.$path);
} else {
$source = $this->getSource($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
$dh = $storage->opendir($this->getInternalPath($source));
$modifiedItems = OC_Share::getItemsInFolder($source);
if ($modifiedItems && $dh) {
$sources = array();
$targets = array();
// Remove any duplicate or trailing '/'
$path = preg_replace('{(/)\1+}', "/", $path);
$targetFolder = rtrim($this->datadir.$path, "/");
foreach ($modifiedItems as $item) {
// If the item is in the current directory and the item exists add it to the arrays
if (dirname($item['target']) == $targetFolder && $this->file_exists($path."/".basename($item['target']))) {
// If the item was unshared from self, add it it to the arrays
if ($item['permissions'] == OC_Share::UNSHARED) {
$sources[] = basename($item['source']);
$targets[] = "";
} else {
$sources[] = basename($item['source']);
$targets[] = basename($item['target']);
}
}
}
// Don't waste time if there aren't any modified items in the current directory
if (empty($sources)) {
return $dh;
} else {
global $FAKEDIRS;
$files = array();
while (($filename = readdir($dh)) !== false) {
if ($filename != "." && $filename != "..") {
// If the file isn't in the sources array it isn't modified and can be added as is
if (!in_array($filename, $sources)) {
$files[] = $filename;
// The file has a different name than the source and is added to the fakedirs
} else {
$target = $targets[array_search($filename, $sources)];
// Don't add the file if it was unshared from self by the user
if ($target != "") {
$files[] = $target;
}
}
}
}
$FAKEDIRS['shared'] = $files;
return opendir('fakedir://shared');
}
} else {
return $dh;
}
}
if ($path == '' || $path == '/') {
$files = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_Folder::FORMAT_OPENDIR);
OC_FakeDirStream::$dirs['shared'] = $files;
return opendir('fakedir://shared');
} else if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->opendir($this->getInternalPath($source));
}
return false;
}
public function is_dir($path) {
if ($path == "" || $path == "/") {
if ($path == '' || $path == '/') {
return true;
} else {
$source = $this->getSource($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
return $storage->is_dir($this->getInternalPath($source));
}
} else if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->is_dir($this->getInternalPath($source));
}
return false;
}
public function is_file($path) {
$source = $this->getSource($path);
if ($source) {
if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->is_file($this->getInternalPath($source));
}
return false;
}
// TODO fill in other components of array
public function stat($path) {
if ($path == "" || $path == "/") {
$stat["size"] = $this->filesize($path);
$stat["mtime"] = $this->filemtime($path);
$stat["ctime"] = $this->filectime($path);
if ($path == '' || $path == '/') {
$stat['size'] = $this->filesize($path);
$stat['mtime'] = $this->filemtime($path);
$stat['ctime'] = $this->filectime($path);
return $stat;
} else {
$source = $this->getSource($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
return $storage->stat($this->getInternalPath($source));
}
} else if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->stat($this->getInternalPath($source));
}
return false;
}
public function filetype($path) {
if ($path == "" || $path == "/") {
return "dir";
} else {
$source = $this->getSource($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
return $storage->filetype($this->getInternalPath($source));
}
if ($path == '' || $path == '/') {
return 'dir';
} else if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->filetype($this->getInternalPath($source));
}
return false;
}
public function filesize($path) {
if ($path == "" || $path == "/" || $this->is_dir($path)) {
if ($path == '' || $path == '/' || $this->is_dir($path)) {
return 0;
} else {
$source = $this->getSource($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
return $storage->filesize($this->getInternalPath($source));
}
} else if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->filesize($this->getInternalPath($source));
}
return false;
}
public function is_readable($path) {
return true;
}
public function is_writable($path) {
if($path == "" || $path == "/"){
return false;
}elseif (OC_Share::getPermissions($this->datadir.$path) & OC_Share::WRITE) {
return true;
} else {
public function isCreatable($path) {
if ($path == '') {
return false;
}
return ($this->getPermissions($path) & OCP\Share::PERMISSION_CREATE);
}
public function isReadable($path) {
return $this->file_exists($path);
}
public function isUpdatable($path) {
if ($path == '') {
return false;
}
return ($this->getPermissions($path) & OCP\Share::PERMISSION_UPDATE);
}
public function isDeletable($path) {
if ($path == '') {
return false;
}
return ($this->getPermissions($path) & OCP\Share::PERMISSION_DELETE);
}
public function isSharable($path) {
if ($path == '') {
return false;
}
return ($this->getPermissions($path) & OCP\Share::PERMISSION_SHARE);
}
public function file_exists($path) {
if ($path == "" || $path == "/") {
if ($path == '' || $path == '/') {
return true;
} else {
$source = $this->getSource($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
return $storage->file_exists($this->getInternalPath($source));
}
} else if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->file_exists($this->getInternalPath($source));
}
return false;
}
public function filectime($path) {
if ($path == "" || $path == "/") {
if ($path == '' || $path == '/') {
$ctime = 0;
if ($dh = $this->opendir($path)) {
while (($filename = readdir($dh)) !== false) {
@ -238,7 +242,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
}
return $ctime;
} else {
$source = $this->getSource($path);
$source = $this->getSourcePath($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
return $storage->filectime($this->getInternalPath($source));
@ -247,7 +251,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
}
public function filemtime($path) {
if ($path == "" || $path == "/") {
if ($path == '' || $path == '/') {
$mtime = 0;
if ($dh = $this->opendir($path)) {
while (($filename = readdir($dh)) !== false) {
@ -259,7 +263,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
}
return $mtime;
} else {
$source = $this->getSource($path);
$source = $this->getSourcePath($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
return $storage->filemtime($this->getInternalPath($source));
@ -268,10 +272,10 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
}
public function file_get_contents($path) {
$source = $this->getSource($path);
$source = $this->getSourcePath($path);
if ($source) {
$info = array(
'target' => $this->datadir.$path,
'target' => $this->sharedFolder.$path,
'source' => $source,
);
OCP\Util::emitHook('OC_Filestorage_Shared', 'file_get_contents', $info);
@ -281,92 +285,66 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
}
public function file_put_contents($path, $data) {
if ($this->is_writable($path)) {
$source = $this->getSource($path);
if ($source) {
$info = array(
'target' => $this->datadir.$path,
'source' => $source,
);
OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info);
$storage = OC_Filesystem::getStorage($source);
$result = $storage->file_put_contents($this->getInternalPath($source), $data);
return $result;
if ($source = $this->getSourcePath($path)) {
// Check if permission is granted
if (($this->file_exists($path) && !$this->isUpdatable($path)) || ($this->is_dir($path) && !$this->isCreatable($path))) {
return false;
}
$info = array(
'target' => $this->sharedFolder.$path,
'source' => $source,
);
OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info);
$storage = OC_Filesystem::getStorage($source);
$result = $storage->file_put_contents($this->getInternalPath($source), $data);
return $result;
}
return false;
}
public function unlink($path) {
// The item will be removed from the database, but won't be touched on the owner's filesystem
$target = $this->datadir.$path;
// Check if the item is inside a shared folder
if (OC_Share::getParentFolders($target)) {
// If entry for item already exists
if (OC_Share::getItem($target)) {
OC_Share::unshareFromMySelf($target, false);
} else {
OC_Share::pullOutOfFolder($target, $target);
OC_Share::unshareFromMySelf($target, false);
}
// Delete the database entry
} else {
OC_Share::unshareFromMySelf($target);
// Delete the file if DELETE permission is granted
if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->unlink($this->getInternalPath($source));
}
return true;
return false;
}
public function rename($path1, $path2) {
$oldTarget = $this->datadir.$path1;
$newTarget = $this->datadir.$path2;
// Check if the item is inside a shared folder
if ($folders = OC_Share::getParentFolders($oldTarget)) {
$root1 = substr($path1, 0, strpos($path1, "/"));
$root2 = substr($path1, 0, strpos($path2, "/"));
// Prevent items from being moved into different shared folders until versioning (cut and paste) and prevent items going into 'Shared'
if ($root1 !== $root2) {
return false;
// Check if both paths have write permission
} else if ($this->is_writable($path1) && $this->is_writable($path2)) {
$oldSource = $this->getSource($path1);
$newSource = $folders['source'].substr($newTarget, strlen($folders['target']));
if ($oldSource) {
$storage = OC_Filesystem::getStorage($oldSource);
if ($oldSource = $this->getSourcePath($path1)) {
$root1 = substr($path1, 0, strpos($path1, '/'));
$root2 = substr($path2, 0, strpos($path2, '/'));
// Moving/renaming is only allowed within the same shared folder
if ($root1 == $root2) {
$storage = OC_Filesystem::getStorage($oldSource);
$newSource = substr($oldSource, 0, strpos($oldSource, $root1)).$path2;
if (dirname($path1) == dirname($path2)) {
// Rename the file if UPDATE permission is granted
if ($this->isUpdatable($path1)) {
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));
}
// If the user doesn't have write permission, items can only be renamed and not moved
} else if (dirname($path1) !== dirname($path2)) {
return false;
// The item will be renamed in the database, but won't be touched on the owner's filesystem
} else {
OC_Share::pullOutOfFolder($oldTarget, $newTarget);
// If this is a folder being renamed, call setTarget in case there are any database entries inside the folder
if (self::is_dir($path1)) {
OC_Share::setTarget($oldTarget, $newTarget);
}
}
} else {
OC_Share::setTarget($oldTarget, $newTarget);
}
return true;
return false;
}
public function copy($path1, $path2) {
if ($path2 == "" || $path2 == "/") {
// TODO Construct new shared item or should this not be allowed?
} else {
if ($this->is_writable($path2)) {
$tmpFile = $this->toTmpFile($path1);
$result = $this->fromTmpFile($tmpFile, $path2);
return $result;
} else {
return false;
}
// Copy the file if CREATE permission is granted
if (($source = $this->getSourcePath($path1)) && $this->isCreatable(dirname($path2))) {
$source = $this->fopen($path1, 'r');
$target = $this->fopen($path2, 'w');
return OC_Helper::streamCopy($source, $target);
}
return true;
}
public function fopen($path, $mode) {
$source = $this->getSource($path);
if ($source) {
if ($source = $this->getSourcePath($path)) {
switch ($mode) {
case 'r+':
case 'rb+':
@ -382,12 +360,12 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
case 'xb':
case 'a':
case 'ab':
if (!$this->is_writable($path)) {
if (!$this->isUpdatable($path)) {
return false;
}
}
$info = array(
'target' => $this->datadir.$path,
'target' => $this->sharedFolder.$path,
'source' => $source,
'mode' => $mode,
);
@ -395,95 +373,46 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
$storage = OC_Filesystem::getStorage($source);
return $storage->fopen($this->getInternalPath($source), $mode);
}
return false;
}
public function toTmpFile($path) {
$source = $this->getSource($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
return $storage->toTmpFile($this->getInternalPath($source));
}
}
public function fromTmpFile($tmpFile, $path) {
if ($this->is_writable($path)) {
$source = $this->getSource($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
$result = $storage->fromTmpFile($tmpFile, $this->getInternalPath($source));
return $result;
}
} else {
return false;
}
}
public function getMimeType($path) {
if ($path == "" || $path == "/") {
if ($path == '' || $path == '/') {
return 'httpd/unix-directory';
}
$source = $this->getSource($path);
if ($source) {
if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->getMimeType($this->getInternalPath($source));
}
return false;
}
public function hash($type, $path, $raw = false) {
$source = $this->getSource($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
return $storage->hash($type, $this->getInternalPath($source), $raw);
}
}
public function free_space($path) {
$source = $this->getSource($path);
$source = $this->getSourcePath($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
return $storage->free_space($this->getInternalPath($source));
}
}
public function search($query) {
return $this->searchInDir($query);
}
protected function searchInDir($query, $path = "") {
$files = array();
if ($dh = $this->opendir($path)) {
while (($filename = readdir($dh)) !== false) {
if ($filename != "." && $filename != "..") {
if (strstr(strtolower($filename), strtolower($query))) {
$files[] = $path."/".$filename;
}
if ($this->is_dir($path."/".$filename)) {
$files = array_merge($files, $this->searchInDir($query, $path."/".$filename));
}
}
}
}
return $files;
}
public function getLocalFile($path) {
$source = $this->getSource($path);
if ($source) {
if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->getLocalFile($this->getInternalPath($source));
}
return false;
}
public function touch($path, $mtime=null){
$source = $this->getSource($path);
if ($source) {
public function touch($path, $mtime = null) {
if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->touch($this->getInternalPath($source),$mtime);
return $storage->touch($this->getInternalPath($source), $mtime);
}
return false;
}
public static function setup($options) {
$user_dir = $options['user_dir'];
OC_Filesystem::mount('OC_Filestorage_Shared', array('datadir' => $user_dir.'/Shared'), $user_dir.'/Shared/');
OC_Filesystem::mount('OC_Filestorage_Shared', array('sharedFolder' => '/Shared'), $user_dir.'/Shared/');
}
/**
@ -493,6 +422,6 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
*/
public function hasUpdated($path,$time){
//TODO
return $this->filemtime($path)>$time;
return false;
}
}

View File

@ -0,0 +1,11 @@
<table>
<thead>
<tr>
<th id="headerSize"><?php echo $l->t( 'Size' ); ?></th>
<th id="headerDate"><span id="modified"><?php echo $l->t( 'Modified' ); ?></span><span class="selectedActions"><a href="" class="delete"><?php echo $l->t('Delete all')?> <img class="svg" alt="<?php echo $l->t('Delete')?>" src="<?php echo OCP\image_path("core", "actions/delete.svg"); ?>" /></a></span></th>
</tr>
</thead>
<tbody id="fileList" data-readonly="<?php echo $_['readonly'];?>">
<?php echo($_['fileList']); ?>
</tbody>
</table>

View File

@ -222,9 +222,17 @@ function showFileEditor(dir,filename){
}
});
// Add the ctrl+s event
window.aceEditor.commands.addCommand({ name: "save", bindKey: { win: "Ctrl-S", mac: "Command-S", sender: "editor" }, exec: function(){
window.aceEditor.commands.addCommand({
name: "save",
bindKey: {
win: "Ctrl-S",
mac: "Command-S",
sender: "editor"
},
exec: function(){
doFileSave();
} });
}
});
});
} else {
// Failed to get the file.
@ -297,11 +305,11 @@ $(window).resize(function() {
var is_editor_shown = false;
$(document).ready(function(){
if(typeof FileActions!=='undefined'){
FileActions.register('text','Edit','',function(filename){
FileActions.register('text','Edit', FileActions.PERMISSION_READ, '',function(filename){
showFileEditor($('#dir').val(),filename);
});
FileActions.setDefault('text','Edit');
FileActions.register('application/xml','Edit','',function(filename){
FileActions.register('application/xml','Edit', FileActions.PERMISSION_READ, '',function(filename){
showFileEditor($('#dir').val(),filename);
});
FileActions.setDefault('application/xml','Edit');

View File

@ -0,0 +1,36 @@
<?php
/**
* ownCloud
*
* @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
return array(
'list' => array('method' => 'GET', 'class' => 'Storage', 'function' => 'getVersions',
'parameters' => array(
'file' => array('required' => true, 'type' => 'string')
)
),
'revert' => array('method' => 'POST', 'class' => 'Storage', 'function' => 'rollback',
'parameters' => array(
'file' => array('required' => true, 'type' => 'string'),
'time' => array('required' => true, 'type' => 'int')
)
)
);
?>

View File

@ -11,7 +11,7 @@ $(document).ready(function() {
$(document).ready(function(){
if (typeof FileActions !== 'undefined') {
// Add history button to files/index.php
FileActions.register('file','History',function(){return OC.imagePath('core','actions/history')},function(filename){
FileActions.register('file','History', FileActions.PERMISSION_UPDATE, function(){return OC.imagePath('core','actions/history')},function(filename){
if (scanFiles.scanning){return;}//workaround to prevent additional http request block scanning feedback

View File

@ -28,6 +28,9 @@ OC::$CLASSPATH['OC_Gallery_Sharing'] = 'gallery/lib/sharing.php';
OC::$CLASSPATH['OC_Gallery_Hooks_Handlers'] = 'gallery/lib/hooks_handlers.php';
OC::$CLASSPATH['Pictures_Managers'] = 'gallery/lib/managers.php';
OC::$CLASSPATH['Pictures_Tiles'] = 'gallery/lib/tiles.php';
OC::$CLASSPATH['OC_Share_Backend_Photo'] = 'gallery/lib/share.php';
// OCP\Share::registerBackend('photo', new OC_Share_Backend_Photo());
$l = OC_L10N::get('gallery');

View File

@ -0,0 +1,42 @@
<?php
/**
* ownCloud
*
* @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
abstract class OC_Share_Photo_Backend implements OCP\Share_Backend {
public $dependsOn = 'file';
public $supportedFileExtensions = array('jpg', 'png', 'gif');
public function getSource($item, $uid) {
return array('item' => 'blah.jpg', 'file' => $item);
}
public function generateTarget($item, $uid, $exclude = null) {
// TODO Make sure target path doesn't exist already
return $item;
}
public function formatItems($items, $format, $parameters = null) {
}
}
?>

View File

@ -45,8 +45,8 @@ $(document).ready(function() {
// FileActions.register('application/ogg','Add to playlist','',addAudio);
if(typeof FileActions!=='undefined'){
FileActions.register('audio','Play','',playAudio);
FileActions.register('application/ogg','','Play',playAudio);
FileActions.register('audio','Play', FileActions.PERMISSION_READ, '',playAudio);
FileActions.register('application/ogg', FileActions.PERMISSION_READ, '','Play',playAudio);
FileActions.setDefault('audio','Play');
FileActions.setDefault('application/ogg','Play');
}

View File

View File

@ -0,0 +1,65 @@
<?php
/**
* ownCloud
*
* @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
class OC_Share_Backend_Artist extends OCP\Share_Backend {
public function getSource($item, $uid) {
$query = OCP\DB::prepare('SELECT artist_id FROM *PREFIX*media_artists WHERE artist_id = ? AND song_user = ?');
$result = $query->execute(array($item, $uid))->fetchRow();
if (is_array($result)) {
return array('item' => $item, 'file' => $result['song_path']);
}
return false;
}
public function generateTarget($item, $uid, $exclude = null) {
// TODO Make sure target path doesn't exist already
return '/Shared'.$item;
}
public function formatItems($items, $format) {
$ids = array();
foreach ($items as $id => $info) {
$ids[] = $id;
}
$ids = "'".implode("','", $ids)."'";
switch ($format) {
case self::FORMAT_SOURCE_PATH:
$query = OCP\DB::prepare('SELECT path FROM *PREFIX*fscache WHERE id IN ('.$ids.')');
return $query->execute()->fetchAll();
case self::FORMAT_FILE_APP:
$query = OCP\DB::prepare('SELECT id, path, name, ctime, mtime, mimetype, size, encrypted, versioned, writable FROM *PREFIX*fscache WHERE id IN ('.$ids.')');
$result = $query->execute();
$files = array();
while ($file = $result->fetchRow()) {
// Set target path
$file['path'] = $items[$file['id']]['item_target'];
$file['name'] = basename($file['path']);
// TODO Set permissions: $file['writable']
$files[] = $file;
}
return $files;
}
}
}
?>

View File

@ -0,0 +1,65 @@
<?php
/**
* ownCloud
*
* @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
class OC_Share_Backend_Song extends OCP\Share_Backend {
public function getSource($item, $uid) {
$query = OCP\DB::prepare('SELECT song_path FROM *PREFIX*media_songs WHERE song_id = ? AND song_user = ?');
$result = $query->execute(array($item, $uid))->fetchRow();
if (is_array($result)) {
return array('item' => $item, 'file' => $result['song_path']);
}
return false;
}
public function generateTarget($item, $uid, $exclude = null) {
// TODO Make sure target path doesn't exist already
return '/Shared'.$item;
}
public function formatItems($items, $format) {
$ids = array();
foreach ($items as $id => $info) {
$ids[] = $id;
}
$ids = "'".implode("','", $ids)."'";
switch ($format) {
case self::FORMAT_SOURCE_PATH:
$query = OCP\DB::prepare('SELECT path FROM *PREFIX*fscache WHERE id IN ('.$ids.')');
return $query->execute()->fetchAll();
case self::FORMAT_FILE_APP:
$query = OCP\DB::prepare('SELECT id, path, name, ctime, mtime, mimetype, size, encrypted, versioned, writable FROM *PREFIX*fscache WHERE id IN ('.$ids.')');
$result = $query->execute();
$files = array();
while ($file = $result->fetchRow()) {
// Set target path
$file['path'] = $items[$file['id']]['item_target'];
$file['name'] = basename($file['path']);
// TODO Set permissions: $file['writable']
$files[] = $file;
}
return $files;
}
}
}
?>

128
core/ajax/share.php Normal file
View File

@ -0,0 +1,128 @@
<?php
/**
* ownCloud
*
* @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
require_once '../../lib/base.php';
OC_JSON::checkLoggedIn();
if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['item'])) {
switch ($_POST['action']) {
case 'share':
if (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']);
// TODO May need to return private link
OC_JSON::success();
} catch (Exception $exception) {
OC_JSON::error(array('data' => array('message' => $exception->getMessage())));
}
}
break;
case 'unshare':
if (isset($_POST['shareType']) && isset($_POST['shareWith'])) {
$return = OCP\Share::unshare($_POST['itemType'], $_POST['item'], $_POST['shareType'], $_POST['shareWith']);
($return) ? OC_JSON::success() : OC_JSON::error();
}
break;
case 'setTarget':
if (isset($_POST['newTarget'])) {
$return = OCP\Share::setTarget($_POST['itemType'], $_POST['item'], $_POST['newTarget']);
($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) ? OC_JSON::success() : OC_JSON::error();
}
break;
}
} else if (isset($_GET['fetch'])) {
switch ($_GET['fetch']) {
case 'getItemsSharedStatuses':
if (isset($_GET['itemType'])) {
$return = OCP\Share::getItemsShared($_GET['itemType'], OCP\Share::FORMAT_STATUSES);
is_array($return) ? OC_JSON::success(array('data' => $return)) : OC_JSON::error();
}
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();
}
break;
case 'getShareWith':
if (isset($_GET['search'])) {
$shareWith = array();
if (OC_App::isEnabled('contacts')) {
// TODO Add function to contacts to only get the 'fullname' column to improve performance
$ids = OC_Contacts_Addressbook::activeIds();
foreach ($ids as $id) {
$vcards = OC_Contacts_VCard::all($id);
foreach ($vcards as $vcard) {
$contact = $vcard['fullname'];
if (stripos($contact, $_GET['search']) !== false
&& (!isset($_GET['itemShares'])
|| !isset($_GET['itemShares'][OCP\Share::SHARE_TYPE_CONTACT])
|| !is_array($_GET['itemShares'][OCP\Share::SHARE_TYPE_CONTACT])
|| !in_array($contact, $_GET['itemShares'][OCP\Share::SHARE_TYPE_CONTACT]))) {
$shareWith[] = array('label' => $contact, 'value' => array('shareType' => 5, 'shareWith' => $vcard['id']));
}
}
}
}
$count = 0;
$users = array();
$limit = 0;
$offset = 0;
while ($count < 4 && count($users) == $limit) {
$limit = 4 - $count;
$users = OC_User::getUsers($_GET['search'], $limit, $offset);
$offset += $limit;
foreach ($users as $user) {
if ((!isset($_GET['itemShares']) || !is_array($_GET['itemShares'][OCP\Share::SHARE_TYPE_USER]) || !in_array($user, $_GET['itemShares'][OCP\Share::SHARE_TYPE_USER])) && $user != OC_User::getUser()) {
$shareWith[] = array('label' => $user, 'value' => array('shareType' => OCP\Share::SHARE_TYPE_USER, 'shareWith' => $user));
$count++;
}
}
}
$count = 0;
$groups = OC_Group::getUserGroups(OC_User::getUser());
foreach ($groups as $group) {
if ($count < 4) {
if (stripos($group, $_GET['search']) !== false
&& (!isset($_GET['itemShares'])
|| !isset($_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP])
|| !is_array($_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP])
|| !in_array($group, $_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP]))) {
$shareWith[] = array('label' => $group.' (group)', 'value' => array('shareType' => OCP\Share::SHARE_TYPE_GROUP, 'shareWith' => $group));
$count++;
}
} else {
break;
}
}
OC_JSON::success(array('data' => $shareWith));
}
break;
}
}
?>

419
core/js/share.js Normal file
View File

@ -0,0 +1,419 @@
OC.Share={
SHARE_TYPE_USER:0,
SHARE_TYPE_GROUP:1,
SHARE_TYPE_PRIVATE_LINK:3,
SHARE_TYPE_EMAIL:4,
PERMISSION_CREATE:4,
PERMISSION_READ:1,
PERMISSION_UPDATE:2,
PERMISSION_DELETE:8,
PERMISSION_SHARE:16,
itemShares:[],
statuses:[],
droppedDown:false,
loadIcons:function(itemType) {
// Load all share icons
$.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getItemsSharedStatuses', itemType: itemType }, function(result) {
if (result && result.status === 'success') {
$.each(result.data, function(item, hasPrivateLink) {
// Private links override shared in terms of icon display
if (itemType != 'file' && itemType != 'folder') {
if (hasPrivateLink) {
var image = OC.imagePath('core', 'actions/public');
} else {
var image = OC.imagePath('core', 'actions/shared');
}
$('a.share[data-item="'+item+'"]').css('background', 'url('+image+') no-repeat center');
}
OC.Share.statuses[item] = hasPrivateLink;
});
}
});
},
loadItem:function(itemType, item) {
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;
}
}});
}
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) {
if (result && result.status === 'success') {
if (callback) {
callback(result.data);
}
} else {
OC.dialogs.alert(result.data.message, 'Error while sharing');
}
});
},
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) {
if (result && result.status === 'success') {
if (callback) {
callback();
}
} else {
OC.dialogs.alert('Error', 'Error while unsharing');
}
});
},
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) {
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+'">';
html += '<input id="shareWith" type="text" placeholder="Share with" style="width:90%;"/>';
html += '<ul id="shareWithList">';
html += '</ul>';
if (privateLink) {
html += '<div id="privateLink">';
html += '<input type="checkbox" name="privateLinkCheckbox" id="privateLinkCheckbox" value="1" /><label for="privateLinkCheckbox">Share with private link</label>';
html += '<br />';
html += '<input id="privateLinkText" style="display:none; width:90%;" readonly="readonly" />';
html += '</div>';
}
html += '</div>';
$(html).appendTo(appendTo);
// Reset item shares
OC.Share.itemShares = [];
var data = OC.Share.loadItem(itemType, item);
if (data) {
$.each(data, function(index, share) {
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 {
// Suggest sharing via email if valid email address
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']);
}
}
});
// }
},
focus: function(event, focused) {
event.preventDefault();
},
select: function(event, selected) {
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($('#dropdown').data('item-type'), $('#dropdown').data('item'), shareType, shareWith, permissions, function() {
OC.Share.addShareWith(shareType, shareWith, permissions, possiblePermissions);
$('#shareWith').val('');
});
return false;
}
});
$('#dropdown').show('blind', function() {
OC.Share.droppedDown = true;
});
$('#shareWith').focus();
},
hideDropDown:function(callback) {
$('#dropdown').hide('blind', function() {
OC.Share.droppedDown = false;
$('#dropdown').remove();
if (typeof FileActions !== 'undefined') {
$('tr').removeClass('mouseOver');
}
if (callback) {
callback.call();
}
});
},
addShareWith:function(shareType, shareWith, permissions, possiblePermissions) {
if (!OC.Share.itemShares[shareType]) {
OC.Share.itemShares[shareType] = [];
}
OC.Share.itemShares[shareType].push(shareWith);
var editChecked = createChecked = updateChecked = deleteChecked = shareChecked = '';
if (permissions & OC.Share.PERMISSION_CREATE) {
createChecked = 'checked="checked"';
editChecked = 'checked="checked"';
}
if (permissions & OC.Share.PERMISSION_UPDATE) {
updateChecked = 'checked="checked"';
editChecked = 'checked="checked"';
}
if (permissions & OC.Share.PERMISSION_DELETE) {
deleteChecked = 'checked="checked"';
editChecked = 'checked="checked"';
}
if (permissions & OC.Share.PERMISSION_SHARE) {
shareChecked = 'checked="checked"';
}
var html = '<li style="clear: both;" data-share-type="'+shareType+'" data-share-with="'+shareWith+'">';
html += shareWith;
if (possiblePermissions & OC.Share.PERMISSION_CREATE || possiblePermissions & OC.Share.PERMISSION_UPDATE || possiblePermissions & OC.Share.PERMISSION_DELETE) {
if (editChecked == '') {
html += '<label style="display:none;">';
} else {
html += '<label>';
}
html += '<input type="checkbox" name="edit" class="permissions" '+editChecked+' />can edit</label>';
}
html += '<a href="#" class="showCruds" style="display:none;"><img class="svg" alt="Unshare" src="'+OC.imagePath('core', 'actions/triangle-s')+'"/></a>';
html += '<a href="#" class="unshare" style="display:none;"><img class="svg" alt="Unshare" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>';
html += '<div class="cruds" style="display:none;">';
if (possiblePermissions & OC.Share.PERMISSION_CREATE) {
html += '<label><input type="checkbox" name="create" class="permissions" '+createChecked+' data-permissions="'+OC.Share.PERMISSION_CREATE+'" />create</label>';
}
if (possiblePermissions & OC.Share.PERMISSION_UPDATE) {
html += '<label><input type="checkbox" name="update" class="permissions" '+updateChecked+' data-permissions="'+OC.Share.PERMISSION_UPDATE+'" />update</label>';
}
if (possiblePermissions & OC.Share.PERMISSION_DELETE) {
html += '<label><input type="checkbox" name="delete" class="permissions" '+deleteChecked+' data-permissions="'+OC.Share.PERMISSION_DELETE+'" />delete</label>';
}
if (possiblePermissions & OC.Share.PERMISSION_SHARE) {
html += '<label><input type="checkbox" name="share" class="permissions" '+shareChecked+' data-permissions="'+OC.Share.PERMISSION_SHARE+'" />share</label>';
}
html += '</div>';
html += '</li>';
$(html).appendTo('#shareWithList');
},
showPrivateLink:function(item, token) {
$('#privateLinkCheckbox').attr('checked', true);
var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&token='+token;
if (token.indexOf('&path=') == -1) {
link += '&file=' + encodeURIComponent(item).replace(/%2F/g, '/');
} else {
// Disable checkbox if inside a shared parent folder
$('#privateLinkCheckbox').attr('disabled', 'true');
}
$('#privateLinkText').val(link);
$('#privateLinkText').show('blind', function() {
$('#privateLinkText').after('<br id="emailBreak" />');
$('#email').show();
$('#emailButton').show();
});
},
hidePrivateLink:function() {
$('#privateLinkText').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) {
return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
}
}
$(document).ready(function() {
$('a.share').live('click', function(event) {
event.stopPropagation();
if ($(this).data('item-type') !== undefined && $(this).data('item') !== undefined) {
var itemType = $(this).data('item-type');
var item = $(this).data('item');
var appendTo = $(this).parent().parent();
var privateLink = false;
var possiblePermissions = $(this).data('possible-permissions');
if ($(this).data('private-link') !== undefined && $(this).data('private-link') == true) {
privateLink = true;
}
if (OC.Share.droppedDown) {
if (item != $('#dropdown').data('item')) {
OC.Share.hideDropDown(function () {
OC.Share.showDropDown(itemType, item, appendTo, privateLink, possiblePermissions);
});
} else {
OC.Share.hideDropDown();
}
} else {
OC.Share.showDropDown(itemType, item, appendTo, privateLink, possiblePermissions);
}
}
});
if (typeof FileActions !== 'undefined') {
OC.Share.loadIcons('file');
FileActions.register('all', 'Share', FileActions.PERMISSION_SHARE, function(filename) {
// Return the correct sharing icon
if (scanFiles.scanning) { return; } // workaround to prevent additional http request block scanning feedback
var item = $('#dir').val() + filename;
// Check if status is in cache
if (OC.Share.statuses[item] === true) {
return OC.imagePath('core', 'actions/public');
} else if (OC.Share.statuses[item] === false) {
return OC.imagePath('core', 'actions/shared');
} else {
var last = '';
var path = OC.Share.dirname(item);
// Search for possible parent folders that are shared
while (path != last) {
if (OC.Share.statuses[path] === true) {
return OC.imagePath('core', 'actions/public');
} else if (OC.Share.statuses[path] === false) {
return OC.imagePath('core', 'actions/shared');
}
last = path;
path = OC.Share.dirname(path);
}
return OC.imagePath('core', 'actions/share');
}
}, function(filename) {
var item = $('#dir').val() + filename;
if ($('tr').filterAttr('data-file', filename).data('type') == 'dir') {
var itemType = 'folder';
var possiblePermissions = OC.Share.PERMISSION_CREATE | OC.Share.PERMISSION_UPDATE | OC.Share.PERMISSION_DELETE | OC.Share.PERMISSION_SHARE;
} else {
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');
// Check if drop down is already visible for a different file
if (OC.Share.droppedDown) {
if (item != $('#dropdown').data('item')) {
OC.Share.hideDropDown(function () {
$('tr').filterAttr('data-file', filename).addClass('mouseOver');
OC.Share.showDropDown(itemType, item, appendTo, true, possiblePermissions);
});
} else {
OC.Share.hideDropDown();
}
} else {
$('tr').filterAttr('data-file',filename).addClass('mouseOver');
OC.Share.showDropDown(itemType, item, appendTo, true, possiblePermissions);
}
});
}
$(this).click(function(event) {
if (OC.Share.droppedDown && !($(event.target).hasClass('drop')) && $('#dropdown').has(event.target).length === 0) {
OC.Share.hideDropDown();
}
});
$('#shareWithList li').live('mouseenter', function(event) {
// Show permissions and unshare button
$(':hidden', this).filter(':not(.cruds)').show();
});
$('#shareWithList li').live('mouseleave', function(event) {
// Hide permissions and unshare button
if (!$('.cruds', this).is(':visible')) {
$('a', this).hide();
if (!$('input[name="edit"]', this).is(':checked')) {
$('input:[type=checkbox]', this).hide();
$('label', this).hide();
}
} else {
$('a.unshare', this).hide();
}
});
$('.showCruds').live('click', function() {
$(this).parent().find('.cruds').toggle();
});
$('.unshare').live('click', 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() {
$(li).remove();
var index = OC.Share.itemShares[shareType].indexOf(shareWith);
OC.Share.itemShares[shareType].splice(index, 1);
});
});
$('.permissions').live('change', function() {
if ($(this).attr('name') == 'edit') {
var li = $(this).parent().parent()
var checkboxes = $('.permissions', li);
var checked = $(this).is(':checked');
// Check/uncheck Create, Update, and Delete checkboxes if Edit is checked/unck
$(checkboxes).filter('input[name="create"]').attr('checked', checked);
$(checkboxes).filter('input[name="update"]').attr('checked', checked);
$(checkboxes).filter('input[name="delete"]').attr('checked', checked);
} else {
var li = $(this).parent().parent().parent();
var checkboxes = $('.permissions', li);
// Uncheck Edit if Create, Update, and Delete are not checked
if (!$(this).is(':checked') && !$(checkboxes).filter('input[name="create"]').is(':checked') && !$(checkboxes).filter('input[name="update"]').is(':checked') && !$(checkboxes).filter('input[name="delete"]').is(':checked')) {
$(checkboxes).filter('input[name="edit"]').attr('checked', false);
// Check Edit if Create, Update, or Delete is checked
} else if (($(this).attr('name') == 'create' || $(this).attr('name') == 'update' || $(this).attr('name') == 'delete')) {
$(checkboxes).filter('input[name="edit"]').attr('checked', true);
}
}
var permissions = OC.Share.PERMISSION_READ;
$(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);
});
$('#privateLinkCheckbox').live('change', function() {
var itemType = $('#dropdown').data('item-type');
var item = $('#dropdown').data('item');
if (this.checked) {
// Create a private link
OC.Share.share(itemType, item, OC.Share.SHARE_TYPE_PRIVATE_LINK, 0, 0, function(token) {
OC.Share.showPrivateLink(item, 'foo');
// Change icon
OC.Share.icons[item] = OC.imagePath('core', 'actions/public');
});
} else {
// Delete private link
OC.Share.unshare(item, 'public', function() {
OC.Share.hidePrivateLink();
// 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() {
$(this).focus();
$(this).select();
});
$('#emailPrivateLink').live('submit', function() {
OC.Share.emailPrivateLink();
});
});

View File

@ -506,6 +506,121 @@
</table>
<table>
<name>*dbprefix*share</name>
<declaration>
<field>
<name>id</name>
<autoincrement>1</autoincrement>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<length>4</length>
</field>
<field>
<name>share_type</name>
<type>integer</type>
<default></default>
<notnull>true</notnull>
<length>1</length>
</field>
<field>
<name>share_with</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>255</length>
</field>
<field>
<name>uid_owner</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>255</length>
</field>
<field>
<name>parent</name>
<type>integer</type>
<default></default>
<notnull>false</notnull>
<length>4</length>
</field>
<field>
<name>item_type</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>item_source</name>
<type>text</type>
<default></default>
<notnull>false</notnull>
<length>255</length>
</field>
<field>
<name>item_target</name>
<type>text</type>
<default></default>
<notnull>false</notnull>
<length>255</length>
</field>
<field>
<name>file_source</name>
<type>integer</type>
<default></default>
<notnull>false</notnull>
<length>4</length>
</field>
<field>
<name>file_target</name>
<type>text</type>
<default></default>
<notnull>false</notnull>
<length>512</length>
</field>
<field>
<name>permissions</name>
<type>integer</type>
<default></default>
<notnull>true</notnull>
<length>1</length>
</field>
<field>
<name>stime</name>
<type>integer</type>
<default></default>
<notnull>true</notnull>
<length>8</length>
</field>
<field>
<name>accepted</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<length>1</length>
</field>
</declaration>
</table>
<table>
<name>*dbprefix*queuedtasks</name>

View File

@ -358,6 +358,10 @@ class OC_FileCache{
$eventSource->send('scanning',array('file'=>$path,'count'=>$count));
}
$lastSend=$count;
// NOTE: Ugly hack to prevent shared files from going into the cache (the source already exists somewhere in the cache)
if (substr($path, 0, 7) == '/Shared') {
return;
}
if($root===false){
$view=OC_Filesystem::getView();
}else{
@ -395,6 +399,10 @@ class OC_FileCache{
* @return int size of the scanned file
*/
public static function scanFile($path,$root=false){
// NOTE: Ugly hack to prevent shared files from going into the cache (the source already exists somewhere in the cache)
if (substr($path, 0, 7) == '/Shared') {
return;
}
if($root===false){
$view=OC_Filesystem::getView();
}else{

View File

@ -37,10 +37,38 @@ class OC_Files {
if($directory=='/'){
$directory='';
}
$files=OC_FileCache::getFolderContent($directory, false, $mimetype_filter);
foreach($files as &$file){
$file['directory']=$directory;
$file['type']=($file['mimetype']=='httpd/unix-directory')?'dir':'file';
$files = array();
if (substr($directory, 0, 7) == '/Shared') {
if ($directory == '/Shared') {
$files = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_File::FORMAT_FILE_APP, array('folder' => $directory, 'mimetype_filter' => $mimetype_filter));
} else {
$pos = strpos($directory, '/', 8);
// Get shared folder name
if ($pos !== false) {
$itemTarget = substr($directory, 7, $pos - 7);
} else {
$itemTarget = substr($directory, 7);
}
$files = OCP\Share::getItemSharedWith('folder', $itemTarget, OC_Share_Backend_File::FORMAT_FILE_APP, array('folder' => $directory, 'mimetype_filter' => $mimetype_filter));
}
} else {
$files = OC_FileCache::getFolderContent($directory, false, $mimetype_filter);
foreach ($files as &$file) {
$file['directory'] = $directory;
$file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file';
$permissions = OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE;
if ($file['type'] == 'dir' && $file['writable']) {
$permissions |= OCP\Share::PERMISSION_CREATE;
}
if ($file['writable']) {
$permissions |= OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_DELETE;
}
$file['permissions'] = $permissions;
}
if ($directory == '') {
// Add 'Shared' folder
$files = array_merge($files, OCP\Share::getItemsSharedWith('file', OC_Share_Backend_File::FORMAT_FILE_APP_ROOT));
}
}
usort($files, "fileCmp");//TODO: remove this once ajax is merged
return $files;
@ -108,8 +136,7 @@ class OC_Files {
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($filename));
}else{
$fileData=OC_FileCache::get($filename);
header('Content-Type: ' . $fileData['mimetype']);
header('Content-Type: '.OC_Filesystem::getMimeType($filename));
}
}elseif($zip or !OC_Filesystem::file_exists($filename)){
header("HTTP/1.0 404 Not Found");

View File

@ -33,8 +33,11 @@ abstract class OC_Filestorage{
abstract public function stat($path);
abstract public function filetype($path);
abstract public function filesize($path);
abstract public function is_readable($path);
abstract public function is_writable($path);
abstract public function isCreatable($path);
abstract public function isReadable($path);
abstract public function isUpdatable($path);
abstract public function isDeletable($path);
abstract public function isSharable($path);
abstract public function file_exists($path);
abstract public function filectime($path);
abstract public function filemtime($path);

View File

@ -54,8 +54,17 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
return $stat['size'];
}
}
// abstract public function is_readable($path);
// abstract public function is_writable($path);
public function isCreatable($path) {
return $this->isUpdatable($path);
}
// abstract public function isReadable($path);
// abstract public function isUpdatable($path);
public function isDeletable($path) {
return $this->isUpdatable($path);
}
public function isSharable($path) {
return $this->isReadable($path);
}
// abstract public function file_exists($path);
public function filectime($path) {
$stat = $this->stat($path);

View File

@ -51,11 +51,11 @@ class OC_Filestorage_CommonTest extends OC_Filestorage_Common{
public function filetype($path){
return $this->storage->filetype($path);
}
public function is_readable($path){
return $this->storage->is_readable($path);
public function isReadable($path){
return $this->storage->isReadable($path);
}
public function is_writable($path){
return $this->storage->is_writable($path);
public function isUpdatable($path){
return $this->storage->isUpdatable($path);
}
public function file_exists($path){
return $this->storage->file_exists($path);

View File

@ -45,10 +45,10 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{
return filesize($this->datadir.$path);
}
}
public function is_readable($path){
public function isReadable($path){
return is_readable($this->datadir.$path);
}
public function is_writable($path){
public function isUpdatable($path){
return is_writable($this->datadir.$path);
}
public function file_exists($path){
@ -85,7 +85,7 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{
return $this->delTree($path);
}
public function rename($path1,$path2){
if (!$this->is_writable($path1)) {
if (!$this->isUpdatable($path1)) {
OC_Log::write('core','unable to rename, file is not writable : '.$path1,OC_Log::ERROR);
return false;
}
@ -128,7 +128,7 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{
}
public function getMimeType($path){
if($this->is_readable($path)){
if($this->isReadable($path)){
return OC_Helper::getMimeType($this->datadir.$path);
}else{
return false;

View File

@ -426,12 +426,33 @@ class OC_Filesystem{
static public function readfile($path){
return self::$defaultInstance->readfile($path);
}
/**
* @deprecated Replaced by isReadable() as part of CRUDS
*/
static public function is_readable($path){
return self::$defaultInstance->is_readable($path);
}
/**
* @deprecated Replaced by isCreatable(), isUpdatable(), isDeletable() as part of CRUDS
*/
static public function is_writable($path){
return self::$defaultInstance->is_writable($path);
}
static public function isCreatable($path) {
return self::$defaultInstance->isCreatable($path);
}
static public function isReadable($path) {
return self::$defaultInstance->isReadable($path);
}
static public function isUpdatable($path) {
return self::$defaultInstance->isUpdatable($path);
}
static public function isDeletable($path) {
return self::$defaultInstance->isDeletable($path);
}
static public function isSharable($path) {
return self::$defaultInstance->isSharable($path);
}
static public function file_exists($path){
return self::$defaultInstance->file_exists($path);
}

View File

@ -211,11 +211,32 @@ class OC_FilesystemView {
}
return false;
}
public function is_readable($path) {
return $this->basicOperation('is_readable', $path);
/**
* @deprecated Replaced by isReadable() as part of CRUDS
*/
public function is_readable($path){
return $this->basicOperation('isReadable',$path);
}
public function is_writable($path) {
return $this->basicOperation('is_writable', $path);
/**
* @deprecated Replaced by isCreatable(), isUpdatable(), isDeletable() as part of CRUDS
*/
public function is_writable($path){
return $this->basicOperation('isUpdatable',$path);
}
public function isCreatable($path) {
return $this->basicOperation('isCreatable', $path);
}
public function isReadable($path) {
return $this->basicOperation('isReadable', $path);
}
public function isUpdatable($path) {
return $this->basicOperation('isUpdatable', $path);
}
public function isDeletable($path) {
return $this->basicOperation('isDeletable', $path);
}
public function isSharable($path) {
return $this->basicOperation('isSharable', $path);
}
public function file_exists($path) {
if($path=='/'){

View File

@ -105,6 +105,7 @@ abstract class OC_Group_Backend implements OC_Group_Interface {
*
* Returns a list with all groups
*/
public function getGroups($search = '', $limit = -1, $offset = 0) {
return array();
}
@ -115,7 +116,7 @@ abstract class OC_Group_Backend implements OC_Group_Interface {
* @return bool
*/
public function groupExists($gid){
return in_array($gid, $this->getGroups());
return in_array($gid, $this->getGroups($gid, 1));
}
/**

View File

@ -178,6 +178,20 @@ class OC_Group_Database extends OC_Group_Backend {
return $groups;
}
/**
* check if a group exists
* @param string $gid
* @return bool
*/
public function groupExists($gid) {
$query = OC_DB::prepare('SELECT gid FROM *PREFIX*groups WHERE gid = ?');
$result = $query->execute(array($gid))->fetchOne();
if ($result) {
return true;
}
return false;
}
/**
* @brief get a list of all users in a group
* @returns array with user ids

1054
lib/public/share.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -31,13 +31,13 @@ abstract class Test_FileStorage extends UnitTestCase {
*/
public function testRoot(){
$this->assertTrue($this->instance->file_exists('/'),'Root folder does not exist');
$this->assertTrue($this->instance->is_readable('/'),'Root folder is not readable');
$this->assertTrue($this->instance->isReadable('/'),'Root folder is not readable');
$this->assertTrue($this->instance->is_dir('/'),'Root folder is not a directory');
$this->assertFalse($this->instance->is_file('/'),'Root folder is a file');
$this->assertEqual('dir',$this->instance->filetype('/'));
//without this, any further testing would be useless, not an acutal requirement for filestorage though
$this->assertTrue($this->instance->is_writable('/'),'Root folder is not writable');
$this->assertTrue($this->instance->isUpdatable('/'),'Root folder is not writable');
}
public function testDirectories(){
@ -50,8 +50,8 @@ abstract class Test_FileStorage extends UnitTestCase {
$this->assertFalse($this->instance->is_file('/folder'));
$this->assertEqual('dir',$this->instance->filetype('/folder'));
$this->assertEqual(0,$this->instance->filesize('/folder'));
$this->assertTrue($this->instance->is_readable('/folder'));
$this->assertTrue($this->instance->is_writable('/folder'));
$this->assertTrue($this->instance->isReadable('/folder'));
$this->assertTrue($this->instance->isUpdatable('/folder'));
$dh=$this->instance->opendir('/');
$content=array();
@ -154,7 +154,7 @@ abstract class Test_FileStorage extends UnitTestCase {
$textFile=OC::$SERVERROOT.'/tests/data/lorem.txt';
$ctimeStart=time();
$this->instance->file_put_contents('/lorem.txt',file_get_contents($textFile));
$this->assertTrue($this->instance->is_readable('/lorem.txt'));
$this->assertTrue($this->instance->isReadable('/lorem.txt'));
$ctimeEnd=time();
$cTime=$this->instance->filectime('/lorem.txt');
$mTime=$this->instance->filemtime('/lorem.txt');

View File

@ -0,0 +1,67 @@
<?php
/**
* ownCloud
*
* @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
class Test_Share_Backend implements OCP\Share_Backend {
const FORMAT_SOURCE = 0;
const FORMAT_TARGET = 1;
const FORMAT_PERMISSIONS = 2;
private $testItem = 'test.txt';
public function isValidSource($itemSource, $uidOwner) {
if ($itemSource == $this->testItem) {
return true;
}
}
public function generateTarget($itemSource, $shareWith, $exclude = null) {
$target = $itemSource;
if (isset($exclude)) {
$pos = strrpos($target, '.');
$name = substr($target, 0, $pos);
$ext = substr($target, $pos);
$append = '';
$i = 1;
while (in_array($name.$append.$ext, $exclude)) {
$append = $i;
$i++;
}
$target = $name.$append.$ext;
}
return $target;
}
public function formatItems($items, $format, $parameters = null) {
$testItems = array();
foreach ($items as $item) {
if ($format == self::FORMAT_SOURCE) {
$testItems[] = $item['item_source'];
} else if ($format == self::FORMAT_TARGET) {
$testItems[] = $item['item_target'];
} else if ($format == self::FORMAT_PERMISSIONS) {
$testItems[] = $item['permissions'];
}
}
return $testItems;
}
}

380
tests/lib/share/share.php Normal file
View File

@ -0,0 +1,380 @@
<?php
/**
* ownCloud
*
* @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
class Test_Share extends UnitTestCase {
protected $itemType;
protected $userBackend;
protected $user1;
protected $user2;
protected $groupBackend;
protected $group1;
protected $group2;
public function setUp() {
OC_User::clearBackends();
OC_User::useBackend('dummy');
$this->user1 = uniqid('user_');
$this->user2 = uniqid('user_');
$this->user3 = uniqid('user_');
$this->user4 = uniqid('user_');
OC_User::createUser($this->user1, 'pass');
OC_User::createUser($this->user2, 'pass');
OC_User::createUser($this->user3, 'pass');
OC_User::createUser($this->user4, 'pass');
OC_User::setUserId($this->user1);
OC_Group::clearBackends();
OC_Group::useBackend(new OC_Group_Dummy);
$this->group1 = uniqid('group_');
$this->group2 = uniqid('group_');
OC_Group::createGroup($this->group1);
OC_Group::createGroup($this->group2);
OC_Group::addToGroup($this->user1, $this->group1);
OC_Group::addToGroup($this->user2, $this->group1);
OC_Group::addToGroup($this->user3, $this->group1);
OC_Group::addToGroup($this->user2, $this->group2);
OC_Group::addToGroup($this->user4, $this->group2);
OCP\Share::registerBackend('test', 'Test_Share_Backend');
}
public function tearDown() {
$query = OC_DB::prepare('DELETE FROM *PREFIX*share WHERE item_type = ?');
$query->execute(array('test'));
}
public function testShareInvalidShareType() {
$this->expectException(new Exception('Share type foobar is not valid for test.txt'));
OCP\Share::shareItem('test', 'test.txt', 'test.txt', 'foobar', $this->user2, OCP\Share::PERMISSION_READ);
}
public function testInvalidItemType() {
$message = 'Sharing backend for foobar not found';
try {
OCP\Share::shareItem('foobar', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
try {
OCP\Share::getItemsSharedWith('foobar');
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
try {
OCP\Share::getItemSharedWith('foobar', 'test.txt');
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
try {
OCP\Share::getItemSharedWithBySource('foobar', 'test.txt');
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
try {
OCP\Share::getItemShared('foobar', 'test.txt');
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
try {
OCP\Share::unshare('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
try {
OCP\Share::setPermissions('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_UPDATE);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
}
public function testShareWithUser() {
// Invalid shares
$message = 'Sharing test.txt failed, because the user '.$this->user1.' is the item owner';
try {
OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\Share::PERMISSION_READ);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
$message = 'Sharing test.txt failed, because the user foobar does not exist';
try {
OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, 'foobar', OCP\Share::PERMISSION_READ);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
$message = 'Sharing foobar failed, because the sharing backend for test could not find its source';
try {
OCP\Share::shareItem('test', 'foobar', 'foobar', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
// Valid share
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ));
$this->assertEqual(OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt'));
OC_User::setUserId($this->user2);
$this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt'));
// Attempt to share again
OC_User::setUserId($this->user1);
$message = 'Sharing test.txt failed, because this item is already shared with '.$this->user2;
try {
OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
// Attempt to share back
OC_User::setUserId($this->user2);
$message = 'Sharing test.txt failed, because the user '.$this->user1.' is the original sharer';
try {
OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\Share::PERMISSION_READ);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
// Unshare
OC_User::setUserId($this->user1);
$this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2));
// Attempt reshare without share permission
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ));
OC_User::setUserId($this->user2);
$message = 'Sharing test.txt failed, because resharing is not allowed';
try {
OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
// Owner grants share and update permission
OC_User::setUserId($this->user1);
$this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_SHARE));
// Attempt reshare with escalated permissions
OC_User::setUserId($this->user2);
$message = 'Sharing test.txt failed, because the permissions exceed permissions granted to '.$this->user2;
try {
OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
// Valid reshare
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE));
$this->assertEqual(OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt'));
OC_User::setUserId($this->user3);
$this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt'));
$this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE));
// Attempt to escalate permissions
OC_User::setUserId($this->user2);
$message = 'Setting permissions for test.txt failed, because the permissions exceed permissions granted to '.$this->user2;
try {
OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
// Remove update permission
OC_User::setUserId($this->user1);
$this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE));
OC_User::setUserId($this->user2);
$this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE));
OC_User::setUserId($this->user3);
$this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ));
// Remove share permission
OC_User::setUserId($this->user1);
$this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ));
OC_User::setUserId($this->user2);
$this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ));
OC_User::setUserId($this->user3);
$this->assertFalse(OCP\Share::getItemSharedWith('test', 'test.txt'));
// Reshare again, and then have owner unshare
OC_User::setUserId($this->user1);
$this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE));
OC_User::setUserId($this->user2);
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ));
OC_User::setUserId($this->user1);
$this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2));
OC_User::setUserId($this->user2);
$this->assertFalse(OCP\Share::getItemSharedWith('test', 'test.txt'));
OC_User::setUserId($this->user3);
$this->assertFalse(OCP\Share::getItemSharedWith('test', 'test.txt'));
// Attempt target conflict
OC_User::setUserId($this->user1);
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ));
OC_User::setUserId($this->user3);
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ));
OC_User::setUserId($this->user2);
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt', 'test1.txt'));
// Remove user
OC_User::deleteUser($this->user1);
OC_User::setUserId($this->user2);
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test1.txt'));
}
public function testShareWithGroup() {
// Invalid shares
$message = 'Sharing test.txt failed, because the group foobar does not exist';
try {
OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, 'foobar', OCP\Share::PERMISSION_READ);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
$message = 'Sharing test.txt failed, because '.$this->user1.' is not a member of the group '.$this->group2;
try {
OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group2, OCP\Share::PERMISSION_READ);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
// Valid share
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ));
$this->assertEqual(OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt'));
OC_User::setUserId($this->user2);
$this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt'));
OC_User::setUserId($this->user3);
$this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt'));
// Attempt to share again
OC_User::setUserId($this->user1);
$message = 'Sharing test.txt failed, because this item is already shared with '.$this->group1;
try {
OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
// Attempt to share back to owner of group share
OC_User::setUserId($this->user2);
$message = 'Sharing test.txt failed, because the user '.$this->user1.' is the original sharer';
try {
OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\Share::PERMISSION_READ);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
// Attempt to share back to group
$message = 'Sharing test.txt failed, because the item was orignally shared with the group '.$this->group1;
try {
OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
// Attempt to share back to member of group
$message = 'Sharing test.txt failed, because the user '.$this->user3.' is a member of the original group share';
try {
OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ);
$this->fail('Exception was expected: '.$message);
} catch (Exception $exception) {
$this->assertEqual($exception->getMessage(), $message);
}
// Unshare
OC_User::setUserId($this->user1);
$this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1));
// Valid share with same person - user then group
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE | OCP\Share::PERMISSION_SHARE));
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE));
OC_User::setUserId($this->user2);
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt'));
$this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_DELETE | OCP\Share::PERMISSION_SHARE));
OC_User::setUserId($this->user3);
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt'));
$this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE));
// Valid reshare
OC_User::setUserId($this->user2);
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\Share::PERMISSION_READ));
OC_User::setUserId($this->user4);
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt'));
// Unshare from user only
OC_User::setUserId($this->user1);
$this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2));
OC_User::setUserId($this->user2);
$this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE));
OC_User::setUserId($this->user4);
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array());
// Valid share with same person - group then user
OC_User::setUserId($this->user1);
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE));
OC_User::setUserId($this->user2);
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt'));
$this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_DELETE));
// Unshare from group only
OC_User::setUserId($this->user1);
$this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1));
OC_User::setUserId($this->user2);
$this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE));
// Attempt user specific target conflict
OC_User::setUserId($this->user3);
$this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE));
OC_User::setUserId($this->user2);
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt', 'test1.txt'));
// Valid reshare TODO Broken
$this->assertTrue(OCP\Share::shareItem('test', 'test1.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE));
OC_User::setUserId($this->user4);
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test1.txt'));
// Remove user from group
OC_Group::removeFromGroup($this->user2, $this->group1);
OC_User::setUserId($this->user2);
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt'));
OC_User::setUserId($this->user4);
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array());
// Add user to group
// Remove group
}
}