Guest can finally edit
This commit is contained in:
parent
b3bb4730ef
commit
4c30cf0e71
@ -17,6 +17,7 @@ class DocumentController extends Controller{
|
|||||||
|
|
||||||
public static function create($args){
|
public static function create($args){
|
||||||
$uid = self::preDispatch();
|
$uid = self::preDispatch();
|
||||||
|
|
||||||
$view = new \OC\Files\View('/' . $uid . '/files');
|
$view = new \OC\Files\View('/' . $uid . '/files');
|
||||||
$path = Helper::getNewFileName($view, '/New Document.odt');
|
$path = Helper::getNewFileName($view, '/New Document.odt');
|
||||||
|
|
||||||
@ -32,9 +33,15 @@ class DocumentController extends Controller{
|
|||||||
* @param array $args - array containing session id as anelement with a key es_id
|
* @param array $args - array containing session id as anelement with a key es_id
|
||||||
*/
|
*/
|
||||||
public static function serve($args){
|
public static function serve($args){
|
||||||
self::preDispatch(false);
|
|
||||||
|
|
||||||
$session = Session::getSession(@$args['es_id']);
|
$session = Session::getSession(@$args['es_id']);
|
||||||
|
|
||||||
|
$file = new File(@$session['file_id']);
|
||||||
|
if (!$file->isPublicShare()){
|
||||||
|
self::preDispatch(false);
|
||||||
|
} else {
|
||||||
|
self::preDispatchGuest(false);
|
||||||
|
}
|
||||||
|
|
||||||
$filename = isset($session['genesis_url']) ? $session['genesis_url'] : '';
|
$filename = isset($session['genesis_url']) ? $session['genesis_url'] : '';
|
||||||
$documentsView = new View('/' . $session['owner']);
|
$documentsView = new View('/' . $session['owner']);
|
||||||
$download = new Download($documentsView->initDocumentsView(), $filename);
|
$download = new Download($documentsView->initDocumentsView(), $filename);
|
||||||
|
@ -37,17 +37,20 @@
|
|||||||
|
|
||||||
namespace OCA\Documents;
|
namespace OCA\Documents;
|
||||||
|
|
||||||
|
|
||||||
//TODO: check if the session is related to a public share
|
|
||||||
//\OCP\JSON::checkLoggedIn();
|
|
||||||
|
|
||||||
|
|
||||||
\OCP\JSON::checkAppEnabled('documents');
|
|
||||||
// session_write_close();
|
|
||||||
|
|
||||||
$response = array();
|
$response = array();
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
|
$esId = $request->getParam('args/es_id');
|
||||||
|
|
||||||
|
$session = Session::getSession($esId);
|
||||||
|
$file = new File(@$session['file_id']);
|
||||||
|
if (!$file->isPublicShare()){
|
||||||
|
Controller::preDispatch(false);
|
||||||
|
} else {
|
||||||
|
Controller::preDispatchGuest(false);
|
||||||
|
}
|
||||||
|
|
||||||
$command = $request->getParam('command');
|
$command = $request->getParam('command');
|
||||||
switch ($command){
|
switch ($command){
|
||||||
case 'query_memberdata_list':
|
case 'query_memberdata_list':
|
||||||
@ -84,7 +87,6 @@ try{
|
|||||||
case 'sync_ops':
|
case 'sync_ops':
|
||||||
$seqHead = (string) $request->getParam('args/seq_head');
|
$seqHead = (string) $request->getParam('args/seq_head');
|
||||||
if (!is_null($seqHead)){
|
if (!is_null($seqHead)){
|
||||||
$esId = $request->getParam('args/es_id');
|
|
||||||
$memberId = $request->getParam('args/member_id');
|
$memberId = $request->getParam('args/member_id');
|
||||||
$ops = $request->getParam('args/client_ops');
|
$ops = $request->getParam('args/client_ops');
|
||||||
$hasOps = is_array($ops) && count($ops)>0;
|
$hasOps = is_array($ops) && count($ops)>0;
|
||||||
|
@ -44,7 +44,6 @@ class SessionController extends Controller{
|
|||||||
* Store the document content to its origin
|
* Store the document content to its origin
|
||||||
*/
|
*/
|
||||||
public static function save(){
|
public static function save(){
|
||||||
$uid = self::preDispatch();
|
|
||||||
try {
|
try {
|
||||||
$sessionID = @$_SERVER['HTTP_WEBODF_SESSION_ID'];
|
$sessionID = @$_SERVER['HTTP_WEBODF_SESSION_ID'];
|
||||||
if (!$sessionID){
|
if (!$sessionID){
|
||||||
@ -65,6 +64,13 @@ class SessionController extends Controller{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$file = new File($session['file_id']);
|
$file = new File($session['file_id']);
|
||||||
|
if (!$file->isPublicShare()){
|
||||||
|
self::preDispatch();
|
||||||
|
} else {
|
||||||
|
self::preDispatchGuest();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
list($view, $path) = $file->getOwnerViewAndPath();
|
list($view, $path) = $file->getOwnerViewAndPath();
|
||||||
|
|
||||||
$isWritable = ($view->file_exists($path) && $view->isUpdatable($path)) || $view->isCreatable($path);
|
$isWritable = ($view->file_exists($path) && $view->isUpdatable($path)) || $view->isCreatable($path);
|
||||||
|
129
lib/file.php
129
lib/file.php
@ -27,6 +27,7 @@ class File {
|
|||||||
protected $fileId;
|
protected $fileId;
|
||||||
protected $owner;
|
protected $owner;
|
||||||
protected $path;
|
protected $path;
|
||||||
|
protected $sharing;
|
||||||
|
|
||||||
public function __construct($fileId){
|
public function __construct($fileId){
|
||||||
if (!$fileId){
|
if (!$fileId){
|
||||||
@ -34,6 +35,10 @@ class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->fileId = $fileId;
|
$this->fileId = $fileId;
|
||||||
|
|
||||||
|
//if you know how to get sharing info by fileId via API,
|
||||||
|
//please send me a link to video tutorial :/
|
||||||
|
$this->sharing = $this->getSharingOps();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getByShareToken($token){
|
public static function getByShareToken($token){
|
||||||
@ -47,8 +52,6 @@ class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$file = new File($rootLinkItem['file_source']);
|
$file = new File($rootLinkItem['file_source']);
|
||||||
$file->setOwner($rootLinkItem['uid_owner']);
|
|
||||||
$file->setPath('/files' . $rootLinkItem['file_target']);
|
|
||||||
|
|
||||||
return $file;
|
return $file;
|
||||||
}
|
}
|
||||||
@ -64,6 +67,18 @@ class File {
|
|||||||
public function setPath($path){
|
public function setPath($path){
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isPublicShare(){
|
||||||
|
foreach ($this->sharing as $share){
|
||||||
|
if (
|
||||||
|
$share['share_type'] == \OCP\Share::SHARE_TYPE_LINK
|
||||||
|
|| $share['share_type'] == \OCP\Share::SHARE_TYPE_EMAIL
|
||||||
|
){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -71,69 +86,87 @@ class File {
|
|||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function getOwnerViewAndPath(){
|
public function getOwnerViewAndPath(){
|
||||||
if (!$this->owner || !$this->path){
|
if (!$this->owner || !$this->path){
|
||||||
$fileInfo = \OC\Files\Cache\Cache::getById($this->fileId);
|
$info = $this->getSharedFileOwnerAndPath();
|
||||||
|
if (is_array($info) && count($info)){
|
||||||
//is it shared
|
$owner = $info[0];
|
||||||
$sharedInfo = $this->getSharedBySource();
|
$path = $info[1];
|
||||||
|
|
||||||
if (is_array($sharedInfo)){
|
|
||||||
$owner = $sharedInfo['uid_owner'];
|
|
||||||
$path = $sharedInfo['path'];
|
|
||||||
} else {
|
} else {
|
||||||
// owner is myself
|
list($owner, $path) = $this->getLocalFileOwnerAndPath();
|
||||||
$owner = \OCP\User::getUser();
|
|
||||||
$path = @$fileInfo[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$path){
|
if (!$path){
|
||||||
throw new \Exception($this->fileId . ' can not be resolved');
|
throw new \Exception($this->fileId . ' can not be resolved');
|
||||||
}
|
}
|
||||||
|
|
||||||
$view = new View('/' . $owner);
|
|
||||||
|
|
||||||
|
$this->path = $path;
|
||||||
$this->owner = $owner;
|
$this->owner = $owner;
|
||||||
} else {
|
|
||||||
$view = new View('/' . $this->owner);
|
|
||||||
$path = $this->path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$view->file_exists($path)){
|
$view = new View('/' . $this->owner);
|
||||||
throw new \Exception($path . ' doesn\'t exist');
|
if (!$view->file_exists($this->path)){
|
||||||
|
throw new \Exception($this->path . ' doesn\'t exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
return array($view, $path);
|
return array($view, $this->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOwner(){
|
public function getOwner(){
|
||||||
if (!$this->owner){
|
if (!$this->owner){
|
||||||
|
$this->getOwnerViewAndPath();
|
||||||
$fileInfo = \OC\Files\Cache\Cache::getById($this->fileId);
|
|
||||||
|
|
||||||
//is it shared
|
|
||||||
$sharedInfo = $this->getSharedBySource();
|
|
||||||
if (!is_array($sharedInfo)){
|
|
||||||
$sharedInfo = $this->getSharedByLink();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($sharedInfo)){
|
|
||||||
$this->owner = $sharedInfo['uid_owner'];
|
|
||||||
} else {
|
|
||||||
// owner is myself
|
|
||||||
$this->owner = \OCP\User::getUser();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $this->owner;
|
return $this->owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getSharedBySource(){
|
protected function getSharedFileOwnerAndPath(){
|
||||||
return \OCP\Share::getItemSharedWithBySource(
|
$result = array();
|
||||||
'file',
|
foreach ($this->sharing as $share){
|
||||||
$this->fileId,
|
return array(
|
||||||
\OCP\Share::FORMAT_NONE,
|
$share['uid_owner'],
|
||||||
null,
|
$share['path']
|
||||||
true
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
protected function getLocalFileOwnerAndPath(){
|
||||||
|
$fileInfo = \OC\Files\Cache\Cache::getById($this->fileId);
|
||||||
|
$owner = \OCP\User::getUser();
|
||||||
|
if (!$owner){
|
||||||
|
throw new Exception('Guest users can\'t access local files. This one was probably unshared recently.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return array ($owner, @$fileInfo[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getSharingOps(){
|
||||||
|
|
||||||
|
$where = 'AND `file_source`=?';
|
||||||
|
$values = array($this->fileId);
|
||||||
|
|
||||||
|
if (\OCP\User::isLoggedIn()){
|
||||||
|
$where .= ' AND ((`share_type`=' . \OCP\Share::SHARE_TYPE_USER . ' AND `share_with`=?) OR `share_type`=' . \OCP\Share::SHARE_TYPE_LINK . ')';
|
||||||
|
$values[] = \OCP\User::getUser();
|
||||||
|
} else {
|
||||||
|
$where .= ' AND (`share_type`=' . \OCP\Share::SHARE_TYPE_LINK . ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = \OC_DB::prepare('SELECT `*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, '
|
||||||
|
.'`share_type`, `share_with`, `file_source`, `path`, `file_target`, '
|
||||||
|
.'`permissions`, `expiration`, `storage`, `*PREFIX*filecache`.`parent` as `file_parent`, '
|
||||||
|
.'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`'
|
||||||
|
.'FROM `*PREFIX*share` INNER JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` WHERE `item_type` = `file` ' . $where);
|
||||||
|
$result = $query->execute($values);
|
||||||
|
$shares = $result->fetchAll();
|
||||||
|
|
||||||
|
$origins = array();
|
||||||
|
if (is_array($shares)){
|
||||||
|
foreach ($shares as $share){
|
||||||
|
$origins[] = \OCP\Share::resolveReShare($share);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $origins;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -55,9 +55,10 @@ class Member extends Db{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function updateMemberActivity($memberId){
|
public static function updateMemberActivity($memberId){
|
||||||
$query = \OCP\DB::prepare('UPDATE ' . self::DB_TABLE . ' SET `last_activity`=? WHERE `member_id`=?');
|
$query = \OCP\DB::prepare('UPDATE ' . self::DB_TABLE . ' SET `last_activity`=?, `status`=? WHERE `member_id`=?');
|
||||||
$query->execute(array(
|
$query->execute(array(
|
||||||
time(),
|
time(),
|
||||||
|
self::MEMBER_STATUS_ACTIVE,
|
||||||
$memberId
|
$memberId
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user