Further switch to member is_guest property
This commit is contained in:
parent
8a5f3ca076
commit
f81e41dc63
@ -51,16 +51,10 @@ class DocumentController extends Controller{
|
||||
* @param array $args - array containing session id as an element with a key es_id
|
||||
*/
|
||||
public static function serve($args){
|
||||
|
||||
$session = new Db_Session();
|
||||
$sessionData = $session->load(@$args['es_id'])->getData();
|
||||
|
||||
$file = new File(@$sessionData['file_id']);
|
||||
if (!$file->isPublicShare()){
|
||||
self::preDispatch();
|
||||
} else {
|
||||
self::preDispatchGuest();
|
||||
}
|
||||
self::preDispatchGuest();
|
||||
|
||||
$filename = isset($sessionData['genesis_url']) ? $sessionData['genesis_url'] : '';
|
||||
$download = new Download($sessionData['owner'], $filename);
|
||||
|
@ -33,6 +33,16 @@ try{
|
||||
|
||||
$session = new Db_Session();
|
||||
$sessionData = $session->load($esId)->getData();
|
||||
|
||||
$memberId = $request->getParam('args/member_id');
|
||||
$member = new Db_Member();
|
||||
$memberData = $member->load($memberId)->getData();
|
||||
|
||||
if (isset($memberData['is_guest']) && $memberData['is_guest']){
|
||||
Controller::preDispatchGuest(false);
|
||||
} else {
|
||||
Controller::preDispatch(false);
|
||||
}
|
||||
|
||||
try {
|
||||
$file = new File(@$sessionData['file_id']);
|
||||
@ -42,25 +52,18 @@ try{
|
||||
$ex->setBody($request->getRawRequest());
|
||||
throw $ex;
|
||||
}
|
||||
if (!$file->isPublicShare()){
|
||||
Controller::preDispatch(false);
|
||||
} else {
|
||||
Controller::preDispatchGuest(false);
|
||||
}
|
||||
|
||||
$command = $request->getParam('command');
|
||||
switch ($command){
|
||||
case 'sync_ops':
|
||||
$seqHead = (string) $request->getParam('args/seq_head');
|
||||
if (!is_null($seqHead)){
|
||||
$memberId = $request->getParam('args/member_id');
|
||||
$ops = $request->getParam('args/client_ops');
|
||||
$hasOps = is_array($ops) && count($ops)>0;
|
||||
|
||||
$op = new Db_Op();
|
||||
$currentHead = $op->getHeadSeq($esId);
|
||||
|
||||
$member = new Db_Member();
|
||||
try {
|
||||
$member->updateActivity($memberId);
|
||||
} catch (\Exception $e){
|
||||
|
@ -22,8 +22,8 @@ class SessionController extends Controller{
|
||||
|
||||
try {
|
||||
$token = Helper::getArrayValueByKey($args, 'token');
|
||||
$fileId = File::getIdByShareToken($token);
|
||||
$session = Db_Session::start($uid, $fileId, true);
|
||||
$file = File::getByShareToken($token);
|
||||
$session = Db_Session::start($uid, $file, true);
|
||||
\OCP\JSON::success($session);
|
||||
} catch (\Exception $e){
|
||||
Helper::warnLog('Starting a session failed. Reason: ' . $e->getMessage());
|
||||
@ -34,14 +34,15 @@ class SessionController extends Controller{
|
||||
|
||||
public static function joinAsUser($args){
|
||||
$uid = self::preDispatch();
|
||||
$fileId = intval(@$args['file_id']);
|
||||
$fileId = Helper::getArrayValueByKey($args, 'file_id');
|
||||
|
||||
try {
|
||||
$view = \OC\Files\Filesystem::getView();
|
||||
$path = $view->getPath($fileId);
|
||||
|
||||
if ($view->isUpdatable($path)) {
|
||||
$session = Db_Session::start($uid, $fileId, false);
|
||||
$file = new File($fileId);
|
||||
$session = Db_Session::start($uid, $file);
|
||||
\OCP\JSON::success($session);
|
||||
} else {
|
||||
$info = $view->getFileInfo();
|
||||
@ -73,7 +74,8 @@ class SessionController extends Controller{
|
||||
$currentMember = new Db_Member();
|
||||
$currentMemberData = $currentMember->load($memberId)->getData();
|
||||
if (isset($currentMemberData['is_guest']) && $currentMemberData['is_guest']){
|
||||
self::preDispatchGuest();
|
||||
$uid = self::preDispatchGuest();
|
||||
$isGuest = true;
|
||||
} else {
|
||||
self::preDispatch();
|
||||
}
|
||||
@ -100,11 +102,14 @@ class SessionController extends Controller{
|
||||
$sessionData = $session->getData();
|
||||
try {
|
||||
$file = new File($sessionData['file_id']);
|
||||
if ($isGuest){
|
||||
$file->setToken('yes');
|
||||
}
|
||||
|
||||
list($view, $path) = $file->getOwnerViewAndPath();
|
||||
} catch (\Exception $e){
|
||||
//File was deleted or unshared. We need to save content as new file anyway
|
||||
//Sorry, but for guests it would be lost :(
|
||||
$uid = self::preDispatch();
|
||||
$view = new \OC\Files\View('/' . $uid . '/files');
|
||||
|
||||
$dir = \OCP\Config::getUserValue(\OCP\User::getUser(), 'documents', 'save_path', '');
|
||||
|
@ -35,9 +35,7 @@ class Db_Session extends \OCA\Documents\Db {
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function start($uid, $fileId, $isGuest){
|
||||
|
||||
$file = new File($fileId);
|
||||
public static function start($uid, $file){
|
||||
// Create a directory to store genesis
|
||||
$genesis = new Genesis($file);
|
||||
|
||||
@ -70,7 +68,7 @@ class Db_Session extends \OCA\Documents\Db {
|
||||
$uid,
|
||||
$memberColor,
|
||||
time(),
|
||||
intval($isGuest)
|
||||
intval($file->isPublicShare())
|
||||
));
|
||||
|
||||
if ($member->insert()){
|
||||
@ -81,7 +79,7 @@ class Db_Session extends \OCA\Documents\Db {
|
||||
$imageUrl = $uid;
|
||||
}
|
||||
|
||||
$displayName = $isGuest ? $uid . ' ' . Db_Member::getGuestPostfix() : \OCP\User::getDisplayName($uid);
|
||||
$displayName = $file->isPublicShare() ? $uid . ' ' . Db_Member::getGuestPostfix() : \OCP\User::getDisplayName($uid);
|
||||
|
||||
$session['member_id'] = (string) $member->getLastInsertId();
|
||||
$op = new Db_Op();
|
||||
|
39
lib/file.php
39
lib/file.php
@ -28,6 +28,7 @@ class File {
|
||||
protected $owner;
|
||||
protected $path;
|
||||
protected $sharing;
|
||||
protected $token ='';
|
||||
protected $passwordProtected = false;
|
||||
|
||||
|
||||
@ -47,22 +48,6 @@ class File {
|
||||
}
|
||||
}
|
||||
|
||||
public static function getIdByShareToken($token){
|
||||
$linkItem = \OCP\Share::getShareByToken($token, false);
|
||||
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'];
|
||||
}
|
||||
|
||||
return $rootLinkItem['file_source'];
|
||||
}
|
||||
|
||||
public static function getByShareToken($token){
|
||||
$linkItem = \OCP\Share::getShareByToken($token, false);
|
||||
@ -78,7 +63,7 @@ class File {
|
||||
$rootLinkItem['path'] = $rootLinkItem['file_target'];
|
||||
}
|
||||
$file = new File($rootLinkItem['file_source'], array($rootLinkItem));
|
||||
|
||||
$file->setToken($token);
|
||||
|
||||
if (isset($rootLinkItem['uid_owner'])){
|
||||
\OC_Util::tearDownFS();
|
||||
@ -106,16 +91,12 @@ class File {
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
public function setToken($token){
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
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;
|
||||
return !empty($this->token);
|
||||
}
|
||||
|
||||
public function isPasswordProtected(){
|
||||
@ -217,11 +198,11 @@ class File {
|
||||
} else {
|
||||
$owner = false;
|
||||
}
|
||||
\OC_Util::tearDownFS();
|
||||
\OC_Util::setupFS($owner);
|
||||
$view = new View('/' . $owner . '/files');
|
||||
|
||||
return array(
|
||||
$owner,
|
||||
\OC\Files\Filesystem::getPath($rootLinkItem['file_source'])
|
||||
$view->getPath($rootLinkItem['file_source'])
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user