Making the Debug Menu not always shown as easily.
This commit is contained in:
56
src/lib/ae_utils/perm_checks.test.ts
Normal file
56
src/lib/ae_utils/perm_checks.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { compare_access_levels, process_permission_checks, access_level_order } from './ae_utils__perm_checks';
|
||||
|
||||
describe('Permission Hierarchy Tests', () => {
|
||||
describe('compare_access_levels', () => {
|
||||
it('should correctly identify upgrades', () => {
|
||||
// High to Low should return 1 (Upgrade if target is high, current is low)
|
||||
expect(compare_access_levels('super', 'manager')).toBe(1);
|
||||
expect(compare_access_levels('manager', 'administrator')).toBe(1);
|
||||
expect(compare_access_levels('administrator', 'trusted')).toBe(1);
|
||||
expect(compare_access_levels('trusted', 'authenticated')).toBe(1);
|
||||
expect(compare_access_levels('authenticated', 'anonymous')).toBe(1);
|
||||
});
|
||||
|
||||
it('should correctly identify downgrades', () => {
|
||||
// Low to High should return -1
|
||||
expect(compare_access_levels('manager', 'super')).toBe(-1);
|
||||
expect(compare_access_levels('anonymous', 'authenticated')).toBe(-1);
|
||||
});
|
||||
|
||||
it('should return 0 for equal levels', () => {
|
||||
expect(compare_access_levels('manager', 'manager')).toBe(0);
|
||||
expect(compare_access_levels('anonymous', 'anonymous')).toBe(0);
|
||||
});
|
||||
|
||||
it('should handle null/empty as anonymous', () => {
|
||||
expect(compare_access_levels('trusted', '')).toBe(1);
|
||||
expect(compare_access_levels(null as any, 'authenticated')).toBe(-1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('process_permission_checks hierarchy', () => {
|
||||
it('manager should imply administrator and trusted', () => {
|
||||
const perms = process_permission_checks('manager');
|
||||
expect(perms.manager_access).toBe(true);
|
||||
expect(perms.administrator_access).toBe(true);
|
||||
expect(perms.trusted_access).toBe(true);
|
||||
expect(perms.authenticated_access).toBe(true);
|
||||
expect(perms.super_access).toBe(false);
|
||||
});
|
||||
|
||||
it('administrator should imply trusted', () => {
|
||||
const perms = process_permission_checks('administrator');
|
||||
expect(perms.administrator_access).toBe(true);
|
||||
expect(perms.trusted_access).toBe(true);
|
||||
expect(perms.manager_access).toBe(false);
|
||||
});
|
||||
|
||||
it('anonymous should imply nothing but anonymous_access', () => {
|
||||
const perms = process_permission_checks('anonymous');
|
||||
expect(perms.anonymous_access).toBe(true);
|
||||
expect(perms.authenticated_access).toBe(false);
|
||||
expect(perms.trusted_access).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -257,5 +257,9 @@
|
||||
|
||||
{#if browser && (!$ae_loc?.iframe || $ae_loc?.trusted_access)}
|
||||
<E_app_sys_menu {data} bind:hide={$ae_loc.sys_menu.hide} bind:expand={$ae_sess.sys_menu.expand} />
|
||||
<E_app_debug_menu bind:hide={$ae_loc.debug_menu.hide} bind:expand={$ae_loc.debug_menu.expand} />
|
||||
|
||||
<!-- You must be in Edit Mode to initially see the Debug expand button. Once expanded, you can toggle the Edit Mode while still seeing the expanded Debug content. -->
|
||||
{#if $ae_loc.edit_mode || $ae_loc.debug_menu.expand}
|
||||
<E_app_debug_menu bind:hide={$ae_loc.debug_menu.hide} bind:expand={$ae_loc.debug_menu.expand} />
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
64
src/routes/journals/journal_entry_visibility.test.ts
Normal file
64
src/routes/journals/journal_entry_visibility.test.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
// Simulating the filter logic from ae_comp__journal_entry_obj_li.svelte
|
||||
function filterEntries(list: any[], ae_loc: any) {
|
||||
if (!list) return null;
|
||||
return list.filter((item: any) => {
|
||||
if (!item) return false;
|
||||
|
||||
const is_hidden = item.hide === true || item.hide === 1;
|
||||
const is_disabled = item.enable === false || item.enable === 0;
|
||||
|
||||
// Standard Visibility: Filter out hidden/disabled if not in Edit Mode
|
||||
if (!ae_loc.edit_mode) {
|
||||
return !is_hidden && !is_disabled;
|
||||
}
|
||||
|
||||
// Edit Mode Gating:
|
||||
// - To see Hidden: Must have Trusted Access or higher
|
||||
if (is_hidden && !ae_loc.trusted_access) return false;
|
||||
|
||||
// - To see Disabled: Must have Administrator Access or higher
|
||||
if (is_disabled && !ae_loc.administrator_access) return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
describe('Journal Entry Visibility Filtering', () => {
|
||||
const mockEntries = [
|
||||
{ id: '1', name: 'Normal Entry', hide: false, enable: true },
|
||||
{ id: '2', name: 'Hidden Entry', hide: true, enable: true },
|
||||
{ id: '3', name: 'Disabled Entry', hide: false, enable: false },
|
||||
{ id: '4', name: 'Hidden & Disabled', hide: true, enable: false },
|
||||
];
|
||||
|
||||
it('should show only normal entries when Edit Mode is OFF (Manager)', () => {
|
||||
const ae_loc = { edit_mode: false, trusted_access: true, administrator_access: true };
|
||||
const result = filterEntries(mockEntries, ae_loc);
|
||||
expect(result?.length).toBe(1);
|
||||
expect(result?.[0].id).toBe('1');
|
||||
});
|
||||
|
||||
it('should show hidden entries to Trusted users when Edit Mode is ON', () => {
|
||||
const ae_loc = { edit_mode: true, trusted_access: true, administrator_access: false };
|
||||
const result = filterEntries(mockEntries, ae_loc);
|
||||
// Should see Normal (1) and Hidden (2). Should NOT see Disabled (3, 4)
|
||||
expect(result?.length).toBe(2);
|
||||
expect(result?.map(r => r.id)).toContain('1');
|
||||
expect(result?.map(r => r.id)).toContain('2');
|
||||
});
|
||||
|
||||
it('should show everything to Administrators when Edit Mode is ON', () => {
|
||||
const ae_loc = { edit_mode: true, trusted_access: true, administrator_access: true };
|
||||
const result = filterEntries(mockEntries, ae_loc);
|
||||
expect(result?.length).toBe(4);
|
||||
});
|
||||
|
||||
it('should hide everything sensitive to Public users even if Edit Mode is ON (Safety Check)', () => {
|
||||
const ae_loc = { edit_mode: true, trusted_access: false, administrator_access: false };
|
||||
const result = filterEntries(mockEntries, ae_loc);
|
||||
expect(result?.length).toBe(1);
|
||||
expect(result?.[0].id).toBe('1');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user