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:
@@ -94,44 +94,42 @@ export async function load_ae_obj_li__user({
|
||||
}): Promise<ae_User[]> {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user