Made code formatting of new methods more consistent

This commit is contained in:
Sam Tuke 2013-05-07 17:16:16 +02:00
parent 4b53f72d0d
commit 763c8f78ed
1 changed files with 157 additions and 118 deletions

View File

@ -202,6 +202,7 @@ class Hooks {
// [id] => 10
// [token] =>
// TODO: Should other kinds of item be encrypted too?
if ( $params['itemType'] === 'file' || $params['itemType'] === 'folder' ) {
$view = new \OC_FilesystemView( '/' );
@ -223,13 +224,19 @@ class Hooks {
$path = '/Shared'.$parent['file_target'];
} else {
// parent is folder but shared was a file!
// NOTE: parent is folder but shared was a file!
// we try to rebuild the missing path
// some examples we face here
// user1 share folder1 with user2 folder1 has the following structure /folder1/subfolder1/subsubfolder1/somefile.txt
// user1 share folder1 with user2 folder1 has
// the following structure
// /folder1/subfolder1/subsubfolder1/somefile.txt
// user2 re-share subfolder2 with user3
// user3 re-share somefile.txt user4
// so our path should be /Shared/subfolder1/subsubfolder1/somefile.txt while user3 is sharing
// so our path should be
// /Shared/subfolder1/subsubfolder1/somefile.txt
// while user3 is sharing
if ( $params['itemType'] === 'file' ) {
// get target path
$targetPath = $util->fileIdToPath( $params['fileSource'] );
@ -241,11 +248,17 @@ class Hooks {
// rebuild path
foreach ( $targetPathSplit as $pathPart ) {
if( $pathPart !== $sharedPart ) {
$path = '/' . $pathPart . $path;
} else {
break;
}
}
// prefix path with Shared
@ -265,10 +278,13 @@ class Hooks {
if ( $params['itemType'] === 'folder' ) {
$allFiles = $util->getAllFiles($path);
} else {
$allFiles = array( $path );
}
foreach ( $allFiles as $path ) {
$usersSharing = $util->getSharingUsersArray( $sharingEnabled, $path );
$failed = array();
@ -282,9 +298,13 @@ class Hooks {
// If no attempts to set keyfiles failed
if ( empty( $failed ) ) {
return true;
} else {
return false;
}
}
}
@ -292,8 +312,7 @@ class Hooks {
/**
* @brief
*/
public static function postUnshare($params)
{
public static function postUnshare( $params ) {
// NOTE: $params has keys:
// [itemType] => file
@ -325,11 +344,17 @@ class Hooks {
// rebuild path
foreach ( $targetPathSplit as $pathPart ) {
if ( $pathPart !== $sharedPart ) {
$path = '/' . $pathPart . $path;
} else {
break;
}
}
// prefix path with Shared
@ -338,15 +363,22 @@ class Hooks {
// for group shares get a list of the group members
if ( $params['shareType'] == \OCP\Share::SHARE_TYPE_GROUP ) {
$userIds = \OC_Group::usersInGroup($params['shareWith']);
} else {
$userIds = array( $params['shareWith'] );
}
// if we unshare a folder we need a list of all (sub-)files
if ( $params['itemType'] === 'folder' ) {
$allFiles = $util->getAllFiles( $path );
} else {
$allFiles = array( $path );
}
@ -357,17 +389,24 @@ class Hooks {
// Unshare every user who no longer has access to the file
$delUsers = array_diff( $userIds, $sharingUsers);
if ( !Keymanager::delShareKey( $view, $delUsers, $path ) ) {
$failed[] = $path;
}
}
// If no attempts to set keyfiles failed
if ( empty( $failed ) ) {
return true;
} else {
return false;
}
}
}