use right location of the file is the source and not the target it is shared to

This commit is contained in:
Björn Schießle 2013-02-12 12:45:54 +01:00
parent 8eef919a75
commit 1e5d03da80
2 changed files with 22 additions and 16 deletions

View File

@ -163,6 +163,20 @@ class Hooks {
}
/**
* @brief get path of a file.
* @param $fileId id of the file
* @return path of the file
*/
private static function getFilePath($fileId) {
$query = \OC_DB::prepare('SELECT `path`'
.' FROM `*PREFIX*filecache`'
.' WHERE `fileid` = ?');
$result = $query->execute(array($fileId));
$row = $result->fetchRow();
return $row['path'];
}
/**
* @brief
*/
@ -182,7 +196,7 @@ class Hooks {
$shares = \OCP\Share::getUsersSharingFile( $params['itemSource'], 1 );
return Crypt::encKeyfileToMultipleUsers($shares, $params['fileTarget']);
return Crypt::encKeyfileToMultipleUsers($shares, self::getFilePath($params['itemSource']));
}
@ -191,25 +205,17 @@ class Hooks {
*/
public static function preUnshare( $params ) {
$shares = \OCP\Share::getUsersSharingFile( $params['itemSource'], 1 );
$userIds = array();
foreach ( $shares as $share ) {
error_log("keek user id: " . $share['userId']);
$userIds[] = $share['userId'];
}
// 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']);
unset($shares[$params['shareWith']]);
return Crypt::encKeyfileToMultipleUsers($shares, self::getFilePath($params['itemSource']));
}
/**
* @brief
*/
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']);
return Crypt::encKeyfileToMultipleUsers(array(\OCP\User::getUser()), self::getFilePath($params['itemSource']));
}
}

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, $fileTarget) {
public static function encKeyfileToMultipleUsers($users, $filePath) {
$view = new \OC_FilesystemView( '/' );
$owner = \OCP\User::getUser();
$util = new Util( $view, $userId );
@ -785,7 +785,7 @@ class Crypt {
\OC_FileProxy::$enabled = false;
// get the keyfile
$encKeyfile = Keymanager::getFileKey( $view, $owner, $fileTarget );
$encKeyfile = Keymanager::getFileKey( $view, $owner, $filePath );
$privateKey = $session->getPrivateKey();
@ -796,7 +796,7 @@ class Crypt {
$shareKeys = Crypt::multiKeyEncrypt( $plainKeyfile, $userPubKeys );
// save sharekeys
if ( ! Keymanager::setShareKeys( $view, $fileTarget, $shareKeys['keys'] ) ) {
if ( ! Keymanager::setShareKeys( $view, $filePath, $shareKeys['keys'] ) ) {
trigger_error( "SET Share keys failed" );