From f23b515f1151fa98b3ec09d9771236f232150b60 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Thu, 15 Jan 2026 14:58:52 -0500 Subject: [PATCH] fix(core): resolve zero-results and incorrect scoping in User Management - Refined load_ae_obj_li__user to use List API for simple account filtering and Search API for complex cases. - Fixed 'Global Only' scope returning all users by ensuring correct NULL filtering. - Improved search query structure with top-level 'or' for inclusive global support. - Added detailed logging to load_ae_obj_li__user for easier debugging. --- src/lib/ae_core/ae_core__user.ts | 69 ++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/src/lib/ae_core/ae_core__user.ts b/src/lib/ae_core/ae_core__user.ts index 57c671c7..1839bd9c 100644 --- a/src/lib/ae_core/ae_core__user.ts +++ b/src/lib/ae_core/ae_core__user.ts @@ -94,44 +94,42 @@ export async function load_ae_obj_li__user({ }): Promise { let promise; - // Use search if we have a query string OR if we are filtering by account (to support include_global OR logic) - if (qry_str || for_obj_id) { + // Use search if we have a query string OR if we are using inclusive global logic + const use_search = qry_str || (for_obj_id && include_global) || (!for_obj_id && include_global); + + if (use_search) { const search_query: any = { and: [] }; if (qry_str) { search_query.q = qry_str; } - // If filtering by account, we might want to include users where account_id is NULL - if (for_obj_id) { - if (include_global) { - search_query.and.push({ - or: [ - { - field: `${for_obj_type}_id_random`, - op: 'eq', - value: for_obj_id - }, - { - field: `account_id`, // Try direct field name if random doesn't work on backend for user - op: 'eq', - value: null - } - ] - }); - } else { - search_query.and.push({ - field: `${for_obj_type}_id_random`, + // Handle Account Scoping in Search Query + if (for_obj_id && include_global) { + // Case: (Account == current OR Account == null) + search_query.or = [ + { + field: `account_id_random`, op: 'eq', value: for_obj_id - }); - } - } else if (include_global && !qry_str) { - // If NO account filter AND include_global is requested explicitly (and no qry_str) - // we could filter for account_id IS NULL, but usually "all" means everything. - // However, the component sets for_obj_id to null for 'global' scope. + }, + { + field: `account_id_random`, + op: 'eq', + value: null + } + ]; + } else if (for_obj_id) { + // Case: (Account == current) - should be handled by List API but search also works search_query.and.push({ - field: `account_id`, + field: `account_id_random`, + op: 'eq', + value: for_obj_id + }); + } else if (include_global) { + // Case: (Account == null) - Global Only + search_query.and.push({ + field: `account_id_random`, op: 'eq', value: null }); @@ -149,12 +147,14 @@ export async function load_ae_obj_li__user({ search_query.and.push({ field: 'hide', op: 'eq', value: false }); } + if (log_lvl) { + console.log(`load_ae_obj_li__user() - Using Search API`, search_query); + } + promise = api.search_ae_obj_v3({ api_cfg, obj_type: 'user', search_query, - for_obj_type: for_obj_id ? for_obj_type : undefined, - for_obj_id: for_obj_id || undefined, enabled, hidden, view, @@ -164,9 +164,16 @@ export async function load_ae_obj_li__user({ log_lvl }); } else { + // Simple case: Standard List API (Account Only or No Filter) + if (log_lvl) { + console.log(`load_ae_obj_li__user() - Using List API (for_obj_id=${for_obj_id})`); + } + promise = api.get_ae_obj_li_v3({ api_cfg, obj_type: 'user', + for_obj_type: for_obj_id ? for_obj_type : undefined, + for_obj_id: for_obj_id || undefined, enabled, hidden, view,