Move File out of controller
This commit is contained in:
parent
d770cec140
commit
857c03a103
@ -15,12 +15,15 @@ namespace OCA\Documents;
|
|||||||
class SessionController extends Controller{
|
class SessionController extends Controller{
|
||||||
|
|
||||||
public static function joinAsGuest($args){
|
public static function joinAsGuest($args){
|
||||||
$uid = self::preDispatchGuest();
|
$postfix = self::preDispatchGuest();
|
||||||
$uid = substr(@$_POST['name'], 0, 16) .' '. $uid;
|
|
||||||
$token = @$args['token'];
|
$uid = Helper::getArrayValueByKey($_POST, 'name');
|
||||||
|
$guestUid = substr($uid, 0, 16) .' '. $postfix;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$file = File::getByShareToken($token);
|
$token = Helper::getArrayValueByKey($args, 'token');
|
||||||
self::join($uid, $file);
|
$fileId = File::getIdByShareToken($token);
|
||||||
|
self::join($guestUid, $fileId);
|
||||||
} catch (\Exception $e){
|
} catch (\Exception $e){
|
||||||
Helper::warnLog('Starting a session failed. Reason: ' . $e->getMessage());
|
Helper::warnLog('Starting a session failed. Reason: ' . $e->getMessage());
|
||||||
\OCP\JSON::error();
|
\OCP\JSON::error();
|
||||||
@ -33,13 +36,15 @@ class SessionController extends Controller{
|
|||||||
$fileId = intval(@$args['file_id']);
|
$fileId = intval(@$args['file_id']);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$file = new File($fileId);
|
$view = \OC\Files\Filesystem::getView();
|
||||||
|
$path = $view->getPath($fileId);
|
||||||
if ($file->getPermissions() & \OCP\PERMISSION_UPDATE) {
|
|
||||||
self::join($uid, $file);
|
if ($view->isUpdatable($path)) {
|
||||||
|
self::join($uid, $fileId);
|
||||||
} else {
|
} else {
|
||||||
|
$info = $view->getFileInfo();
|
||||||
\OCP\JSON::success(array(
|
\OCP\JSON::success(array(
|
||||||
'permissions' => $file->getPermissions(),
|
'permissions' => $info['permissions'],
|
||||||
'id' => $fileId
|
'id' => $fileId
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -51,8 +56,8 @@ class SessionController extends Controller{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function join($uid, $file){
|
protected static function join($uid, $fileId){
|
||||||
$session = Db_Session::start($uid, $file);
|
$session = Db_Session::start($uid, $fileId);
|
||||||
\OCP\JSON::success($session);
|
\OCP\JSON::success($session);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,8 @@ class Db_Session extends \OCA\Documents\Db {
|
|||||||
* @return array
|
* @return array
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function start($uid, File $file){
|
public static function start($uid, $fileId){
|
||||||
|
$file = new File($fileId);
|
||||||
list($ownerView, $path) = $file->getOwnerViewAndPath();
|
list($ownerView, $path) = $file->getOwnerViewAndPath();
|
||||||
|
|
||||||
// Create a directory to store genesis
|
// Create a directory to store genesis
|
||||||
|
17
lib/file.php
17
lib/file.php
@ -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){
|
public static function getByShareToken($token){
|
||||||
$linkItem = \OCP\Share::getShareByToken($token, false);
|
$linkItem = \OCP\Share::getShareByToken($token, false);
|
||||||
if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
|
if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user