-
Notifications
You must be signed in to change notification settings - Fork 0
feat(auth): LogicalModel scope for Method ACL and FieldRule #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
buke
wants to merge
10
commits into
main
Choose a base branch
from
feat/logical-model-acl-field-rule
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2eb050b
feat(auth): add LogicalModel scope for Method ACL and FieldRule
buke 9e269e5
fix(task): harden e2e smoke login against auth init race
buke 7da554f
fix(auth): address LogicalModel ACL review findings
buke 87ab23f
test(auth): bring LogicalModel ACL patch coverage to 100%
buke 53ed309
fix(auth): fail closed when renaming LogicalModel without methods
buke 5cdc04d
fix(auth): allow same LogicalModelName reaffirm without methods
buke 1e4a145
fix(auth): harden bulk LogicalModelName reaffirm checks
buke 8ec8177
test(auth): assert Mode unchanged after rejected bulk logical update
buke 27d3cfb
fix(auth): align bulk LogicalModel reaffirm Count with Update options
buke 75936a8
test(auth): bring RoleMethodAccess LogicalModel patch coverage to 100%
buke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // SPDX-FileCopyrightText: 2026-present Brian Wang <wangbuke@gmail.com> | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /** | ||
| * Auth-side helpers for LogicalModel ACL scope. | ||
| * | ||
| * Short-name eligibility comes from core platform-inject bases via | ||
| * {@link registerLogicalModelName} (not an auth constant list). | ||
| * See `.dev/docs/auth/logical_model_acl_field_rule_design.md` §5. | ||
| */ | ||
|
|
||
| // Ensure platform store bases have self-registered before write validation. | ||
| import '@/core/service/orm/model/app_setting_base_model'; | ||
| import '@/core/service/orm/model/field_default_base_model'; | ||
| import '@/core/service/orm/model/translation_term_base_model'; | ||
| import { | ||
| isRegisteredLogicalModelName, | ||
| listLogicalModelNames, | ||
| listLogicalModelSelection, | ||
| } from '@/core/service/orm/model/logical_model_registry'; | ||
|
|
||
| export { isRegisteredLogicalModelName, listLogicalModelNames, listLogicalModelSelection }; | ||
|
|
||
| /** | ||
| * Normalize a logical model short name for write validation. | ||
| * Empty → null. Non-empty unregistered → throws. | ||
| */ | ||
| export function normalizeLogicalModelName(raw: unknown): string | null { | ||
| if (raw == null) return null; | ||
| const n = String(raw).trim(); | ||
| if (!n) return null; | ||
| if (!isRegisteredLogicalModelName(n)) { | ||
| throw new Error(`invalid LogicalModelName: ${n} is not a registered logical model`); | ||
| } | ||
| return n; | ||
| } | ||
|
|
||
| /** | ||
| * Canonicalize one RPC short name: trim, drop empties, PascalCase first letter. | ||
| * Comparison at eval time is case-insensitive (toLowerCase). | ||
| */ | ||
| export function canonicalizeLogicalMethodName(raw: unknown): string { | ||
| const t = String(raw ?? '').trim(); | ||
| if (!t) return ''; | ||
| return t.charAt(0).toUpperCase() + t.slice(1); | ||
| } | ||
|
|
||
| /** | ||
| * Normalize LogicalMethods JSON payload to string[] | null. | ||
| * null / [] / missing → null (meaning "all methods" at eval time). | ||
| */ | ||
| export function normalizeLogicalMethods(raw: unknown): string[] | null { | ||
| if (raw == null) return null; | ||
| let arr: unknown[] | null = null; | ||
| if (Array.isArray(raw)) { | ||
| arr = raw; | ||
| } else if (typeof raw === 'string') { | ||
| const s = raw.trim(); | ||
| if (!s) return null; | ||
| try { | ||
| const parsed = JSON.parse(s); | ||
| if (Array.isArray(parsed)) arr = parsed; | ||
| else throw new Error('not an array'); | ||
| } catch { | ||
| throw new Error('invalid LogicalMethods: must be a JSON string array'); | ||
| } | ||
| } else { | ||
| throw new Error('invalid LogicalMethods: must be a string array'); | ||
| } | ||
|
|
||
| const out: string[] = []; | ||
| const seen = new Set<string>(); | ||
| for (const item of arr) { | ||
| if (typeof item !== 'string') { | ||
| throw new Error('invalid LogicalMethods: each entry must be a string'); | ||
| } | ||
| const name = canonicalizeLogicalMethodName(item); | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| if (!name) continue; | ||
| const key = name.toLowerCase(); | ||
| if (seen.has(key)) continue; | ||
| seen.add(key); | ||
| out.push(name); | ||
| } | ||
| return out.length === 0 ? null : out; | ||
| } | ||
|
|
||
| /** | ||
| * Whether a LogicalMethods whitelist (null/empty = all) covers `methodName`. | ||
| * Malformed payloads throw; callers that must not abort evaluation should catch. | ||
| */ | ||
| export function logicalMethodsAllow(methods: unknown, methodName: string): boolean { | ||
| const want = String(methodName || '') | ||
| .trim() | ||
| .toLowerCase(); | ||
| if (!want) return false; | ||
| const list = normalizeLogicalMethods(methods); | ||
|
buke marked this conversation as resolved.
|
||
| if (list == null) return true; | ||
| return list.some(m => m.toLowerCase() === want); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.