From 227c806318e4dffd6b64e4dbf7bd21a8d8198a35 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Thu, 15 Jan 2026 14:45:34 -0500 Subject: [PATCH] fix(core): improve User Management filtering and scope support - Updated load_ae_obj_li__user to use search_ae_obj_v3 for complex account OR global filtering. - Fixed zero-results issue by defaulting to 'All' scope (Current Account + Global). - Added visual 'Account' vs 'Global' badges to user cards. - Added 'Scope' selector to User Management page. --- src/lib/ae_core/ae_core__user.ts | 43 +++++++++++++++++++++--- src/routes/core/users/+page.svelte | 53 +++++++++++++++++++++++++----- 2 files changed, 84 insertions(+), 12 deletions(-) diff --git a/src/lib/ae_core/ae_core__user.ts b/src/lib/ae_core/ae_core__user.ts index fb551a3e..57c671c7 100644 --- a/src/lib/ae_core/ae_core__user.ts +++ b/src/lib/ae_core/ae_core__user.ts @@ -60,11 +60,12 @@ export async function load_ae_obj_id__user({ return ae_promises.load__user_obj; } -// Updated 2026-01-06 +// Updated 2026-01-15 export async function load_ae_obj_li__user({ api_cfg, for_obj_type = 'account', for_obj_id = null, + include_global = true, qry_str = null, enabled = 'enabled', hidden = 'not_hidden', @@ -79,6 +80,7 @@ export async function load_ae_obj_li__user({ api_cfg: any; for_obj_type?: string; for_obj_id?: string | null; + include_global?: boolean; qry_str?: string | null; enabled?: 'enabled' | 'all' | 'not_enabled'; hidden?: 'hidden' | 'all' | 'not_hidden'; @@ -92,18 +94,46 @@ 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) { 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`, + 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. search_query.and.push({ - field: `${for_obj_type}_id_random`, + field: `account_id`, op: 'eq', - value: for_obj_id + value: null }); } @@ -123,6 +153,11 @@ export async function load_ae_obj_li__user({ 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, order_by_li, limit, offset, diff --git a/src/routes/core/users/+page.svelte b/src/routes/core/users/+page.svelte index 43cd1e9f..d0d71897 100644 --- a/src/routes/core/users/+page.svelte +++ b/src/routes/core/users/+page.svelte @@ -3,18 +3,31 @@ import { load_ae_obj_li__user, create_ae_obj__user } from '$lib/ae_core/ae_core__user'; import { ae_api, ae_loc } from '$lib/stores/ae_stores'; import { goto } from '$app/navigation'; - import { Plus, Search, User, ShieldCheck, Mail } from 'lucide-svelte'; + import { Plus, Search, User, ShieldCheck, Mail, Globe, Landmark } from 'lucide-svelte'; let user_li: any[] = $state([]); let loading = $state(true); let qry_str = $state(''); let qry_enabled = $state('all'); + let qry_account_scope = $state('all'); // 'all', 'account', 'global' async function load_users() { loading = true; + + let for_obj_id: string | null = $ae_loc.account_id; + let include_global = true; + + if (qry_account_scope === 'account') { + include_global = false; + } else if (qry_account_scope === 'global') { + for_obj_id = null; + include_global = true; // This will trigger the (account_id IS NULL) logic in the search if no qry_str + } + user_li = await load_ae_obj_li__user({ api_cfg: $ae_api, - for_obj_id: $ae_loc.account_id, + for_obj_id: for_obj_id, + include_global: include_global, qry_str: qry_str || null, enabled: qry_enabled as any, log_lvl: 1 @@ -35,9 +48,12 @@ if (!username) return; const email = prompt('Enter email address:'); + // Link to account if scope is 'account' or 'all', otherwise create global user + const account_id = qry_account_scope === 'global' ? undefined : $ae_loc.account_id; + await create_ae_obj__user({ api_cfg: $ae_api, - account_id: $ae_loc.account_id, + account_id: account_id, data_kv: { username, email, enable: true }, log_lvl: 1 }); @@ -65,6 +81,16 @@ + + +