From 5a64c96d06db50c3ca13bb3c6c10c3a0e32a3380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 11 Feb 2013 15:13:42 +0100 Subject: [PATCH] go back to preUnshare hooks since sharing doesn't trigger post unshare hooks --- apps/files_encryption/appinfo/app.php | 4 ++-- apps/files_encryption/hooks/hooks.php | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/files_encryption/appinfo/app.php b/apps/files_encryption/appinfo/app.php index 6778e1faa3..f83109a18e 100644 --- a/apps/files_encryption/appinfo/app.php +++ b/apps/files_encryption/appinfo/app.php @@ -16,8 +16,8 @@ OCP\Util::connectHook( 'OC_User', 'pre_setPassword','OCA\Encryption\Hooks', 'set // 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', 'post_unshareAll', 'OCA\Encryption\Hooks', 'postUnshareAll' ); +OCP\Util::connectHook( 'OCP\Share', 'pre_unshare', 'OCA\Encryption\Hooks', 'preUnshare' ); +OCP\Util::connectHook( 'OCP\Share', 'pre_unshareAll', 'OCA\Encryption\Hooks', 'preUnshareAll' ); // Webdav-related hooks OCP\Util::connectHook( 'OC_Webdav_Properties', 'update', 'OCA\Encryption\Hooks', 'updateKeyfile' ); diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 550593daf6..17bcb9238a 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -157,8 +157,6 @@ class Hooks { , \OC_Log::ERROR ); - error_log( "Client side encryption is enabled but the client doesn't provide an encryption key for the file!" ); - } } @@ -169,7 +167,7 @@ class Hooks { * @brief */ public static function postShared( $params ) { - + error_log("post shared triggered!"); // NOTE: $params is an array with these keys: // itemSource -> int, filecache file ID // shareWith -> string, uid of user being shared to @@ -214,22 +212,27 @@ class Hooks { /** * @brief */ - public static function postUnshare( $params ) { - $shares = \OCP\Share::getUsersSharingFile( $params['fileTarget'], 1 ); + public static function preUnshare( $params ) { + $items = \OCP\Share::getItemSharedWithBySource($params['itemType'], $params['itemSource']); + $shares = \OCP\Share::getUsersSharingFile( $item[0]['file_target'], 1 ); $userIds = array(); foreach ( $shares as $share ) { $userIds[] = $share['userId']; } - return Crypt::encKeyfileToMultipleUsers($userIDs, $params['fileTarget']); + // remove the user from the list from which the file will be unshared + unset($userIds[$params['shareWith']]); + + return Crypt::encKeyfileToMultipleUsers($userIDs, $item[0]['file_target']); } /** * @brief */ - public static function postUnshareAll( $params ) { - return self::postUnshare($params); + public static function preUnshareAll( $params ) { + $items = \OCP\Share::getItemSharedWithBySource($params['itemType'], $params['itemSource']); + return Crypt::encKeyfileToMultipleUsers(array($items[0]['uid_owner']), $items[0]['file_target']); } }