You are working on the hyperswitch repository (Rust payment processing system).…
- User
You are working on the hyperswitch repository (Rust payment processing system).
REPOSITORY SETUP:
- Repository: juspay/hyperswitch
- Working directory: ./repos/hyperswitch_pool_6 (already cloned)
- Base commit: 99885b699d7524e87697f78608e6f2b36c9d8a8e
- Task ID: juspay__hyperswitch-8601
- Version: v1.115.0
TASK DESCRIPTION: Bug: Deleting a user role and again assigning a role to user is not updating its previous role to new role
Role id is not getting updated in the invited user account in case the role is deleted and assigned again to invited user. This is happening due to the lineage context stored in db not updating the role id in case that role id does not exist any more.
Steps to duplicate this edge case:
- Invite a user with any user role
- Accept the invitation and login to invited user account
- Delete the user role from the account who invited the user
- Assign a user role, then try to login to the invited account
- Invited account still operates on the previous user role because of the lineage context getting stored in db
DETAILED CONTEXT & HINTS:
Type of Change
- Bugfix
- New feature
- Enhancement
- Refactoring
- Dependency updates
- Documentation
- CI/CD
Description
This PR fixes an issue where a stale
role_idfrom the cachedlineage_contextwas being used to generate the JWT token during sign-in, even if the actual user role was modified (e.g., role deleted and recreated with a differentrole_idbut same lineage).Previously, we only validated if a user role existed for the lineage (
user_id,tenant_id,org_id,merchant_id,profile_id), but did not verify that therole_idmatched the current assigned role. This led to JWTs being issued with outdatedrole_idvalues.Changes Made
- During sign-in, added a strict match check for in the fetched user role.
Assistant
I'll tackle this bug where deleting and reassigning a user role doesn't properly update the lineage context in the hyperswitch repository. Let me start by exploring the codebase to understand how user roles and lineage context are handled.
First, let me create a plan for this task:
Assistant
Let me search for files related to user roles, lineage context, and sign-in functionality to understand how this is implemented:
Assistant
(no content)
Assistant
(no content)
Assistant
Let me look for files related to user authentication and sign-in functionality:
Assistant
Now let me examine the key files that seem most relevant - the user core module and the user role implementation:
Assistant
Let me search more specifically for the JWT token generation and sign-in flow:
Assistant
Let me look at the JWT service and authentication files specifically:
Assistant
(no content)
Assistant
Let me focus on the user role and lineage context files that I found earlier:
Assistant
(no content)
Assistant
(no content)
Assistant
Now let me examine the types for the LineageContext:
Assistant
(no content)
Assistant
(no content)
Assistant
Let me look more specifically at the user role and authentication implementation to understand the flow better:
Assistant
Let me examine the diesel models to understand the structure better:
Assistant
Now let me check for the specific authentication/sign-in logic by looking at the routes or services:
Assistant
Now I need to look at the user_core module where the actual sign-in logic seems to be:
Assistant
Let me search for the NextFlow and get_token methods which are likely involved in sign-in:
Assistant
(no content)
Assistant
Let me check where domain modules are defined in the workspace:
Assistant
Let me check the user domain file which likely contains NextFlow:
Assistant
Let me check the authentication code more thoroughly to understand how tokens are generated:
Assistant
Let me now look at how the
from_originandget_tokenmethods work by checking the authentication service:Assistant
Let me look at a more specific area around the authentication flow, especially focusing on the lineage context usage:
Assistant
Let me now check how the lineage context gets used in JWT token generation by looking at the actual implementation in the user flow that generates the tokens:
Assistant
Let me find how
NextFlowand theget_tokenmethod are implemented by searching for it:Assistant
Based on the context and my exploration of the codebase, I can now clearly see the issue. The bug is that when a user signs in with a cached lineage context, the system doesn't validate whether the role_id in that cached context still exists in the database.
Looking at the task description, I can see that:
- The issue is in the user role management where deleting a role and reassigning it causes problems
- The lineage context in the database stores a role_id but doesn't validate if that role still exists
- When a user logs in, it uses the cached lineage context role_id without verifying if the role still exists
Let me now examine where the issue is located and implement the fix.
Let me examine the specific function that handles sign-in and token generation:
Assistant
Let me now actually search for the specific issue. Looking at the bug description, the issue is with lineage context validation during sign-in. Let me check for the actual
get_tokenfunction that's being called from theNextFlow:Assistant
Let me approach this differently. I'll look directly at the sign-in flow in the core/user.rs file to understand how tokens are generated:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.