Started work on post unshare hook

Development snapshot
This commit is contained in:
Sam Tuke 2013-02-26 18:33:31 +00:00
parent 4550ae6a69
commit aae9b0b1bf
3 changed files with 108 additions and 35 deletions

View File

@ -168,11 +168,25 @@ class Hooks {
*/ */
public static function postShared( $params ) { public static function postShared( $params ) {
// NOTE: $params is an array with these keys: // NOTE: $params has keys:
// [itemType] => file
// itemSource -> int, filecache file ID // itemSource -> int, filecache file ID
// [parent] =>
// [itemTarget] => /13
// shareWith -> string, uid of user being shared to // shareWith -> string, uid of user being shared to
// fileTarget -> path of file being shared // fileTarget -> path of file being shared
// uidOwner -> owner of the original file being shared // uidOwner -> owner of the original file being shared
// [shareType] => 0
// [shareWith] => test1
// [uidOwner] => admin
// [permissions] => 17
// [fileSource] => 13
// [fileTarget] => /test8
// [id] => 10
// [token] =>
// TODO: Should other kinds of item be encrypted too?
if ( $params['itemType'] === 'file' ) {
$view = new \OC_FilesystemView( '/' ); $view = new \OC_FilesystemView( '/' );
$session = new Session(); $session = new Session();
@ -209,18 +223,52 @@ class Hooks {
} }
}
/** /**
* @brief * @brief
*/ */
public static function postUnshare( $params ) { public static function postUnshare( $params ) {
// $view = new \OC_FilesystemView( '/' ); // NOTE: $params has keys:
// $session = new Session(); // [itemType] => file
// $userId = \OCP\User::getUser(); // [itemSource] => 13
// $util = new Util( $view, $userId ); // [shareType] => 0
// $path = $util->fileIdToPath( $params['itemSource'] ); // [shareWith] => test1
//
// return Crypt::updateKeyfile( $view, $util, $session, $userId, $path ); // TODO: Should other kinds of item be encrypted too?
if ( $params['itemType'] === 'file' ) {
$view = new \OC_FilesystemView( '/' );
$session = new Session();
$userId = \OCP\User::getUser();
$util = new Util( $view, $userId );
$path = $util->fileIdToPath( $params['itemSource'] );
$allPaths = $util->getPaths( $path );
foreach ( $allPaths as $path ) {
if ( ! Keymanager::delShareKey( $view, $userId, $path ) ) {
$failed[] = $path;
}
}
// If no attempts to set keyfiles failed
if ( empty( $failed ) ) {
return true;
} else {
return false;
}
}
} }

View File

@ -350,6 +350,30 @@ class Keymanager {
} }
/**
* @brief Delete a single user's shareKey for a single file
*/
public static function delShareKey( \OC_FilesystemView $view, $userId, $filePath ) {
$trimmed = ltrim( $filePath, '/' );
$shareKeyPath = '/' . $userId . '/files_encryption/share-keys/' . $trimmed . '.shareKey';
// Unlink doesn't tell us if file was deleted (not found returns
// true), so we perform our own test
if ( $view->file_exists( $shareKeyPath ) ) {
return $view->unlink( $shareKeyPath );
} else {
\OC_Log::write( 'Encryption library', 'Could not delete shareKey; does not exist: "' . $shareKeyPath, \OC_Log::ERROR );
return false;
}
}
/** /**
* @brief Make preparations to vars and filesystem for saving a keyfile * @brief Make preparations to vars and filesystem for saving a keyfile
*/ */

View File

@ -580,7 +580,8 @@ class Util {
* @brief Expand given path to all sub files & folders * @brief Expand given path to all sub files & folders
* @param Session $session * @param Session $session
* @param string $path path which needs to be updated * @param string $path path which needs to be updated
* @return bool outcome of attempt to set keyfiles * @return array $pathsArray all found file paths
* @note Paths of directories excluded, only *file* paths are returned
*/ */
public function getPaths( $path ) { public function getPaths( $path ) {