Skip to content
Snippets Groups Projects
Unverified Commit 0bcc643d authored by Roeland Jago Douma's avatar Roeland Jago Douma Committed by Morris Jobke
Browse files

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: default avatarRoeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: default avatarnpmbuildbot[bot] <npmbuildbot[bot]@users.noreply.github.com>
Signed-off-by: default avatarMorris Jobke <hey@morrisjobke.de>
parent 52af709c
No related branches found
No related tags found
No related merge requests found
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -178,7 +178,7 @@ export default class Config {
* @memberof Config
*/
get isMailShareAllowed() {
return OC.appConfig.shareByMailEnabled !== undefined
return OC.getCapabilities()['files_sharing']['sharebymail'] !== undefined
&& OC.getCapabilities()['files_sharing']['public']['enabled'] === true
}
......@@ -223,7 +223,7 @@ export default class Config {
* @memberof Config
*/
get isPasswordForMailSharesRequired() {
return (OC.appConfig.shareByMail === undefined) ? false : OC.appConfig.shareByMail.enforcePasswordProtection === true
return (OC.getCapabilities()['files_sharing']['sharebymail'] === undefined) ? false : OC.getCapabilities()['files_sharing']['sharebymail']['password']['enforced']
}
/**
......
<?php
/**
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
*
* @author Bjoern Schiessle <bjoern@schiessle.org>
* @author Robin Appelman <robin@icewind.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/>.
*
*/
use OCA\ShareByMail\AppInfo\Application;
$app = \OC::$server->query(Application::class);
......@@ -9,7 +9,6 @@ return array(
'OCA\\ShareByMail\\Activity' => $baseDir . '/../lib/Activity.php',
'OCA\\ShareByMail\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
'OCA\\ShareByMail\\Capabilities' => $baseDir . '/../lib/Capabilities.php',
'OCA\\ShareByMail\\Settings' => $baseDir . '/../lib/Settings.php',
'OCA\\ShareByMail\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',
'OCA\\ShareByMail\\Settings\\SettingsManager' => $baseDir . '/../lib/Settings/SettingsManager.php',
'OCA\\ShareByMail\\ShareByMailProvider' => $baseDir . '/../lib/ShareByMailProvider.php',
......
......@@ -24,7 +24,6 @@ class ComposerStaticInitShareByMail
'OCA\\ShareByMail\\Activity' => __DIR__ . '/..' . '/../lib/Activity.php',
'OCA\\ShareByMail\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
'OCA\\ShareByMail\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php',
'OCA\\ShareByMail\\Settings' => __DIR__ . '/..' . '/../lib/Settings.php',
'OCA\\ShareByMail\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',
'OCA\\ShareByMail\\Settings\\SettingsManager' => __DIR__ . '/..' . '/../lib/Settings/SettingsManager.php',
'OCA\\ShareByMail\\ShareByMailProvider' => __DIR__ . '/..' . '/../lib/ShareByMailProvider.php',
......
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
*
......@@ -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 {
}
}
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
*
......@@ -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,
],
]
]
];
......
<?php
/**
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
*
* @author Bjoern Schiessle <bjoern@schiessle.org>
*
* @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\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);
}
}
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
*
......@@ -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';
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment