summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-02-12 17:00:33 +0100
committerBjörn Schießle <schiessle@owncloud.com>2013-02-12 17:00:33 +0100
commita692264fa416fec44d774bd955a06a65c7c0d158 (patch)
treed8c511f9e05ff523efe437a877c72fdddbb25360
parentd1bbb30385260d77b01bc5998465ebe68ccd83d7 (diff)
downloadnextcloud-server-a692264fa416fec44d774bd955a06a65c7c0d158.tar.gz
nextcloud-server-a692264fa416fec44d774bd955a06a65c7c0d158.zip
add option to keep duplicates in the list of users with access to a file, e.g. for the unshare operation we need to know if access was granted more than once, for example as group share and as individual share
-rw-r--r--apps/files_encryption/hooks/hooks.php6
-rw-r--r--apps/files_encryption/lib/proxy.php11
-rw-r--r--lib/public/share.php17
3 files changed, 16 insertions, 18 deletions
diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php
index ffd3e4544f1..5e06948aa50 100644
--- a/apps/files_encryption/hooks/hooks.php
+++ b/apps/files_encryption/hooks/hooks.php
@@ -182,7 +182,7 @@ class Hooks {
$path = Util::getFilePath($params['itemSource']);
- $shares = \OCP\Share::getUsersSharingFile( $path, 1 );
+ $shares = \OCP\Share::getUsersSharingFile( $path, true );
return Crypt::encKeyfileToMultipleUsers($shares, $path);
@@ -194,11 +194,11 @@ class Hooks {
public static function preUnshare( $params ) {
$path = Util::getFilePath($params['itemSource']);
- $shares = \OCP\Share::getUsersSharingFile( $path, 1 );
+ $shares = \OCP\Share::getUsersSharingFile( $path, true, false );
// remove the user from the list from which the file will be unshared
unset($shares[$params['shareWith']]);
- return Crypt::encKeyfileToMultipleUsers($shares, $path );
+ return Crypt::encKeyfileToMultipleUsers(array_unique($shares), $path );
}
/**
diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index 40ac411539b..3e4178e8a87 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -118,15 +118,8 @@ class Proxy extends \OC_FileProxy {
// $fileOwner = \OC\Files\Filesystem::getOwner( $path );
// List everyone sharing the file
- $shares = \OCP\Share::getUsersSharingFile( $filePath, 1 );
-
- $userIds = array();
-
- foreach ( $shares as $share ) {
-
- $userIds[] = $share['userId'];
-
- }
+ //TODO check, is this path always the path to the source file?
+ $userIds = \OCP\Share::getUsersSharingFile( $filePath, true );
$publicKeys = Keymanager::getPublicKeys( $rootView, $userIds );
diff --git a/lib/public/share.php b/lib/public/share.php
index 55ff4d4738f..68f5e93baa7 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -145,11 +145,14 @@ class Share {
/**
* @brief Find which users can access a shared item
- * @return bool / array
+ * @param $path to the file
+ * @param include owner to the list of users with access to the file
+ * @param remove duplicates in the result
+ * @return 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, $includeOwner = 0 ) {
+ public static function getUsersSharingFile( $path, $includeOwner = false, $removeDuplicates = true ) {
$user = \OCP\User::getUser();
$path_parts = explode(DIRECTORY_SEPARATOR, trim($path, DIRECTORY_SEPARATOR));
@@ -204,14 +207,16 @@ class Share {
if ( ! empty( $shares ) ) {
// Include owner in list of users, if requested
- if ( $includeOwner == 1 ) {
+ if ( $includeOwner ) {
$shares[] = $user;
}
+ }
+
+ if ( $removeDuplicates )
return array_unique($shares);
- } else {
- return false;
+ else {
+ return $shares;
}
-
}
/**