fix sharing of folders. First we need to collect all files. Than we need to find all users with access to the file because this can vary from file to file and than we can encrypt it for all recipients
This commit is contained in:
parent
12785b93f1
commit
a2ba3c8a43
|
@ -184,9 +184,8 @@ class Hooks {
|
||||||
// [fileTarget] => /test8
|
// [fileTarget] => /test8
|
||||||
// [id] => 10
|
// [id] => 10
|
||||||
// [token] =>
|
// [token] =>
|
||||||
|
|
||||||
// TODO: Should other kinds of item be encrypted too?
|
// TODO: Should other kinds of item be encrypted too?
|
||||||
if ( $params['itemType'] === 'file' ) {
|
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
|
||||||
|
|
||||||
$view = new \OC_FilesystemView('/');
|
$view = new \OC_FilesystemView('/');
|
||||||
$session = new Session($view);
|
$session = new Session($view);
|
||||||
|
@ -195,38 +194,35 @@ class Hooks {
|
||||||
$path = $util->fileIdToPath($params['itemSource']);
|
$path = $util->fileIdToPath($params['itemSource']);
|
||||||
|
|
||||||
$sharingEnabled = \OCP\Share::isEnabled();
|
$sharingEnabled = \OCP\Share::isEnabled();
|
||||||
|
|
||||||
|
if ($params['itemType'] === 'folder') {
|
||||||
|
//list($owner, $ownerPath) = $util->getUidAndFilename($filePath);
|
||||||
|
$allFiles = $util->getAllFiles($path);
|
||||||
|
} else {
|
||||||
|
$allFiles = array($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($allFiles as $path) {
|
||||||
$usersSharing = $util->getSharingUsersArray($sharingEnabled, $path);
|
$usersSharing = $util->getSharingUsersArray($sharingEnabled, $path);
|
||||||
|
|
||||||
// Recursively expand path to include subfiles
|
|
||||||
$allPaths = $util->getPaths( $path );
|
|
||||||
|
|
||||||
$failed = array();
|
$failed = array();
|
||||||
|
|
||||||
// Loop through all subfiles
|
|
||||||
foreach ( $allPaths as $path ) {
|
|
||||||
|
|
||||||
// Attempt to set shareKey
|
// Attempt to set shareKey
|
||||||
if (!$util->setSharedFileKeyfiles($session, $usersSharing, $path)) {
|
if (!$util->setSharedFileKeyfiles($session, $usersSharing, $path)) {
|
||||||
|
|
||||||
$failed[] = $path;
|
$failed[] = $path;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no attempts to set keyfiles failed
|
// If no attempts to set keyfiles failed
|
||||||
if (empty($failed)) {
|
if (empty($failed)) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -939,4 +939,24 @@ class Util {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*@ brief geo recursively through a dir and collect all files and sub files.
|
||||||
|
* @param type $dir relative to the users files folder
|
||||||
|
* @return array with list of files relative to the users files folder
|
||||||
|
*/
|
||||||
|
public function getAllFiles($dir) {
|
||||||
|
$result = array();
|
||||||
|
$path = $this->view->getLocalFile();
|
||||||
|
$content = $this->view->getDirectoryContent("/".$this->userFilesDir.'/'.$this->filesFolderName.$dir);
|
||||||
|
|
||||||
|
foreach ($content as $c) {
|
||||||
|
if ($c['type'] === "dir" ) {
|
||||||
|
$result = array_merge($result, $this->getAllFiles(substr($c['path'],5)));
|
||||||
|
} else {
|
||||||
|
$result[] = substr($c['path'], 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue