fix: auth inconcistency around API keys & manager role#7634
fix: auth inconcistency around API keys & manager role#7634
Conversation
|
Caution Review failedAn error occurred during the review process. Please try again later. WalkthroughThe pull request extends API key management capabilities to users with manager roles. In the navigation component, 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/web/modules/organization/settings/api-keys/actions.ts (1)
23-32: 🧹 Nitpick | 🔵 TrivialExtract repeated org-role access config to a shared constant.
The same access block is duplicated three times. Centralizing it reduces auth drift risk.
♻️ Proposed refactor
const ZDeleteApiKeyAction = z.object({ id: ZId, }); +const OWNER_MANAGER_ORG_ACCESS = [ + { + type: "organization" as const, + roles: ["owner", "manager"] as const, + }, +]; + export const deleteApiKeyAction = authenticatedActionClient.inputSchema(ZDeleteApiKeyAction).action( withAuditLogging("deleted", "apiKey", async ({ ctx, parsedInput }) => { const organizationId = await getOrganizationIdFromApiKeyId(parsedInput.id); await checkAuthorizationUpdated({ userId: ctx.user.id, organizationId, - access: [ - { - type: "organization", - roles: ["owner", "manager"], - }, - ], + access: OWNER_MANAGER_ORG_ACCESS, }); @@ await checkAuthorizationUpdated({ userId: ctx.user.id, organizationId: parsedInput.organizationId, - access: [ - { - type: "organization", - roles: ["owner", "manager"], - }, - ], + access: OWNER_MANAGER_ORG_ACCESS, }); @@ await checkAuthorizationUpdated({ userId: ctx.user.id, organizationId, - access: [ - { - type: "organization", - roles: ["owner", "manager"], - }, - ], + access: OWNER_MANAGER_ORG_ACCESS, });As per coding guidelines "Keep code DRY (Don't Repeat Yourself) and small; remove dead code and unused imports".
Also applies to: 50-59, 78-87
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/web/modules/organization/settings/api-keys/actions.ts` around lines 23 - 32, Extract the repeated access block into a shared constant (e.g., ORG_OWNER_MANAGER_ACCESS) and replace the three inline usages passed to checkAuthorizationUpdated(...) with that constant; locate the occurrences where checkAuthorizationUpdated is called (the calls that pass access: [{ type: "organization", roles: ["owner","manager"] }]) and import/define the constant adjacent to the module-level scope so all calls use the same reference to avoid duplication and future drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@apps/web/modules/organization/settings/api-keys/actions.ts`:
- Around line 23-32: Extract the repeated access block into a shared constant
(e.g., ORG_OWNER_MANAGER_ACCESS) and replace the three inline usages passed to
checkAuthorizationUpdated(...) with that constant; locate the occurrences where
checkAuthorizationUpdated is called (the calls that pass access: [{ type:
"organization", roles: ["owner","manager"] }]) and import/define the constant
adjacent to the module-level scope so all calls use the same reference to avoid
duplication and future drift.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 303e15a1-3af7-4a22-baf9-2983018cd9ee
📒 Files selected for processing (2)
apps/web/app/(app)/environments/[environmentId]/settings/(organization)/components/OrganizationSettingsNavbar.tsxapps/web/modules/organization/settings/api-keys/actions.ts
mattinannt
left a comment
There was a problem hiding this comment.
Looks good; thank you for the fix :-)
…fix/managers-to-create-api-keys
|
These changes were already added in #7635 |
|



Lets managers create API keys