From ea60557f53be659dd5c5d04cc098223bde50791d Mon Sep 17 00:00:00 2001 From: Jan Drees Date: Wed, 15 Nov 2023 21:44:21 +0100 Subject: [PATCH 01/11] Remove the filtering for blocked users from the database queries --- lib/Query/QueryProvider.php | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/lib/Query/QueryProvider.php b/lib/Query/QueryProvider.php index 13514f0..b33153e 100644 --- a/lib/Query/QueryProvider.php +++ b/lib/Query/QueryProvider.php @@ -134,22 +134,19 @@ private function loadQueries() (empty($uDisabled) ? "" : "LEFT JOIN $user u ON u.$uUID = ug.$ugUID ") . "WHERE ug.$ugGID = g.$gGID " . "AND ug.$ugUID = :$uidParam " . - "AND g.$gAdmin" . - (empty($uDisabled) ? "" : " AND NOT u.$uDisabled"), + "AND g.$gAdmin", Query::COUNT_GROUPS => "SELECT COUNT(DISTINCT ug.$ugUID) " . "FROM $userGroup ug " . (empty($uDisabled) ? "" : "LEFT JOIN $user u ON u.$uUID = ug.$ugUID ") . "WHERE ug.$ugGID LIKE :$gidParam " . - "AND ug.$ugUID LIKE :$searchParam" . - (empty($uDisabled) ? "" : " AND NOT u.$uDisabled"), + "AND ug.$ugUID LIKE :$searchParam", Query::COUNT_USERS => "SELECT COUNT(u.$uUID) AS count " . "FROM $user u " . - "WHERE u.$uUID LIKE :$searchParam " . - (empty($uDisabled) ? "" : "AND NOT u.$uDisabled"), + "WHERE u.$uUID LIKE :$searchParam ", Query::FIND_GROUP => "SELECT $groupColumns " . @@ -162,7 +159,6 @@ private function loadQueries() "LEFT JOIN $userGroup ug ON u.$uUID = ug.$ugUID " . "WHERE ug.$ugGID LIKE :$gidParam " . "AND u.$uUID LIKE :$searchParam " . - (empty($uDisabled) ? "" : "AND NOT u.$uDisabled ") . "ORDER BY u.$uUID", Query::FIND_GROUP_USERS => @@ -171,7 +167,6 @@ private function loadQueries() "LEFT JOIN $userGroup ug ON u.$uUID = ug.$ugUID " . "WHERE ug.$ugGID LIKE :$gidParam " . "AND u.$uUID LIKE :$searchParam " . - (empty($uDisabled) ? "" : "AND NOT u.$uDisabled ") . "ORDER BY u.$uUID", Query::FIND_GROUPS => @@ -184,32 +179,27 @@ private function loadQueries() Query::FIND_USER_BY_UID => "SELECT $userColumns " . "FROM $user u " . - "WHERE u.$uUID = :$uidParam" . - (empty($uDisabled) ? "" : " AND NOT u.$uDisabled"), + "WHERE u.$uUID = :$uidParam", Query::FIND_USER_BY_USERNAME => "SELECT $userColumns, u.$uPassword AS password " . "FROM $user u " . - "WHERE u.$uUsername = :$usernameParam" . - (empty($uDisabled) ? "" : " AND NOT u.$uDisabled"), + "WHERE u.$uUsername = :$usernameParam", Query::FIND_USER_BY_USERNAME_CASE_INSENSITIVE => "SELECT $userColumns, u.$uPassword AS password " . "FROM $user u " . - "WHERE lower(u.$uUsername) = lower(:$usernameParam)" . - (empty($uDisabled) ? "" : " AND NOT u.$uDisabled"), + "WHERE lower(u.$uUsername) = lower(:$usernameParam)", Query::FIND_USER_BY_USERNAME_OR_EMAIL => "SELECT $userColumns, u.$uPassword AS password " . "FROM $user u " . - "WHERE u.$uUsername = :$usernameParam OR u.$uEmail = :$emailParam" . - (empty($uDisabled) ? "" : " AND NOT u.$uDisabled"), + "WHERE u.$uUsername = :$usernameParam OR u.$uEmail = :$emailParam", Query::FIND_USER_BY_USERNAME_OR_EMAIL_CASE_INSENSITIVE => "SELECT $userColumns, u.$uPassword AS password " . "FROM $user u " . - "WHERE lower(u.$uUsername) = lower(:$usernameParam) OR lower(u.$uEmail) = lower(:$emailParam)" . - (empty($uDisabled) ? "" : " AND NOT u.$uDisabled"), + "WHERE lower(u.$uUsername) = lower(:$usernameParam) OR lower(u.$uEmail) = lower(:$emailParam)", Query::FIND_USER_GROUPS => "SELECT $groupColumns " . @@ -226,7 +216,6 @@ private function loadQueries() (empty($uName) ? "" : "OR u.$uName LIKE :$searchParam ") . (empty($uEmail) ? "" : "OR u.$uEmail LIKE :$searchParam ") . ")" . - (empty($uDisabled) ? "" : " AND NOT u.$uDisabled ") . "ORDER BY u.$uUID", Query::UPDATE_DISPLAY_NAME => From f29917933b9e5854765f9e4a1e6b5e5107179bd2 Mon Sep 17 00:00:00 2001 From: Jan Drees Date: Wed, 15 Nov 2023 22:23:50 +0100 Subject: [PATCH 02/11] create mock placeholder users when query returns nothing --- lib/Repository/UserRepository.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Repository/UserRepository.php b/lib/Repository/UserRepository.php index aa87f8a..0c30821 100644 --- a/lib/Repository/UserRepository.php +++ b/lib/Repository/UserRepository.php @@ -62,9 +62,18 @@ public function __construct(DataQuery $dataQuery) */ public function findByUid($uid) { - return $this->dataQuery->queryEntity( + $query_result = $this->dataQuery->queryEntity( Query::FIND_USER_BY_UID, User::class, [Query::UID_PARAM => $uid] ); + if($query_result === null or $query_result === false){ + $query_result = new User(); + $query_result->uid = $uid; + $query_result->active = false; + $query_result->email = ""; + $query_result->name = "Deleted User"; + $query_result->username = "deleted"; + } + return $query_result; } /** From 0801a26996ebe8472a2b479927173ff07f75d5f4 Mon Sep 17 00:00:00 2001 From: Jan Drees Date: Wed, 15 Nov 2023 22:45:17 +0100 Subject: [PATCH 03/11] Make placeholder user objects an optional backend parameter --- lib/Backend/UserBackend.php | 7 +++++++ lib/Constant/Opt.php | 1 + lib/Properties.php | 2 +- lib/Repository/UserRepository.php | 11 +---------- templates/admin.php | 3 ++- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/Backend/UserBackend.php b/lib/Backend/UserBackend.php index 1824c4a..8d531b8 100644 --- a/lib/Backend/UserBackend.php +++ b/lib/Backend/UserBackend.php @@ -264,6 +264,13 @@ private function getUser($uid) foreach ($this->actions as $action) { $action->doAction($user); } + }elseif ($this->properties[Opt::PLACEHOLDER_USERS]){ + $user = new User(); + $user->uid = $uid; + $user->active = false; + $user->email = ""; + $user->name = "Deleted User"; + $user->username = "deleted"; } return $user; diff --git a/lib/Constant/Opt.php b/lib/Constant/Opt.php index 005122c..f7a1b44 100644 --- a/lib/Constant/Opt.php +++ b/lib/Constant/Opt.php @@ -48,4 +48,5 @@ final class Opt const REVERSE_ACTIVE = "opt.reverse_active"; const SAFE_STORE = "opt.safe_store"; const USE_CACHE = "opt.use_cache"; + const PLACEHOLDER_USERS = "opt.placeholder_users"; } diff --git a/lib/Properties.php b/lib/Properties.php index 762ce3c..bd90314 100644 --- a/lib/Properties.php +++ b/lib/Properties.php @@ -176,7 +176,7 @@ private function isBooleanParam($param) $param, [ Opt::APPEND_SALT, Opt::CASE_INSENSITIVE_USERNAME, Opt::EMAIL_LOGIN, Opt::NAME_CHANGE, Opt::PASSWORD_CHANGE, Opt::PREPEND_SALT, - Opt::PROVIDE_AVATAR, Opt::REVERSE_ACTIVE, Opt::SAFE_STORE, + Opt::PROVIDE_AVATAR, Opt::REVERSE_ACTIVE, Opt::PLACEHOLDER_USERS, Opt::SAFE_STORE, Opt::USE_CACHE ] ); diff --git a/lib/Repository/UserRepository.php b/lib/Repository/UserRepository.php index 0c30821..aa87f8a 100644 --- a/lib/Repository/UserRepository.php +++ b/lib/Repository/UserRepository.php @@ -62,18 +62,9 @@ public function __construct(DataQuery $dataQuery) */ public function findByUid($uid) { - $query_result = $this->dataQuery->queryEntity( + return $this->dataQuery->queryEntity( Query::FIND_USER_BY_UID, User::class, [Query::UID_PARAM => $uid] ); - if($query_result === null or $query_result === false){ - $query_result = new User(); - $query_result->uid = $uid; - $query_result->active = false; - $query_result->email = ""; - $query_result->name = "Deleted User"; - $query_result->username = "deleted"; - } - return $query_result; } /** diff --git a/templates/admin.php b/templates/admin.php index 74772e7..629f48d 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -118,7 +118,8 @@ function print_select_options( print_checkbox_input($l, "opt-password_change", "Allow password change", $_["opt.password_change"]); print_checkbox_input($l, "opt-provide_avatar", "Allow providing avatar", $_["opt.provide_avatar"]); print_checkbox_input($l, "opt-case_insensitive_username", "Case-insensitive username", $_["opt.case_insensitive_username"]); - print_checkbox_input($l, "opt-reverse_active", "Reverse active column", $_["opt.reverse_active"]); ?> + print_checkbox_input($l, "opt-reverse_active", "Reverse ACTIVE column", $_["opt.reverse_active"]); + print_checkbox_input($l, "opt-placeholder_users", "Placeholders for missing users in SQL database", $_["opt.placeholder_users"]); ?>
"> From cc692d0059e66f83f591a5382f2300446da66cfd Mon Sep 17 00:00:00 2001 From: Jan Drees Date: Tue, 28 Nov 2023 19:44:58 +0100 Subject: [PATCH 04/11] Lie about the number of users --- lib/Repository/UserRepository.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Repository/UserRepository.php b/lib/Repository/UserRepository.php index aa87f8a..de5f18e 100644 --- a/lib/Repository/UserRepository.php +++ b/lib/Repository/UserRepository.php @@ -142,9 +142,7 @@ public function findAllBySearchTerm($search = "", $limit = -1, $offset = 0) */ public function countAll($search = "") { - return $this->dataQuery->queryValue( - Query::COUNT_USERS, [Query::SEARCH_PARAM => $search] - ); + return 499; } /** From 54ac84f553f37c9e06ba82e2a12b8d7abeafad9f Mon Sep 17 00:00:00 2001 From: Jan Drees Date: Tue, 28 Nov 2023 23:38:30 +0100 Subject: [PATCH 05/11] Properly evaluate the number of users --- lib/Repository/UserRepository.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Repository/UserRepository.php b/lib/Repository/UserRepository.php index de5f18e..aa87f8a 100644 --- a/lib/Repository/UserRepository.php +++ b/lib/Repository/UserRepository.php @@ -142,7 +142,9 @@ public function findAllBySearchTerm($search = "", $limit = -1, $offset = 0) */ public function countAll($search = "") { - return 499; + return $this->dataQuery->queryValue( + Query::COUNT_USERS, [Query::SEARCH_PARAM => $search] + ); } /** From a484e1a3279d160fcf95b8ea63b22c3d272e193e Mon Sep 17 00:00:00 2001 From: Claus-Justus Heine Date: Sat, 6 Jan 2024 18:50:58 +0100 Subject: [PATCH 06/11] Update appinfo vo NC 28 --- appinfo/info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 78b30f4..20bd864 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -22,7 +22,7 @@ auth - + \OCA\UserSQL\Settings\Admin From 9d0ef4e4fe4c11af8a67c812d6b2c9c1c4a029a8 Mon Sep 17 00:00:00 2001 From: Claus-Justus Heine Date: Mon, 29 Jan 2024 08:58:38 +0100 Subject: [PATCH 07/11] Add getBackendName() and inherit from INamedBackend --- lib/Backend/GroupBackend.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Backend/GroupBackend.php b/lib/Backend/GroupBackend.php index e48a2a5..cd61048 100644 --- a/lib/Backend/GroupBackend.php +++ b/lib/Backend/GroupBackend.php @@ -32,6 +32,7 @@ use OCP\Group\Backend\IGroupDetailsBackend; use OCP\Group\Backend\IIsAdminBackend; use OCP\Group\Backend\ISearchableGroupBackend; +use OCP\Group\Backend\INamedBackedn; use OCP\ILogger; use OCP\IUserManager; @@ -91,7 +92,15 @@ public function __construct( $this->groupRepository = $groupRepository; } - /** + /** + * @inheritdoc + */ + public function getBackendName(): string + { + return "User SQL"; + } + + /** * @inheritdoc */ public function getGroups($search = "", $limit = null, $offset = null) From c1475ce7435b60f79943c19a9b184a1abca26ec2 Mon Sep 17 00:00:00 2001 From: Claus-Justus Heine Date: Mon, 8 Apr 2024 17:11:20 +0200 Subject: [PATCH 08/11] Claim to support v29 --- appinfo/info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 20bd864..8afbf0d 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -22,7 +22,7 @@ auth - + \OCA\UserSQL\Settings\Admin From ccffdc863413d31ce694ea3ae5327ebea9d69801 Mon Sep 17 00:00:00 2001 From: Ivo Date: Sat, 20 Apr 2024 18:08:39 +0200 Subject: [PATCH 09/11] bump to NC29 --- appinfo/info.xml | 2 +- lib/Backend/GroupBackend.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 78b30f4..aa3dfd8 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -22,7 +22,7 @@ auth - + \OCA\UserSQL\Settings\Admin diff --git a/lib/Backend/GroupBackend.php b/lib/Backend/GroupBackend.php index e48a2a5..cbe1ba8 100644 --- a/lib/Backend/GroupBackend.php +++ b/lib/Backend/GroupBackend.php @@ -32,6 +32,7 @@ use OCP\Group\Backend\IGroupDetailsBackend; use OCP\Group\Backend\IIsAdminBackend; use OCP\Group\Backend\ISearchableGroupBackend; +use OCP\Group\Backend\INamedBackend; use OCP\ILogger; use OCP\IUserManager; @@ -90,7 +91,15 @@ public function __construct( $this->properties = $properties; $this->groupRepository = $groupRepository; } + /** + * @inheritdoc + */ + public function getBackendName(): string + { + return "User SQL"; + } + /** /** * @inheritdoc */ From 1dfe332e78ecd70c35141db2c2de167764268e2a Mon Sep 17 00:00:00 2001 From: Claus-Justus Heine Date: Sat, 17 Aug 2024 17:44:19 +0200 Subject: [PATCH 10/11] Claim to support NC 30 --- appinfo/info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 8afbf0d..5dd60cf 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -22,7 +22,7 @@ auth - + \OCA\UserSQL\Settings\Admin From 6d089d8f56f39b34c838f4ff5a12987ca79f1a49 Mon Sep 17 00:00:00 2001 From: Jan Drees Date: Sat, 12 Oct 2024 20:01:39 +0200 Subject: [PATCH 11/11] Revert "Remove the filtering for blocked users from the database queries" This reverts commit ea60557f53be659dd5c5d04cc098223bde50791d since we can achieve the same thing with the active instead of disabled column --- lib/Query/QueryProvider.php | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/Query/QueryProvider.php b/lib/Query/QueryProvider.php index b33153e..13514f0 100644 --- a/lib/Query/QueryProvider.php +++ b/lib/Query/QueryProvider.php @@ -134,19 +134,22 @@ private function loadQueries() (empty($uDisabled) ? "" : "LEFT JOIN $user u ON u.$uUID = ug.$ugUID ") . "WHERE ug.$ugGID = g.$gGID " . "AND ug.$ugUID = :$uidParam " . - "AND g.$gAdmin", + "AND g.$gAdmin" . + (empty($uDisabled) ? "" : " AND NOT u.$uDisabled"), Query::COUNT_GROUPS => "SELECT COUNT(DISTINCT ug.$ugUID) " . "FROM $userGroup ug " . (empty($uDisabled) ? "" : "LEFT JOIN $user u ON u.$uUID = ug.$ugUID ") . "WHERE ug.$ugGID LIKE :$gidParam " . - "AND ug.$ugUID LIKE :$searchParam", + "AND ug.$ugUID LIKE :$searchParam" . + (empty($uDisabled) ? "" : " AND NOT u.$uDisabled"), Query::COUNT_USERS => "SELECT COUNT(u.$uUID) AS count " . "FROM $user u " . - "WHERE u.$uUID LIKE :$searchParam ", + "WHERE u.$uUID LIKE :$searchParam " . + (empty($uDisabled) ? "" : "AND NOT u.$uDisabled"), Query::FIND_GROUP => "SELECT $groupColumns " . @@ -159,6 +162,7 @@ private function loadQueries() "LEFT JOIN $userGroup ug ON u.$uUID = ug.$ugUID " . "WHERE ug.$ugGID LIKE :$gidParam " . "AND u.$uUID LIKE :$searchParam " . + (empty($uDisabled) ? "" : "AND NOT u.$uDisabled ") . "ORDER BY u.$uUID", Query::FIND_GROUP_USERS => @@ -167,6 +171,7 @@ private function loadQueries() "LEFT JOIN $userGroup ug ON u.$uUID = ug.$ugUID " . "WHERE ug.$ugGID LIKE :$gidParam " . "AND u.$uUID LIKE :$searchParam " . + (empty($uDisabled) ? "" : "AND NOT u.$uDisabled ") . "ORDER BY u.$uUID", Query::FIND_GROUPS => @@ -179,27 +184,32 @@ private function loadQueries() Query::FIND_USER_BY_UID => "SELECT $userColumns " . "FROM $user u " . - "WHERE u.$uUID = :$uidParam", + "WHERE u.$uUID = :$uidParam" . + (empty($uDisabled) ? "" : " AND NOT u.$uDisabled"), Query::FIND_USER_BY_USERNAME => "SELECT $userColumns, u.$uPassword AS password " . "FROM $user u " . - "WHERE u.$uUsername = :$usernameParam", + "WHERE u.$uUsername = :$usernameParam" . + (empty($uDisabled) ? "" : " AND NOT u.$uDisabled"), Query::FIND_USER_BY_USERNAME_CASE_INSENSITIVE => "SELECT $userColumns, u.$uPassword AS password " . "FROM $user u " . - "WHERE lower(u.$uUsername) = lower(:$usernameParam)", + "WHERE lower(u.$uUsername) = lower(:$usernameParam)" . + (empty($uDisabled) ? "" : " AND NOT u.$uDisabled"), Query::FIND_USER_BY_USERNAME_OR_EMAIL => "SELECT $userColumns, u.$uPassword AS password " . "FROM $user u " . - "WHERE u.$uUsername = :$usernameParam OR u.$uEmail = :$emailParam", + "WHERE u.$uUsername = :$usernameParam OR u.$uEmail = :$emailParam" . + (empty($uDisabled) ? "" : " AND NOT u.$uDisabled"), Query::FIND_USER_BY_USERNAME_OR_EMAIL_CASE_INSENSITIVE => "SELECT $userColumns, u.$uPassword AS password " . "FROM $user u " . - "WHERE lower(u.$uUsername) = lower(:$usernameParam) OR lower(u.$uEmail) = lower(:$emailParam)", + "WHERE lower(u.$uUsername) = lower(:$usernameParam) OR lower(u.$uEmail) = lower(:$emailParam)" . + (empty($uDisabled) ? "" : " AND NOT u.$uDisabled"), Query::FIND_USER_GROUPS => "SELECT $groupColumns " . @@ -216,6 +226,7 @@ private function loadQueries() (empty($uName) ? "" : "OR u.$uName LIKE :$searchParam ") . (empty($uEmail) ? "" : "OR u.$uEmail LIKE :$searchParam ") . ")" . + (empty($uDisabled) ? "" : " AND NOT u.$uDisabled ") . "ORDER BY u.$uUID", Query::UPDATE_DISPLAY_NAME =>