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;
|
return ae_promises.load__user_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updated 2026-01-06
|
// Updated 2026-01-15
|
||||||
export async function load_ae_obj_li__user({
|
export async function load_ae_obj_li__user({
|
||||||
api_cfg,
|
api_cfg,
|
||||||
for_obj_type = 'account',
|
for_obj_type = 'account',
|
||||||
for_obj_id = null,
|
for_obj_id = null,
|
||||||
|
include_global = true,
|
||||||
qry_str = null,
|
qry_str = null,
|
||||||
enabled = 'enabled',
|
enabled = 'enabled',
|
||||||
hidden = 'not_hidden',
|
hidden = 'not_hidden',
|
||||||
@@ -79,6 +80,7 @@ export async function load_ae_obj_li__user({
|
|||||||
api_cfg: any;
|
api_cfg: any;
|
||||||
for_obj_type?: string;
|
for_obj_type?: string;
|
||||||
for_obj_id?: string | null;
|
for_obj_id?: string | null;
|
||||||
|
include_global?: boolean;
|
||||||
qry_str?: string | null;
|
qry_str?: string | null;
|
||||||
enabled?: 'enabled' | 'all' | 'not_enabled';
|
enabled?: 'enabled' | 'all' | 'not_enabled';
|
||||||
hidden?: 'hidden' | 'all' | 'not_hidden';
|
hidden?: 'hidden' | 'all' | 'not_hidden';
|
||||||
@@ -92,18 +94,46 @@ 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)
|
||||||
if (qry_str || for_obj_id) {
|
if (qry_str || for_obj_id) {
|
||||||
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
|
||||||
if (for_obj_id) {
|
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({
|
search_query.and.push({
|
||||||
field: `${for_obj_type}_id_random`,
|
field: `account_id`,
|
||||||
op: 'eq',
|
op: 'eq',
|
||||||
value: for_obj_id
|
value: null
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,6 +153,11 @@ export async function load_ae_obj_li__user({
|
|||||||
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,
|
||||||
|
hidden,
|
||||||
|
view,
|
||||||
order_by_li,
|
order_by_li,
|
||||||
limit,
|
limit,
|
||||||
offset,
|
offset,
|
||||||
|
|||||||
@@ -3,18 +3,31 @@
|
|||||||
import { load_ae_obj_li__user, create_ae_obj__user } from '$lib/ae_core/ae_core__user';
|
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 { ae_api, ae_loc } from '$lib/stores/ae_stores';
|
||||||
import { goto } from '$app/navigation';
|
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 user_li: any[] = $state([]);
|
||||||
let loading = $state(true);
|
let loading = $state(true);
|
||||||
let qry_str = $state('');
|
let qry_str = $state('');
|
||||||
let qry_enabled = $state('all');
|
let qry_enabled = $state('all');
|
||||||
|
let qry_account_scope = $state('all'); // 'all', 'account', 'global'
|
||||||
|
|
||||||
async function load_users() {
|
async function load_users() {
|
||||||
loading = true;
|
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({
|
user_li = await load_ae_obj_li__user({
|
||||||
api_cfg: $ae_api,
|
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,
|
qry_str: qry_str || null,
|
||||||
enabled: qry_enabled as any,
|
enabled: qry_enabled as any,
|
||||||
log_lvl: 1
|
log_lvl: 1
|
||||||
@@ -35,9 +48,12 @@
|
|||||||
if (!username) return;
|
if (!username) return;
|
||||||
const email = prompt('Enter email address:');
|
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({
|
await create_ae_obj__user({
|
||||||
api_cfg: $ae_api,
|
api_cfg: $ae_api,
|
||||||
account_id: $ae_loc.account_id,
|
account_id: account_id,
|
||||||
data_kv: { username, email, enable: true },
|
data_kv: { username, email, enable: true },
|
||||||
log_lvl: 1
|
log_lvl: 1
|
||||||
});
|
});
|
||||||
@@ -65,6 +81,16 @@
|
|||||||
<button class="variant-filled-secondary" onclick={load_users}>Go</button>
|
<button class="variant-filled-secondary" onclick={load_users}>Go</button>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</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">
|
<label class="label">
|
||||||
<span>Status</span>
|
<span>Status</span>
|
||||||
<select class="select w-32" bind:value={qry_enabled} onchange={load_users}>
|
<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>
|
<p class="text-xs opacity-60">{user.name || '--'}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{#if user.super}
|
<div class="flex flex-col items-end gap-1">
|
||||||
<span class="badge variant-filled-error">Super</span>
|
{#if user.super}
|
||||||
{:else if user.manager}
|
<span class="badge variant-filled-error">Super</span>
|
||||||
<span class="badge variant-filled-warning">Manager</span>
|
{:else if user.manager}
|
||||||
{/if}
|
<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>
|
</header>
|
||||||
<div class="flex items-center gap-2 text-sm opacity-80">
|
<div class="flex items-center gap-2 text-sm opacity-80">
|
||||||
<Mail size={14} />
|
<Mail size={14} />
|
||||||
|
|||||||
Reference in New Issue
Block a user