Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix view-only code after code review comments
Signed-off-by: Vincent Petry <[email protected]>
  • Loading branch information
PVince81 authored and CarlSchwan committed Jul 28, 2022
commit 2ee659e54787c938e57787261442ad4037270322
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/ServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function createServer(string $baseUri,

// Allow view-only plugin for webdav requests
$server->addPlugin(new ViewOnlyPlugin(
\OC::$server->getLogger()
$this->logger
));

if ($this->userSession->isLoggedIn()) {
Expand Down
8 changes: 4 additions & 4 deletions apps/dav/lib/DAV/ViewOnlyPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use OCA\DAV\Meta\MetaFile;
use OCP\Files\FileInfo;
use OCP\Files\NotFoundException;
use OCP\ILogger;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
use Sabre\HTTP\RequestInterface;
Expand All @@ -40,13 +40,13 @@ class ViewOnlyPlugin extends ServerPlugin {
/** @var Server $server */
private $server;

/** @var ILogger $logger */
/** @var LoggerInterface $logger */
private $logger;

/**
* @param ILogger $logger
* @param LoggerInterface $logger
*/
public function __construct(ILogger $logger) {
public function __construct(LoggerInterface $logger) {
$this->logger = $logger;
$this->server = null;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function __construct(IRequest $request, string $baseUri) {

// Allow view-only plugin for webdav requests
$this->server->addPlugin(new ViewOnlyPlugin(
\OC::$server->getLogger()
$logger
));

if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/tests/unit/DAV/ViewOnlyPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
use OCA\DAV\Connector\Sabre\File as DavFile;
use OCP\Files\File;
use OCP\Files\Storage\IStorage;
use OCP\ILogger;
use OCP\Share\IAttributes;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Server;
use Sabre\DAV\Tree;
use Test\TestCase;
Expand All @@ -45,7 +45,7 @@ class ViewOnlyPluginTest extends TestCase {

public function setUp(): void {
$this->plugin = new ViewOnlyPlugin(
$this->createMock(ILogger::class)
$this->createMock(LoggerInterface::class)
);
$this->request = $this->createMock(RequestInterface::class);
$this->tree = $this->createMock(Tree::class);
Expand Down
10 changes: 5 additions & 5 deletions apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ public function boot(IBootContext $context): void {
}


public function registerMountProviders(IMountProviderCollection $mountProviderCollection, MountProvider $mountProvider, ExternalMountProvider $externalMountProvider) {
public function registerMountProviders(IMountProviderCollection $mountProviderCollection, MountProvider $mountProvider, ExternalMountProvider $externalMountProvider): void {
$mountProviderCollection->registerProvider($mountProvider);
$mountProviderCollection->registerProvider($externalMountProvider);
}

public function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher) {
public function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher): void {
// sidebar and files scripts
$dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
$dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class);
Expand Down Expand Up @@ -159,12 +159,12 @@ public function registerDownloadEvents(
IEventDispatcher $dispatcher,
?IUserSession $userSession,
IRootFolder $rootFolder
) {
): void {

$dispatcher->addListener(
'file.beforeGetDirect',
function (GenericEvent $event) use ($userSession, $rootFolder) {
$pathsToCheck[] = $event->getArgument('path');
$pathsToCheck = [$event->getArgument('path')];

// Check only for user/group shares. Don't restrict e.g. share links
if ($userSession && $userSession->isLoggedIn()) {
Expand Down Expand Up @@ -213,7 +213,7 @@ function (GenericEvent $event) use ($userSession, $rootFolder) {
);
}

public function setupSharingMenus(IManager $shareManager, IFactory $l10nFactory, IUserSession $userSession) {
public function setupSharingMenus(IManager $shareManager, IFactory $l10nFactory, IUserSession $userSession): void {
if (!$shareManager->shareApiEnabled() || !class_exists('\OCA\Files\App')) {
return;
}
Expand Down
13 changes: 9 additions & 4 deletions apps/files_sharing/lib/ViewOnly.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(Folder $userFolder) {
* @param string[] $pathsToCheck
* @return bool
*/
public function check($pathsToCheck) {
public function check(array $pathsToCheck): bool {
// If any of elements cannot be downloaded, prevent whole download
foreach ($pathsToCheck as $file) {
try {
Expand Down Expand Up @@ -70,7 +70,7 @@ public function check($pathsToCheck) {
* @return bool
* @throws NotFoundException
*/
private function dirRecursiveCheck(Folder $dirInfo) {
private function dirRecursiveCheck(Folder $dirInfo): bool {
if (!$this->checkFileInfo($dirInfo)) {
return false;
}
Expand All @@ -94,7 +94,7 @@ private function dirRecursiveCheck(Folder $dirInfo) {
* @return bool
* @throws NotFoundException
*/
private function checkFileInfo(Node $fileInfo) {
private function checkFileInfo(Node $fileInfo): bool {
// Restrict view-only to nodes which are shared
$storage = $fileInfo->getStorage();
if (!$storage->instanceOfStorage(SharedStorage::class)) {
Expand All @@ -105,9 +105,14 @@ private function checkFileInfo(Node $fileInfo) {
/** @var \OCA\Files_Sharing\SharedStorage $storage */
$share = $storage->getShare();

$canDownload = true;

// Check if read-only and on whether permission can download is both set and disabled.
$attributes = $share->getAttributes();
if ($attributes !== null) {
$canDownload = $attributes->getAttribute('permissions', 'download');
}

$canDownload = $share->getAttributes()->getAttribute('permissions', 'download');
if ($canDownload !== null && !$canDownload) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Share20/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public function getPermissions() {
/**
* @inheritdoc
*/
public function newAttributes() {
public function newAttributes(): IAttributes {
return new ShareAttributes();
}

Expand Down
6 changes: 4 additions & 2 deletions lib/public/Share/IShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
use OCP\Share\Exceptions\IllegalIDChangeException;

/**
* Interface IShare
* This interface allows to represent a share object.
*
* This interface must not be implemented in your application.
*
* @since 9.0.0
*/
Expand Down Expand Up @@ -320,7 +322,7 @@ public function getPermissions();
* @since 25.0.0
* @return IAttributes
*/
public function newAttributes();
public function newAttributes(): IAttributes;

/**
* Set share attributes
Expand Down