// [shareType] => 0\r
// [shareWith] => test1\r
\r
- // TODO: Should other kinds of item be encrypted too?\r
- if ( $params['itemType'] === 'file' ) {\r
+ if ( $params['itemType'] === 'file' || $params['itemType'] === 'folder' ) {\r
\r
$view = new \OC_FilesystemView( '/' );\r
- $session = new Session();\r
+ $session = new Session($view);\r
$userId = \OCP\User::getUser();\r
$util = new Util( $view, $userId );\r
$path = $util->fileIdToPath( $params['itemSource'] );\r
- \r
+\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 path is a folder, get all children\r
$allPaths = $util->getPaths( $path );\r
\r
foreach ( $allPaths as $path ) {\r
\r
// Unshare each child path\r
- if ( ! Keymanager::delShareKey( $view, $params['shareWith'], $path ) ) {\r
+ if ( ! Keymanager::delShareKey( $view, $userIds, $path ) ) {\r
\r
$failed[] = $path;\r
\r
/**
* @brief Delete a single user's shareKey for a single file
*/
- public static function delShareKey( \OC_FilesystemView $view, $userId, $filePath ) {
+ public static function delShareKey( \OC_FilesystemView $view, $userIds, $filePath ) {
\OC_FileProxy::$enabled = false;
- $shareKeyPath = '/' . $userId . '/files_encryption/share-keys/' . $filePath;
+ //here we need the currently logged in user, while userId can be a different user
+ $util = new Util( $view, \OCP\User::getUser() );
+
+ list($owner, $filename) = $util->getUidAndFilename($filePath);
+
+ $shareKeyPath = '/' . $owner . '/files_encryption/share-keys/' . $filename;
$result = false;
if ( $view->is_dir($shareKeyPath) ) {
- $result = $view->unlink($shareKeyPath);
- } else {
- $absPath = $view->getLocalFile($shareKeyPath);
-
- $matches = glob(preg_quote($absPath).'.*.shareKey' );
- if ( $matches ) {
+ $localPath = \OC_Filesystem::normalizePath($view->getLocalFolder($shareKeyPath));
+ $result = self::recursiveDelShareKeys($localPath, $userIds);
- foreach ( $matches as $ma ) {
- unlink($ma);
- }
+ } else {
+ foreach ($userIds as $userId) {
+ $view->unlink($shareKeyPath.'.'.$userId.'.shareKey');
}
$result = true;
return $result;
}
-
+
+ /**
+ * @brief recursively delete share keys from given users
+ *
+ * @param type $dir directory
+ * @param type $userIds user ids for which the share keys should be deleted
+ */
+ private static function recursiveDelShareKeys($dir, $userIds) {
+ foreach ($userIds as $userId) {
+ $completePath = $dir.'/.*'.'.'.$userId.'.shareKey';
+ $matches = glob(preg_quote($dir).'/*'.preg_quote('.'.$userId.'.shareKey'));
+ }
+ foreach ($matches as $ma) {
+ unlink($ma);
+ }
+ $subdirs = $directories = glob(preg_quote($dir) . '/*' , GLOB_ONLYDIR);
+ foreach ( $subdirs as $subdir ) {
+ self::recursiveDelShareKeys($subdir, $userIds);
+ }
+ return $true;
+ }
+
/**
* @brief Make preparations to vars and filesystem for saving a keyfile
*/