\r
namespace OCA\Encryption;\r
\r
+use OC\Files\Filesystem;\r
+\r
/**\r
* Class for hook specific logic\r
*/\r
-\r
class Hooks {\r
\r
// TODO: use passphrase for encrypting private key that is separate to \r
} else {\r
\r
// prefix path with Shared\r
- $path = '/Shared'.$parent['file_target'];\r
+ $path = '/Shared'.$parent['file_target'].$params['fileTarget'];\r
}\r
}\r
-\r
}\r
\r
$sharingEnabled = \OCP\Share::isEnabled();\r
\r
// If no attempts to set keyfiles failed\r
if (empty($failed)) {\r
-\r
return true;\r
} else {\r
-\r
return false;\r
}\r
}\r
/**\r
* @brief \r
*/\r
- public static function postUnshare( $params ) {\r
- \r
- // NOTE: $params has keys:\r
- // [itemType] => file\r
- // [itemSource] => 13\r
- // [shareType] => 0\r
- // [shareWith] => test1\r
- \r
- if ( $params['itemType'] === 'file' || $params['itemType'] === 'folder' ) {\r
- \r
- $view = new \OC_FilesystemView( '/' );\r
- $session = new Session($view);\r
- $userId = \OCP\User::getUser();\r
- $util = new Util( $view, $userId );\r
- $path = $util->fileIdToPath( $params['itemSource'] );\r
+ public static function postUnshare($params)\r
+ {\r
\r
- // for group shares get a list of the group members\r
- if ($params['shareType'] == \OCP\Share::SHARE_TYPE_GROUP) {\r
- $userIds = \OC_Group::usersInGroup($params['shareWith']);\r
- } else {\r
- $userIds = array($params['shareWith']);\r
- }\r
+ // NOTE: $params has keys:\r
+ // [itemType] => file\r
+ // [itemSource] => 13\r
+ // [shareType] => 0\r
+ // [shareWith] => test1\r
+ // [itemParent] =>\r
\r
- // if we unshare a folder we need a list of all (sub-)files\r
- if ($params['itemType'] === 'folder') {\r
- $allFiles = $util->getAllFiles($path);\r
- } else {\r
- $allFiles = array($path);\r
- }\r
+ if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {\r
+\r
+ $view = new \OC_FilesystemView('/');\r
+ $userId = \OCP\User::getUser();\r
+ $util = new Util($view, $userId);\r
+ $path = $util->fileIdToPath($params['itemSource']);\r
\r
+ // check if this is a re-share\r
+ if ($params['itemParent']) {\r
+\r
+ // get the parent from current share\r
+ $parent = $util->getShareParent($params['itemParent']);\r
\r
- foreach ( $allFiles as $path ) {\r
+ // get target path\r
+ $targetPath = $util->fileIdToPath($params['itemSource']);\r
+ $targetPathSplit = array_reverse(explode('/', $targetPath));\r
\r
- // check if the user still has access to the file, otherwise delete share key\r
- $sharingUsers = $util->getSharingUsersArray(true, $path);\r
+ // init values\r
+ $path = '';\r
+ $sharedPart = ltrim($parent['file_target'], '/');\r
+\r
+ // rebuild path\r
+ foreach ($targetPathSplit as $pathPart) {\r
+ if ($pathPart !== $sharedPart) {\r
+ $path = '/' . $pathPart . $path;\r
+ } else {\r
+ break;\r
+ }\r
+ }\r
+\r
+ // prefix path with Shared\r
+ $path = '/Shared' . $parent['file_target'] . $path;\r
+ }\r
+\r
+ // for group shares get a list of the group members\r
+ if ($params['shareType'] == \OCP\Share::SHARE_TYPE_GROUP) {\r
+ $userIds = \OC_Group::usersInGroup($params['shareWith']);\r
+ } else {\r
+ $userIds = array($params['shareWith']);\r
+ }\r
+\r
+ // if we unshare a folder we need a list of all (sub-)files\r
+ if ($params['itemType'] === 'folder') {\r
+ $allFiles = $util->getAllFiles($path);\r
+ } else {\r
+ $allFiles = array($path);\r
+ }\r
+\r
+ foreach ($allFiles as $path) {\r
+\r
+ // check if the user still has access to the file, otherwise delete share key\r
+ $sharingUsers = $util->getSharingUsersArray(true, $path);\r
\r
// Unshare every user who no longer has access to the file\r
- //TODO: does not work properly atm\r
- $delUsers = array_diff($userIds, $sharingUsers);\r
- if ( ! Keymanager::delShareKey( $view, $delUsers, $path ) ) {\r
- \r
- $failed[] = $path;\r
- \r
- }\r
- \r
- }\r
- \r
- // If no attempts to set keyfiles failed\r
- if ( empty( $failed ) ) {\r
- \r
- return true;\r
- \r
- } else {\r
- \r
- return false;\r
- \r
- }\r
+ $delUsers = array_diff($userIds, $sharingUsers);\r
+ if (!Keymanager::delShareKey($view, $delUsers, $path)) {\r
+ $failed[] = $path;\r
+ }\r
\r
- }\r
+ }\r
\r
- }\r
+ // If no attempts to set keyfiles failed\r
+ if (empty($failed)) {\r
+ return true;\r
+ } else {\r
+ return false;\r
+ }\r
+ }\r
+ }\r
\r
/**\r
* @brief \r
*/\r
public static function postUnshareAll( $params ) {\r
- \r
+\r
// NOTE: It appears that this is never called for files, so \r
// we may not need to implement it\r
\r
}
foreach ($content as $c) {
+ $sharedPart = $path_split[sizeof($path_split)-1];
+ $targetPathSplit = array_reverse(explode('/', $c['path']));
+
+ $path = '';
+
+ // rebuild path
+ foreach ($targetPathSplit as $pathPart) {
+ if($pathPart !== $sharedPart) {
+ $path = '/'.$pathPart.$path;
+ } else {
+ break;
+ }
+ }
+
+ $path = $dir.$path;
+
if ($c['type'] === "dir" ) {
- $result = array_merge($result, $this->getAllFiles($shared.substr($c['path'],5)));
+ $result = array_merge($result, $this->getAllFiles($path));
} else {
- $result[] = $shared.substr($c['path'], 5);
+ $result[] = $path;
}
}
return $result;
}
+ /**
+ * @brief get owner of the shared files.
+ * @param int $Id of a share
+ * @return owner
+ */
+ public function getOwnerFromSharedFile($id) {
+ $query = \OC_DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1);
+ $source = $query->execute(array($id))->fetchRow();
+
+ if (isset($source['parent'])) {
+ $parent = $source['parent'];
+ while (isset($parent)) {
+ $query = \OC_DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1);
+ $item = $query->execute(array($parent))->fetchRow();
+ if (isset($item['parent'])) {
+ $parent = $item['parent'];
+ } else {
+ $fileOwner = $item['uid_owner'];
+ break;
+ }
+ }
+ } else {
+ $fileOwner = $source['uid_owner'];
+ }
+
+ return $fileOwner;
+ }
+
}