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.
This commit is contained in:
Scott Idem
2026-01-15 14:58:52 -05:00
parent 227c806318
commit f23b515f11

View File

@@ -94,44 +94,42 @@ export async function load_ae_obj_li__user({
}): Promise<ae_User[]> { }): Promise<ae_User[]> {
let promise; let promise;
// Use search if we have a query string OR if we are filtering by account (to support include_global OR logic) // Use search if we have a query string OR if we are using inclusive global logic
if (qry_str || for_obj_id) { const use_search = qry_str || (for_obj_id && include_global) || (!for_obj_id && include_global);
if (use_search) {
const search_query: any = { and: [] }; const search_query: any = { and: [] };
if (qry_str) { if (qry_str) {
search_query.q = qry_str; search_query.q = qry_str;
} }
// If filtering by account, we might want to include users where account_id is NULL // Handle Account Scoping in Search Query
if (for_obj_id) { if (for_obj_id && include_global) {
if (include_global) { // Case: (Account == current OR Account == null)
search_query.and.push({ search_query.or = [
or: [ {
{ field: `account_id_random`,
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`,
op: 'eq', op: 'eq',
value: for_obj_id value: for_obj_id
}); },
} {
} else if (include_global && !qry_str) { field: `account_id_random`,
// If NO account filter AND include_global is requested explicitly (and no qry_str) op: 'eq',
// we could filter for account_id IS NULL, but usually "all" means everything. value: null
// However, the component sets for_obj_id to null for 'global' scope. }
];
} else if (for_obj_id) {
// Case: (Account == current) - should be handled by List API but search also works
search_query.and.push({ 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', op: 'eq',
value: null value: null
}); });
@@ -149,12 +147,14 @@ export async function load_ae_obj_li__user({
search_query.and.push({ field: 'hide', op: 'eq', value: false }); 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({ promise = api.search_ae_obj_v3({
api_cfg, api_cfg,
obj_type: 'user', obj_type: 'user',
search_query, search_query,
for_obj_type: for_obj_id ? for_obj_type : undefined,
for_obj_id: for_obj_id || undefined,
enabled, enabled,
hidden, hidden,
view, view,
@@ -164,9 +164,16 @@ export async function load_ae_obj_li__user({
log_lvl log_lvl
}); });
} else { } 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({ promise = api.get_ae_obj_li_v3({
api_cfg, api_cfg,
obj_type: 'user', obj_type: 'user',
for_obj_type: for_obj_id ? for_obj_type : undefined,
for_obj_id: for_obj_id || undefined,
enabled, enabled,
hidden, hidden,
view, view,