Skip to content

feat(users): custom role at profile read#6875

Merged
Gnanasundari24 merged 48 commits intomainfrom
custom-role-at-profile-read
Feb 5, 2025
Merged

feat(users): custom role at profile read#6875
Gnanasundari24 merged 48 commits intomainfrom
custom-role-at-profile-read

Conversation

@Riddhiagrawal001
Copy link
Contributor

@Riddhiagrawal001 Riddhiagrawal001 commented Dec 18, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

This pr adds the functionality to read custom role at profile level

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

Closes #6488

How did you test it?

  1. Create custom role at profile-level
    Request
curl --location 'http://localhost:9000/api/user/role' \
--header 'authorization: Bearer JWT' \
--data '{
    "role_scope": "merchant",
    "groups": [
        "operations_manage",
        "connectors_view"
    ],
    "role_name": "profile-level-custom-role",
    "entity_type":"profile"
}'

Response

{
    "error": {
        "type": "invalid_request",
        "message": "User Role Operation Not Supported",
        "code": "UR_23"
    }
}
  1. Older flows should work as before . Changes for create profile custom roles will be in consecutive pr
  2. Validate custom role
    If a role with the same name is created either below me or in my lineage , then i wouldn't be able to create the role with that same name
    Request
curl 'http://localhost:9000/api/user/role' \
  -H 'Accept: */*' \
  -H 'authorization: Bearer JWT' \
  --data-raw '{"role_scope":"merchant","groups":["operations_view","operations_manage"],"role_name":"m2-org"}'

Response

{
    "error": {
        "type": "invalid_request",
        "message": "Role name already exists",
        "code": "UR_35"
    }
}

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

Riddhiagrawal001 and others added 24 commits November 28, 2024 15:44
@Riddhiagrawal001 Riddhiagrawal001 requested review from a team as code owners December 18, 2024 07:41
@semanticdiff-com
Copy link

semanticdiff-com bot commented Dec 18, 2024

@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Dec 18, 2024
Comment on lines +175 to +176
.filter(dsl::tenant_id.eq(tenant_id))
.filter(dsl::org_id.eq(org_id))
Copy link
Contributor

Choose a reason for hiding this comment

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

take these filter out of the match statement. dry!

Comment on lines +83 to +89
Profile(
id_type::OrganizationId,
id_type::MerchantId,
id_type::ProfileId,
),
Merchant(id_type::OrganizationId, id_type::MerchantId),
Organization(id_type::OrganizationId),
Copy link
Contributor

Choose a reason for hiding this comment

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

can organisation_id be passed as a function argument instead of inside the enum.

@ThisIsMani ThisIsMani added the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Feb 3, 2025
}
let (org_id, merchant_id, profile_id) = match role_entity_type {
EntityType::Organization | EntityType::Tenant => {
(user_from_token.org_id, user_from_token.merchant_id, None)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably throw error here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will take this up in the next PR

@Riddhiagrawal001 Riddhiagrawal001 removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Feb 5, 2025
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Feb 5, 2025
Merged via the queue into main with commit 899c207 Feb 5, 2025
17 of 20 checks passed
@Gnanasundari24 Gnanasundari24 deleted the custom-role-at-profile-read branch February 5, 2025 14:28
Narayanbhat166 pushed a commit that referenced this pull request Feb 6, 2025
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Gnanasundari24 <118818938+Gnanasundari24@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

M-database-changes Metadata: This PR involves database schema changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(users): Add profile level custom role

7 participants