// Sharing-related hooks
OCP\Util::connectHook( 'OCP\Share', 'post_shared', 'OCA\Encryption\Hooks', 'postShared' );
OCP\Util::connectHook( 'OCP\Share', 'post_unshare', 'OCA\Encryption\Hooks', 'postUnshare' );
-OCP\Util::connectHook( 'OCP\Share', 'pre_unshareAll', 'OCA\Encryption\Hooks', 'preUnshareAll' );
+OCP\Util::connectHook( 'OCP\Share', 'post_unshareAll', 'OCA\Encryption\Hooks', 'postUnshareAll' );
// Webdav-related hooks
OCP\Util::connectHook( 'OC_Webdav_Properties', 'update', 'OCA\Encryption\Hooks', 'updateKeyfile' );
\r
//TODO: We don't deal with shared folder yet, need to recursively update every file in the folder\r
\r
- if ($params['shareType'] == \OCP\Share::SHARE_TYPE_LINK)\r
- \r
$view = new \OC_FilesystemView( '/' );\r
$userId = \OCP\User::getUser();\r
$util = new Util( $view, $userId );\r
\r
$path = Util::getFilePath($params['itemSource']);\r
\r
- $shares = \OCP\Share::getUsersSharingFile( $path, true );\r
- \r
- return Crypt::encKeyfileToMultipleUsers($shares, $path);\r
+ return Crypt::updateKeyfile($path);\r
\r
}\r
\r
*/\r
public static function postUnshare( $params ) {\r
$path = Util::getFilePath($params['itemSource']);\r
- $shares = \OCP\Share::getUsersSharingFile( $path, true );\r
\r
- return Crypt::encKeyfileToMultipleUsers(array_unique($shares), $path );\r
+ return Crypt::updateKeyfile($path);\r
}\r
\r
/**\r
* @brief \r
*/\r
- public static function preUnshareAll( $params ) {\r
- return Crypt::encKeyfileToMultipleUsers(array(\OCP\User::getUser()), Util::getFilePath($params['itemSource']));\r
+ public static function postUnshareAll( $params ) {\r
+ $path = Util::getFilePath($params['itemSource']);\r
+ \r
+ return Crypt::updateKeyfile($path);\r
}\r
\r
}\r
* @param $users list of users which should be able to access the file\r
* @param $fileTarget target of the file\r
*/\r
- public static function encKeyfileToMultipleUsers($users, $filePath) {\r
+ private static function encKeyfileToMultipleUsers($users, $filePath) {\r
$view = new \OC_FilesystemView( '/' );\r
$owner = \OCP\User::getUser();\r
$util = new Util( $view, $userId );\r
\r
return true;\r
}\r
+ \r
+ /**\r
+ * @brief update keyfile encryption for given path and all sub folders/files\r
+ * @param path which needs to be updated\r
+ * @return bool success\r
+ */\r
+ public static function updateKeyfile($path) {\r
+ \r
+ $filesView = \OCP\Files::getStorage('files');\r
+ \r
+ $result = true;\r
+ \r
+ if ( $filesView->is_dir($path) ) {\r
+ $content = $filesView->getDirectoryContent($path);\r
+ foreach ( $content as $c) {\r
+ $path = substr($c['path'], 5);\r
+ if ( $filesView->is_dir($path) ) {\r
+ error_log("dive into $path");\r
+ $result &= self::updateKeyfile($path);\r
+ } else {\r
+ error_log("encKeyFileToMultipleUsers $path");\r
+ $shares = \OCP\Share::getUsersSharingFile( $path, true );\r
+ $result &= self::encKeyfileToMultipleUsers($shares, $path);\r
+ }\r
+ }\r
+ } else {\r
+ error_log("encKeyFileToMultipleUsers single file: " . $path);\r
+ $shares = \OCP\Share::getUsersSharingFile( $path, true );\r
+ $result = self::encKeyfileToMultipleUsers($shares, $path);\r
+ }\r
+ \r
+ return $result;\r
+\r
+ }\r
}
\ No newline at end of file
foreach ($shares as $share) {
self::delete($share['id']);
}
+ \OC_Hook::emit('OCP\Share', 'post_unshareAll', array(
+ 'itemType' => $itemType,
+ 'itemSource' => $itemSource,
+ 'shares' => $shares
+ ));
return true;
}
return false;