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(user_roles): Add accept invitation API and UserJWTAuth #3365

Merged
merged 6 commits into from
Jan 19, 2024

Conversation

ThisIsMani
Copy link
Contributor

@ThisIsMani ThisIsMani commented Jan 17, 2024

Type of Change

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

Description

This PR will add a new API for accepting invitation and also a new JWT auth type which has only user_id.

Additional Changes

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

Motivation and Context

To support the Accept Invite flow in the following flow.

flowchart TD
    A["Connect Account"] -- Email --> B{"User Exists"}
    B -- No --> C["Create new \n Org \n Merchant \n User \n User Role"]
    C --> D["Send Verify Email"]
    D --> E["Verify Email Token"]
    B -- Yes --> D
    E --> H{"Is there\n any perferred \nmerchant"}
    F -- ==0 --> I{{"Send list of \nmerchants which\n user has access to\n along with an\n intermediate token"}}
    F -- >1 --> G[Select the first role with active status]
    H -- Yes --> M["Send the token \nwith that merchant_id"]
    H -- No --> F{"How many \n active merchants\n does user have \naccess to"}
    I -- merchant_ids, \nintermediate_token --> O["Accept Invite"]
    subgraph Accept Invite
        O --> P["Change status to active"]
        P --> G
        G --> M
    end
    K["Sign In"] -- Email, Password --> H
Loading

How did you test it?

curl --location 'http://localhost:8080/user/user/invite/accept' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer JWT' \
--data '{
    "merchant_ids": [
         "merchant_id1",
         "merchant_id2",
         "merchant_id3"
    ],
    "need_dashboard_entry_response": true
}'

If any of the merchant_id status is active, then you will be getting the following response.

{
    "token": "JWT with merchant_id, user_id, user_role",
    "merchant_id": "merchant_id",
    "name": "user name",
    "email": "user email",
    "verification_days_left": null,
    "user_role": "user role"
}

If need_dashboard_entry_response is false or not sent, then the response will be 200 OK.

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
  • I added a CHANGELOG entry if applicable

@ThisIsMani ThisIsMani added C-feature Category: Feature request or enhancement S-waiting-on-review Status: This PR has been implemented and needs to be reviewed A-users Area: Users labels Jan 17, 2024
@ThisIsMani ThisIsMani self-assigned this Jan 17, 2024
@ThisIsMani ThisIsMani requested review from a team as code owners January 17, 2024 07:14
@ThisIsMani ThisIsMani linked an issue Jan 17, 2024 that may be closed by this pull request
Copy link
Contributor

@racnan racnan left a comment

Choose a reason for hiding this comment

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

Lets give this API the possibility to not send the signin payload as response payload. Maybe query params?

@ThisIsMani ThisIsMani requested a review from racnan January 17, 2024 09:44
crates/router/src/routes/app.rs Outdated Show resolved Hide resolved
crates/router/src/services/authentication.rs Outdated Show resolved Hide resolved
@ThisIsMani ThisIsMani requested a review from a team as a code owner January 17, 2024 13:02
@ThisIsMani ThisIsMani requested a review from racnan January 17, 2024 13:37
Copy link
Contributor

@racnan racnan left a comment

Choose a reason for hiding this comment

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

Check if need_dashboard_entry_response needs to be in query param.

crates/router/src/routes/app.rs Show resolved Hide resolved
@likhinbopanna likhinbopanna added this pull request to the merge queue Jan 19, 2024
Merged via the queue into main with commit a47372a Jan 19, 2024
10 checks passed
@likhinbopanna likhinbopanna deleted the accept-invite branch January 19, 2024 13:19
@ThisIsMani ThisIsMani added the M-api-contract-changes Metadata: This PR involves API contract changes label Jan 19, 2024
@SanchithHegde SanchithHegde removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-users Area: Users C-feature Category: Feature request or enhancement M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(invite): make accept invite api
6 participants