-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
View-only dav plugin using IShare extra share permissions
- Loading branch information
Showing
16 changed files
with
665 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
/** | ||
* @author Piotr Mrowczynski piotr@owncloud.com | ||
* | ||
* @copyright Copyright (c) 2018, ownCloud GmbH | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program 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, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\DAV\DAV; | ||
|
||
use OCA\DAV\Connector\Sabre\Exception\Forbidden; | ||
use OCA\DAV\Connector\Sabre\File; | ||
use OCP\Files\InvalidPathException; | ||
use Sabre\DAV\Exception\ServiceUnavailable; | ||
use Sabre\DAV\Server; | ||
use Sabre\DAV\ServerPlugin; | ||
use Sabre\HTTP\RequestInterface; | ||
use Sabre\DAV\Exception\NotFound; | ||
use \OCP\Files\NotFoundException; | ||
|
||
/** | ||
* Sabre plugin for the the file secure-view: | ||
*/ | ||
class ViewOnlyPlugin extends ServerPlugin { | ||
|
||
/** @var \Sabre\DAV\Server $server */ | ||
private $server; | ||
|
||
/** | ||
* ViewOnlyPlugin plugin | ||
*/ | ||
public function __construct() { | ||
} | ||
|
||
/** | ||
* This initializes the plugin. | ||
* | ||
* This function is called by Sabre\DAV\Server, after | ||
* addPlugin is called. | ||
* | ||
* This method should set up the required event subscriptions. | ||
* | ||
* @param Server $server | ||
* @return void | ||
*/ | ||
public function initialize(Server $server) { | ||
$this->server = $server; | ||
//priority 90 to make sure the plugin is called before | ||
//Sabre\DAV\CorePlugin::httpGet | ||
$this->server->on('method:GET', [$this, 'checkViewOnly'], 90); | ||
} | ||
|
||
/** | ||
* | ||
* @param RequestInterface $request request object | ||
* @return boolean | ||
* @throws Forbidden | ||
* @throws ServiceUnavailable | ||
*/ | ||
public function checkViewOnly( | ||
RequestInterface $request | ||
) { | ||
$path = $request->getPath(); | ||
|
||
try { | ||
$node = $this->server->tree->getNodeForPath($path); | ||
|
||
// Restrict view-only only to files | ||
if (!($node instanceof File)) { | ||
return true; | ||
} | ||
|
||
// Restrict view-only to files which are shared | ||
$file = $node->getNode(); | ||
$storage = $file->getStorage(); | ||
if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { | ||
return true; | ||
} | ||
|
||
// Extract extra permissions | ||
/** @var \OCA\Files_Sharing\SharedStorage $storage */ | ||
$share = $storage->getShare(); | ||
|
||
// Check if read-only and on whether permission can download is both set and disabled. | ||
$canDownload = $share->getExtraPermissions()->getPermission('dav', 'can-download'); | ||
if (!$file->isUpdateable() && $canDownload !== null && !$canDownload) { | ||
throw new Forbidden('File is in secure-view mode and cannot be directly downloaded.'); | ||
} | ||
} catch (NotFound $e) { | ||
} catch (NotFoundException $e) { | ||
} catch (InvalidPathException $e) { | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
namespace OC\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\DBAL\Types\Type; | ||
use OCP\Migration\ISchemaMigration; | ||
|
||
/** | ||
* Auto-generated migration step: Please modify to your needs! | ||
*/ | ||
class Version20181220085457 implements ISchemaMigration { | ||
|
||
public function changeSchema(Schema $schema, array $options) { | ||
$prefix = $options['tablePrefix']; | ||
|
||
// FIXME: Should Type::TEXT or Type::JSON be used? For now use STRING | ||
if ($schema->hasTable("${prefix}share")) { | ||
$shareTable = $schema->getTable("${prefix}share"); | ||
|
||
if (!$shareTable->hasColumn('extra_permissions')) { | ||
$shareTable->addColumn( | ||
'extra_permissions', | ||
Type::STRING, | ||
[ | ||
'default' => null, | ||
'length' => 4096, | ||
'notnull' => false | ||
] | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.