diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2015-04-23 16:48:11 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2015-04-23 17:18:48 +0200 |
commit | 2990b0e07e418577d55368c21200ada86c381b51 (patch) | |
tree | f09260b3be548d9ea0a86dd9d54b28ee8323ef14 /lib/private/encryption/update.php | |
parent | f8f354b351a349898bbb5cdf2d9bee1c798c0f73 (diff) | |
download | nextcloud-server-2990b0e07e418577d55368c21200ada86c381b51.tar.gz nextcloud-server-2990b0e07e418577d55368c21200ada86c381b51.zip |
update share keys if a file is moved to a shared folder
Diffstat (limited to 'lib/private/encryption/update.php')
-rw-r--r-- | lib/private/encryption/update.php | 66 |
1 files changed, 47 insertions, 19 deletions
diff --git a/lib/private/encryption/update.php b/lib/private/encryption/update.php index 7a170a03adc..f262099a3c5 100644 --- a/lib/private/encryption/update.php +++ b/lib/private/encryption/update.php @@ -22,6 +22,7 @@ namespace OC\Encryption; +use OC\Files\Filesystem; use \OC\Files\Mount; use \OC\Files\View; @@ -74,46 +75,73 @@ class Update { $this->uid = $uid; } + /** + * hook after file was shared + * + * @param array $params + */ public function postShared($params) { if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { - $this->update($params['fileSource']); + $path = Filesystem::getPath($params['fileSource']); + list($owner, $ownerPath) = $this->getOwnerPath($path); + $absPath = '/' . $owner . '/files/' . $ownerPath; + $this->update($absPath); } } + /** + * hook after file was unshared + * + * @param array $params + */ public function postUnshared($params) { if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { - $this->update($params['fileSource']); + $path = Filesystem::getPath($params['fileSource']); + list($owner, $ownerPath) = $this->getOwnerPath($path); + $absPath = '/' . $owner . '/files/' . $ownerPath; + $this->update($absPath); } } /** - * update keyfiles and share keys recursively + * get owner and path relative to data/<owner>/files * - * @param int $fileSource file source id + * @param string $path path to file for current user + * @return array ['owner' => $owner, 'path' => $path] + * @throw \InvalidArgumentException */ - private function update($fileSource) { - $path = \OC\Files\Filesystem::getPath($fileSource); - $info = \OC\Files\Filesystem::getFileInfo($path); - $owner = \OC\Files\Filesystem::getOwner($path); - $view = new \OC\Files\View('/' . $owner . '/files'); - $ownerPath = $view->getPath($info->getId()); - $absPath = '/' . $owner . '/files' . $ownerPath; + private function getOwnerPath($path) { + $info = Filesystem::getFileInfo($path); + $owner = Filesystem::getOwner($path); + $view = new View('/' . $owner . '/files'); + $path = $view->getPath($info->getId()); + if ($path === null) { + throw new \InvalidArgumentException('No file found for ' . $info->getId()); + } + + return array($owner, $path); + } - $mount = $this->mountManager->find($path); - $mountPoint = $mount->getMountPoint(); + /** + * notify encryption module about added/removed users from a file/folder + * + * @param string $path relative to data/ + * @throws Exceptions\ModuleDoesNotExistsException + */ + public function update($path) { // if a folder was shared, get a list of all (sub-)folders - if ($this->view->is_dir($absPath)) { - $allFiles = $this->util->getAllFiles($absPath, $mountPoint); + if ($this->view->is_dir($path)) { + $allFiles = $this->util->getAllFiles($path); } else { - $allFiles = array($absPath); + $allFiles = array($path); } $encryptionModule = $this->encryptionManager->getDefaultEncryptionModule(); - foreach ($allFiles as $path) { - $usersSharing = $this->file->getAccessList($path); - $encryptionModule->update($path, $this->uid, $usersSharing); + foreach ($allFiles as $file) { + $usersSharing = $this->file->getAccessList($file); + $encryptionModule->update($file, $this->uid, $usersSharing); } } |