aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r--apps/files_sharing/lib/Capabilities.php3
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php6
-rw-r--r--apps/files_sharing/lib/Controller/ShareesAPIController.php4
-rw-r--r--apps/files_sharing/lib/External/Cache.php2
-rw-r--r--apps/files_sharing/lib/External/Scanner.php2
-rw-r--r--apps/files_sharing/lib/External/Storage.php4
-rw-r--r--apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php25
-rw-r--r--apps/files_sharing/lib/Migration/Version11300Date20201120141438.php1
-rw-r--r--apps/files_sharing/lib/Migration/Version22000Date20210216084241.php55
-rw-r--r--apps/files_sharing/lib/Scanner.php4
-rw-r--r--apps/files_sharing/lib/Settings/Personal.php10
-rw-r--r--apps/files_sharing/lib/SharedStorage.php45
12 files changed, 104 insertions, 57 deletions
diff --git a/apps/files_sharing/lib/Capabilities.php b/apps/files_sharing/lib/Capabilities.php
index 097fa1b38ed..88af806b2f9 100644
--- a/apps/files_sharing/lib/Capabilities.php
+++ b/apps/files_sharing/lib/Capabilities.php
@@ -116,7 +116,8 @@ class Capabilities implements ICapability {
// Sharee searches
$res['sharee'] = [
- 'query_lookup_default' => $this->config->getSystemValueBool('gs.enabled', false)
+ 'query_lookup_default' => $this->config->getSystemValueBool('gs.enabled', false),
+ 'always_show_unique' => $this->config->getAppValue('files_sharing', 'always_show_unique', 'yes') === 'yes',
];
return [
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index 12408d8e108..a051f9141ff 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -631,9 +631,11 @@ class ShareAPIController extends OCSController {
try {
$share = $this->shareManager->createShare($share);
} catch (GenericShareException $e) {
+ \OC::$server->getLogger()->logException($e);
$code = $e->getCode() === 0 ? 403 : $e->getCode();
throw new OCSException($e->getHint(), $code);
} catch (\Exception $e) {
+ \OC::$server->getLogger()->logException($e);
throw new OCSForbiddenException($e->getMessage(), $e);
}
@@ -1455,10 +1457,6 @@ class ShareAPIController extends OCSController {
throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
}
- if ($date === false) {
- throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
- }
-
$date->setTime(0, 0, 0);
return $date;
diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php
index 33ac1662a4d..131fe918530 100644
--- a/apps/files_sharing/lib/Controller/ShareesAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php
@@ -223,7 +223,7 @@ class ShareesAPIController extends OCSController {
$this->result['lookupEnabled'] = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'yes') === 'yes';
}
- list($result, $hasMoreResults) = $this->collaboratorSearch->search($search, $shareTypes, $lookup, $this->limit, $this->offset);
+ [$result, $hasMoreResults] = $this->collaboratorSearch->search($search, $shareTypes, $lookup, $this->limit, $this->offset);
// extra treatment for 'exact' subarray, with a single merge expected keys might be lost
if (isset($result['exact'])) {
@@ -290,7 +290,7 @@ class ShareesAPIController extends OCSController {
foreach ($shareTypes as $shareType) {
$sharees = $this->getAllShareesByType($user, $shareType);
$shareTypeResults = [];
- foreach ($sharees as list($sharee, $displayname)) {
+ foreach ($sharees as [$sharee, $displayname]) {
if (!isset($this->searchResultTypeMap[$shareType])) {
continue;
}
diff --git a/apps/files_sharing/lib/External/Cache.php b/apps/files_sharing/lib/External/Cache.php
index 8af5ca1d98d..6a816b166ae 100644
--- a/apps/files_sharing/lib/External/Cache.php
+++ b/apps/files_sharing/lib/External/Cache.php
@@ -40,7 +40,7 @@ class Cache extends \OC\Files\Cache\Cache {
public function __construct($storage, ICloudId $cloudId) {
$this->cloudId = $cloudId;
$this->storage = $storage;
- list(, $remote) = explode('://', $cloudId->getRemote(), 2);
+ [, $remote] = explode('://', $cloudId->getRemote(), 2);
$this->remote = $remote;
$this->remoteUser = $cloudId->getUser();
parent::__construct($storage);
diff --git a/apps/files_sharing/lib/External/Scanner.php b/apps/files_sharing/lib/External/Scanner.php
index 34ef65f0621..71187707ad7 100644
--- a/apps/files_sharing/lib/External/Scanner.php
+++ b/apps/files_sharing/lib/External/Scanner.php
@@ -56,7 +56,7 @@ class Scanner extends \OC\Files\Cache\Scanner {
* @param int $parentId
* @param array | null $cacheData existing data in the cache for the file to be scanned
* @param bool $lock set to false to disable getting an additional read lock during scanning
- * @return array an array of metadata of the scanned file
+ * @return array | null an array of metadata of the scanned file
*/
public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) {
try {
diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php
index 339770c8601..f612aadfb32 100644
--- a/apps/files_sharing/lib/External/Storage.php
+++ b/apps/files_sharing/lib/External/Storage.php
@@ -73,9 +73,9 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage {
$this->cloudId = $options['cloudId'];
$discoveryService = \OC::$server->query(\OCP\OCS\IDiscoveryService::class);
- list($protocol, $remote) = explode('://', $this->cloudId->getRemote());
+ [$protocol, $remote] = explode('://', $this->cloudId->getRemote());
if (strpos($remote, '/')) {
- list($host, $root) = explode('/', $remote, 2);
+ [$host, $root] = explode('/', $remote, 2);
} else {
$host = $remote;
$root = '';
diff --git a/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php b/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php
index c58496a46d7..335b0908a98 100644
--- a/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php
+++ b/apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -33,12 +35,12 @@ use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\NotFoundResponse;
+use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\Utility\IControllerMethodReflector;
use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\IRequest;
-use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
/**
@@ -61,15 +63,7 @@ class SharingCheckMiddleware extends Middleware {
/** @var IRequest */
protected $request;
- /***
- * @param string $appName
- * @param IConfig $config
- * @param IAppManager $appManager
- * @param IControllerMethodReflector $reflector
- * @param IManager $shareManager
- * @param IRequest $request
- */
- public function __construct($appName,
+ public function __construct(string $appName,
IConfig $config,
IAppManager $appManager,
IControllerMethodReflector $reflector,
@@ -91,9 +85,8 @@ class SharingCheckMiddleware extends Middleware {
* @param string $methodName
* @throws NotFoundException
* @throws S2SException
- * @throws ShareNotFound
*/
- public function beforeController($controller, $methodName) {
+ public function beforeController($controller, $methodName): void {
if (!$this->isSharingEnabled()) {
throw new NotFoundException('Sharing is disabled.');
}
@@ -110,10 +103,10 @@ class SharingCheckMiddleware extends Middleware {
* @param Controller $controller
* @param string $methodName
* @param \Exception $exception
- * @return NotFoundResponse
+ * @return Response
* @throws \Exception
*/
- public function afterException($controller, $methodName, \Exception $exception) {
+ public function afterException($controller, $methodName, \Exception $exception): Response {
if (is_a($exception, NotFoundException::class)) {
return new NotFoundResponse();
}
@@ -129,7 +122,7 @@ class SharingCheckMiddleware extends Middleware {
* Checks for externalshares controller
* @return bool
*/
- private function externalSharesChecks() {
+ private function externalSharesChecks(): bool {
if (!$this->reflector->hasAnnotation('NoIncomingFederatedSharingRequired') &&
$this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') !== 'yes') {
return false;
@@ -147,7 +140,7 @@ class SharingCheckMiddleware extends Middleware {
* Check whether sharing is enabled
* @return bool
*/
- private function isSharingEnabled() {
+ private function isSharingEnabled(): bool {
// FIXME: This check is done here since the route is globally defined and not inside the files_sharing app
// Check whether the sharing application is enabled
if (!$this->appManager->isEnabledForUser($this->appName)) {
diff --git a/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php b/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php
index 250a4f12d7c..9d485952ac4 100644
--- a/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php
+++ b/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php
@@ -105,7 +105,6 @@ class Version11300Date20201120141438 extends SimpleMigrationStep {
'default' => 0,
]);
$table->setPrimaryKey(['id']);
- $table->addIndex(['user'], 'sh_external_user');
$table->addUniqueIndex(['user', 'mountpoint_hash'], 'sh_external_mp');
} else {
$table = $schema->getTable('share_external');
diff --git a/apps/files_sharing/lib/Migration/Version22000Date20210216084241.php b/apps/files_sharing/lib/Migration/Version22000Date20210216084241.php
new file mode 100644
index 00000000000..e3e8dc8bc55
--- /dev/null
+++ b/apps/files_sharing/lib/Migration/Version22000Date20210216084241.php
@@ -0,0 +1,55 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2021 Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program 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.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_Sharing\Migration;
+
+use Closure;
+use OCP\DB\ISchemaWrapper;
+use OCP\Migration\IOutput;
+use OCP\Migration\SimpleMigrationStep;
+
+/**
+ * Auto-generated migration step: Please modify to your needs!
+ */
+class Version22000Date20210216084241 extends SimpleMigrationStep {
+ /**
+ * @param IOutput $output
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ * @return null|ISchemaWrapper
+ */
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
+
+ $table = $schema->getTable('share_external');
+ if ($table->hasIndex('sh_external_user')) {
+ $table->dropIndex('sh_external_user');
+ }
+
+ return $schema;
+ }
+}
diff --git a/apps/files_sharing/lib/Scanner.php b/apps/files_sharing/lib/Scanner.php
index 59b5c8a0b2e..21d2565a4cd 100644
--- a/apps/files_sharing/lib/Scanner.php
+++ b/apps/files_sharing/lib/Scanner.php
@@ -45,7 +45,7 @@ class Scanner extends \OC\Files\Cache\Scanner {
*
* @param string $path path of the file for which to retrieve metadata
*
- * @return array an array of metadata of the file
+ * @return array|null an array of metadata of the file
*/
public function getData($path) {
$data = parent::getData($path);
@@ -63,7 +63,7 @@ class Scanner extends \OC\Files\Cache\Scanner {
}
if ($this->storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
/** @var \OC\Files\Storage\Storage $storage */
- list($storage) = $this->storage->resolvePath('');
+ [$storage] = $this->storage->resolvePath('');
$this->sourceScanner = $storage->getScanner();
return $this->sourceScanner;
} else {
diff --git a/apps/files_sharing/lib/Settings/Personal.php b/apps/files_sharing/lib/Settings/Personal.php
index bfca0b46e07..c265a279393 100644
--- a/apps/files_sharing/lib/Settings/Personal.php
+++ b/apps/files_sharing/lib/Settings/Personal.php
@@ -29,20 +29,20 @@ namespace OCA\Files_Sharing\Settings;
use OCA\Files_Sharing\AppInfo\Application;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\AppFramework\Services\IInitialState;
use OCP\IConfig;
-use OCP\IInitialStateService;
use OCP\Settings\ISettings;
class Personal implements ISettings {
/** @var IConfig */
private $config;
- /** @var IInitialStateService */
+ /** @var IInitialState */
private $initialState;
/** @var string */
private $userId;
- public function __construct(IConfig $config, IInitialStateService $initialState, string $userId) {
+ public function __construct(IConfig $config, IInitialState $initialState, string $userId) {
$this->config = $config;
$this->initialState = $initialState;
$this->userId = $userId;
@@ -52,8 +52,8 @@ class Personal implements ISettings {
$defaultAcceptSystemConfig = $this->config->getSystemValueBool('sharing.enable_share_accept', false) ? 'no' : 'yes';
$acceptDefault = $this->config->getUserValue($this->userId, Application::APP_ID, 'default_accept', $defaultAcceptSystemConfig) === 'yes';
$enforceAccept = $this->config->getSystemValueBool('sharing.force_share_accept', false);
- $this->initialState->provideInitialState(Application::APP_ID, 'accept_default', $acceptDefault);
- $this->initialState->provideInitialState(Application::APP_ID, 'enforce_accept', $enforceAccept);
+ $this->initialState->provideInitialState('accept_default', $acceptDefault);
+ $this->initialState->provideInitialState('enforce_accept', $enforceAccept);
return new TemplateResponse('files_sharing', 'Settings/personal');
}
diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php
index 221d022bb1e..eb0af419983 100644
--- a/apps/files_sharing/lib/SharedStorage.php
+++ b/apps/files_sharing/lib/SharedStorage.php
@@ -45,6 +45,7 @@ use OCP\Files\NotFoundException;
use OCP\Files\Storage\IDisableEncryptionStorage;
use OCP\Files\Storage\IStorage;
use OCP\Lock\ILockingProvider;
+use OCP\Share\IShare;
/**
* Convert target path to source path and pass the function call to the correct storage provider
@@ -159,7 +160,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
/**
* @inheritdoc
*/
- public function instanceOfStorage($class) {
+ public function instanceOfStorage($class): bool {
if ($class === '\OC\Files\Storage\Common') {
return true;
}
@@ -176,7 +177,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
return $this->superShare->getId();
}
- private function isValid() {
+ private function isValid(): bool {
return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE;
}
@@ -185,7 +186,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
*
* @return string
*/
- public function getId() {
+ public function getId(): string {
return 'shared::' . $this->getMountPoint();
}
@@ -195,7 +196,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
* @param string $target Shared target file path
* @return int CRUDS permissions granted
*/
- public function getPermissions($target = '') {
+ public function getPermissions($target = ''): int {
if (!$this->isValid()) {
return 0;
}
@@ -213,11 +214,11 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
return $permissions;
}
- public function isCreatable($path) {
- return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE);
+ public function isCreatable($path): bool {
+ return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE);
}
- public function isReadable($path) {
+ public function isReadable($path): bool {
if (!$this->isValid()) {
return false;
}
@@ -230,19 +231,19 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
return $storage->isReadable($internalPath);
}
- public function isUpdatable($path) {
- return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE);
+ public function isUpdatable($path): bool {
+ return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE);
}
- public function isDeletable($path) {
- return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE);
+ public function isDeletable($path): bool {
+ return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE);
}
- public function isSharable($path) {
+ public function isSharable($path): bool {
if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) {
return false;
}
- return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE);
+ return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE);
}
public function fopen($path, $mode) {
@@ -304,7 +305,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
* @param string $path2
* @return bool
*/
- public function rename($path1, $path2) {
+ public function rename($path1, $path2): bool {
$this->init();
$isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part';
$targetExists = $this->file_exists($path2);
@@ -328,14 +329,14 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
*
* @return string
*/
- public function getMountPoint() {
+ public function getMountPoint(): string {
return $this->superShare->getTarget();
}
/**
* @param string $path
*/
- public function setMountPoint($path) {
+ public function setMountPoint($path): void {
$this->superShare->setTarget($path);
foreach ($this->groupedShares as $share) {
@@ -348,14 +349,14 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
*
* @return string
*/
- public function getSharedFrom() {
+ public function getSharedFrom(): string {
return $this->superShare->getShareOwner();
}
/**
* @return \OCP\Share\IShare
*/
- public function getShare() {
+ public function getShare(): IShare {
return $this->superShare;
}
@@ -364,7 +365,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
*
* @return string
*/
- public function getItemType() {
+ public function getItemType(): string {
return $this->superShare->getNodeType();
}
@@ -396,11 +397,11 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
return new \OCA\Files_Sharing\Scanner($storage);
}
- public function getOwner($path) {
+ public function getOwner($path): string {
return $this->superShare->getShareOwner();
}
- public function getWatcher($path = '', $storage = null) {
+ public function getWatcher($path = '', $storage = null): NullWatcher {
// cache updating is handled by the share source
return new NullWatcher();
}
@@ -410,7 +411,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
*
* @return bool
*/
- public function unshareStorage() {
+ public function unshareStorage(): bool {
foreach ($this->groupedShares as $share) {
\OC::$server->getShareManager()->deleteFromSelf($share, $this->user);
}