Skip to content

Commit

Permalink
[encryption] Remove dependency fetching inside the constructor and mo…
Browse files Browse the repository at this point in the history
…ve them to method call parameters

Signed-off-by: Morris Jobke <[email protected]>
  • Loading branch information
MorrisJobke committed Nov 22, 2020
1 parent 032de4f commit 3180eb4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
9 changes: 5 additions & 4 deletions apps/encryption/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@

\OCP\Util::addscript('encryption', 'encryption');

$encryptionSystemReady = \OC::$server->getEncryptionManager()->isReady();
$encryptionManager = \OC::$server->getEncryptionManager();
$encryptionSystemReady = $encryptionManager->isReady();

/** @var Application $app */
$app = \OC::$server->query(Application::class);
if ($encryptionSystemReady) {
$app->registerEncryptionModule();
$app->registerHooks();
$app->setUp();
$app->registerEncryptionModule($encryptionManager);
$app->registerHooks(\OC::$server->getConfig());
$app->setUp($encryptionManager);
}
21 changes: 6 additions & 15 deletions apps/encryption/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,16 @@
use Symfony\Component\Console\Helper\QuestionHelper;

class Application extends \OCP\AppFramework\App {

/** @var IManager */
private $encryptionManager;
/** @var IConfig */
private $config;

/**
* @param array $urlParams
*/
public function __construct($urlParams = []) {
parent::__construct('encryption', $urlParams);
$this->encryptionManager = \OC::$server->getEncryptionManager();
$this->config = \OC::$server->getConfig();
$this->registerServices();
}

public function setUp() {
if ($this->encryptionManager->isEnabled()) {
public function setUp(IManager $encryptionManager) {
if ($encryptionManager->isEnabled()) {
/** @var Setup $setup */
$setup = $this->getContainer()->query(Setup::class);
$setup->setupSystem();
Expand All @@ -75,8 +67,8 @@ public function setUp() {
/**
* register hooks
*/
public function registerHooks() {
if (!$this->config->getSystemValueBool('maintenance')) {
public function registerHooks(IConfig $config) {
if (!$config->getSystemValueBool('maintenance')) {
$container = $this->getContainer();
$server = $container->getServer();
// Register our hooks and fire them.
Expand All @@ -101,11 +93,10 @@ public function registerHooks() {
}
}

public function registerEncryptionModule() {
public function registerEncryptionModule(IManager $encryptionManager) {
$container = $this->getContainer();


$this->encryptionManager->registerEncryptionModule(
$encryptionManager->registerEncryptionModule(
Encryption::ID,
Encryption::DISPLAY_NAME,
function () use ($container) {
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/Traits/EncryptionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCA\Encryption\AppInfo\Application;
use OCA\Encryption\KeyManager;
use OCA\Encryption\Users\Setup;
use OCP\Encryption\IManager;

/**
* Enables encryption
Expand Down Expand Up @@ -64,7 +65,8 @@ protected function setupForUser($name, $password) {
/** @var Setup $userSetup */
$userSetup = $container->query(Setup::class);
$userSetup->setupUser($name, $password);
$this->encryptionApp->setUp();
$encryptionManager = $container->query(IManager::class);
$this->encryptionApp->setUp($encryptionManager);
$keyManager->init($name, $password);
}

Expand Down

0 comments on commit 3180eb4

Please sign in to comment.