diff options
Diffstat (limited to 'apps/dav/lib')
-rw-r--r-- | apps/dav/lib/connector/sabre/principal.php | 18 | ||||
-rw-r--r-- | apps/dav/lib/server.php | 17 |
2 files changed, 29 insertions, 6 deletions
diff --git a/apps/dav/lib/connector/sabre/principal.php b/apps/dav/lib/connector/sabre/principal.php index 4f26390e3cc..a573124007d 100644 --- a/apps/dav/lib/connector/sabre/principal.php +++ b/apps/dav/lib/connector/sabre/principal.php @@ -49,6 +49,9 @@ class Principal implements BackendInterface { /** @var string */ private $principalPrefix; + /** @var bool */ + private $hasGroups; + /** * @param IUserManager $userManager * @param IGroupManager $groupManager @@ -60,6 +63,7 @@ class Principal implements BackendInterface { $this->userManager = $userManager; $this->groupManager = $groupManager; $this->principalPrefix = trim($principalPrefix, '/'); + $this->hasGroups = ($principalPrefix === 'principals/users/'); } /** @@ -141,13 +145,15 @@ class Principal implements BackendInterface { throw new Exception('Principal not found'); } - $groups = $this->groupManager->getUserGroups($user); - $groups = array_map(function($group) { - /** @var IGroup $group */ - return $this->principalPrefix . '/' . $group->getGID(); - }, $groups); + if ($this->hasGroups) { + $groups = $this->groupManager->getUserGroups($user); + $groups = array_map(function($group) { + /** @var IGroup $group */ + return 'principals/groups/' . $group->getGID(); + }, $groups); - return $groups; + return $groups; + } } return []; } diff --git a/apps/dav/lib/server.php b/apps/dav/lib/server.php index 3bf8e155082..f5f1875a480 100644 --- a/apps/dav/lib/server.php +++ b/apps/dav/lib/server.php @@ -30,6 +30,10 @@ use OCA\DAV\Files\CustomPropertiesBackend; use OCP\IRequest; use OCP\SabrePluginEvent; use Sabre\DAV\Auth\Plugin; +use Sabre\DAV\IFile; +use Sabre\HTTP\RequestInterface; +use Sabre\HTTP\ResponseInterface; +use Sabre\HTTP\Util; class Server { @@ -104,6 +108,19 @@ class Server { $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); } + // Serve all files with an Content-Disposition of type "attachment" + $this->server->on('beforeMethod', function (RequestInterface $requestInterface, ResponseInterface $responseInterface) { + if ($requestInterface->getMethod() === 'GET') { + $path = $requestInterface->getPath(); + if ($this->server->tree->nodeExists($path)) { + $node = $this->server->tree->getNodeForPath($path); + if (($node instanceof IFile)) { + $responseInterface->addHeader('Content-Disposition', 'attachment'); + } + } + } + }); + // wait with registering these until auth is handled and the filesystem is setup $this->server->on('beforeMethod', function () { // custom properties plugin must be the last one |