2015-02-07 08:07:53 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2024-06-06 19:48:28 +02:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-02-07 08:07:53 +01:00
|
|
|
*/
|
|
|
|
namespace OCA\Files_Sharing;
|
|
|
|
|
2015-03-21 20:12:55 +01:00
|
|
|
use OCP\Capabilities\ICapability;
|
2017-12-01 11:35:01 +01:00
|
|
|
use OCP\Constants;
|
2019-11-22 20:52:10 +01:00
|
|
|
use OCP\IConfig;
|
2021-04-23 17:29:34 +02:00
|
|
|
use OCP\Share\IManager;
|
2015-02-07 08:07:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Capabilities
|
|
|
|
*
|
|
|
|
* @package OCA\Files_Sharing
|
|
|
|
*/
|
2015-03-21 20:12:55 +01:00
|
|
|
class Capabilities implements ICapability {
|
2015-02-07 08:07:53 +01:00
|
|
|
|
2024-10-18 12:04:22 +02:00
|
|
|
public function __construct(
|
|
|
|
private IConfig $config,
|
|
|
|
private IManager $shareManager,
|
|
|
|
) {
|
2015-02-07 08:07:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-21 20:12:55 +01:00
|
|
|
* Return this classes capabilities
|
2023-02-15 19:22:09 +01:00
|
|
|
*
|
|
|
|
* @return array{
|
|
|
|
* files_sharing: array{
|
|
|
|
* api_enabled: bool,
|
|
|
|
* public: array{
|
|
|
|
* enabled: bool,
|
|
|
|
* password?: array{
|
|
|
|
* enforced: bool,
|
|
|
|
* askForOptionalPassword: bool
|
|
|
|
* },
|
|
|
|
* multiple_links?: bool,
|
|
|
|
* expire_date?: array{
|
|
|
|
* enabled: bool,
|
|
|
|
* days?: int,
|
|
|
|
* enforced?: bool,
|
|
|
|
* },
|
|
|
|
* expire_date_internal?: array{
|
|
|
|
* enabled: bool,
|
|
|
|
* days?: int,
|
|
|
|
* enforced?: bool,
|
|
|
|
* },
|
|
|
|
* expire_date_remote?: array{
|
|
|
|
* enabled: bool,
|
|
|
|
* days?: int,
|
|
|
|
* enforced?: bool,
|
|
|
|
* },
|
|
|
|
* send_mail?: bool,
|
|
|
|
* upload?: bool,
|
|
|
|
* upload_files_drop?: bool,
|
2024-12-16 15:53:12 -08:00
|
|
|
* custom_tokens?: bool,
|
2023-02-15 19:22:09 +01:00
|
|
|
* },
|
|
|
|
* user: array{
|
|
|
|
* send_mail: bool,
|
|
|
|
* expire_date?: array{
|
|
|
|
* enabled: bool,
|
|
|
|
* },
|
|
|
|
* },
|
|
|
|
* resharing: bool,
|
|
|
|
* group_sharing?: bool,
|
|
|
|
* group?: array{
|
|
|
|
* enabled: bool,
|
|
|
|
* expire_date?: array{
|
|
|
|
* enabled: bool,
|
|
|
|
* },
|
|
|
|
* },
|
|
|
|
* default_permissions?: int,
|
|
|
|
* federation: array{
|
|
|
|
* outgoing: bool,
|
|
|
|
* incoming: bool,
|
|
|
|
* expire_date: array{
|
|
|
|
* enabled: bool,
|
|
|
|
* },
|
|
|
|
* expire_date_supported: array{
|
|
|
|
* enabled: bool,
|
|
|
|
* },
|
|
|
|
* },
|
|
|
|
* sharee: array{
|
|
|
|
* query_lookup_default: bool,
|
|
|
|
* always_show_unique: bool,
|
|
|
|
* },
|
|
|
|
* },
|
|
|
|
* }
|
2015-02-07 08:07:53 +01:00
|
|
|
*/
|
2015-03-21 20:12:55 +01:00
|
|
|
public function getCapabilities() {
|
2015-02-26 08:39:55 +01:00
|
|
|
$res = [];
|
2015-02-07 08:07:53 +01:00
|
|
|
|
2021-04-23 17:29:34 +02:00
|
|
|
if (!$this->shareManager->shareApiEnabled()) {
|
2015-09-25 11:24:23 +02:00
|
|
|
$res['api_enabled'] = false;
|
|
|
|
$res['public'] = ['enabled' => false];
|
|
|
|
$res['user'] = ['send_mail' => false];
|
|
|
|
$res['resharing'] = false;
|
|
|
|
} else {
|
|
|
|
$res['api_enabled'] = true;
|
2015-02-07 08:07:53 +01:00
|
|
|
|
2015-09-25 11:24:23 +02:00
|
|
|
$public = [];
|
2021-04-23 17:29:34 +02:00
|
|
|
$public['enabled'] = $this->shareManager->shareApiAllowLinks();
|
2015-09-25 11:24:23 +02:00
|
|
|
if ($public['enabled']) {
|
|
|
|
$public['password'] = [];
|
2021-04-23 17:29:34 +02:00
|
|
|
$public['password']['enforced'] = $this->shareManager->shareApiLinkEnforcePassword();
|
2015-02-07 08:07:53 +01:00
|
|
|
|
2019-05-09 10:39:39 +02:00
|
|
|
if ($public['password']['enforced']) {
|
|
|
|
$public['password']['askForOptionalPassword'] = false;
|
|
|
|
} else {
|
|
|
|
$public['password']['askForOptionalPassword'] = ($this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no') === 'yes');
|
|
|
|
}
|
|
|
|
|
2015-09-25 11:24:23 +02:00
|
|
|
$public['expire_date'] = [];
|
2018-11-26 14:44:59 +01:00
|
|
|
$public['multiple_links'] = true;
|
2021-04-23 17:29:34 +02:00
|
|
|
$public['expire_date']['enabled'] = $this->shareManager->shareApiLinkDefaultExpireDate();
|
2015-09-25 11:24:23 +02:00
|
|
|
if ($public['expire_date']['enabled']) {
|
2021-04-23 17:29:34 +02:00
|
|
|
$public['expire_date']['days'] = $this->shareManager->shareApiLinkDefaultExpireDays();
|
|
|
|
$public['expire_date']['enforced'] = $this->shareManager->shareApiLinkDefaultExpireDateEnforced();
|
2015-09-25 11:24:23 +02:00
|
|
|
}
|
2015-02-07 08:07:53 +01:00
|
|
|
|
2019-11-13 15:22:27 +01:00
|
|
|
$public['expire_date_internal'] = [];
|
2021-04-23 17:29:34 +02:00
|
|
|
$public['expire_date_internal']['enabled'] = $this->shareManager->shareApiInternalDefaultExpireDate();
|
2019-11-13 15:22:27 +01:00
|
|
|
if ($public['expire_date_internal']['enabled']) {
|
2021-04-23 17:29:34 +02:00
|
|
|
$public['expire_date_internal']['days'] = $this->shareManager->shareApiInternalDefaultExpireDays();
|
|
|
|
$public['expire_date_internal']['enforced'] = $this->shareManager->shareApiInternalDefaultExpireDateEnforced();
|
2019-11-13 15:22:27 +01:00
|
|
|
}
|
|
|
|
|
2021-03-25 17:32:49 +01:00
|
|
|
$public['expire_date_remote'] = [];
|
2021-04-23 17:29:34 +02:00
|
|
|
$public['expire_date_remote']['enabled'] = $this->shareManager->shareApiRemoteDefaultExpireDate();
|
2021-03-25 17:32:49 +01:00
|
|
|
if ($public['expire_date_remote']['enabled']) {
|
2021-04-23 17:29:34 +02:00
|
|
|
$public['expire_date_remote']['days'] = $this->shareManager->shareApiRemoteDefaultExpireDays();
|
|
|
|
$public['expire_date_remote']['enforced'] = $this->shareManager->shareApiRemoteDefaultExpireDateEnforced();
|
2021-03-25 17:32:49 +01:00
|
|
|
}
|
|
|
|
|
2015-09-25 11:24:23 +02:00
|
|
|
$public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes';
|
2021-04-23 17:29:34 +02:00
|
|
|
$public['upload'] = $this->shareManager->shareApiLinkAllowPublicUpload();
|
2016-08-13 14:00:44 +02:00
|
|
|
$public['upload_files_drop'] = $public['upload'];
|
2024-12-16 15:53:12 -08:00
|
|
|
$public['custom_tokens'] = $this->shareManager->allowCustomTokens();
|
2015-09-25 11:24:23 +02:00
|
|
|
}
|
2017-07-24 07:44:09 +02:00
|
|
|
$res['public'] = $public;
|
2015-02-07 08:07:53 +01:00
|
|
|
|
2015-09-25 11:24:23 +02:00
|
|
|
$res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes';
|
2016-03-31 09:27:38 +02:00
|
|
|
|
2016-11-02 11:37:25 +01:00
|
|
|
$res['user']['send_mail'] = false;
|
2017-03-30 16:29:34 +02:00
|
|
|
$res['user']['expire_date']['enabled'] = true;
|
2016-11-02 11:37:25 +01:00
|
|
|
|
2017-03-30 16:29:34 +02:00
|
|
|
// deprecated in favour of 'group', but we need to keep it for now
|
|
|
|
// in order to stay compatible with older clients
|
2021-04-23 17:29:34 +02:00
|
|
|
$res['group_sharing'] = $this->shareManager->allowGroupSharing();
|
2017-03-30 16:29:34 +02:00
|
|
|
|
|
|
|
$res['group'] = [];
|
2021-04-23 17:29:34 +02:00
|
|
|
$res['group']['enabled'] = $this->shareManager->allowGroupSharing();
|
2017-03-30 16:29:34 +02:00
|
|
|
$res['group']['expire_date']['enabled'] = true;
|
2022-10-17 12:36:05 +02:00
|
|
|
$res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL);
|
2015-09-25 11:24:23 +02:00
|
|
|
}
|
2015-09-12 16:25:23 +02:00
|
|
|
|
|
|
|
//Federated sharing
|
|
|
|
$res['federation'] = [
|
2021-04-23 17:29:34 +02:00
|
|
|
'outgoing' => $this->shareManager->outgoingServer2ServerSharesAllowed(),
|
2017-03-30 16:29:34 +02:00
|
|
|
'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes',
|
2021-03-16 14:37:31 +01:00
|
|
|
// old bogus one, expire_date was not working before, keeping for compatibility
|
|
|
|
'expire_date' => ['enabled' => true],
|
|
|
|
// the real deal, signifies that expiration date can be set on federated shares
|
|
|
|
'expire_date_supported' => ['enabled' => true],
|
2015-09-12 16:25:23 +02:00
|
|
|
];
|
|
|
|
|
2019-11-28 10:50:48 +01:00
|
|
|
// Sharee searches
|
|
|
|
$res['sharee'] = [
|
2021-03-03 13:20:58 +01:00
|
|
|
'query_lookup_default' => $this->config->getSystemValueBool('gs.enabled', false),
|
|
|
|
'always_show_unique' => $this->config->getAppValue('files_sharing', 'always_show_unique', 'yes') === 'yes',
|
2019-11-28 10:50:48 +01:00
|
|
|
];
|
|
|
|
|
2015-03-21 20:12:55 +01:00
|
|
|
return [
|
|
|
|
'files_sharing' => $res,
|
|
|
|
];
|
2015-02-07 08:07:53 +01:00
|
|
|
}
|
|
|
|
}
|