Skip to content

Commit 1b82b64

Browse files
xuyushun441-sysos-zhuangclaude
authored
feat(auth): expose isPlatformAdmin on the customSession user (#1859)
* feat(auth): expose isPlatformAdmin on the customSession user The session payload already derives an `admin` role when the user is a platform admin or active-org admin, but it never surfaces the underlying platform-admin boolean. Console action `visible` CEL predicates need to distinguish platform-admin-only actions (e.g. sys_environment.change_plan) from org-admin actions, which a coarse `admin` role cannot do. Capture the platform-admin check once and attach `isPlatformAdmin` to both customSession return paths. Org-admins who are not platform admins get `isPlatformAdmin: false` (correct — those actions are platform-admin-only). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore(changeset): plugin-auth isPlatformAdmin session field Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Jack Zhuang <277994282+os-zhuang@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent f3d1069 commit 1b82b64

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@objectstack/plugin-auth": patch
3+
---
4+
5+
auth: expose `isPlatformAdmin` on the customSession user payload
6+
7+
The session already derives a coarse `admin` role for platform admins or
8+
active-org admins, but never surfaced the underlying platform-admin signal.
9+
Console action `visible` CEL predicates need it to gate platform-admin-only
10+
object actions (e.g. `sys_environment.change_plan`) without hiding org-admin
11+
actions. Both `customSession` return paths now carry the boolean; org-admins
12+
who are not platform admins correctly get `isPlatformAdmin: false`.

packages/plugins/plugin-auth/src/auth-manager.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,15 +1021,16 @@ export class AuthManager {
10211021
}
10221022
};
10231023

1024-
const promote = (await isPlatformAdmin()) || (await isActiveOrgAdmin());
1024+
const platformAdmin = await isPlatformAdmin();
1025+
const promote = platformAdmin || (await isActiveOrgAdmin());
10251026
const storedRole = typeof (user as any).role === 'string' ? (user as any).role : '';
10261027
const roles = storedRole
10271028
.split(',')
10281029
.map((s: string) => s.trim())
10291030
.filter(Boolean);
10301031
if (promote && !roles.includes('admin')) roles.push('admin');
1031-
if (!promote) return { user: { ...user, roles }, session };
1032-
return { user: { ...user, role: 'admin', roles }, session };
1032+
if (!promote) return { user: { ...user, roles, isPlatformAdmin: platformAdmin }, session };
1033+
return { user: { ...user, role: 'admin', roles, isPlatformAdmin: platformAdmin }, session };
10331034
}));
10341035
}
10351036

0 commit comments

Comments
 (0)