general: reduce some DI
parent
04614b9c6e
commit
4c2bc5a675
|
@ -27,7 +27,6 @@ use OC\DB\Connection;
|
||||||
use OC\DB\SchemaWrapper;
|
use OC\DB\SchemaWrapper;
|
||||||
use OCA\Memories\AppInfo\Application;
|
use OCA\Memories\AppInfo\Application;
|
||||||
use OCA\Memories\Db\TimelineWrite;
|
use OCA\Memories\Db\TimelineWrite;
|
||||||
use OCP\Encryption\IManager;
|
|
||||||
use OCP\Files\File;
|
use OCP\Files\File;
|
||||||
use OCP\Files\Folder;
|
use OCP\Files\Folder;
|
||||||
use OCP\Files\IRootFolder;
|
use OCP\Files\IRootFolder;
|
||||||
|
@ -52,7 +51,6 @@ class Index extends Command
|
||||||
protected IPreview $preview;
|
protected IPreview $preview;
|
||||||
protected IConfig $config;
|
protected IConfig $config;
|
||||||
protected OutputInterface $output;
|
protected OutputInterface $output;
|
||||||
protected IManager $encryptionManager;
|
|
||||||
protected IDBConnection $connection;
|
protected IDBConnection $connection;
|
||||||
protected Connection $connectionForSchema;
|
protected Connection $connectionForSchema;
|
||||||
protected TimelineWrite $timelineWrite;
|
protected TimelineWrite $timelineWrite;
|
||||||
|
@ -72,7 +70,6 @@ class Index extends Command
|
||||||
IUserManager $userManager,
|
IUserManager $userManager,
|
||||||
IPreview $preview,
|
IPreview $preview,
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
IManager $encryptionManager,
|
|
||||||
IDBConnection $connection,
|
IDBConnection $connection,
|
||||||
Connection $connectionForSchema
|
Connection $connectionForSchema
|
||||||
) {
|
) {
|
||||||
|
@ -82,7 +79,6 @@ class Index extends Command
|
||||||
$this->rootFolder = $rootFolder;
|
$this->rootFolder = $rootFolder;
|
||||||
$this->preview = $preview;
|
$this->preview = $preview;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->encryptionManager = $encryptionManager;
|
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
$this->connectionForSchema = $connectionForSchema;
|
$this->connectionForSchema = $connectionForSchema;
|
||||||
$this->timelineWrite = new TimelineWrite($connection, $preview);
|
$this->timelineWrite = new TimelineWrite($connection, $preview);
|
||||||
|
@ -180,7 +176,7 @@ class Index extends Command
|
||||||
// Time measurement
|
// Time measurement
|
||||||
$startTime = microtime(true);
|
$startTime = microtime(true);
|
||||||
|
|
||||||
if (\OCA\Memories\Util::isEncryptionEnabled($this->encryptionManager)) {
|
if (\OCA\Memories\Util::isEncryptionEnabled()) {
|
||||||
// Can work with server-side but not with e2e encryption, see https://github.com/pulsejet/memories/issues/99
|
// Can work with server-side but not with e2e encryption, see https://github.com/pulsejet/memories/issues/99
|
||||||
error_log('FATAL: Only server-side encryption (OC_DEFAULT_MODULE) is supported, but another encryption module is enabled. Aborted.');
|
error_log('FATAL: Only server-side encryption (OC_DEFAULT_MODULE) is supported, but another encryption module is enabled. Aborted.');
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ use OCP\App\IAppManager;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
use OCP\AppFramework\Http\JSONResponse;
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
use OCP\Encryption\IManager;
|
|
||||||
use OCP\Files\File;
|
use OCP\Files\File;
|
||||||
use OCP\Files\Folder;
|
use OCP\Files\Folder;
|
||||||
use OCP\Files\IRootFolder;
|
use OCP\Files\IRootFolder;
|
||||||
|
@ -40,18 +39,15 @@ use OCP\IConfig;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
use OCP\IPreview;
|
use OCP\IPreview;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\ISession;
|
|
||||||
use OCP\IUserSession;
|
use OCP\IUserSession;
|
||||||
use OCP\Share\IManager as IShareManager;
|
use OCP\Share\IManager as IShareManager;
|
||||||
|
|
||||||
class ApiBase extends Controller
|
class ApiBase extends Controller
|
||||||
{
|
{
|
||||||
protected IConfig $config;
|
protected IConfig $config;
|
||||||
protected ISession $session;
|
|
||||||
protected IUserSession $userSession;
|
protected IUserSession $userSession;
|
||||||
protected IRootFolder $rootFolder;
|
protected IRootFolder $rootFolder;
|
||||||
protected IAppManager $appManager;
|
protected IAppManager $appManager;
|
||||||
protected IManager $encryptionManager;
|
|
||||||
protected TimelineQuery $timelineQuery;
|
protected TimelineQuery $timelineQuery;
|
||||||
protected TimelineWrite $timelineWrite;
|
protected TimelineWrite $timelineWrite;
|
||||||
protected IShareManager $shareManager;
|
protected IShareManager $shareManager;
|
||||||
|
@ -60,24 +56,20 @@ class ApiBase extends Controller
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
ISession $session,
|
|
||||||
IUserSession $userSession,
|
IUserSession $userSession,
|
||||||
IDBConnection $connection,
|
IDBConnection $connection,
|
||||||
IRootFolder $rootFolder,
|
IRootFolder $rootFolder,
|
||||||
IAppManager $appManager,
|
IAppManager $appManager,
|
||||||
IManager $encryptionManager,
|
|
||||||
IShareManager $shareManager,
|
IShareManager $shareManager,
|
||||||
IPreview $preview
|
IPreview $preview
|
||||||
) {
|
) {
|
||||||
parent::__construct(Application::APPNAME, $request);
|
parent::__construct(Application::APPNAME, $request);
|
||||||
|
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->session = $session;
|
|
||||||
$this->userSession = $userSession;
|
$this->userSession = $userSession;
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
$this->rootFolder = $rootFolder;
|
$this->rootFolder = $rootFolder;
|
||||||
$this->appManager = $appManager;
|
$this->appManager = $appManager;
|
||||||
$this->encryptionManager = $encryptionManager;
|
|
||||||
$this->shareManager = $shareManager;
|
$this->shareManager = $shareManager;
|
||||||
$this->previewManager = $preview;
|
$this->previewManager = $preview;
|
||||||
$this->timelineQuery = new TimelineQuery($connection);
|
$this->timelineQuery = new TimelineQuery($connection);
|
||||||
|
@ -257,10 +249,11 @@ class ApiBase extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if share is password protected
|
// Check if share is password protected
|
||||||
|
$session = \OC::$server->getSession();
|
||||||
if (($password = $share->getPassword()) !== null) {
|
if (($password = $share->getPassword()) !== null) {
|
||||||
// https://github.com/nextcloud/server/blob/0447b53bda9fe95ea0cbed765aa332584605d652/lib/public/AppFramework/PublicShareController.php#L119
|
// https://github.com/nextcloud/server/blob/0447b53bda9fe95ea0cbed765aa332584605d652/lib/public/AppFramework/PublicShareController.php#L119
|
||||||
if ($this->session->get('public_link_authenticated_token') !== $token
|
if ($session->get('public_link_authenticated_token') !== $token
|
||||||
|| $this->session->get('public_link_authenticated_password_hash') !== $password) {
|
|| $session->get('public_link_authenticated_password_hash') !== $password) {
|
||||||
throw new \Exception('Share is password protected and user is not authenticated');
|
throw new \Exception('Share is password protected and user is not authenticated');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ class ImageController extends ApiBase
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for end-to-end encryption
|
// Check for end-to-end encryption
|
||||||
if (\OCA\Memories\Util::isEncryptionEnabled($this->encryptionManager)) {
|
if (\OCA\Memories\Util::isEncryptionEnabled()) {
|
||||||
return new JSONResponse(['message' => 'Cannot change encrypted file'], Http::STATUS_PRECONDITION_FAILED);
|
return new JSONResponse(['message' => 'Cannot change encrypted file'], Http::STATUS_PRECONDITION_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,11 +109,10 @@ class Util
|
||||||
/**
|
/**
|
||||||
* Check if any encryption is enabled that we can not cope with
|
* Check if any encryption is enabled that we can not cope with
|
||||||
* such as end-to-end encryption.
|
* such as end-to-end encryption.
|
||||||
*
|
|
||||||
* @param mixed $encryptionManager
|
|
||||||
*/
|
*/
|
||||||
public static function isEncryptionEnabled(&$encryptionManager): bool
|
public static function isEncryptionEnabled(): bool
|
||||||
{
|
{
|
||||||
|
$encryptionManager = \OC::$server->getEncryptionManager();
|
||||||
if ($encryptionManager->isEnabled()) {
|
if ($encryptionManager->isEnabled()) {
|
||||||
// Server-side encryption (OC_DEFAULT_MODULE) is okay, others like e2e are not
|
// Server-side encryption (OC_DEFAULT_MODULE) is okay, others like e2e are not
|
||||||
return 'OC_DEFAULT_MODULE' !== $encryptionManager->getDefaultEncryptionModuleId();
|
return 'OC_DEFAULT_MODULE' !== $encryptionManager->getDefaultEncryptionModuleId();
|
||||||
|
|
Loading…
Reference in New Issue