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

🔨 OPENID: Refactor mixed stuff #4428

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

Conversation

lelemm
Copy link
Contributor

@lelemm lelemm commented Feb 21, 2025

Removed variable MULTIUSER because it was not being used anymore

Changed how the sync server utilizes the OpenID env vars (and config.json):

  • Now when the variable is present, at startup it tries to configure OpenId with these values
  • This was a user feedback

Removed the command yarn enable-openid because its deprecated on this new model

Made config variable loginMethod to be optional. So when used in the code bellow, it can reach const activeMethod = getActiveLoginMethod();:

export function getLoginMethod(req) {
  if (
    typeof req !== 'undefined' &&
    (req.body || { loginMethod: null }).loginMethod &&
    config.allowedLoginMethods.includes(req.body.loginMethod)
  ) {
    return req.body.loginMethod;
  }

  if (config.openId) {
    return 'openid';
  }

  if (config.loginMethod) {
    return config.loginMethod;
  }

  const activeMethod = getActiveLoginMethod();
  return activeMethod || 'password';
}

@actual-github-bot actual-github-bot bot changed the title 🔨 OPENID: Refactor mixed stuff [WIP] 🔨 OPENID: Refactor mixed stuff Feb 21, 2025
Copy link

netlify bot commented Feb 21, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 152c800
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67bb281a321dd0000850ebce
😎 Deploy Preview https://deploy-preview-4428.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@lelemm lelemm changed the title [WIP] 🔨 OPENID: Refactor mixed stuff 🔨 OPENID: Refactor mixed stuff Feb 21, 2025
Copy link
Contributor

coderabbitai bot commented Feb 21, 2025

Warning

Rate limit exceeded

@lelemm has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 28 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between f0a5fd0 and 152c800.

📒 Files selected for processing (3)
  • packages/sync-server/src/account-db.js (5 hunks)
  • packages/sync-server/src/config-types.ts (1 hunks)
  • packages/sync-server/src/load-config.js (0 hunks)

Walkthrough

The changes refactor the OpenID handling and configuration process in the sync-server package. The "enable-openid" script was removed from the package scripts, eliminating the command-line option to enable OpenID. In the account database module, the getLoginMethod function now prioritizes OpenID when enabled, and the bootstrap function has been updated with a new forced parameter to allow bypassing certain checks during initialization. The application module now imports bootstrap and conditionally executes it when OpenID is configured, including error handling. Additionally, the configuration type definitions have been updated: the loginMethod property is now optional and the multiuser property has been removed, with corresponding updates in the configuration loading script.

Possibly related PRs

  • ✨Enforce OPENID login #4423: The changes in the main PR, which remove the "enable-openid" script, are related to the modifications in the getLoginMethod and listLoginMethods functions in the retrieved PR, as both involve handling OpenID functionality and its configuration.

Suggested labels

:sparkles: Merged

Suggested reviewers

  • youngcw
  • matt-fidd

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/sync-server/src/account-db.js (1)

71-71: Consider improving transaction rollback error handling.

The transaction rollback in the bootstrap function could benefit from better error handling. Consider wrapping the rollback in a try-catch block to handle potential rollback failures.

Apply this diff to improve error handling:

 if (!forced && (!openIdEnabled || countOfOwner > 0)) {
   if (!needsBootstrap()) {
-    accountDb.mutate('ROLLBACK');
-    return { error: 'already-bootstrapped' };
+    try {
+      accountDb.mutate('ROLLBACK');
+      return { error: 'already-bootstrapped' };
+    } catch (rollbackError) {
+      console.error('Failed to rollback transaction:', rollbackError);
+      return { error: 'transaction-rollback-failed' };
+    }
   }
 }

