Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Add a virtual folder at the root of the webdav to make it API-consist…
Browse files Browse the repository at this point in the history
…ent (both folders and files are accessed via /../dav/DocumentName)

Store remoteShares by token, not remoteId
Ping back on Dav access point when receiving a share.
  • Loading branch information
cdujeu committed Feb 25, 2016
1 parent bcefb89 commit 89efd06
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 6 deletions.
8 changes: 5 additions & 3 deletions core/src/plugins/core.ocs/OCSPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ public function remoteRepositoryById($repositoryId, &$repoObject){
if($share != null){
$repoObject = $share->buildVirtualRepository();
$loggedUser = \AuthService::getLoggedUser();
$loggedUser->personalRole->setAcl($repoObject->getId(), "rw");
$loggedUser->recomputeMergedRole();
\AuthService::updateUser($loggedUser);
if($loggedUser != null){
$loggedUser->personalRole->setAcl($repoObject->getId(), "rw");
$loggedUser->recomputeMergedRole();
\AuthService::updateUser($loggedUser);
}
}
}

Expand Down
45 changes: 44 additions & 1 deletion core/src/plugins/core.ocs/src/Model/RemoteShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*/
namespace Pydio\OCS\Model;

use Sabre\DAV;
use Sabre\DAV\Exception;

defined('AJXP_EXEC') or die('Access not allowed');
if(!defined('OCS_INVITATION_STATUS_PENDING')){
define('OCS_INVITATION_STATUS_PENDING', 1);
Expand Down Expand Up @@ -92,6 +95,11 @@ class RemoteShare
*/
var $documentIsLeaf;

/**
* @var bool
*/
var $documentTypeResolved;

/**
* @return int
*/
Expand All @@ -118,7 +126,7 @@ public function buildVirtualRepository(){
"DRIVER" => "webdav",
"DRIVER_OPTIONS"=> array(
"HOST" => $parts["scheme"]."://".$parts["host"],
"PATH" => $parts["path"],
"PATH" => $parts["path"].($this->isDocumentIsLeaf()? "":"/".$this->getDocumentName()),
"USER" => $this->getOcsToken(),
"PASS" => ($this->hasPassword()?$this->getPassword() : ""),
"DEFAULT_RIGHTS"=> "",
Expand All @@ -136,6 +144,41 @@ public function buildVirtualRepository(){
return $repo;
}

public function pingRemoteDAVPoint(){

$fullPath = rtrim($this->getOcsDavUrl(), "/")."/".$this->getDocumentName();
$parts = parse_url($fullPath);
$client = new DAV\Client(array(
'baseUri' => $parts["scheme"]."://".$parts["host"],
'userName' => $this->getOcsToken(),
'password' => ''
));
try {
$result = $client->propFind($parts["path"],
[
'{DAV:}getlastmodified',
'{DAV:}getcontentlength',
'{DAV:}resourcetype'
]
);
} catch (Exception\NotFound $e) {
return false;
} catch (Exception $e) {
return false;
}
/**
* @var \Sabre\DAV\Property\ResourceType $resType;
*/
$resType = $result["{DAV:}resourcetype"];
if($resType->is("{DAV:}collection")) {
$this->setDocumentIsLeaf(false);
} else{
$this->setDocumentIsLeaf(true);
}
$this->documentTypeResolved = true;
return true;
}

/**
* @return boolean
*/
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/core.ocs/src/Model/SQLStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function storeRemoteShare(RemoteShare $remoteShare)
{
$id = $remoteShare->getId();
if(empty($id)){
$id = $remoteShare->getOcsRemoteId();
$id = $remoteShare->getOcsToken();
$remoteShare->setId($id);
}
$this->storage->simpleStoreSet(OCS_SQLSTORE_NS_REMOTE_SHARE, $id, $remoteShare, OCS_SQLSTORE_FORMAT, $remoteShare->getUser());
Expand Down
35 changes: 34 additions & 1 deletion core/src/plugins/core.ocs/src/server/dav/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,47 @@
namespace Pydio\OCS\Server\Dav;

defined('AJXP_EXEC') or die('Access not allowed');
require_once(AJXP_INSTALL_PATH."/".AJXP_PLUGINS_FOLDER."/action.share/class.ShareStore.php");

use Sabre;

class Server
{
/**
* @param $baseUri
* @return \AJXP_Sabre_Collection|SharingCollection
* @throws \Exception
*/
protected function initCollectionForFileOrFolder(&$baseUri){
try{
$testBackend = new BasicAuthNoPass();
$userPass = $testBackend->getUserPass();
if(isSet($userPass[0])){
$shareStore = new \ShareStore(\ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER"));
$shareData = $shareStore->loadShare($userPass[0]);
if(isSet($shareData) && isSet($shareData["REPOSITORY"])){
$repo = \ConfService::getRepositoryById($shareData["REPOSITORY"]);
if(!empty($repo) && !$repo->hasContentFilter()){
$baseDir = basename($repo->getOption("PATH"));
}
}
}
}catch (\Exception $e){}
$rootCollection = new \AJXP_Sabre_Collection("/", null, null);
if(isSet($baseDir)){
$currentPath = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
if($currentPath == $baseUri || $currentPath == $baseUri."/"){
$rootCollection = new SharingCollection("/", null, null);
}else{
$baseUri .= "/$baseDir";
}
}
return $rootCollection;
}

public function start($baseUri = "/"){

$rootCollection = new \AJXP_Sabre_Collection("/", null, null);
$rootCollection = $this->initCollectionForFileOrFolder($baseUri);
$server = new Sabre\DAV\Server($rootCollection);
$server->setBaseUri($baseUri);

Expand Down
40 changes: 40 additions & 0 deletions core/src/plugins/core.ocs/src/server/dav/SharingCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*
* Copyright 2007-2015 Abstrium <contact (at) pydio.com>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://pyd.io/>.
*/

namespace Pydio\OCS\Server\Dav;
defined('AJXP_EXEC') or die('Access not allowed');


class SharingCollection extends \AJXP_Sabre_Collection
{
public function getChildren()
{
$url = $this->getUrl();
if($this->path == "/" && !$this->repository->hasContentFilter()){
$basePath = $this->repository->getOption("PATH");
$dirName = basename($basePath);
$this->children[$dirName] = new \Sabre\DAV\SimpleCollection($dirName);
return $this->children;
}else{
return parent::getChildren(); // TODO: Change the autogenerated stub
}
}
}

0 comments on commit 89efd06

Please sign in to comment.