summaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-02-12 12:08:34 +0100
committerBjörn Schießle <schiessle@owncloud.com>2013-02-12 12:08:34 +0100
commit8eef919a754ff3404df1065d616e66cb9b1ff437 (patch)
treef37515958f17daaaa4fa00f47c2c0561e4d3568c /lib/public
parent5a64c96d06db50c3ca13bb3c6c10c3a0e32a3380 (diff)
downloadnextcloud-server-8eef919a754ff3404df1065d616e66cb9b1ff437.tar.gz
nextcloud-server-8eef919a754ff3404df1065d616e66cb9b1ff437.zip
take group shares into account if we retrieve the list a all recipients
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/share.php65
1 files changed, 30 insertions, 35 deletions
diff --git a/lib/public/share.php b/lib/public/share.php
index 4170783d71e..841240692d8 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -149,62 +149,57 @@ class Share {
* @note $path needs to be relative to user data dir, e.g. 'file.txt'
* not '/admin/data/file.txt'
*/
- public static function getUsersSharingFile( $path, $includeOwner = 0 ) {
-
- $fPath = self::prepFileTarget( $path );
-
+ public static function getUsersSharingFile( $source, $includeOwner = 0 ) {
+ //TODO get also the recipients from folders which are shared above the current file
// Fetch all shares of this file path from DB
$query = \OC_DB::prepare(
- 'SELECT
- share_type
- , share_with
- , uid_owner
- , permissions
+ 'SELECT share_with
FROM
`*PREFIX*share`
WHERE
- file_target = ?'
+ item_source = ? AND share_type = ? AND uid_owner = ?'
);
- $result = $query->execute( array( $fPath ) );
+ $result = $query->execute( array( $source, self::SHARE_TYPE_USER, \OCP\User::getUser() ) );
if ( \OC_DB::isError( $result ) ) {
-
- \OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result) . ', path=' . $fPath, \OC_Log::ERROR );
-
+ \OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR );
}
$shares = array();
while( $row = $result->fetchRow() ) {
+ $shares[] = $row['share_with'];
+ }
- // 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']
- );
+ // We also need to take group shares into account
+
+ $query = \OC_DB::prepare(
+ 'SELECT share_with
+ FROM
+ `*PREFIX*share`
+ WHERE
+ item_source = ? AND share_type = ? AND uid_owner = ?'
+ );
+ $result = $query->execute( array( $source, self::SHARE_TYPE_GROUP, \OCP\User::getUser() ) );
+
+ if ( \OC_DB::isError( $result ) ) {
+ \OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR );
}
+ while( $row = $result->fetchRow() ) {
+ $usersInGroup = \OC_Group::usersInGroup($row['share_with']);
+ $shares = array_merge($shares, $usersInGroup);
+ }
+
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
- );
-
+ $shares[] = \OCP\User::getUser();
}
-
- return $shares;
+
+ return array_unique($shares);
} else {
@@ -235,7 +230,7 @@ class Share {
public static function getItemSharedWith($itemType, $itemTarget, $format = self::FORMAT_NONE, $parameters = null, $includeCollections = false) {
return self::getItems($itemType, $itemTarget, self::$shareTypeUserAndGroups, \OC_User::getUser(), null, $format, $parameters, 1, $includeCollections);
}
-
+
/**
* @brief Get the item of item type shared with the current user by source
* @param string Item type