diff --git a/controller/documentcontroller.php b/controller/documentcontroller.php index a0377614..62dd9f39 100644 --- a/controller/documentcontroller.php +++ b/controller/documentcontroller.php @@ -24,7 +24,7 @@ use \OCA\Documents\Download; use \OCA\Documents\DownloadResponse; use \OCA\Documents\File; use OCA\Documents\Genesis; -use \OCA\Documents\View; +use \OC\Files\View; class DocumentController extends Controller{ @@ -45,7 +45,7 @@ class DocumentController extends Controller{ * @NoAdminRequired */ public function create(){ - $view = new \OC\Files\View('/' . $this->uid . '/files'); + $view = new View('/' . $this->uid . '/files'); $dir = $this->settings->getUserValue($this->uid, $this->appName, 'save_path', '/'); if (!$view->is_dir($dir)){ $dir = '/'; diff --git a/controller/sessioncontroller.php b/controller/sessioncontroller.php index 2c3a3eab..3d2760c7 100644 --- a/controller/sessioncontroller.php +++ b/controller/sessioncontroller.php @@ -21,6 +21,7 @@ use \OCA\Documents\Db; use \OCA\Documents\File; use \OCA\Documents\Helper; use OCA\Documents\Filter; +use \OC\Files\View; class BadRequestException extends \Exception { @@ -105,6 +106,10 @@ class SessionController extends Controller{ return $response; } + /** + * @NoAdminRequired + * @PublicPage + */ public function poll($command, $args){ $response = new JSONResponse(); @@ -260,7 +265,7 @@ class SessionController extends Controller{ //File was deleted or unshared. We need to save content as new file anyway //Sorry, but for guests it would be lost :( if ($this->uid){ - $view = new \OC\Files\View('/' . $this->uid . '/files'); + $view = new View('/' . $this->uid . '/files'); $dir = \OCP\Config::getUserValue($this->uid, 'documents', 'save_path', ''); $path = Helper::getNewFileName($view, $dir . 'New Document.odt'); diff --git a/lib/db/session.php b/lib/db/session.php index e28c5e9b..f0eac207 100644 --- a/lib/db/session.php +++ b/lib/db/session.php @@ -103,7 +103,8 @@ class Session extends \OCA\Documents\Db { } $sessionData['title'] = basename($path); - $sessionData['permissions'] = $ownerView->getFilePermissions($path); + $fileInfo = $ownerView->getFileInfo($path); + $sessionData['permissions'] = $fileInfo->getPermissions(); return $sessionData; } diff --git a/lib/downloadresponse.php b/lib/downloadresponse.php index 8c21d674..a37ee32b 100644 --- a/lib/downloadresponse.php +++ b/lib/downloadresponse.php @@ -13,6 +13,7 @@ namespace OCA\Documents; use \OCP\AppFramework\Http; use \OCP\IRequest; +use \OC\Files\View; class DownloadResponse extends \OCP\AppFramework\Http\Response { private $request; diff --git a/lib/file.php b/lib/file.php index 18699bd9..c3f4b42f 100644 --- a/lib/file.php +++ b/lib/file.php @@ -22,11 +22,13 @@ namespace OCA\Documents; +use \OC\Files\View; + class File { protected $fileId; protected $owner; protected $path; - protected $sharing = array(); + protected $sharing; protected $token =''; protected $passwordProtected = false; @@ -37,12 +39,7 @@ class File { } $this->fileId = $fileId; - - //if you know how to get sharing info by fileId via API, - //please send me a link to video tutorial :/ - if (!is_null($shareOps)){ - $this->sharing = $shareOps; - } + $this->sharing = $shareOps; } @@ -55,7 +52,7 @@ class File { throw new \Exception('This file was probably unshared'); } - $file = new File($rootLinkItem['file_source'], array($rootLinkItem)); + $file = new File($rootLinkItem['file_source'], $rootLinkItem); $file->setToken($token); if (isset($linkItem['share_with']) && !empty($linkItem['share_with'])){ @@ -98,7 +95,7 @@ class File { * @return boolean */ public function checkPassword($password){ - $shareId = $this->sharing[0]['id']; + $shareId = $this->sharing['id']; if (!$this->isPasswordProtected() || (\OC::$server->getSession()->exists('public_link_authenticated') && \OC::$server->getSession()->get('public_link_authenticated') === $shareId @@ -130,26 +127,6 @@ class File { $this->passwordProtected = $value; } - public function getPermissions(){ - if (count($this->sharing)){ - if ($this->isPublicShare()){ - $permissions = \OCP\PERMISSION_READ | \OCP\PERMISSION_UPDATE; - } else { - $permissions = $this->sharing[0]['permissions']; - } - } else { - list($owner, $path) = $this->getOwnerViewAndPath(); - $permissions = 0; - if (\OC\Files\Filesystem::isReadable($path)){ - $permissions |= \OCP\PERMISSION_READ; - } - if (\OC\Files\Filesystem::isUpdatable($path)){ - $permissions |= \OCP\PERMISSION_UPDATE; - } - - } - return $permissions; - } /** * @@ -158,12 +135,11 @@ class File { */ public function getOwnerViewAndPath($useDefaultRoot = false){ if ($this->isPublicShare()){ - $rootLinkItem = \OCP\Share::resolveReShare($this->sharing[0]); - if (isset($rootLinkItem['uid_owner'])){ - $owner = $rootLinkItem['uid_owner']; - \OCP\JSON::checkUserExists($rootLinkItem['uid_owner']); + if (isset($this->sharing['uid_owner'])){ + $owner = $this->sharing['uid_owner']; + \OCP\JSON::checkUserExists($this->sharing['uid_owner']); \OC_Util::tearDownFS(); - \OC_Util::setupFS($rootLinkItem['uid_owner']); + \OC_Util::setupFS($this->sharing['uid_owner']); } else { throw new \Exception($this->fileId . ' is a broken share'); } @@ -201,6 +177,6 @@ class File { protected function getPassword(){ - return $this->sharing[0]['share_with']; + return $this->sharing['share_with']; } } diff --git a/lib/genesis.php b/lib/genesis.php index 65a92942..f030f374 100644 --- a/lib/genesis.php +++ b/lib/genesis.php @@ -22,6 +22,8 @@ namespace OCA\Documents; +use \OC\Files\View; + class Genesis { const DOCUMENTS_DIRNAME='/documents'; @@ -37,7 +39,7 @@ class Genesis { * Create new genesis document * @param File $file * */ - public function __construct(\OCA\Documents\File $file){ + public function __construct(File $file){ list($view, $path) = $file->getOwnerViewAndPath(); $owner = $file->getOwner(); @@ -96,7 +98,7 @@ class Genesis { /** * Check if genesis is valid - * @param OCA\Documents\View $view + * @param \OC\Files\View $view * @param string $path relative to the view * @throws \Exception */ diff --git a/lib/view.php b/lib/view.php deleted file mode 100644 index 3250b19e..00000000 --- a/lib/view.php +++ /dev/null @@ -1,27 +0,0 @@ -isReadable($path)) { - $permissions |= \OCP\PERMISSION_READ; - } - if ($this->isSharable($path)) { - $permissions |= \OCP\PERMISSION_SHARE; - } - return $permissions; - } - -}