Move File out of controller

pull/1/head
Victor Dubiniuk 10 years ago
parent d770cec140
commit 857c03a103

@ -15,12 +15,15 @@ namespace OCA\Documents;
class SessionController extends Controller{
public static function joinAsGuest($args){
$uid = self::preDispatchGuest();
$uid = substr(@$_POST['name'], 0, 16) .' '. $uid;
$token = @$args['token'];
$postfix = self::preDispatchGuest();
$uid = Helper::getArrayValueByKey($_POST, 'name');
$guestUid = substr($uid, 0, 16) .' '. $postfix;
try {
$file = File::getByShareToken($token);
self::join($uid, $file);
$token = Helper::getArrayValueByKey($args, 'token');
$fileId = File::getIdByShareToken($token);
self::join($guestUid, $fileId);
} catch (\Exception $e){
Helper::warnLog('Starting a session failed. Reason: ' . $e->getMessage());
\OCP\JSON::error();
@ -33,13 +36,15 @@ class SessionController extends Controller{
$fileId = intval(@$args['file_id']);
try {
$file = new File($fileId);
if ($file->getPermissions() & \OCP\PERMISSION_UPDATE) {
self::join($uid, $file);
$view = \OC\Files\Filesystem::getView();
$path = $view->getPath($fileId);
if ($view->isUpdatable($path)) {
self::join($uid, $fileId);
} else {
$info = $view->getFileInfo();
\OCP\JSON::success(array(
'permissions' => $file->getPermissions(),
'permissions' => $info['permissions'],
'id' => $fileId
));
}
@ -51,8 +56,8 @@ class SessionController extends Controller{
}
}
protected static function join($uid, $file){
$session = Db_Session::start($uid, $file);
protected static function join($uid, $fileId){
$session = Db_Session::start($uid, $fileId);
\OCP\JSON::success($session);
exit();
}

@ -35,7 +35,8 @@ class Db_Session extends \OCA\Documents\Db {
* @return array
* @throws \Exception
*/
public static function start($uid, File $file){
public static function start($uid, $fileId){
$file = new File($fileId);
list($ownerView, $path) = $file->getOwnerViewAndPath();
// Create a directory to store genesis

@ -47,6 +47,23 @@ 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);
if (is_array($linkItem) && isset($linkItem['uid_owner'])) {

Loading…
Cancel
Save