Changeset 0.37.19 (#232)

Co-authored-by: gobha <jasafpro@gmail.com>
Co-committed-by: gobha <jasafpro@gmail.com>
This commit is contained in:
2026-03-25 00:26:44 +00:00
committed by xcaliber
parent 54ceeb4299
commit be67feaa8e
21 changed files with 173 additions and 88 deletions

View File

@@ -4,7 +4,9 @@
* Reads globals:
* __SECTION__ — active section name (string)
* __BASE__ — base path
* __PAGE_DATA__ — { BYOKEnabled, ... } from Go template
*
* Policy flags (BYOK, personas) come from sw.auth.policies,
* populated at SDK boot via GET /api/v1/profile/permissions.
*
* Layout: topbar + left nav + content area (same CSS classes as before).
* All sections are native Preact components loaded lazily.
@@ -73,21 +75,21 @@ const SECTION_TITLES = {
function SettingsSurface() {
const BASE = window.__BASE__ || '';
const section = window.__SECTION__ || 'general';
const pageData = window.__PAGE_DATA__ || {};
const [byokEnabled, setByokEnabled] = useState(!!pageData.BYOKEnabled);
const [personasEnabled, setPersonasEnabled] = useState(!!pageData.UserPersonasEnabled);
const policies = sw.auth?.policies || {};
const [byokEnabled, setByokEnabled] = useState(policies.allow_user_byok === 'true');
const [personasEnabled, setPersonasEnabled] = useState(policies.allow_user_personas === 'true');
const [SectionComponent, setSectionComponent] = useState(null);
// Fetch policies if not provided by template
// Update when permissions refresh (e.g. after boot or policy change)
useEffect(() => {
if (!pageData.BYOKEnabled || !pageData.UserPersonasEnabled) {
sw.api.admin?.settings?.public?.().then(data => {
const policies = data?.policies || {};
if (policies.allow_user_byok === 'true') setByokEnabled(true);
if (policies.allow_user_personas === 'true') setPersonasEnabled(true);
}).catch(() => {});
function _onPermsChanged() {
const p = sw.auth?.policies || {};
setByokEnabled(p.allow_user_byok === 'true');
setPersonasEnabled(p.allow_user_personas === 'true');
}
sw.on('auth.permissions.changed', _onPermsChanged);
return () => sw.off('auth.permissions.changed', _onPermsChanged);
}, []);
// Load the section component