From 7bf386ed00d9851e2f06808c01f612676f8ba797 Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Thu, 5 Dec 2024 20:10:30 +0530 Subject: [PATCH 1/7] prevent caling addStorageWrapper at firstlogin --- lib/AppInfo/Application.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 1beceac8..93600368 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -56,7 +56,19 @@ class Application extends App implements IBootstrap { } public function register(IRegistrationContext $context): void { - Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper'); + $userManager = \OC::$server->getUserManager(); // Get the user manager instance + $userSession = \OC::$server->getUserSession(); // Get the user session instance + + $currentLoggedInUser = $userSession->getUser(); + if ($currentLoggedInUser) { + $userId = $currentLoggedInUser->getUID(); + $user = $userManager->get($userId); + + if ($user && $user->getLastLogin() !== 0) { + Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper'); + } + } + $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); $context->registerEventListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); $context->registerEventListener(UserChangedEvent::class, UserChangedListener::class); -- GitLab From 2cca36e5bcd4353c4e9cb4ca9bebc714cf65a2fb Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Fri, 6 Dec 2024 10:47:13 +0530 Subject: [PATCH 2/7] logger added --- lib/AppInfo/Application.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 93600368..6d9a86cf 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -42,7 +42,9 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\Files\Storage\IStorage; +use OCP\ILogger; use OCP\IUserManager; +use OCP\IUserSession; use OCP\User\Events\BeforeUserDeletedEvent; use OCP\User\Events\PasswordUpdatedEvent; use OCP\User\Events\UserChangedEvent; @@ -50,22 +52,28 @@ use OCP\Util; class Application extends App implements IBootstrap { public const APP_ID = 'ecloud-accounts'; + private $logger; + private $userManager; + private $userSession; - public function __construct(array $urlParams = []) { + public function __construct(array $urlParams = [], ILogger $logger, IUserManager $userManager, IUserSession $userSession) { + $this->logger = $logger; + $this->userManager = $userManager; + $this->userSession = $userSession; parent::__construct(self::APP_ID, $urlParams); } public function register(IRegistrationContext $context): void { - $userManager = \OC::$server->getUserManager(); // Get the user manager instance - $userSession = \OC::$server->getUserSession(); // Get the user session instance - - $currentLoggedInUser = $userSession->getUser(); + $currentLoggedInUser = $this->userSession->getUser(); if ($currentLoggedInUser) { $userId = $currentLoggedInUser->getUID(); - $user = $userManager->get($userId); - + $user = $this->userManager->get($userId); + $this->logger->info('User logged in at: ' . $user->getLastLogin()); if ($user && $user->getLastLogin() !== 0) { + $this->logger->info('addStorageWrapper called'); Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper'); + } else { + $this->logger->info('skipped addStorageWrapper'); } } -- GitLab From 64ecbf9fd07389dd0efdde9b40ce63c99f70537f Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Fri, 6 Dec 2024 11:05:00 +0530 Subject: [PATCH 3/7] Construct issue --- lib/AppInfo/Application.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 6d9a86cf..f06a0bbd 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -42,9 +42,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\Files\Storage\IStorage; -use OCP\ILogger; use OCP\IUserManager; -use OCP\IUserSession; use OCP\User\Events\BeforeUserDeletedEvent; use OCP\User\Events\PasswordUpdatedEvent; use OCP\User\Events\UserChangedEvent; @@ -56,10 +54,11 @@ class Application extends App implements IBootstrap { private $userManager; private $userSession; - public function __construct(array $urlParams = [], ILogger $logger, IUserManager $userManager, IUserSession $userSession) { - $this->logger = $logger; - $this->userManager = $userManager; - $this->userSession = $userSession; + public function __construct(array $urlParams = []) { + $serverContainer = \OC::$server; + $this->logger = $serverContainer->get(\OCP\ILogger::class); + $this->userManager = $serverContainer->get(\OCP\IUserManager::class); + $this->userSession = $serverContainer->get(\OCP\IUserSession::class); parent::__construct(self::APP_ID, $urlParams); } -- GitLab From 1bed80bc93b9c2421ef001c457d7fcfe0ece94d9 Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Fri, 6 Dec 2024 11:08:27 +0530 Subject: [PATCH 4/7] Construct issue #2 --- lib/AppInfo/Application.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index f06a0bbd..e4eb0974 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -50,29 +50,26 @@ use OCP\Util; class Application extends App implements IBootstrap { public const APP_ID = 'ecloud-accounts'; - private $logger; - private $userManager; - private $userSession; public function __construct(array $urlParams = []) { - $serverContainer = \OC::$server; - $this->logger = $serverContainer->get(\OCP\ILogger::class); - $this->userManager = $serverContainer->get(\OCP\IUserManager::class); - $this->userSession = $serverContainer->get(\OCP\IUserSession::class); parent::__construct(self::APP_ID, $urlParams); } public function register(IRegistrationContext $context): void { - $currentLoggedInUser = $this->userSession->getUser(); + $userSession = \OC::$server->getUserSession(); + $userManager = \OC::$server->getUserManager(); + $logger = \OC::$server->getLogger(); + + $currentLoggedInUser = $userSession->getUser(); if ($currentLoggedInUser) { $userId = $currentLoggedInUser->getUID(); - $user = $this->userManager->get($userId); - $this->logger->info('User logged in at: ' . $user->getLastLogin()); + $user = $userManager->get($userId); + $logger->info('User logged in at: ' . $user->getLastLogin()); if ($user && $user->getLastLogin() !== 0) { - $this->logger->info('addStorageWrapper called'); + $logger->info('addStorageWrapper called'); Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper'); } else { - $this->logger->info('skipped addStorageWrapper'); + $logger->info('skipped addStorageWrapper'); } } -- GitLab From cb4867cdf49fc6ab6c14956299f16f4a2923a5b8 Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Fri, 6 Dec 2024 11:31:14 +0530 Subject: [PATCH 5/7] Construct issue #3 --- lib/AppInfo/Application.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index e4eb0974..d3ecdb92 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -71,6 +71,8 @@ class Application extends App implements IBootstrap { } else { $logger->info('skipped addStorageWrapper'); } + } else { + $logger->info('user not loggedin'); } $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); -- GitLab From 00a04b6a7b1158866996317dc6e1952fd1e351a3 Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Fri, 6 Dec 2024 13:10:51 +0530 Subject: [PATCH 6/7] session changes --- lib/AppInfo/Application.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index d3ecdb92..abc4cf6a 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -64,15 +64,15 @@ class Application extends App implements IBootstrap { if ($currentLoggedInUser) { $userId = $currentLoggedInUser->getUID(); $user = $userManager->get($userId); - $logger->info('User logged in at: ' . $user->getLastLogin()); + $logger->error('User logged in at: ' . $user->getLastLogin()); if ($user && $user->getLastLogin() !== 0) { - $logger->info('addStorageWrapper called'); + $logger->error('addStorageWrapper called'); Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper'); } else { - $logger->info('skipped addStorageWrapper'); + $logger->error('skipped addStorageWrapper'); } } else { - $logger->info('user not loggedin'); + $logger->error('user not loggedin'); } $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); -- GitLab From c7f881169438ae82daf39aa7dbc12aa8bc52d66b Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Mon, 9 Dec 2024 11:08:54 +0530 Subject: [PATCH 7/7] temp cmmented --- lib/AppInfo/Application.php | 19 +------------------ lib/Filesystem/StorageWrapper.php | 1 + 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index abc4cf6a..aaff525b 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -56,24 +56,7 @@ class Application extends App implements IBootstrap { } public function register(IRegistrationContext $context): void { - $userSession = \OC::$server->getUserSession(); - $userManager = \OC::$server->getUserManager(); - $logger = \OC::$server->getLogger(); - - $currentLoggedInUser = $userSession->getUser(); - if ($currentLoggedInUser) { - $userId = $currentLoggedInUser->getUID(); - $user = $userManager->get($userId); - $logger->error('User logged in at: ' . $user->getLastLogin()); - if ($user && $user->getLastLogin() !== 0) { - $logger->error('addStorageWrapper called'); - Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper'); - } else { - $logger->error('skipped addStorageWrapper'); - } - } else { - $logger->error('user not loggedin'); - } + // Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper'); $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); $context->registerEventListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); diff --git a/lib/Filesystem/StorageWrapper.php b/lib/Filesystem/StorageWrapper.php index f35a5510..74d0011d 100644 --- a/lib/Filesystem/StorageWrapper.php +++ b/lib/Filesystem/StorageWrapper.php @@ -39,6 +39,7 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { */ public function mkdir($path) { $this->checkFileAccess($path, true); + } /** -- GitLab