From ad7426a1c92cd7489c907d14bc68e0175c3dcc30 Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Tue, 15 Oct 2024 21:43:55 +0000 Subject: [PATCH 1/2] disable storage wrapper for storage_enable group --- lib/AppInfo/Application.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index a6f4e9c6..0cb7a6a4 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -47,6 +47,8 @@ use OCP\User\Events\BeforeUserDeletedEvent; use OCP\User\Events\PasswordUpdatedEvent; use OCP\User\Events\UserChangedEvent; use OCP\Util; +use OCP\IUserSession; +use OCP\IGroupManager; class Application extends App implements IBootstrap { public const APP_ID = 'ecloud-accounts'; @@ -79,8 +81,25 @@ class Application extends App implements IBootstrap { * @internal */ public function addStorageWrapper(): void { - Filesystem::addStorageWrapper('ecloud-accounts', [$this, 'addStorageWrapperCallback'], -10); - } + $userSession = \OC::$server->get(IUserSession::class); + $currentUser = $userSession->getUser(); + if ($currentUser !== null) { + $groupManager = \OC::$server->get(IGroupManager::class); + $groups = $groupManager->getUserGroups($currentUser); + $hasAccess = false; + if (!empty($groups)) { + foreach ($groups as $group) { + if($group->getGID() === "storage_enable"){ + $hasAccess = true; + break; + } + } + } + if(!$hasAccess){ + Filesystem::addStorageWrapper('ecloud-accounts', [$this, 'addStorageWrapperCallback'], -10); + } + } + /** * @internal -- GitLab From 8a275735ee8a3dc354a056adc70ff3757004a3e2 Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Wed, 16 Oct 2024 11:29:44 +0000 Subject: [PATCH 2/2] Apply 1 suggestion(s) to 1 file(s) Co-authored-by: Fahim Salam Chowdhury --- lib/AppInfo/Application.php | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 0cb7a6a4..e35a5d4c 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -83,22 +83,28 @@ class Application extends App implements IBootstrap { public function addStorageWrapper(): void { $userSession = \OC::$server->get(IUserSession::class); $currentUser = $userSession->getUser(); - if ($currentUser !== null) { - $groupManager = \OC::$server->get(IGroupManager::class); - $groups = $groupManager->getUserGroups($currentUser); - $hasAccess = false; - if (!empty($groups)) { - foreach ($groups as $group) { - if($group->getGID() === "storage_enable"){ + if ($currentUser === null) { + Filesystem::addStorageWrapper('ecloud-accounts', [$this, 'addStorageWrapperCallback'], -10); + return; + } + + $groupManager = \OC::$server->get(IGroupManager::class); + $groups = $groupManager->getUserGroups($currentUser); + $hasAccess = false; + + if (!empty($groups)) { + foreach ($groups as $group) { + if($group->getGID() === "storage_enable") { $hasAccess = true; - break; - } + break; } } - if(!$hasAccess){ - Filesystem::addStorageWrapper('ecloud-accounts', [$this, 'addStorageWrapperCallback'], -10); - } } + + if(!$hasAccess) { + Filesystem::addStorageWrapper('ecloud-accounts', [$this, 'addStorageWrapperCallback'], -10); + } + } /** -- GitLab