-
Notifications
You must be signed in to change notification settings - Fork 161
fix-publisher routes are not blocked for read only user #1212
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
e164bf7
edfd06d
cff0e9d
68b6de6
a5c6647
c8b51d9
62d9caf
7dae15f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -204,33 +204,43 @@ class AuthManager { | |||||||||||||||||||||||
| * @param {*} api | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| static isRestricted(scopesAllowedToEdit, api = {}) { | ||||||||||||||||||||||||
| const user = AuthManager.getUser(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (!user) { | ||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| // Block read-only users right away | ||||||||||||||||||||||||
| if (AuthManager.isReadOnlyUser()) { | ||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| // determines whether the apiType is API PRODUCT and user has publisher role, then allow access. | ||||||||||||||||||||||||
| if (api.apiType === 'APIPRODUCT') { | ||||||||||||||||||||||||
| if (AuthManager.getUser().scopes.includes('apim:api_publish')) { | ||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| return !user.scopes.includes('apim:api_publish'); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| // If user doesn't have any of the required scopes → restrict | ||||||||||||||||||||||||
| const hasAllowedScope = | ||||||||||||||||||||||||
| scopesAllowedToEdit.some(scope => user.scopes.includes(scope)); | ||||||||||||||||||||||||
| if (!hasAllowedScope) { | ||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| // Check for publisher override (publisher can always access) | ||||||||||||||||||||||||
| const isPublisherOverride = | ||||||||||||||||||||||||
| user.scopes.includes('apim:api_publish') || | ||||||||||||||||||||||||
| (api.apiType === 'MCP' && user.scopes.includes('apim:mcp_server_publish')); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // determines whether the user is a publisher or creator (based on what is passed from the element) | ||||||||||||||||||||||||
| // if (scopesAllowedToEdit.filter(element => AuthManager.getUser().scopes.includes(element)).length > 0) { | ||||||||||||||||||||||||
| if (AuthManager.getUser() | ||||||||||||||||||||||||
| && scopesAllowedToEdit.find((element) => AuthManager.getUser().scopes.includes(element))) { | ||||||||||||||||||||||||
| // if the user has publisher role, no need to consider the api LifeCycleStatus | ||||||||||||||||||||||||
| const isPublisherOverride = AuthManager.getUser().scopes.includes('apim:api_publish') | ||||||||||||||||||||||||
| || (api.apiType === 'MCP' && AuthManager.getUser().scopes.includes('apim:mcp_server_publish')); | ||||||||||||||||||||||||
| if ((Object.keys(api).length === 0 && api.constructor === Object) || isPublisherOverride) { | ||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||
| } else if ( | ||||||||||||||||||||||||
| // if the user has creator role, but not the publisher role | ||||||||||||||||||||||||
| api.lifeCycleStatus === 'CREATED' | ||||||||||||||||||||||||
| || api.lifeCycleStatus === 'PROTOTYPED' | ||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| if (isPublisherOverride) { | ||||||||||||||||||||||||
| return false; // unrestricted | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Handle create-page case (empty api object) | ||||||||||||||||||||||||
| if (Object.keys(api).length === 0 && api.constructor === Object) { | ||||||||||||||||||||||||
| // Only allow users with create permission on create pages | ||||||||||||||||||||||||
| return !user.scopes.includes('apim:api_create'); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| if (Object.keys(api).length === 0 && api.constructor === Object) { | |
| // Only allow users with create permission on create pages | |
| return !user.scopes.includes('apim:api_create'); | |
| } | |
| if ( | |
| !api | |
| || (api.constructor === Object && Object.keys(api).length === 0) | |
| ) { | |
| // Only allow users with create permission on create pages | |
| return !user.scopes.includes('apim:api_create'); | |
| } |
🤖 Prompt for AI Agents
In portals/publisher/src/main/webapp/source/src/app/data/AuthManager.js around
lines 235 to 238, guard against api being null/undefined before calling
Object.keys by short-circuiting when api is falsy; change the condition to first
check if (!api) return <appropriate value> or combine as if (!api ||
(Object.keys(api).length === 0 && api.constructor === Object)) { ... } so you
never call Object.keys on null/undefined and preserve the existing behavior of
only allowing users with 'apim:api_create' on create pages.
Uh oh!
There was an error while loading. Please reload this page.