Skip to content

Conversation

@PaulAdamDavis
Copy link
Member

@PaulAdamDavis PaulAdamDavis commented Apr 2, 2025

no ref

  • Sends the owner email to the self-service migration tool, so that we can ensure all users have a great experience of migrating

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 2, 2025

Walkthrough

This pull request updates the owner user retrieval mechanism within the admin migration flow. A new asynchronous method ownerUser is added to the migration service to query the data store for a user marked as the owner. The service first checks locally using a peek operation and, if necessary, reloads user data from the server. In the migration iframe component, the owner's email is now retrieved using the ownerUser method and appended to the data payload sent via postMessage to the iframe. Minor syntactical adjustments in the component are also included.

Possibly related PRs

Suggested reviewers

  • sagzy

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ghost/admin/app/components/gh-migrate-iframe.js

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Failed to load parser '@babel/eslint-parser' declared in 'ghost/admin/.eslintrc.js': Cannot find module '@babel/eslint-parser'
Require stack:

  • /ghost/admin/.eslintrc.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object.resolve (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2346:46)
    at ConfigArrayFactory._loadParser (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3325:39)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3099:43)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3040:20)
    at _normalizeObjectConfigData.next ()
    at ConfigArrayFactory.loadInDirectory (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2886:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3871:46)
ghost/admin/app/services/migrate.js

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Failed to load parser '@babel/eslint-parser' declared in 'ghost/admin/.eslintrc.js': Cannot find module '@babel/eslint-parser'
Require stack:

  • /ghost/admin/.eslintrc.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object.resolve (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2346:46)
    at ConfigArrayFactory._loadParser (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3325:39)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3099:43)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3040:20)
    at _normalizeObjectConfigData.next ()
    at ConfigArrayFactory.loadInDirectory (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2886:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3871:46)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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: 0

🔭 Outside diff range comments (1)
ghost/admin/app/components/gh-migrate-iframe.js (1)

58-70: 🛠️ Refactor suggestion

Add null check for owner user before accessing email property

The code assumes theOwner will always be defined and have an email property. If no owner user is found by the ownerUser() method, accessing theOwner.email will throw an error.

Consider adding a null check before accessing the email property:

  async _handleUrlRequest() {
      const theToken = await this.migrate.apiToken();
      const theOwner = await this.migrate.ownerUser();

      this.migrate.getMigrateIframe().contentWindow.postMessage({
          request: 'initialData',
          response: {
              apiUrl: this.migrate.apiUrl,
              apiToken: theToken,
              darkMode: this.feature.nightShift,
              stripe: this.migrate.isStripeConnected,
              ghostVersion: this.migrate.ghostVersion,
-             ownerEmail: theOwner.email
+             ownerEmail: theOwner?.email
          }
      }, new URL(this.migrate.getIframeURL()).origin);
  }
🧹 Nitpick comments (1)
ghost/admin/app/services/migrate.js (1)

67-78: Add error handling and JSDoc documentation to ownerUser method

The method has good logic but lacks error handling for API calls and documentation.

Consider enhancing the method with:

  1. Error handling for the API call
  2. JSDoc documentation to clarify the return type (especially that it could be undefined)
+  /**
+   * Fetches the owner user of the Ghost instance
+   * @returns {Promise<Object|undefined>} The owner user object or undefined if not found
+   */
   async ownerUser() {
       // Try to receive the owner user from the store
       let user = this.store.peekAll('user').findBy('isOwnerOnly', true);

       if (!user) {
           // load it when it's not there yet
-          await this.store.findAll('user', {reload: true});
-          user = this.store.peekAll('user').findBy('isOwnerOnly', true);
+          try {
+              await this.store.findAll('user', {reload: true});
+              user = this.store.peekAll('user').findBy('isOwnerOnly', true);
+          } catch (error) {
+              console.error('Failed to load users:', error);
+              // Optionally re-throw or handle specifically
+          }
       }

       return user;
   }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 245d67e and ccb971f.

📒 Files selected for processing (2)
  • ghost/admin/app/components/gh-migrate-iframe.js (2 hunks)
  • ghost/admin/app/services/migrate.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Admin tests - Chrome
🔇 Additional comments (1)
ghost/admin/app/services/migrate.js (1)

11-11: LGTM!

The store service injection is correctly added and necessary for the ownerUser() method.

@ErisDS ErisDS self-requested a review April 3, 2025 09:12
Copy link
Member

@ErisDS ErisDS left a comment

Choose a reason for hiding this comment

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

Ideally, there'd be at least one test added for this change to prove it works and we get an email address

@PaulAdamDavis PaulAdamDavis enabled auto-merge (squash) June 27, 2025 13:59
@PaulAdamDavis PaulAdamDavis disabled auto-merge June 27, 2025 13:59
@PaulAdamDavis PaulAdamDavis enabled auto-merge (squash) June 27, 2025 14:04
@PaulAdamDavis PaulAdamDavis merged commit 7084a09 into main Jun 27, 2025
23 checks passed
@PaulAdamDavis PaulAdamDavis deleted the owner-user-self-service branch June 27, 2025 14:05
cmraible pushed a commit that referenced this pull request Jun 28, 2025
no ref

- Sends the owner email address to the self-service migration tool, so that we
can ensure all users have a great experience of migrating
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.

3 participants