Store share token to guest users

pull/1/head
Victor Dubiniuk 10 years ago
parent f81e41dc63
commit 13b73b12c1

@ -101,9 +101,10 @@ class SessionController extends Controller{
} }
$sessionData = $session->getData(); $sessionData = $session->getData();
try { try {
$file = new File($sessionData['file_id']);
if ($isGuest){ if ($isGuest){
$file->setToken('yes'); $file = File::getByShareToken($currentMemberData['token']);
} else {
$file = new File($sessionData['file_id']);
} }
list($view, $path) = $file->getOwnerViewAndPath(); list($view, $path) = $file->getOwnerViewAndPath();
@ -129,7 +130,6 @@ class SessionController extends Controller{
$memberCount = count($memberIds) - 1; $memberCount = count($memberIds) - 1;
if ($view->file_exists($path)){ if ($view->file_exists($path)){
$proxyStatus = \OC_FileProxy::$enabled; $proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false; \OC_FileProxy::$enabled = false;
$currentHash = sha1($view->file_get_contents($path)); $currentHash = sha1($view->file_get_contents($path));
@ -152,7 +152,6 @@ class SessionController extends Controller{
if ($memberCount>0){ if ($memberCount>0){
// Update genesis hash to prevent conflicts // Update genesis hash to prevent conflicts
Helper::debugLog('Update hash'); Helper::debugLog('Update hash');
$session->updateGenesisHash($esId, sha1($data['content'])); $session->updateGenesisHash($esId, sha1($data['content']));
} else { } else {
// Last user. Kill session data // Last user. Kill session data

@ -99,6 +99,13 @@
<unsigned>true</unsigned> <unsigned>true</unsigned>
<length>1</length> <length>1</length>
</field> </field>
<field>
<name>token</name>
<type>text</type>
<default></default>
<notnull>false</notnull>
<length>32</length>
</field>
<field> <field>
<name>status</name> <name>status</name>
<type>integer</type> <type>integer</type>

@ -1 +1 @@
0.8 0.8.1

@ -23,8 +23,8 @@ class Db_Member extends Db{
protected $tableName = '`*PREFIX*documents_member`'; protected $tableName = '`*PREFIX*documents_member`';
protected $insertStatement = 'INSERT INTO `*PREFIX*documents_member` (`es_id`, `uid`, `color`, `last_activity`, `is_guest`) protected $insertStatement = 'INSERT INTO `*PREFIX*documents_member` (`es_id`, `uid`, `color`, `last_activity`, `is_guest`, `token`)
VALUES (?, ?, ?, ?, ?)'; VALUES (?, ?, ?, ?, ?, ?)';
protected $loadStatement = 'SELECT * FROM `*PREFIX*documents_member` WHERE `member_id`= ?'; protected $loadStatement = 'SELECT * FROM `*PREFIX*documents_member` WHERE `member_id`= ?';

@ -68,7 +68,8 @@ class Db_Session extends \OCA\Documents\Db {
$uid, $uid,
$memberColor, $memberColor,
time(), time(),
intval($file->isPublicShare()) intval($file->isPublicShare()),
$file->getToken()
)); ));
if ($member->insert()){ if ($member->insert()){

@ -54,24 +54,13 @@ class File {
if (is_array($linkItem) && isset($linkItem['uid_owner'])) { if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
// seems to be a valid share // seems to be a valid share
$rootLinkItem = \OCP\Share::resolveReShare($linkItem); $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
$fileOwner = $rootLinkItem['uid_owner'];
} else { } else {
throw new \Exception('This file was probably unshared'); throw new \Exception('This file was probably unshared');
} }
if (!isset($rootLinkItem['path']) && isset($rootLinkItem['file_target'])){
$rootLinkItem['path'] = $rootLinkItem['file_target'];
}
$file = new File($rootLinkItem['file_source'], array($rootLinkItem)); $file = new File($rootLinkItem['file_source'], array($rootLinkItem));
$file->setToken($token); $file->setToken($token);
if (isset($rootLinkItem['uid_owner'])){
\OC_Util::tearDownFS();
\OC_Util::setupFS($rootLinkItem['uid_owner']);
$file->setOwner($rootLinkItem['uid_owner']);
$file->setPath(\OC\Files\Filesystem::getPath($linkItem['file_source']));
}
if (isset($linkItem['share_with']) && !empty($linkItem['share_with'])){ if (isset($linkItem['share_with']) && !empty($linkItem['share_with'])){
$file->setPasswordProtected(true); $file->setPasswordProtected(true);
} }
@ -79,6 +68,10 @@ class File {
return $file; return $file;
} }
public function getToken($token){
return $this->token;
}
public function getFileId(){ public function getFileId(){
return $this->fileId; return $this->fileId;
} }
@ -156,22 +149,27 @@ class File {
* @throws \Exception * @throws \Exception
*/ */
public function getOwnerViewAndPath(){ public function getOwnerViewAndPath(){
if (!$this->owner || !$this->path){ if ($this->isPublicShare()){
if ($this->isPublicShare()){ $rootLinkItem = \OCP\Share::resolveReShare($this->sharing[0]);
list($owner, $path) = $this->getSharedFileOwnerAndPath(); if (isset($rootLinkItem['uid_owner'])){
$owner = $rootLinkItem['uid_owner'];
} else { } else {
$owner = \OCP\User::getUser(); throw new \Exception($this->fileId . ' is a broken share');
$path = Storage::resolvePath($this->fileId);
if (!$path){
throw new \Exception($this->fileId . ' can not be resolved');
}
} }
$view = new View('/' . $owner . '/files');
$path = $rootLinkItem['file_target'];
} else {
$owner = \OCP\User::getUser();
$view = new View('/' . $this->owner);
$path = $view->getPath($this->fileId);
}
$this->path = $path; if (!$path){
$this->owner = $owner; throw new \Exception($this->fileId . ' can not be resolved');
} }
$this->path = $path;
$this->owner = $owner;
$view = new View('/' . $this->owner . '/files');
if (!$view->file_exists($this->path)){ if (!$view->file_exists($this->path)){
throw new \Exception($this->path . ' doesn\'t exist'); throw new \Exception($this->path . ' doesn\'t exist');
} }
@ -179,6 +177,7 @@ class File {
return array($view, $this->path); return array($view, $this->path);
} }
public function getOwner(){ public function getOwner(){
if (!$this->owner){ if (!$this->owner){
$this->getOwnerViewAndPath(); $this->getOwnerViewAndPath();
@ -186,28 +185,6 @@ class File {
return $this->owner; return $this->owner;
} }
/**
* public links only
* @return array
*/
protected function getSharedFileOwnerAndPath(){
foreach ($this->sharing as $share){
$rootLinkItem = \OCP\Share::resolveReShare($share);
if (isset($rootLinkItem['uid_owner'])){
$owner = $rootLinkItem['uid_owner'];
} else {
$owner = false;
}
$view = new View('/' . $owner . '/files');
return array(
$owner,
$view->getPath($rootLinkItem['file_source'])
);
}
return $result;
}
protected function getPassword(){ protected function getPassword(){
return $this->sharing[0]['share_with']; return $this->sharing[0]['share_with'];

@ -38,8 +38,8 @@ class Genesis {
* @param OCA\Documents\File $file * @param OCA\Documents\File $file
* */ * */
public function __construct(\OCA\Documents\File $file){ public function __construct(\OCA\Documents\File $file){
$owner = $file->getOwner();
list($view, $path) = $file->getOwnerViewAndPath(); list($view, $path) = $file->getOwnerViewAndPath();
$owner = $file->getOwner();
$this->view = new View('/' . $owner); $this->view = new View('/' . $owner);

Loading…
Cancel
Save