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_4 (already cloned)
- Base commit: bca8979a0cd25472b2f9b5e9d9daf7509a7b3cbb
- Task ID: juspay__hyperswitch-7878
- Version: v1.113.0
TASK DESCRIPTION: Bug: Add support to create profile level custom role
Closes issue : https://github.com/juspay/hyperswitch/issues/7740
DETAILED CONTEXT & HINTS:
Type of Change
- Bugfix
- New feature
- Enhancement
- Refactoring
- Dependency updates
- Documentation
- CI/CD
Description
This pr will enable profile level custom creation from API and also enable org level custom role read
Additional Changes
- This PR modifies the API contract
- This PR modifies the database schema
- This PR modifies application configuration/environment variables
Motivation and Context
How did you test it?
1 . Valid operation Request :
curl --location 'http://localhost:8080/user/role' \ --header 'authorization: Bearer JWT' \ --header 'cookie: login_token=JWT' \ --data '{ "role_scope": "profile", "entity_type": "profile", "groups": [ "operations_view", "operations_manage" ], "role_name": "profile-role-at-profile-scope" }'Response
{ "role_id": "role_vcPMQVtjv0jblNi1tOxB", "groups": [ "operations_view", "operations_manage" ], "role_name": "profile-role-at-profile-scope", "role_scope": "profile", "entity_type": "profile" }- Invalid operation Request
Assistant
I'll help you implement the feature to add support for creating profile-level custom roles in the hyperswitch repository. Let me start by examining the repository structure and understanding the current role management implementation.
First, let me create a plan of action based on the requirements:
Assistant
Let me first explore the repository structure to understand where role-related code might be located:
Assistant
(no content)
Assistant
Now let me look at the specific files related to role creation and the API endpoint mentioned in the issue:
Assistant
Let me examine the role creation API endpoint and the associated models:
Assistant
Let me now examine the API models for role creation:
Assistant
Now let me check the core role creation implementation:
Assistant
I can see the issue! In lines 83-86 of the
create_rolefunction, there's explicit logic preventing profile-level custom roles from being created:// TODO: Remove in PR custom-role-write-pr if matches!(role_entity_type, EntityType::Profile) { return Err(report!(UserErrors::InvalidRoleOperation)) .attach_printable("User trying to create profile level custom role"); }Now let me check what the error enum looks like and what the validation logic does:
Assistant
(no content)
Assistant
Perfect! Now I understand the current implementation. I need to make two changes to support profile-level custom role creation:
- Remove the restriction that prevents profile-level custom role creation (lines 83-86 in create_role)
- Add validation to ensure that when role_scope is "profile", the entity_type must also be "profile"
Let me also check the Entity Type and Role Scope enums to make sure I understand the expected values:
Assistant
(no content)
Assistant
Let me search more specifically for EntityType and RoleScope definitions:
Assistant
Let me use a broader search approach to find the enum definitions:
Assistant
Now let me examine these enums:
Assistant
(no content)
Assistant
Perfect! Now I have a clear understanding. Based on the issue description and the code analysis, I need to:
- Remove the restriction preventing profile-level custom role creation
- Add validation to ensure that when
role_scopeis "profile", theentity_typemust also be "profile"
Let me now update the implementation:
Assistant
Now I'll modify the create_role function to remove the restriction on profile-level custom role creation and add the proper validation:
Assistant
Let me first read the file to make sure I understand its structure correctly before making changes:
Assistant
Now I'll make the edit to remove the restriction on profile-level custom roles and add the proper validation:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.