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

feat(users): handle edge features for users in tenancy #6990

Merged
merged 9 commits into from
Jan 8, 2025

Conversation

apoorvdixit88
Copy link
Contributor

@apoorvdixit88 apoorvdixit88 commented Jan 5, 2025

Type of Change

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

Description

This PR

  • add tenant_id in roles table
  • add support for genenric query to serach user across all tenancies
  • Fixes custom roles creates by tenant_level user
  • List view for tenant level user
  • Fix bug to search across envs for tenant admin

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 #6999

How did you test it?

Tenant admin able to create custom org level role

curl --location 'http://localhost:8080/user/role' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer JWT' \
--data '{
  "role_name": "custom_role_7",
  "groups": ["users_view"],
  "role_scope": "organization"
}'

Response

{
    "role_id": "role_KQxGGeCs6usRwxubnU2Y",
    "groups": [
        "users_view"
    ],
    "role_name": "custom_role_7",
    "role_scope": "organization"
}

For tenant level user, list api is showing that user in list, if we don't pass query, its coming with remaning org users

curl --location 'http://localhost:8080/user/user/list?entity_type=tenant' \
--header 'x-tenant-id: test' \
--header 'Authorization: Bearer JWT' \

Response

[
    {
        "email": "cd1@juspay.in",
        "roles": [
            {
                "role_id": "tenant_admin",
                "role_name": "tenant_admin"
            }
        ]
    }
]

For global search now, we are getting org_id in the query
Screenshot 2025-01-07 at 3 23 14 PM

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

@apoorvdixit88 apoorvdixit88 added C-bug Category: Bug C-feature Category: Feature request or enhancement A-users Area: Users labels Jan 5, 2025
@apoorvdixit88 apoorvdixit88 self-assigned this Jan 5, 2025
@apoorvdixit88 apoorvdixit88 requested review from a team as code owners January 5, 2025 20:12
Copy link

semanticdiff-com bot commented Jan 5, 2025

@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Jan 5, 2025
Comment on lines 113 to 114
#[error("User role not found")]
UserRoleNotFound,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove this if this is not being used.

racnan
racnan previously approved these changes Jan 7, 2025
@@ -294,4 +294,34 @@ impl UserRole {
},
}
}

pub async fn list_user_roles_by_user_id_across_tenants(
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this required ?

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 be using this query in future, to search for a user across tenancies.

@@ -110,6 +110,8 @@ pub enum UserErrors {
MissingEmailConfig,
#[error("Invalid Auth Method Operation: {0}")]
InvalidAuthMethodOperationWithMessage(String),
#[error("User role not found")]
UserRoleNotFound,
Copy link
Contributor

Choose a reason for hiding this comment

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

why ?

Comment on lines +123 to +126
user_from_token
.tenant_id
.as_ref()
.unwrap_or(&state.tenant.tenant_id),
Copy link
Contributor

Choose a reason for hiding this comment

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

this could be a util, seeing this code everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will be removing option from tenant_id,

dracarys18
dracarys18 previously approved these changes Jan 7, 2025
ThisIsMani
ThisIsMani previously approved these changes Jan 7, 2025
@apoorvdixit88 apoorvdixit88 dismissed stale reviews from ThisIsMani and dracarys18 via 68bff43 January 7, 2025 13:08
@likhinbopanna likhinbopanna added this pull request to the merge queue Jan 8, 2025
Merged via the queue into main with commit d04e840 Jan 8, 2025
17 of 19 checks passed
@likhinbopanna likhinbopanna deleted the add-tenant-id-for-custom-roles branch January 8, 2025 09:34
pixincreate added a commit that referenced this pull request Jan 9, 2025
…d-memory-cache

* 'main' of github.com:juspay/hyperswitch:
  chore(version): 2025.01.09.0
  fix(cypress): backup and restore sessions when using user apis (#6978)
  feat(users): handle edge features for users in tenancy (#6990)
  chore(dynamic-fields): [Worldpay] update dynamic fields for payments (#7002)
  chore(version): 2025.01.08.0
  fix: consider status of payment method before filtering wallets in list pm (#7004)
  feat(core): add columns unified error code and error message in refund table (#6933)
  feat(connector): [Fiuu] Consume transaction id for error cases for Fiuu (#6998)
  docs(cypress): update cypress documentation (#6956)
pixincreate added a commit to Ankesh2004/hyperswitch that referenced this pull request Jan 9, 2025
…r-verifyurl-in-redirection-handler

* 'main' of github.com:juspay/hyperswitch: (30 commits)
  test(cypress): add test for In Memory Cache (juspay#6961)
  chore(version): 2025.01.09.1
  fix(dummyconnector): add tenant id in dummyconnector requests (juspay#7008)
  chore(version): 2025.01.09.0
  fix(cypress): backup and restore sessions when using user apis (juspay#6978)
  feat(users): handle edge features for users in tenancy (juspay#6990)
  chore(dynamic-fields): [Worldpay] update dynamic fields for payments (juspay#7002)
  chore(version): 2025.01.08.0
  fix: consider status of payment method before filtering wallets in list pm (juspay#7004)
  feat(core): add columns unified error code and error message in refund table (juspay#6933)
  feat(connector): [Fiuu] Consume transaction id for error cases for Fiuu (juspay#6998)
  docs(cypress): update cypress documentation (juspay#6956)
  chore(version): 2025.01.07.0
  chore(keymanager): add tenant-id to keymanager requests (juspay#6968)
  ci(cypress): Add Session Token Testcases (juspay#6683)
  Ci(Cypress): Add PML test and Dynamic Fields Test for Novalnet (juspay#6544)
  chore(version): 2025.01.06.0
  ci(cypress): fix adyen sofort in cypress (juspay#6984)
  chore: add migrations for Currency type in DB (juspay#6980)
  chore(version): 2025.01.03.0
  ...
pixincreate added a commit that referenced this pull request Jan 9, 2025
…d-memory-cache

* 'main' of github.com:juspay/hyperswitch:
  test(cypress): add test for In Memory Cache (#6961)
  chore(version): 2025.01.09.1
  fix(dummyconnector): add tenant id in dummyconnector requests (#7008)
  chore(version): 2025.01.09.0
  fix(cypress): backup and restore sessions when using user apis (#6978)
  feat(users): handle edge features for users in tenancy (#6990)
  chore(dynamic-fields): [Worldpay] update dynamic fields for payments (#7002)
  chore(version): 2025.01.08.0
  fix: consider status of payment method before filtering wallets in list pm (#7004)
  feat(core): add columns unified error code and error message in refund table (#6933)
  feat(connector): [Fiuu] Consume transaction id for error cases for Fiuu (#6998)
  docs(cypress): update cypress documentation (#6956)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-users Area: Users C-bug Category: Bug C-feature Category: Feature request or enhancement M-database-changes Metadata: This PR involves database schema changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(roles): edge cases for multi-tenancy - I
7 participants