summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/dav/lib/connector/sabre/filesplugin.php37
-rw-r--r--apps/dav/lib/connector/sabre/serverfactory.php3
-rw-r--r--apps/dav/lib/server.php3
-rw-r--r--lib/private/Share20/DefaultShareProvider.php51
-rw-r--r--lib/private/appframework/http/request.php9
-rw-r--r--tests/lib/share20/defaultshareprovidertest.php112
6 files changed, 53 insertions, 162 deletions
diff --git a/apps/dav/lib/connector/sabre/filesplugin.php b/apps/dav/lib/connector/sabre/filesplugin.php
index e973b4e8682..fb2af554c68 100644
--- a/apps/dav/lib/connector/sabre/filesplugin.php
+++ b/apps/dav/lib/connector/sabre/filesplugin.php
@@ -27,10 +27,13 @@
namespace OCA\DAV\Connector\Sabre;
+use OC\Files\View;
+use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\IFile;
use \Sabre\DAV\PropFind;
use \Sabre\DAV\PropPatch;
+use Sabre\DAV\Tree;
use \Sabre\HTTP\RequestInterface;
use \Sabre\HTTP\ResponseInterface;
use OCP\Files\StorageNotAvailableException;
@@ -58,7 +61,7 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
private $server;
/**
- * @var \Sabre\DAV\Tree
+ * @var Tree
*/
private $tree;
@@ -71,21 +74,29 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
private $isPublic;
/**
- * @var \OC\Files\View
+ * @var View
*/
private $fileView;
/**
- * @param \Sabre\DAV\Tree $tree
- * @param \OC\Files\View $view
+ * @var bool
+ */
+ private $downloadAttachment;
+
+ /**
+ * @param Tree $tree
+ * @param View $view
* @param bool $isPublic
+ * @param bool $downloadAttachment
*/
- public function __construct(\Sabre\DAV\Tree $tree,
- \OC\Files\View $view,
- $isPublic = false) {
+ public function __construct(Tree $tree,
+ View $view,
+ $isPublic = false,
+ $downloadAttachment = true) {
$this->tree = $tree;
$this->fileView = $view;
$this->isPublic = $isPublic;
+ $this->downloadAttachment = $downloadAttachment;
}
/**
@@ -135,7 +146,7 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
* Plugin that checks if a move can actually be performed.
* @param string $source source path
* @param string $destination destination path
- * @throws \Sabre\DAV\Exception\Forbidden
+ * @throws Forbidden
*/
function checkMove($source, $destination) {
list($sourceDir,) = \Sabre\HTTP\URLUtil::splitPath($source);
@@ -145,11 +156,11 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
$sourceFileInfo = $this->fileView->getFileInfo($source);
if ($sourceFileInfo === false) {
- throw new \Sabre\DAV\Exception\NotFound($source . ' does not exist');
+ throw new NotFound($source . ' does not exist');
}
if (!$sourceFileInfo->isDeletable()) {
- throw new \Sabre\DAV\Exception\Forbidden($source . " cannot be deleted");
+ throw new Forbidden($source . " cannot be deleted");
}
}
}
@@ -192,7 +203,9 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
if (!($node instanceof IFile)) return;
// adds a 'Content-Disposition: attachment' header
- $response->addHeader('Content-Disposition', 'attachment');
+ if ($this->downloadAttachment) {
+ $response->addHeader('Content-Disposition', 'attachment');
+ }
if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
//Add OC-Checksum header
@@ -233,7 +246,7 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
});
$propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
- return $node->getEtag();
+ return $node->getETag();
});
$propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
diff --git a/apps/dav/lib/connector/sabre/serverfactory.php b/apps/dav/lib/connector/sabre/serverfactory.php
index 080f889ae71..8158db3e92a 100644
--- a/apps/dav/lib/connector/sabre/serverfactory.php
+++ b/apps/dav/lib/connector/sabre/serverfactory.php
@@ -132,7 +132,8 @@ class ServerFactory {
}
$objectTree->init($root, $view, $this->mountManager);
- $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesPlugin($objectTree, $view));
+ $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesPlugin($objectTree, $view, false,
+ !$this->config->getSystemValue('debug', false)));
$server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view));
if($this->userSession->isLoggedIn()) {
diff --git a/apps/dav/lib/server.php b/apps/dav/lib/server.php
index f624137f316..e74292282a7 100644
--- a/apps/dav/lib/server.php
+++ b/apps/dav/lib/server.php
@@ -125,7 +125,8 @@ class Server {
$user = \OC::$server->getUserSession()->getUser();
if (!is_null($user)) {
$view = \OC\Files\Filesystem::getView();
- $this->server->addPlugin(new FilesPlugin($this->server->tree, $view));
+ $this->server->addPlugin(new FilesPlugin($this->server->tree, $view, false,
+ !\OC::$server->getConfig()->getSystemValue('debug', false)));
$this->server->addPlugin(
new \Sabre\DAV\PropertyStorage\Plugin(
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php
index b91ac24d44f..f6171f87992 100644
--- a/lib/private/Share20/DefaultShareProvider.php
+++ b/lib/private/Share20/DefaultShareProvider.php
@@ -471,18 +471,7 @@ class DefaultShareProvider implements IShareProvider {
* Reshares for this user are shares where they are the owner.
*/
if ($reshares === false) {
- //Special case for old shares created via the web UI
- $or1 = $qb->expr()->andX(
- $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
- $qb->expr()->isNull('uid_initiator')
- );
-
- $qb->andWhere(
- $qb->expr()->orX(
- $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)),
- $or1
- )
- );
+ $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
} else {
$qb->andWhere(
$qb->expr()->orX(
@@ -765,18 +754,8 @@ class DefaultShareProvider implements IShareProvider {
$share->setToken($data['token']);
}
- if ($data['uid_initiator'] === null) {
- //OLD SHARE
- $share->setSharedBy($data['uid_owner']);
- $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
-
- $owner = $path->getOwner();
- $share->setShareOwner($owner->getUID());
- } else {
- //New share!
- $share->setSharedBy($data['uid_initiator']);
- $share->setShareOwner($data['uid_owner']);
- }
+ $share->setSharedBy($data['uid_initiator']);
+ $share->setShareOwner($data['uid_owner']);
$share->setNodeId((int)$data['file_source']);
$share->setNodeType($data['item_type']);
@@ -792,30 +771,6 @@ class DefaultShareProvider implements IShareProvider {
}
/**
- * Get the node with file $id for $user
- *
- * @param string $user The userId
- * @param int $id
- * @return \OCP\Files\File|\OCP\Files\Folder
- * @throws InvalidShare
- */
- private function getNode($user, $id) {
- try {
- $userFolder = $this->rootFolder->getUserFolder($user);
- } catch (NotFoundException $e) {
- throw new InvalidShare();
- }
-
- $nodes = $userFolder->getById($id);
-
- if (empty($nodes)) {
- throw new InvalidShare();
- }
-
- return $nodes[0];
- }
-
- /**
* Resolve a group share to a user specific share
* Thus if the user moved their group share make sure this is properly reflected here.
*
diff --git a/lib/private/appframework/http/request.php b/lib/private/appframework/http/request.php
index caddb5a235d..2dc636fcff2 100644
--- a/lib/private/appframework/http/request.php
+++ b/lib/private/appframework/http/request.php
@@ -44,6 +44,13 @@ use OCP\Security\ISecureRandom;
/**
* Class for accessing variables in the request.
* This class provides an immutable object with request variables.
+ *
+ * @property mixed[] cookies
+ * @property mixed[] env
+ * @property mixed[] files
+ * @property string method
+ * @property mixed[] parameters
+ * @property mixed[] server
*/
class Request implements \ArrayAccess, \Countable, IRequest {
@@ -260,7 +267,7 @@ class Request implements \ArrayAccess, \Countable, IRequest {
* @param string $id
*/
public function __unset($id) {
- throw new \RunTimeException('You cannot change the contents of the request object');
+ throw new \RuntimeException('You cannot change the contents of the request object');
}
/**
diff --git a/tests/lib/share20/defaultshareprovidertest.php b/tests/lib/share20/defaultshareprovidertest.php
index 60024989681..610de3b6232 100644
--- a/tests/lib/share20/defaultshareprovidertest.php
+++ b/tests/lib/share20/defaultshareprovidertest.php
@@ -123,7 +123,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
->values([
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER),
'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('sharedBy'),
+ 'uid_owner' => $qb->expr()->literal('shareOwner'),
+ 'uid_initiator' => $qb->expr()->literal('sharedBy'),
'item_type' => $qb->expr()->literal('file'),
'file_source' => $qb->expr()->literal(42),
'file_target' => $qb->expr()->literal('myTarget'),
@@ -133,27 +134,18 @@ class DefaultShareProviderTest extends \Test\TestCase {
$id = $qb->getLastInsertId();
- $sharedWith = $this->getMock('OCP\IUser');
$sharedBy = $this->getMock('OCP\IUser');
$sharedBy->method('getUID')->willReturn('sharedBy');
$shareOwner = $this->getMock('OCP\IUser');
$shareOwner->method('getUID')->willReturn('shareOwner');
- $sharedByPath = $this->getMock('\OCP\Files\File');
$ownerPath = $this->getMock('\OCP\Files\File');
-
- $sharedByPath->method('getOwner')->willReturn($shareOwner);
-
- $sharedByFolder = $this->getMock('\OCP\Files\Folder');
- $sharedByFolder->method('getById')->with(42)->willReturn([$sharedByPath]);
-
$shareOwnerFolder = $this->getMock('\OCP\Files\Folder');
$shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
$this->rootFolder
->method('getUserFolder')
->will($this->returnValueMap([
- ['sharedBy', $sharedByFolder],
['shareOwner', $shareOwnerFolder],
]));
@@ -257,7 +249,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
->values([
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP),
'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('sharedBy'),
+ 'uid_owner' => $qb->expr()->literal('shareOwner'),
+ 'uid_initiator' => $qb->expr()->literal('sharedBy'),
'item_type' => $qb->expr()->literal('file'),
'file_source' => $qb->expr()->literal(42),
'file_target' => $qb->expr()->literal('myTarget'),
@@ -268,27 +261,13 @@ class DefaultShareProviderTest extends \Test\TestCase {
// Get the id
$id = $qb->getLastInsertId();
- $sharedWith = $this->getMock('OCP\IGroup');
- $sharedBy = $this->getMock('OCP\IUser');
- $sharedBy->method('getUID')->willReturn('sharedBy');
- $shareOwner = $this->getMock('OCP\IUser');
- $shareOwner->method('getUID')->willReturn('shareOwner');
-
- $sharedByPath = $this->getMock('\OCP\Files\Folder');
$ownerPath = $this->getMock('\OCP\Files\Folder');
-
- $sharedByPath->method('getOwner')->willReturn($shareOwner);
-
- $sharedByFolder = $this->getMock('\OCP\Files\Folder');
- $sharedByFolder->method('getById')->with(42)->willReturn([$sharedByPath]);
-
$shareOwnerFolder = $this->getMock('\OCP\Files\Folder');
$shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
$this->rootFolder
->method('getUserFolder')
->will($this->returnValueMap([
- ['sharedBy', $sharedByFolder],
['shareOwner', $shareOwnerFolder],
]));
@@ -351,7 +330,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
->values([
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK),
'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('sharedBy'),
+ 'uid_owner' => $qb->expr()->literal('shareOwner'),
+ 'uid_initiator' => $qb->expr()->literal('sharedBy'),
'item_type' => $qb->expr()->literal('file'),
'file_source' => $qb->expr()->literal(42),
'file_target' => $qb->expr()->literal('myTarget'),
@@ -363,36 +343,16 @@ class DefaultShareProviderTest extends \Test\TestCase {
$id = $qb->getLastInsertId();
- $sharedBy = $this->getMock('OCP\IUser');
- $sharedBy->method('getUID')->willReturn('sharedBy');
- $shareOwner = $this->getMock('OCP\IUser');
- $shareOwner->method('getUID')->willReturn('shareOwner');
-
- $sharedByPath = $this->getMock('\OCP\Files\Folder');
$ownerPath = $this->getMock('\OCP\Files\Folder');
-
- $sharedByPath->method('getOwner')->willReturn($shareOwner);
-
- $sharedByFolder = $this->getMock('\OCP\Files\Folder');
- $sharedByFolder->method('getById')->with(42)->willReturn([$sharedByPath]);
-
$shareOwnerFolder = $this->getMock('\OCP\Files\Folder');
$shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
$this->rootFolder
->method('getUserFolder')
->will($this->returnValueMap([
- ['sharedBy', $sharedByFolder],
['shareOwner', $shareOwnerFolder],
]));
- $this->userManager
- ->method('get')
- ->will($this->returnValueMap([
- ['sharedBy', $sharedBy],
- ['shareOwner', $shareOwner],
- ]));
-
$share = $this->provider->getShareById($id);
$this->assertEquals($id, $share->getId());
@@ -544,7 +504,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
->values([
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER),
'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('sharedBy'),
+ 'uid_owner' => $qb->expr()->literal('shareOwner'),
+ 'uid_initiator' => $qb->expr()->literal('sharedBy'),
'item_type' => $qb->expr()->literal('file'),
'file_source' => $qb->expr()->literal(42),
'file_target' => $qb->expr()->literal('myTarget'),
@@ -553,22 +514,15 @@ class DefaultShareProviderTest extends \Test\TestCase {
$qb->execute();
// Get the id
- $qb = $this->dbConn->getQueryBuilder();
- $cursor = $qb->select('id')
- ->from('share')
- ->setMaxResults(1)
- ->orderBy('id', 'DESC')
- ->execute();
- $id = $cursor->fetch();
- $id = $id['id'];
- $cursor->closeCursor();
+ $id = $qb->getLastInsertId();
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->values([
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER),
'share_with' => $qb->expr()->literal('user1'),
- 'uid_owner' => $qb->expr()->literal('user2'),
+ 'uid_owner' => $qb->expr()->literal('shareOwner'),
+ 'uid_initiator' => $qb->expr()->literal('user2'),
'item_type' => $qb->expr()->literal('file'),
'file_source' => $qb->expr()->literal(1),
'file_target' => $qb->expr()->literal('myTarget1'),
@@ -582,7 +536,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
->values([
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP),
'share_with' => $qb->expr()->literal('group1'),
- 'uid_owner' => $qb->expr()->literal('user3'),
+ 'uid_owner' => $qb->expr()->literal('shareOwner'),
+ 'uid_initiator' => $qb->expr()->literal('user3'),
'item_type' => $qb->expr()->literal('folder'),
'file_source' => $qb->expr()->literal(3),
'file_target' => $qb->expr()->literal('myTarget2'),
@@ -591,30 +546,6 @@ class DefaultShareProviderTest extends \Test\TestCase {
]);
$qb->execute();
- $shareOwner = $this->getMock('OCP\IUser');
- $shareOwner->method('getUID')->willReturn('shareOwner');
- $user1 = $this->getMock('OCP\IUser');
- $user2 = $this->getMock('OCP\IUser');
- $user2->method('getUID')->willReturn('user2');
- $user3 = $this->getMock('OCP\IUser');
- $user3->method('getUID')->willReturn('user3');
-
- $user2Path = $this->getMock('\OCP\Files\File');
- $user2Path->expects($this->once())->method('getOwner')->willReturn($shareOwner);
- $user2Folder = $this->getMock('\OCP\Files\Folder');
- $user2Folder->expects($this->once())
- ->method('getById')
- ->with(1)
- ->willReturn([$user2Path]);
-
- $user3Path = $this->getMock('\OCP\Files\Folder');
- $user3Path->expects($this->once())->method('getOwner')->willReturn($shareOwner);
- $user3Folder = $this->getMock('\OCP\Files\Folder');
- $user3Folder->expects($this->once())
- ->method('getById')
- ->with(3)
- ->willReturn([$user3Path]);
-
$ownerPath = $this->getMock('\OCP\Files\Folder');
$ownerFolder = $this->getMock('\OCP\Files\Folder');
$ownerFolder->method('getById')->willReturn([$ownerPath]);
@@ -623,23 +554,6 @@ class DefaultShareProviderTest extends \Test\TestCase {
->method('getUserFolder')
->will($this->returnValueMap([
['shareOwner', $ownerFolder],
- ['user2', $user2Folder],
- ['user3', $user3Folder],
- ]));
-
- $this->userManager
- ->method('get')
- ->will($this->returnValueMap([
- ['user1', $user1],
- ['user2', $user2],
- ['user3', $user3],
- ]));
-
- $group1 = $this->getMock('OCP\IGroup');
- $this->groupManager
- ->method('get')
- ->will($this->returnValueMap([
- ['group1', $group1]
]));
$share = $this->getMock('\OCP\Share\IShare');