From 0bcc643d6e8fdc369e8c7117a619b1dcc8f8822d Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Sun, 5 Jul 2020 13:23:30 +0200 Subject: Cleanup share by mail a bit * Moved to ned IBootstrap * Register everything via the capabilities api (So clients can use it as well) - This applies to the enforcing passwords * Updated the sharing js code to use it * removed app.php * removed unused settings now * typehints * strict typing Signed-off-by: Roeland Jago Douma Signed-off-by: npmbuildbot[bot] Signed-off-by: Morris Jobke --- apps/sharebymail/lib/AppInfo/Application.php | 27 ++++++------ apps/sharebymail/lib/Capabilities.php | 31 ++++++++----- apps/sharebymail/lib/Settings.php | 53 ----------------------- apps/sharebymail/lib/Settings/SettingsManager.php | 6 ++- 4 files changed, 39 insertions(+), 78 deletions(-) delete mode 100644 apps/sharebymail/lib/Settings.php (limited to 'apps/sharebymail/lib') diff --git a/apps/sharebymail/lib/AppInfo/Application.php b/apps/sharebymail/lib/AppInfo/Application.php index 7acb43cfbed..572e754d934 100644 --- a/apps/sharebymail/lib/AppInfo/Application.php +++ b/apps/sharebymail/lib/AppInfo/Application.php @@ -1,4 +1,6 @@ * @@ -27,23 +29,22 @@ namespace OCA\ShareByMail\AppInfo; use OCA\ShareByMail\Capabilities; -use OCA\ShareByMail\Settings; use OCP\AppFramework\App; -use OCP\Util; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; -class Application extends App { - public function __construct(array $urlParams = []) { - parent::__construct('sharebymail', $urlParams); +class Application extends App implements IBootstrap { + public const APP_ID = 'sharebymail'; - $settingsManager = \OC::$server->query(Settings\SettingsManager::class); - $settings = new Settings($settingsManager); + public function __construct() { + parent::__construct(self::APP_ID); + } - /** register capabilities */ - $container = $this->getContainer(); - $container->registerCapability(Capabilities::class); + public function register(IRegistrationContext $context): void { + $context->registerCapability(Capabilities::class); + } - /** register hooks */ - Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareProvider'); - Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareByMailSettings'); + public function boot(IBootContext $context): void { } } diff --git a/apps/sharebymail/lib/Capabilities.php b/apps/sharebymail/lib/Capabilities.php index e703b9b1e5f..bc2d2baf817 100644 --- a/apps/sharebymail/lib/Capabilities.php +++ b/apps/sharebymail/lib/Capabilities.php @@ -1,4 +1,6 @@ * @@ -23,26 +25,35 @@ namespace OCA\ShareByMail; +use OCA\ShareByMail\Settings\SettingsManager; use OCP\Capabilities\ICapability; class Capabilities implements ICapability { - /** - * Function an app uses to return the capabilities - * - * @return array Array containing the apps capabilities - * @since 8.2.0 - */ - public function getCapabilities() { + /** @var SettingsManager */ + private $manager; + + public function __construct(SettingsManager $manager) { + $this->manager = $manager; + } + + public function getCapabilities(): array { return [ 'files_sharing' => [ 'sharebymail' => [ 'enabled' => true, - 'upload_files_drop' => ['enabled' => true], - 'password' => ['enabled' => true], - 'expire_date' => ['enabled' => true] + 'upload_files_drop' => [ + 'enabled' => true, + ], + 'password' => [ + 'enabled' => true, + 'enforced' => $this->manager->enforcePasswordProtection(), + ], + 'expire_date' => [ + 'enabled' => true, + ], ] ] ]; diff --git a/apps/sharebymail/lib/Settings.php b/apps/sharebymail/lib/Settings.php deleted file mode 100644 index 721050c83c4..00000000000 --- a/apps/sharebymail/lib/Settings.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * @author Bjoern Schiessle - * - * @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 . - * - */ - -namespace OCA\ShareByMail; - -use OCA\ShareByMail\Settings\SettingsManager; - -class Settings { - - /** @var SettingsManager */ - private $settingsManager; - - public function __construct(SettingsManager $settingsManager) { - $this->settingsManager = $settingsManager; - } - - /** - * announce that the share-by-mail share provider is enabled - * - * @param array $settings - */ - public function announceShareProvider(array $settings) { - $array = json_decode($settings['array']['oc_appconfig'], true); - $array['shareByMailEnabled'] = true; - $settings['array']['oc_appconfig'] = json_encode($array); - } - - public function announceShareByMailSettings(array $settings) { - $array = json_decode($settings['array']['oc_appconfig'], true); - $array['shareByMail']['enforcePasswordProtection'] = $this->settingsManager->enforcePasswordProtection(); - $settings['array']['oc_appconfig'] = json_encode($array); - } -} diff --git a/apps/sharebymail/lib/Settings/SettingsManager.php b/apps/sharebymail/lib/Settings/SettingsManager.php index cded3e1713d..00826b9b6f5 100644 --- a/apps/sharebymail/lib/Settings/SettingsManager.php +++ b/apps/sharebymail/lib/Settings/SettingsManager.php @@ -1,4 +1,6 @@ * @@ -43,7 +45,7 @@ class SettingsManager { * * @return bool */ - public function sendPasswordByMail() { + public function sendPasswordByMail(): bool { $sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->sendPasswordByMailDefault); return $sendPasswordByMail === 'yes'; } @@ -53,7 +55,7 @@ class SettingsManager { * * @return bool */ - public function enforcePasswordProtection() { + public function enforcePasswordProtection(): bool { $enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault); return $enforcePassword === 'yes'; } -- cgit v1.2.3