Skip to content

Authx to genrate url#1131

Open
tarunnjoshi wants to merge 3 commits intodevfrom
authx-to-genrate-url
Open

Authx to genrate url#1131
tarunnjoshi wants to merge 3 commits intodevfrom
authx-to-genrate-url

Conversation

@tarunnjoshi
Copy link
Copy Markdown
Member

@tarunnjoshi tarunnjoshi commented Apr 8, 2025

Authx to genrate url

Summary by CodeRabbit

  • New Features

    • Introduced secure, time-limited feedback form links using encrypted tokens, enhancing user data protection.
    • Improved session management for a more consistent experience during authentication flows.
  • Chores

    • Adjusted script dependencies to ensure reliable and smooth frontend behavior.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 8, 2025

Walkthrough

This pull request updates the UrbanPlannedVisitService by modifying the email-related functions. In the service, the database update marking feedback emails as sent is commented out, and the feedback form URL is now secured using a JWT with a three-day expiry. Additionally, the theme’s functions enqueue a new JavaScript dependency, jwt-decode, ensuring the proper load order for the dependent script. A new self-invoking function in the main JavaScript file decodes an auth token from the URL hash, manages session storage of the visit ID, and updates the URL as needed.

Changes

File(s) Change Summary
wp-content/civi-extensions/goonjcustom/Civi/UrbanPlannedVisitService.php Commented out the database update in sendFeedbackEmailToExtCoordPoc. Modified getExtCoordPocFeedbackEmailHtml to generate a feedback URL secured by a JWT with a three-day expiration.
wp-content/themes/goonj-crm/functions.php Enqueued a new JavaScript dependency jwt-decode from a CDN and updated goonj-script to depend on it, ensuring proper script load ordering.
wp-content/themes/goonj-crm/main.js Added a self-invoking function that extracts the _authx token from the URL hash, decodes it using jwt_decode, stores the extracted visit_id in sessionStorage, and updates the URL hash appropriately. Error handling logs any issues during JWT decoding.

Sequence Diagram(s)

sequenceDiagram
    participant B as Browser
    participant JS as main.js
    participant JWT as jwt_decode

    B->>JS: Page load with URL hash (_authx token)
    JS->>JWT: Decode _authx token
    JWT-->>JS: Return decoded token (visit_id, exp)
    JS->>B: Store visit_id in sessionStorage
    JS->>B: Update URL hash to include visit_id
    JS->>B: Restore _authx token after delay
Loading

Possibly related PRs

Suggested labels

status : ready for review

Suggested reviewers

  • belwalshubham

Poem

In a code realm where tokens dance,
Feedback emails get a new romance.
JWT secures the path so bright,
Scripts load in just the right light.
May our sessions hold tight with cheer –
CodeRabbit sings, "Great job, my dear!"
🚀🐇

✨ 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
Copy Markdown

@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 (2)
wp-content/themes/goonj-crm/main.js (1)

165-202: New token handling implementation looks good, but consider improving error logging.

The self-invoking function for JWT token processing adds secure handling of visit_id via URL hash parameters. The implementation properly handles token decoding, session storage persistence, and URL manipulation.

The error handling at line 181 could be enhanced by logging additional details about the token that caused the error (without exposing sensitive data). This would help with debugging:

-      console.error("JWT decode error:", err);
+      console.error("JWT decode error:", err.message, "Token format invalid");
wp-content/civi-extensions/goonjcustom/Civi/UrbanPlannedVisitService.php (1)

921-926: Secure URL generation with JWT token - good security practice!

The implementation of JWT token generation for the feedback form URL is a good security practice. The token includes a 3-day expiration time, which balances security with usability.

Consider extracting the JWT generation into a reusable helper method in case it needs to be used elsewhere:

private static function generateVisitToken($visitId, $expiryDays = 3) {
  $jwt = \Civi::service('crypto.jwt');
  return $jwt->encode([
    'exp' => time() + (86400 * $expiryDays),
    'visit_id' => $visitId,
  ]);
}

Then call it as: $token = self::generateVisitToken($visitId);

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 172f80f and fcda475.

