]> source.dussan.org Git - nextcloud-server.git/commitdiff
add post_unshareALll hook, update recursively all keyfiles if a folder was shared...
authorBjörn Schießle <schiessle@owncloud.com>
Wed, 13 Feb 2013 16:23:27 +0000 (17:23 +0100)
committerBjörn Schießle <schiessle@owncloud.com>
Wed, 13 Feb 2013 16:23:27 +0000 (17:23 +0100)
apps/files_encryption/appinfo/app.php
apps/files_encryption/hooks/hooks.php
apps/files_encryption/lib/crypt.php
lib/public/share.php

index 932e8855d074e15640bafdbedcaed3cb50b27cb9..6778e1faa3c152ef5708ffe004a5d13ad9872b9c 100644 (file)
@@ -17,7 +17,7 @@ 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', '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' );
index ae05ba78012b9aabed32720bf5a5c4d01197b9a5..34ed11c7e2462d215d2f3c3cf21d6da14f02e0fd 100644 (file)
@@ -176,17 +176,13 @@ class Hooks {
                \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
@@ -195,16 +191,17 @@ class Hooks {
         */\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
index 0f465d7d95a9eba5787853a9a2d3a8097a2c6ff4..18e9535bf35f641ca9e9635e6b1adbe9218f2b51 100755 (executable)
@@ -750,7 +750,7 @@ class Crypt {
         * @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
@@ -810,4 +810,38 @@ class Crypt {
 \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
index f691ae9b39f4a923bcdd7691166390c06c4b2722..d1297c6e59ec8239db16c06bbd6b612afb8b6988 100644 (file)
@@ -520,6 +520,11 @@ class Share {
                        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;