Store share token to guest users
This commit is contained in:
parent
f81e41dc63
commit
13b73b12c1
@ -101,9 +101,10 @@ class SessionController extends Controller{
|
||||
}
|
||||
$sessionData = $session->getData();
|
||||
try {
|
||||
$file = new File($sessionData['file_id']);
|
||||
if ($isGuest){
|
||||
$file->setToken('yes');
|
||||
$file = File::getByShareToken($currentMemberData['token']);
|
||||
} else {
|
||||
$file = new File($sessionData['file_id']);
|
||||
}
|
||||
|
||||
list($view, $path) = $file->getOwnerViewAndPath();
|
||||
@ -128,8 +129,7 @@ class SessionController extends Controller{
|
||||
// Active users except current user
|
||||
$memberCount = count($memberIds) - 1;
|
||||
|
||||
if ($view->file_exists($path)){
|
||||
|
||||
if ($view->file_exists($path)){
|
||||
$proxyStatus = \OC_FileProxy::$enabled;
|
||||
\OC_FileProxy::$enabled = false;
|
||||
$currentHash = sha1($view->file_get_contents($path));
|
||||
@ -152,7 +152,6 @@ class SessionController extends Controller{
|
||||
if ($memberCount>0){
|
||||
// Update genesis hash to prevent conflicts
|
||||
Helper::debugLog('Update hash');
|
||||
|
||||
$session->updateGenesisHash($esId, sha1($data['content']));
|
||||
} else {
|
||||
// Last user. Kill session data
|
||||
|
@ -99,6 +99,13 @@
|
||||
<unsigned>true</unsigned>
|
||||
<length>1</length>
|
||||
</field>
|
||||
<field>
|
||||
<name>token</name>
|
||||
<type>text</type>
|
||||
<default></default>
|
||||
<notnull>false</notnull>
|
||||
<length>32</length>
|
||||
</field>
|
||||
<field>
|
||||
<name>status</name>
|
||||
<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 $insertStatement = 'INSERT INTO `*PREFIX*documents_member` (`es_id`, `uid`, `color`, `last_activity`, `is_guest`)
|
||||
VALUES (?, ?, ?, ?, ?)';
|
||||
protected $insertStatement = 'INSERT INTO `*PREFIX*documents_member` (`es_id`, `uid`, `color`, `last_activity`, `is_guest`, `token`)
|
||||
VALUES (?, ?, ?, ?, ?, ?)';
|
||||
|
||||
protected $loadStatement = 'SELECT * FROM `*PREFIX*documents_member` WHERE `member_id`= ?';
|
||||
|
||||
|
@ -68,7 +68,8 @@ class Db_Session extends \OCA\Documents\Db {
|
||||
$uid,
|
||||
$memberColor,
|
||||
time(),
|
||||
intval($file->isPublicShare())
|
||||
intval($file->isPublicShare()),
|
||||
$file->getToken()
|
||||
));
|
||||
|
||||
if ($member->insert()){
|
||||
|
67
lib/file.php
67
lib/file.php
@ -54,23 +54,12 @@ class File {
|
||||
if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
|
||||
// seems to be a valid share
|
||||
$rootLinkItem = \OCP\Share::resolveReShare($linkItem);
|
||||
$fileOwner = $rootLinkItem['uid_owner'];
|
||||
} else {
|
||||
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->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'])){
|
||||
$file->setPasswordProtected(true);
|
||||
@ -79,6 +68,10 @@ class File {
|
||||
return $file;
|
||||
}
|
||||
|
||||
public function getToken($token){
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
public function getFileId(){
|
||||
return $this->fileId;
|
||||
}
|
||||
@ -156,28 +149,34 @@ class File {
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getOwnerViewAndPath(){
|
||||
if (!$this->owner || !$this->path){
|
||||
if ($this->isPublicShare()){
|
||||
list($owner, $path) = $this->getSharedFileOwnerAndPath();
|
||||
if ($this->isPublicShare()){
|
||||
$rootLinkItem = \OCP\Share::resolveReShare($this->sharing[0]);
|
||||
if (isset($rootLinkItem['uid_owner'])){
|
||||
$owner = $rootLinkItem['uid_owner'];
|
||||
} else {
|
||||
$owner = \OCP\User::getUser();
|
||||
$path = Storage::resolvePath($this->fileId);
|
||||
if (!$path){
|
||||
throw new \Exception($this->fileId . ' can not be resolved');
|
||||
}
|
||||
throw new \Exception($this->fileId . ' is a broken share');
|
||||
}
|
||||
|
||||
$this->path = $path;
|
||||
$this->owner = $owner;
|
||||
$view = new View('/' . $owner . '/files');
|
||||
$path = $rootLinkItem['file_target'];
|
||||
} else {
|
||||
$owner = \OCP\User::getUser();
|
||||
$view = new View('/' . $this->owner);
|
||||
$path = $view->getPath($this->fileId);
|
||||
}
|
||||
|
||||
if (!$path){
|
||||
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)){
|
||||
throw new \Exception($this->path . ' doesn\'t exist');
|
||||
}
|
||||
|
||||
return array($view, $this->path);
|
||||
}
|
||||
|
||||
|
||||
public function getOwner(){
|
||||
if (!$this->owner){
|
||||
@ -186,28 +185,6 @@ class File {
|
||||
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(){
|
||||
return $this->sharing[0]['share_with'];
|
||||
|
@ -38,8 +38,8 @@ class Genesis {
|
||||
* @param OCA\Documents\File $file
|
||||
* */
|
||||
public function __construct(\OCA\Documents\File $file){
|
||||
$owner = $file->getOwner();
|
||||
list($view, $path) = $file->getOwnerViewAndPath();
|
||||
$owner = $file->getOwner();
|
||||
|
||||
$this->view = new View('/' . $owner);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user