aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/lib/Settings/Admin/Sharing.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings/lib/Settings/Admin/Sharing.php')
-rw-r--r--apps/settings/lib/Settings/Admin/Sharing.php177
1 files changed, 63 insertions, 114 deletions
diff --git a/apps/settings/lib/Settings/Admin/Sharing.php b/apps/settings/lib/Settings/Admin/Sharing.php
index 56c89c515a8..ec5dcdf624d 100644
--- a/apps/settings/lib/Settings/Admin/Sharing.php
+++ b/apps/settings/lib/Settings/Admin/Sharing.php
@@ -1,64 +1,35 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Sascha Wiswedel <sascha.wiswedel@nextcloud.com>
- * @author Vincent Petry <vincent@nextcloud.com>
- * @author Thomas Citharel <nextcloud@tcit.fr>
- *
- * @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/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\Settings\Admin;
+use OC\Core\AppInfo\ConfigLexicon;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\AppFramework\Services\IInitialState;
use OCP\Constants;
+use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IL10N;
+use OCP\IURLGenerator;
use OCP\Settings\IDelegatedSettings;
use OCP\Share\IManager;
use OCP\Util;
class Sharing implements IDelegatedSettings {
- /** @var IConfig */
- private $config;
-
- /** @var IL10N */
- private $l;
-
- /** @var IManager */
- private $shareManager;
-
- /** @var IAppManager */
- private $appManager;
-
- public function __construct(IConfig $config, IL10N $l, IManager $shareManager, IAppManager $appManager) {
- $this->config = $config;
- $this->l = $l;
- $this->shareManager = $shareManager;
- $this->appManager = $appManager;
+ public function __construct(
+ private IConfig $config,
+ private IAppConfig $appConfig,
+ private IL10N $l,
+ private IManager $shareManager,
+ private IAppManager $appManager,
+ private IURLGenerator $urlGenerator,
+ private IInitialState $initialState,
+ private string $appName,
+ ) {
}
/**
@@ -66,84 +37,62 @@ class Sharing implements IDelegatedSettings {
*/
public function getForm() {
$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
- $excludeGroupsList = !is_null(json_decode($excludedGroups))
- ? implode('|', json_decode($excludedGroups, true)) : '';
$linksExcludedGroups = $this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', '');
- $linksExcludeGroupsList = !is_null(json_decode($linksExcludedGroups))
- ? implode('|', json_decode($linksExcludedGroups, true)) : '';
-
$excludedPasswordGroups = $this->config->getAppValue('core', 'shareapi_enforce_links_password_excluded_groups', '');
- $excludedPasswordGroupsList = !is_null(json_decode($excludedPasswordGroups))
- ? implode('|', json_decode($excludedPasswordGroups, true)) : '';
-
+ $onlyShareWithGroupMembersExcludeGroupList = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members_exclude_group_list', '');
$parameters = [
// Built-In Sharing
- 'sharingAppEnabled' => $this->appManager->isEnabledForUser('files_sharing'),
- 'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'),
- 'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'),
- 'allowLinksExcludeGroups' => $linksExcludeGroupsList,
- 'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'),
- 'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'),
- 'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'),
- 'restrictUserEnumerationToGroup' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no'),
- 'restrictUserEnumerationToPhone' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no'),
- 'restrictUserEnumerationFullMatch' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes'),
- 'restrictUserEnumerationFullMatchUserId' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_userid', 'yes'),
- 'restrictUserEnumerationFullMatchIgnoreSecondDisplayName' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_display_name', 'no'),
- 'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(false),
- 'passwordExcludedGroups' => $excludedPasswordGroupsList,
- 'passwordExcludedGroupsFeatureEnabled' => $this->config->getSystemValueBool('sharing.allow_disabled_password_enforcement_groups', false),
+ 'enabled' => $this->getHumanBooleanConfig('core', 'shareapi_enabled', true),
+ 'allowGroupSharing' => $this->getHumanBooleanConfig('core', 'shareapi_allow_group_sharing', true),
+ 'allowLinks' => $this->getHumanBooleanConfig('core', 'shareapi_allow_links', true),
+ 'allowLinksExcludeGroups' => json_decode($linksExcludedGroups, true) ?? [],
+ 'allowPublicUpload' => $this->getHumanBooleanConfig('core', 'shareapi_allow_public_upload', true),
+ 'allowResharing' => $this->getHumanBooleanConfig('core', 'shareapi_allow_resharing', true),
+ 'allowShareDialogUserEnumeration' => $this->getHumanBooleanConfig('core', 'shareapi_allow_share_dialog_user_enumeration', true),
+ 'allowFederationOnPublicShares' => $this->appConfig->getValueBool('core', ConfigLexicon::SHAREAPI_ALLOW_FEDERATION_ON_PUBLIC_SHARES),
+ 'restrictUserEnumerationToGroup' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_group'),
+ 'restrictUserEnumerationToPhone' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_phone'),
+ 'restrictUserEnumerationFullMatch' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match', true),
+ 'restrictUserEnumerationFullMatchUserId' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_userid', true),
+ 'restrictUserEnumerationFullMatchEmail' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_email', true),
+ 'restrictUserEnumerationFullMatchIgnoreSecondDN' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn'),
+ 'enforceLinksPassword' => Util::isPublicLinkPasswordRequired(false),
+ 'enforceLinksPasswordExcludedGroups' => json_decode($excludedPasswordGroups) ?? [],
+ 'enforceLinksPasswordExcludedGroupsEnabled' => $this->config->getSystemValueBool('sharing.allow_disabled_password_enforcement_groups', false),
'onlyShareWithGroupMembers' => $this->shareManager->shareWithGroupMembersOnly(),
- 'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'),
- 'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'),
- 'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'),
- 'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'),
- 'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes',
- 'shareExcludedGroupsList' => $excludeGroupsList,
- 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null),
- 'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'),
- 'shareApiDefaultPermissions' => $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL),
- 'shareApiDefaultPermissionsCheckboxes' => $this->getSharePermissionList(),
- 'shareDefaultInternalExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no'),
- 'shareInternalExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'),
- 'shareInternalEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no'),
- 'shareDefaultRemoteExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no'),
- 'shareRemoteExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'),
- 'shareRemoteEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no'),
+ 'onlyShareWithGroupMembersExcludeGroupList' => json_decode($onlyShareWithGroupMembersExcludeGroupList) ?? [],
+ 'defaultExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_expire_date'),
+ 'expireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'),
+ 'enforceExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_expire_date'),
+ 'excludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no'),
+ 'excludeGroupsList' => json_decode($excludedGroups, true) ?? [],
+ 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext'),
+ 'enableLinkPasswordByDefault' => $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_LINK_PASSWORD_DEFAULT),
+ 'defaultPermissions' => (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL),
+ 'defaultInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_internal_expire_date'),
+ 'internalExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'),
+ 'enforceInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_internal_expire_date'),
+ 'defaultRemoteExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_remote_expire_date'),
+ 'remoteExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'),
+ 'enforceRemoteExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_remote_expire_date'),
+ 'allowCustomTokens' => $this->shareManager->allowCustomTokens(),
+ 'allowViewWithoutDownload' => $this->shareManager->allowViewWithoutDownload(),
];
- return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, '');
+ $this->initialState->provideInitialState('sharingAppEnabled', $this->appManager->isEnabledForUser('files_sharing'));
+ $this->initialState->provideInitialState('sharingDocumentation', $this->urlGenerator->linkToDocs('admin-sharing'));
+ $this->initialState->provideInitialState('sharingSettings', $parameters);
+
+ Util::addScript($this->appName, 'vue-settings-admin-sharing');
+ return new TemplateResponse($this->appName, 'settings/admin/sharing', [], '');
}
/**
- * get share permission list for template
- *
- * @return array
+ * Helper function to retrive boolean values from human readable strings ('yes' / 'no')
*/
- private function getSharePermissionList() {
- return [
- [
- 'id' => 'cancreate',
- 'label' => $this->l->t('Create'),
- 'value' => Constants::PERMISSION_CREATE
- ],
- [
- 'id' => 'canupdate',
- 'label' => $this->l->t('Change'),
- 'value' => Constants::PERMISSION_UPDATE
- ],
- [
- 'id' => 'candelete',
- 'label' => $this->l->t('Delete'),
- 'value' => Constants::PERMISSION_DELETE
- ],
- [
- 'id' => 'canshare',
- 'label' => $this->l->t('Reshare'),
- 'value' => Constants::PERMISSION_SHARE
- ],
- ];
+ private function getHumanBooleanConfig(string $app, string $key, bool $default = false): bool {
+ return $this->config->getAppValue($app, $key, $default ? 'yes' : 'no') === 'yes';
}
/**
@@ -155,8 +104,8 @@ class Sharing implements IDelegatedSettings {
/**
* @return int whether the form should be rather on the top or bottom of
- * the admin section. The forms are arranged in ascending order of the
- * priority values. It is required to return a value between 0 and 100.
+ * the admin section. The forms are arranged in ascending order of the
+ * priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
*/