add post_unshareALll hook, update recursively all keyfiles if a folder was shared/unshared

This commit is contained in:
Björn Schießle 2013-02-13 17:23:27 +01:00
parent 4952dfe956
commit 9356f9a6bf
4 changed files with 47 additions and 11 deletions

View 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' );

View file

@ -176,17 +176,13 @@ class Hooks {
//TODO: We don't deal with shared folder yet, need to recursively update every file in the folder
if ($params['shareType'] == \OCP\Share::SHARE_TYPE_LINK)
$view = new \OC_FilesystemView( '/' );
$userId = \OCP\User::getUser();
$util = new Util( $view, $userId );
$path = Util::getFilePath($params['itemSource']);
$shares = \OCP\Share::getUsersSharingFile( $path, true );
return Crypt::encKeyfileToMultipleUsers($shares, $path);
return Crypt::updateKeyfile($path);
}
@ -195,16 +191,17 @@ class Hooks {
*/
public static function postUnshare( $params ) {
$path = Util::getFilePath($params['itemSource']);
$shares = \OCP\Share::getUsersSharingFile( $path, true );
return Crypt::encKeyfileToMultipleUsers(array_unique($shares), $path );
return Crypt::updateKeyfile($path);
}
/**
* @brief
*/
public static function preUnshareAll( $params ) {
return Crypt::encKeyfileToMultipleUsers(array(\OCP\User::getUser()), Util::getFilePath($params['itemSource']));
public static function postUnshareAll( $params ) {
$path = Util::getFilePath($params['itemSource']);
return Crypt::updateKeyfile($path);
}
}

View file

@ -750,7 +750,7 @@ class Crypt {
* @param $users list of users which should be able to access the file
* @param $fileTarget target of the file
*/
public static function encKeyfileToMultipleUsers($users, $filePath) {
private static function encKeyfileToMultipleUsers($users, $filePath) {
$view = new \OC_FilesystemView( '/' );
$owner = \OCP\User::getUser();
$util = new Util( $view, $userId );
@ -810,4 +810,38 @@ class Crypt {
return true;
}
/**
* @brief update keyfile encryption for given path and all sub folders/files
* @param path which needs to be updated
* @return bool success
*/
public static function updateKeyfile($path) {
$filesView = \OCP\Files::getStorage('files');
$result = true;
if ( $filesView->is_dir($path) ) {
$content = $filesView->getDirectoryContent($path);
foreach ( $content as $c) {
$path = substr($c['path'], 5);
if ( $filesView->is_dir($path) ) {
error_log("dive into $path");
$result &= self::updateKeyfile($path);
} else {
error_log("encKeyFileToMultipleUsers $path");
$shares = \OCP\Share::getUsersSharingFile( $path, true );
$result &= self::encKeyfileToMultipleUsers($shares, $path);
}
}
} else {
error_log("encKeyFileToMultipleUsers single file: " . $path);
$shares = \OCP\Share::getUsersSharingFile( $path, true );
$result = self::encKeyfileToMultipleUsers($shares, $path);
}
return $result;
}
}

View 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;