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.
This commit is contained in:
@@ -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<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) {
|
||||
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,
|
||||
|
||||
@@ -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 @@
|
||||
<button class="variant-filled-secondary" onclick={load_users}>Go</button>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label class="label">
|
||||
<span>Scope</span>
|
||||
<select class="select w-48" bind:value={qry_account_scope} onchange={load_users}>
|
||||
<option value="all">All (Current + Global)</option>
|
||||
<option value="account">Current Account Only</option>
|
||||
<option value="global">Global Only (No Account)</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<label class="label">
|
||||
<span>Status</span>
|
||||
<select class="select w-32" bind:value={qry_enabled} onchange={load_users}>
|
||||
@@ -94,11 +120,22 @@
|
||||
<p class="text-xs opacity-60">{user.name || '--'}</p>
|
||||
</div>
|
||||
</div>
|
||||
{#if user.super}
|
||||
<span class="badge variant-filled-error">Super</span>
|
||||
{:else if user.manager}
|
||||
<span class="badge variant-filled-warning">Manager</span>
|
||||
{/if}
|
||||
<div class="flex flex-col items-end gap-1">
|
||||
{#if user.super}
|
||||
<span class="badge variant-filled-error">Super</span>
|
||||
{:else if user.manager}
|
||||
<span class="badge variant-filled-warning">Manager</span>
|
||||
{/if}
|
||||
{#if !user.account_id && !user.account_id_random}
|
||||
<span class="badge variant-soft-secondary flex items-center gap-1">
|
||||
<Globe size={10} /> Global
|
||||
</span>
|
||||
{:else}
|
||||
<span class="badge variant-soft-primary flex items-center gap-1">
|
||||
<Landmark size={10} /> Account
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</header>
|
||||
<div class="flex items-center gap-2 text-sm opacity-80">
|
||||
<Mail size={14} />
|
||||
|
||||
Reference in New Issue
Block a user