-
Notifications
You must be signed in to change notification settings - Fork 184
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'); | ||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GavinHemsada the |
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| // 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'); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard against Several callers pass Apply this diff to avoid the crash: - 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');
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Allow creator access based on lifecycle status | ||||||||||||||||||||||||
| if (api.lifeCycleStatus === 'CREATED' || api.lifeCycleStatus === 'PROTOTYPED') { | ||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.