Also applies to: 88-93

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f5a1293 and fd0ad1e.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/4428.md is excluded by !**/*.md
📒 Files selected for processing (5)
  • packages/sync-server/package.json (0 hunks)
  • packages/sync-server/src/account-db.js (5 hunks)
  • packages/sync-server/src/app.js (2 hunks)
  • packages/sync-server/src/config-types.ts (1 hunks)
  • packages/sync-server/src/load-config.js (0 hunks)
💤 Files with no reviewable changes (2)
  • packages/sync-server/package.json
  • packages/sync-server/src/load-config.js
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: matt-fidd
PR: actualbudget/actual#4363
File: packages/sync-server/src/scripts/enable-openid.js:6-6
Timestamp: 2025-02-11T23:39:06.219Z
Learning: In the Actual codebase, when `config` is used as a function parameter, the imported configuration should use the alias `finalConfig` to avoid naming conflicts. Example: `import { config as finalConfig } from '../load-config.js'`.
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Visual regression
  • GitHub Check: Functional
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Build Docker image (alpine)
  • GitHub Check: Build Docker image (ubuntu)
🔇 Additional comments (4)
packages/sync-server/src/config-types.ts (1)

7-7: LGTM! Making loginMethod optional aligns with the refactoring.

The change to make loginMethod optional is appropriate as it allows for more flexible configuration and better supports the new OpenID implementation where the login method can be determined dynamically.

packages/sync-server/src/app.js (1)

9-9: LGTM! Import of bootstrap function.

The import is correctly placed and aligns with the new OpenID configuration functionality.

packages/sync-server/src/account-db.js (2)

59-61: LGTM! Prioritizing OpenID when configured.

The change correctly prioritizes OpenID when it's configured, which aligns with the PR objectives.


113-119:

❓ Verification inconclusive

Verify OpenID configuration consistency.

The forced parameter is used to bypass OpenID checks, but we should verify that this doesn't lead to inconsistent states in the database.


🏁 Script executed:

#!/bin/bash
# Description: Check for potential inconsistent auth states in the database
ast-grep --pattern $'accountDb.mutate(\'SELECT * FROM auth WHERE method = \'openid\' AND active = 1 AND EXISTS (SELECT 1 FROM auth WHERE method = \'password\' AND active = 1)\')'

Length of output: 191


Review Comment Update: Verify OpenID Configuration Consistency

The forced parameter bypasses the standard OpenID checks, so it's important to ensure that doing so doesn't leave the database in an inconsistent state between OpenID and password authentication entries. Although the automated AST grep search did not yield any evidence of inconsistent auth states, please manually verify—and consider running additional checks—that the integration of these two authentication methods remains consistent in all cases.

  • Confirm that no conflicting records are created in the auth table when forced OpenID login is used.
  • Verify on staging or through manual DB inspection that the forced parameter truly bypasses only the intended checks without leaving residual authentication issues.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/sync-server/src/app.js (1)

109-111: Improve error logging consistency.

The error object is logged using console.log while other errors use console.error. For consistency and better error tracking:

-        console.log(error);
+        console.error('Failed to configure OpenID:', error);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fd0ad1e and f0a5fd0.

📒 Files selected for processing (1)
  • packages/sync-server/src/app.js (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: matt-fidd
PR: actualbudget/actual#4363
File: packages/sync-server/src/scripts/enable-openid.js:6-6
Timestamp: 2025-02-11T23:39:06.219Z
Learning: In the Actual codebase, when `config` is used as a function parameter, the imported configuration should use the alias `finalConfig` to avoid naming conflicts. Example: `import { config as finalConfig } from '../load-config.js'`.
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Functional
  • GitHub Check: Visual regression
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (windows-latest)
  • GitHub Check: Analyze
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Build Docker image (alpine)
  • GitHub Check: Build Docker image (ubuntu)
🔇 Additional comments (1)
packages/sync-server/src/app.js (1)

9-9: LGTM!

The import of bootstrap is correctly placed and necessary for the OpenID configuration functionality.

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

Successfully merging this pull request may close these issues.

1 participant