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

Feature/user model upsert #2087

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

pitwegner
Copy link
Contributor

@pitwegner pitwegner commented Sep 20, 2024

When not using the frontend, users do not get created automatically, because there is no login. When simply using the backend, it would be desirable to allow user creation from the first time the token is used.

Summary by CodeRabbit

  • New Features

    • Introduced a configuration option to allow user model creation without requiring a login.
    • Enhanced user model creation process to support scenarios where a user is not logged in.
  • Bug Fixes

    • Improved control flow to handle user model creation when a token is provided but no user model exists.

Copy link
Contributor

coderabbitai bot commented Sep 20, 2024

Walkthrough

Walkthrough

The changes introduce a new configuration option, SPIFFWORKFLOW_BACKEND_CREATE_USERMODEL_WITHOUT_LOGIN, in the spiffworkflow_backend module, allowing for the creation of a user model without requiring a login. This option is incorporated into the config_from_env function with a default value of False. Additionally, the _get_user_model_from_token function in the authentication_controller.py file has been modified to utilize this configuration setting, enabling the creation of a user model when the user model is not found, contingent on the new configuration.

Changes

File Path Change Summary
spiffworkflow-backend/src/spiffworkflow_backend/config/default.py Added a new configuration option SPIFFWORKFLOW_BACKEND_CREATE_USERMODEL_WITHOUT_LOGIN with a default value of False.
spiffworkflow-backend/src/spiffworkflow_backend/routes/authentication_controller.py Modified _get_user_model_from_token to conditionally create a user model based on the new configuration setting.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AuthService
    participant Config

    User->>AuthService: Request user model
    AuthService->>Config: Check SPIFFWORKFLOW_BACKEND_CREATE_USERMODEL_WITHOUT_LOGIN
    alt User model found
        AuthService-->>User: Return user model
    else User model not found
        alt Feature enabled
            AuthService->>AuthService: create_user_from_sign_in(decoded_token)
            AuthService-->>User: Return new user model
        else Feature disabled
            AuthService-->>User: Return error (no user model)
        end
    end
Loading

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 31ded57 and 7382791.

Files selected for processing (2)
  • spiffworkflow-backend/src/spiffworkflow_backend/config/default.py (1 hunks)
  • spiffworkflow-backend/src/spiffworkflow_backend/routes/authentication_controller.py (1 hunks)
Additional comments not posted (2)
spiffworkflow-backend/src/spiffworkflow_backend/config/default.py (1)

116-116: LGTM!

The addition of the SPIFFWORKFLOW_BACKEND_CREATE_USERMODEL_WITHOUT_LOGIN configuration option looks good. The naming is clear, and using config_from_env with a default value of False ensures that the feature is opt-in, preserving the existing behavior by default.

Please ensure that the implementation of the feature controlled by this configuration follows security best practices, considering the potential implications of creating user models without a login.

spiffworkflow-backend/src/spiffworkflow_backend/routes/authentication_controller.py (1)

380-381: Approve the user model creation feature controlled by the configuration setting.

The introduced code segment enhances the user experience by automatically creating a user model when one doesn't exist, based on the SPIFFWORKFLOW_BACKEND_CREATE_USERMODEL_WITHOUT_LOGIN configuration setting. This eliminates the need for a separate login process to initiate user accounts, streamlining the user flow.

The feature is well-implemented and provides flexibility through the use of a configuration setting to control its behavior.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@@ -377,6 +377,8 @@ def _get_user_model_from_token(decoded_token: dict) -> UserModel | None:
.first()
)
if user_model is None:
if current_app.config["SPIFFWORKFLOW_BACKEND_CREATE_USERMODEL_WITHOUT_LOGIN"]:
user_model = AuthorizationService.create_user_from_sign_in(decoded_token)
AuthenticationService.set_user_has_logged_out()
raise ApiError(
error_code="invalid_user",
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a cool feature, thanks. it looks like right after it creates the user model in this case, it will return an ApiError. is it possible for the request to succeed to make it more seamless?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants