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:
@@ -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