Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/richdocuments.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVictor Dubiniuk <victor.dubiniuk@gmail.com>2015-09-18 00:15:18 +0300
committerVictor Dubiniuk <victor.dubiniuk@gmail.com>2015-09-18 21:47:19 +0300
commitb8917435f37b2c076aaeb27c25d5ca2e4e0eee40 (patch)
tree0e67fa94a994f43d536ec58fdd70e8cbaeec93fc /lib
parenta6be42cb266d198a5def8b53bff796b93787aff4 (diff)
Use different entry points for users and guests
Diffstat (limited to 'lib')
-rw-r--r--lib/db/session.php18
-rw-r--r--lib/file.php60
-rw-r--r--lib/genesis.php12
3 files changed, 43 insertions, 47 deletions
diff --git a/lib/db/session.php b/lib/db/session.php
index cbfe0cb8..31b2ab30 100644
--- a/lib/db/session.php
+++ b/lib/db/session.php
@@ -49,12 +49,7 @@ class Session extends \OCA\Documents\Db {
public static function start($uid, $file){
// Create a directory to store genesis
$genesis = new \OCA\Documents\Genesis($file);
-
- list($ownerView, $path) = $file->getOwnerViewAndPath();
- $mimetype = $ownerView->getMimeType($path);
- if (!Filter::isSupportedMimetype($mimetype)){
- throw new \Exception( $path . ' is ' . $mimetype . ' and is not supported by Documents app');
- }
+
$oldSession = new Session();
$oldSession->loadBy('file_id', $file->getFileId());
@@ -78,14 +73,14 @@ class Session extends \OCA\Documents\Db {
;
$memberColor = \OCA\Documents\Helper::getMemberColor($uid);
- $member = new \OCA\Documents\Db\Member(array(
+ $member = new \OCA\Documents\Db\Member([
$sessionData['es_id'],
$uid,
$memberColor,
time(),
intval($file->isPublicShare()),
$file->getToken()
- ));
+ ]);
if (!$member->insert()){
throw new \Exception('Failed to add member into database');
@@ -113,10 +108,9 @@ class Session extends \OCA\Documents\Db {
$memberColor,
$imageUrl
);
-
- $sessionData['title'] = basename($path);
- $fileInfo = $ownerView->getFileInfo($path);
- $sessionData['permissions'] = $fileInfo->getPermissions();
+
+ $sessionData['title'] = basename($file->getPath());
+ $sessionData['permissions'] = $file->getPermissions();
return $sessionData;
}
diff --git a/lib/file.php b/lib/file.php
index 58542673..fb6ae9fb 100644
--- a/lib/file.php
+++ b/lib/file.php
@@ -28,14 +28,14 @@ class File {
protected $fileId;
protected $owner;
protected $sharing;
- protected $token ='';
+ protected $token;
protected $passwordProtected = false;
protected $ownerView;
protected $ownerViewFiles;
protected $path;
protected $pathFiles;
- public function __construct($fileId, $shareOps = null, $token = null){
+ public function __construct($fileId, $shareOps = null, $token = ''){
if (!$fileId){
throw new \Exception('No valid file has been passed');
}
@@ -43,6 +43,22 @@ class File {
$this->fileId = $fileId;
$this->sharing = $shareOps;
$this->token = $token;
+
+ if ($this->isPublicShare()) {
+ if (isset($this->sharing['uid_owner'])){
+ $this->owner = $this->sharing['uid_owner'];
+ if (!\OC::$server->getUserManager()->userExists($this->sharing['uid_owner'])) {
+ throw new \Exception('Share owner' . $this->sharing['uid_owner'] . ' does not exist ');
+ }
+
+ \OC_Util::tearDownFS();
+ \OC_Util::setupFS($this->sharing['uid_owner']);
+ } else {
+ throw new \Exception($this->fileId . ' is a broken share');
+ }
+ } else {
+ $this->owner = \OC::$server->getUserSession()->getUser()->getUID();
+ }
$this->initViews();
}
@@ -131,15 +147,6 @@ class File {
public function setPasswordProtected($value){
$this->passwordProtected = $value;
}
-
- /**
- *
- * @return string owner of the current file item
- * @throws \Exception
- */
- public function getOwnerViewAndPath($useDefaultRoot = false){
- return $useDefaultRoot ? [$this->ownerViewFiles, $this->pathFiles] : [$this->ownerView, $this->path];
- }
public function getOwner(){
return $this->owner;
@@ -153,23 +160,12 @@ class File {
return $relativeToFiles ? $this->pathFiles : $this->path;
}
+ public function getPermissions(){
+ $fileInfo = $this->ownerView->getFileInfo($this->path);
+ return $fileInfo->getPermissions();
+ }
+
protected function initViews(){
- if ($this->isPublicShare()) {
- if (isset($this->sharing['uid_owner'])){
- $this->owner = $this->sharing['uid_owner'];
- if (!\OC::$server->getUserManager()->userExists($this->sharing['uid_owner'])) {
- throw new \Exception('Share owner' . $this->sharing['uid_owner'] . ' does not exist ');
- }
-
- \OC_Util::tearDownFS();
- \OC_Util::setupFS($this->sharing['uid_owner']);
- } else {
- throw new \Exception($this->fileId . ' is a broken share');
- }
- } else {
- $this->owner = \OC::$server->getUserSession()->getUser()->getUID();
- }
-
$this->ownerView = new View('/' . $this->owner);
$this->ownerViewFiles = new View('/' . $this->owner . '/files');
$this->path = $this->ownerView->getPath($this->fileId);
@@ -186,6 +182,16 @@ class File {
if (!$this->ownerViewFiles->file_exists($this->pathFiles)) {
throw new \Exception($this->pathFiles . ' doesn\'t exist');
}
+
+ if (!$this->ownerView->is_file($this->path)){
+ throw new \Exception('Object ' . $this->path . ' is not a file.');
+ }
+ //TODO check if it is a valid odt
+
+ $mimetype = $this->ownerView->getMimeType($this->path);
+ if (!Filter::isSupportedMimetype($mimetype)){
+ throw new \Exception( $this->path . ' is ' . $mimetype . ' and is not supported by Documents app');
+ }
}
protected function getPassword(){
diff --git a/lib/genesis.php b/lib/genesis.php
index a74d3274..345e7a78 100644
--- a/lib/genesis.php
+++ b/lib/genesis.php
@@ -40,7 +40,8 @@ class Genesis {
* @param File $file
* */
public function __construct(File $file){
- list($view, $path) = $file->getOwnerViewAndPath();
+ $view = $file->getOwnerView();
+ $path = $file->getPath();
$owner = $file->getOwner();
$this->view = new View('/' . $owner);
@@ -48,8 +49,9 @@ class Genesis {
if (!$this->view->file_exists(self::DOCUMENTS_DIRNAME)){
$this->view->mkdir(self::DOCUMENTS_DIRNAME );
}
+ $this->validate($view, $path);
- $this->hash = $this->getDocumentHash($view, $path);
+ $this->hash = $view->hash('sha1', $path, false);
$this->path = self::DOCUMENTS_DIRNAME . '/' . $this->hash . '.odt';
if (!$this->view->file_exists($this->path)){
//copy new genesis to /user/documents/{hash}.odt
@@ -76,12 +78,6 @@ class Genesis {
return $this->hash;
}
- protected function getDocumentHash($view, $path){
- $this->validate($view, $path);
- $hash = sha1($view->file_get_contents($path));
- return $hash;
- }
-
/**
* Check if genesis is valid
* @param \OC\Files\View $view