Skip to content
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

fix user id #184

Merged
merged 1 commit into from
Oct 30, 2024
Merged

fix user id #184

merged 1 commit into from
Oct 30, 2024

Conversation

zacharyblasczyk
Copy link
Member

@zacharyblasczyk zacharyblasczyk commented Oct 30, 2024

Summary by CodeRabbit

  • New Features

    • Simplified approval and rejection processes by removing the userId parameter from relevant components and API calls.
    • Enhanced user experience by streamlining the approval dialog and policy approval row components.
  • Bug Fixes

    • Addressed potential runtime errors related to undefined currentUserId in the PolicyApprovalRow component.
  • Documentation

    • Updated method signatures to reflect the removal of the userId parameter in the approval and rejection procedures.

Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Walkthrough

The changes in this pull request involve the removal of the userId parameter from various components and mutation procedures related to approval actions. Specifically, the ApprovalDialog component in FlowPolicyNode.tsx and the PolicyApprovalRow component in PolicyApprovalRow.tsx have been updated to eliminate the userId prop. Additionally, the approve and reject mutation procedures in the environmentRouter have been modified to derive the user ID from the session context instead of requiring it as an input. These changes simplify the function calls and streamline user ID handling.

Changes

File Change Summary
apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/FlowPolicyNode.tsx Removed userId from ApprovalDialog component signature and its usage, updated mutateAsync calls accordingly.
apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/PolicyApprovalRow.tsx Removed definition of currentUserId, modified mutation calls to use currentUserId! directly, risking runtime errors.
packages/api/src/router/environment.ts Removed userId from approve and reject mutation input parameters, now using ctx.session.user.id instead.

Possibly related PRs

  • Fix: Approval Usability #172: The changes in the PolicyApprovalRow.tsx component regarding the handling of the userId in approval and rejection actions are directly related to the modifications made in the main PR, which also involves the removal of the userId prop from the ApprovalDialog component and its usage in related functions.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
packages/api/src/router/environment.ts (2)

173-173: Add session verification.

The change to use ctx.session.user.id improves security by preventing impersonation. However, we should add a null check for the session context.

Consider adding a type guard or assertion:

-  .set({ status: "approved", userId: ctx.session.user.id })
+  .set({ 
+    status: "approved", 
+    userId: ctx.session?.user?.id ?? 
+      (() => { throw new Error("User session required") })()
+  })

233-233: Add session verification (similar to approve mutation).

The change to use ctx.session.user.id is good, but needs the same session verification as the approve mutation.

Apply the same session verification pattern:

-  .set({ status: "rejected", userId: ctx.session.user.id })
+  .set({ 
+    status: "rejected", 
+    userId: ctx.session?.user?.id ?? 
+      (() => { throw new Error("User session required") })()
+  })
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d6f51df and c805a2a.

📒 Files selected for processing (3)
  • apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/FlowPolicyNode.tsx (3 hunks)
  • apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/PolicyApprovalRow.tsx (0 hunks)
  • packages/api/src/router/environment.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/PolicyApprovalRow.tsx
🔇 Additional comments (3)
apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/FlowPolicyNode.tsx (3)

36-36: LGTM: Component signature updated correctly.

The removal of the userId prop aligns with the PR objective to handle user identification through session context instead of prop drilling.


193-193: LGTM: Component usage updated correctly.

The ApprovalDialog is now correctly invoked without the userId prop, maintaining all existing functionality while simplifying the props interface.


54-54: Verify mutation calls are updated consistently.

The mutation calls have been correctly updated to remove the userId parameter. Let's verify that all related mutation definitions are consistent.

Also applies to: 62-62

✅ Verification successful

Mutation calls are consistently updated across the codebase

The verification shows that all mutation calls in the codebase are using the new signature with just releaseId and policyId parameters. The only instances found are in FlowPolicyNode.tsx and they match the expected pattern without userId. No inconsistencies were detected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining approve/reject mutation calls that might still use userId
rg -g '*.{ts,tsx}' 'environment\.policy\.approval\.(approve|reject)\..*mutate.*userId'

Length of output: 88


Script:

#!/bin/bash
# Search for all approve/reject mutation calls in the codebase
rg -g '*.{ts,tsx}' 'policy\.approval\.(approve|reject)\.mutate'

# Search for the mutation definitions in the router
rg -g '*.{ts,tsx}' 'approval.*approve.*=.*publicProcedure|approval.*reject.*=.*publicProcedure'

Length of output: 163


Script:

#!/bin/bash
# Search for any mutation calls with mutateAsync
rg -g '*.{ts,tsx}' '\.mutateAsync.*releaseId.*policyId'

# Search for router definitions related to approval
ast-grep --pattern 'approval: {
  $$$
  approve: $_,
  reject: $_,
  $$$
}'

Length of output: 528

@zacharyblasczyk zacharyblasczyk merged commit 1e661cb into main Oct 30, 2024
6 checks passed
@zacharyblasczyk zacharyblasczyk deleted the zacharyb/user-id-fix branch October 30, 2024 01:53
This was referenced Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants