Conflicts: apps/contacts/lib/vcard.php apps/files/index.php lib/files.phpremotes/origin/stable45
commit
82d81e8d39
@ -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; |
||||
} |
||||
|
||||
} |
@ -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; |
||||
} |
||||
|
||||
} |
@ -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 { |
||||
|
||||
} |
||||
|
||||
|
||||
?> |
@ -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; |
||||
} |
||||
|
||||
} |
@ -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; |
||||
} |
||||
|
||||
} |
@ -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) { |
||||
|
||||
} |
||||
} |
||||
|
||||
?> |
@ -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; |
||||
// |
||||
// } |
||||
|
||||
?> |
@ -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')); |
||||
|
@ -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); |
||||
?> |
@ -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(); |
||||
} |
||||
|
||||
} |
@ -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; |
||||
} |
||||
|
||||
} |
@ -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> |
@ -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') |
||||
) |
||||
) |
||||
); |
||||
|
||||
?> |
@ -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) { |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
?> |
@ -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; |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
?> |
@ -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; |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
?> |
@ -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; |
||||
} |
||||
} |
||||
|
||||
?> |
@ -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(); |
||||
}); |
||||
}); |
File diff suppressed because it is too large
Load Diff
@ -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; |
||||
} |
||||
|
||||
} |
@ -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 |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue