summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSam Tuke <samtuke@owncloud.com>2013-02-11 10:21:23 +0000
committerSam Tuke <samtuke@owncloud.com>2013-02-11 10:21:23 +0000
commit92f06243be62945b5ff5e7542e9984f7bb45d74b (patch)
tree2a5438297946a2e85ec1563d7fd480f78bc172e3 /lib
parentb3e59ca1e31f162d7ac720d8729958f438b23a02 (diff)
downloadnextcloud-server-92f06243be62945b5ff5e7542e9984f7bb45d74b.tar.gz
nextcloud-server-92f06243be62945b5ff5e7542e9984f7bb45d74b.zip
Implementing sharing support
New file-specific methods in lib/public/share Changes to how keyfiles are stored
Diffstat (limited to 'lib')
-rw-r--r--lib/public/share.php82
1 files changed, 75 insertions, 7 deletions
diff --git a/lib/public/share.php b/lib/public/share.php
index 936f85021c0..4170783d71e 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -93,19 +93,72 @@ class Share {
}
/**
+ * @brief Prepare a path to be passed to DB as file_target
+ * @return string Prepared path
+ */
+ public static function prepFileTarget( $path ) {
+
+ // Paths in DB are stored with leading slashes, so add one if necessary
+ if ( substr( $path, 0, 1 ) !== '/' ) {
+
+ $path = '/' . $path;
+
+ }
+
+ return $path;
+
+ }
+
+ public static function isSharedFile( $path ) {
+
+ $fPath = self::prepFileTarget( $path );
+
+ // Fetch all shares of this file path from DB
+ $query = \OC_DB::prepare(
+ 'SELECT
+ id
+ FROM
+ `*PREFIX*share`
+ WHERE
+ file_target = ?'
+ );
+
+ $result = $query->execute( array( $fPath ) );
+
+ if ( \OC_DB::isError( $result ) ) {
+
+ \OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage( $result ) . ', path=' . $fPath, \OC_Log::ERROR );
+
+ }
+
+ if ( $result->fetchRow() !== false ) {
+
+ return true;
+
+ } else {
+
+ return false;
+
+ }
+
+ }
+
+ /**
* @brief Find which users can access a shared item
- * @param string Item type
- * @param int Format (optional) Format type must be defined by the backend
- * @param int Number of items to return (optional) Returns all by default
- * @return Return depends on format
+ * @return bool / array
+ * @note $path needs to be relative to user data dir, e.g. 'file.txt'
+ * not '/admin/data/file.txt'
*/
- public static function getUsersSharingFile( $path ) {
+ public static function getUsersSharingFile( $path, $includeOwner = 0 ) {
+
+ $fPath = self::prepFileTarget( $path );
// Fetch all shares of this file path from DB
$query = \OC_DB::prepare(
'SELECT
share_type
, share_with
+ , uid_owner
, permissions
FROM
`*PREFIX*share`
@@ -113,11 +166,11 @@ class Share {
file_target = ?'
);
- $result = $query->execute( array( $path ) );
+ $result = $query->execute( array( $fPath ) );
if ( \OC_DB::isError( $result ) ) {
- \OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result) . ', path=' . $path, \OC_Log::ERROR );
+ \OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result) . ', path=' . $fPath, \OC_Log::ERROR );
}
@@ -128,6 +181,7 @@ class Share {
// Set helpful array keys
$shares[] = array(
'userId' => $row['share_with']
+ , 'owner' => $row['uid_owner'] // we just set this so it can be used once, hugly hack :/
, 'shareType' => $row['share_type']
, 'permissions' => $row['permissions']
);
@@ -136,6 +190,20 @@ class Share {
if ( ! empty( $shares ) ) {
+ // Include owner in list of users, if requested
+ if ( $includeOwner == 1 ) {
+
+ // NOTE: The values are incorrect for shareType and
+ // permissions of the owner; we just include them for
+ // optional convenience
+ $shares[] = array(
+ 'userId' => $shares[0]['owner']
+ , 'shareType' => 0
+ , 'permissions' => 0
+ );
+
+ }
+
return $shares;
} else {