📒 Files selected for processing (3)
  • wp-content/civi-extensions/goonjcustom/Civi/UrbanPlannedVisitService.php (1 hunks)
  • wp-content/themes/goonj-crm/functions.php (1 hunks)
  • wp-content/themes/goonj-crm/main.js (1 hunks)
🔇 Additional comments (2)
wp-content/themes/goonj-crm/functions.php (2)

26-26: LGTM! Dependency declaration ensures proper script loading order.

The addition of 'jwt-decode' as a dependency for 'goonj-script' ensures that the JWT library is loaded before the main script attempts to use it, preventing potential "undefined function" errors.


14-21:

Details

❓ Verification inconclusive

External dependency introduced - ensure version pinning and security monitoring.

Adding jwt-decode from a CDN is appropriate for this use case. The script is properly added with null versioning, which is consistent with CDN usage.

Verify that the jwt-decode library version (3.1.2) is the latest stable version and doesn't have known vulnerabilities:


🏁 Script executed:

#!/bin/bash
# Check for the latest version of jwt-decode
curl -s https://registry.npmjs.org/jwt-decode | jq '.["dist-tags"].latest'

# Check for known vulnerabilities 
curl -s https://registry.npmjs.org/jwt-decode | jq '.versions["3.1.2"].deprecated'

Length of output: 174


Upgrade Reminder for the jwt-decode Dependency

It looks like the enqueueing of the jwt-decode script is implemented correctly, and using a CDN with a null version is consistent with common practices. However, note that while the code pins the version to 3.1.2, our verification shows the latest stable version is now 4.0.0. Although 3.1.2 isn’t deprecated or known to have vulnerabilities, please review the changelog and compatibility implications to determine if an upgrade to 4.0.0 would be beneficial.

  • File: wp-content/themes/goonj-crm/functions.php (lines 14–21)
  • Action: Verify if migrating from 3.1.2 to 4.0.0 aligns with your project’s compatibility requirements and risk profile, and ensure ongoing security monitoring for external dependencies.

Comment on lines +907 to +913
// Only for testing need to remove the comment code later.
// If ($emailSendResultToExternalPoc) {
// EckEntity::update('Institution_Visit', FALSE)
// ->addValue('Visit_Feedback.Feedback_Email_Sent', 1)
// ->addWhere('id', '=', $visit['id'])
// ->execute();
// }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove commented-out code intended for temporary testing.

The code that updates the feedback email status has been commented out with a note indicating it's "Only for testing". Commented-out code reduces maintainability and creates confusion about whether this functionality should be enabled in production.

Either remove the commented code entirely if the functionality is no longer needed, or reinstate it if the functionality should be active in production. If this is a temporary state for debugging, add a TODO comment with a specific timeline:

-    // Only for testing need to remove the comment code later.
-    // If ($emailSendResultToExternalPoc) {
-    //   EckEntity::update('Institution_Visit', FALSE)
-    //     ->addValue('Visit_Feedback.Feedback_Email_Sent', 1)
-    //     ->addWhere('id', '=', $visit['id'])
-    //     ->execute();
-    // }
+    // Track email sent status in database
+    if ($emailSendResultToExternalPoc) {
+      EckEntity::update('Institution_Visit', FALSE)
+        ->addValue('Visit_Feedback.Feedback_Email_Sent', 1)
+        ->addWhere('id', '=', $visit['id'])
+        ->execute();
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Only for testing need to remove the comment code later.
// If ($emailSendResultToExternalPoc) {
// EckEntity::update('Institution_Visit', FALSE)
// ->addValue('Visit_Feedback.Feedback_Email_Sent', 1)
// ->addWhere('id', '=', $visit['id'])
// ->execute();
// }
// Track email sent status in database
if ($emailSendResultToExternalPoc) {
EckEntity::update('Institution_Visit', FALSE)
->addValue('Visit_Feedback.Feedback_Email_Sent', 1)
->addWhere('id', '=', $visit['id'])
->execute();
}

Base automatically changed from develop to dev July 25, 2025 11:40
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.

1 participant