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
This commit is contained in:
parent
d1bbb30385
commit
a692264fa4
|
@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
return array_unique($shares);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if ( $removeDuplicates )
|
||||
return array_unique($shares);
|
||||
else {
|
||||
return $shares;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue