Skip to content

feat: cohort entitlements #469

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

Merged
merged 2 commits into from
May 9, 2025
Merged

feat: cohort entitlements #469

merged 2 commits into from
May 9, 2025

Conversation

joelhooks
Copy link
Collaborator

@joelhooks joelhooks commented May 8, 2025

https://www.loom.com/share/eee2bb6ef2fb42bb9825b550b2bdd78e

Summary by CodeRabbit

  • New Features

    • Users who purchase a cohort product are now automatically granted access entitlements to all cohort resources, enabling immediate content access.
  • Improvements

    • Cohort resource products now default to an empty list if not specified, improving reliability when no resources are provided.
    • Organization membership queries now return full organization and user details, enhancing membership data completeness.
    • Live event quantity information is now only shown when the event is live and quantities are available, preventing display of unavailable events.

Copy link

vercel bot commented May 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ai-hero ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 9, 2025 7:45am
course-builder-egghead ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 9, 2025 7:45am
course-builder-poc ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 9, 2025 7:45am
cursor-pro ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 9, 2025 7:45am
epic-react-builder ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 9, 2025 7:45am
epic-web-builder ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 9, 2025 7:45am
epicai-pro ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 9, 2025 7:45am
go-local-first ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 9, 2025 7:45am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
astro-party ⬜️ Ignored (Inspect) Visit Preview May 9, 2025 7:45am

Copy link
Contributor

coderabbitai bot commented May 8, 2025

Walkthrough

The updates introduce entitlement assignment for cohort content access after cohort purchases, set a default value for the resourceProducts field in the cohort schema, enhance organization membership queries to include related entities, and adjust a UI component to display only when both an event is live and quantities are available.

Changes

File(s) Change Summary
apps/ai-hero/src/inngest/functions/post-cohort-purchase-workflow.ts Added logic to assign cohort content access entitlements after cohort purchase, inserting records for each resource.
apps/ai-hero/src/lib/cohort.ts Updated CohortSchema to set a default empty array for the resourceProducts field.
packages/adapter-drizzle/src/lib/mysql/index.ts Enhanced addMemberToOrganization to include related organization and user in the fetched membership object.
packages/commerce-next/src/pricing/pricing.tsx Modified LiveQuantity component to render only if the event is live and quantityAvailable is greater than zero.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Workflow
    participant DB

    User->>Workflow: Purchase cohort product
    Workflow->>DB: Retrieve organization membership
    alt Membership found
        Workflow->>DB: Assign entitlements for each cohort resource
        DB-->>Workflow: Entitlement records inserted
    end
    Workflow-->>User: Access granted to cohort resources
Loading

Poem

In the warren of code, a new path appears,
Entitlements hop in, dispelling old fears.
Schemas grow defaults, so errors are few,
Memberships fetch friends, not just the crew.
Live events now peek, only when stocks are bright—
A carrot of logic, nibbled just right! 🥕

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this 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.

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

🧹 Nitpick comments (2)
packages/commerce-next/src/pricing/pricing.tsx (1)

664-664: Enhanced conditional rendering of LiveQuantity

The component now only renders when both conditions are true: the event is live AND there are quantities available. This prevents showing "spots left" indicators when there's nothing available.

You might consider adding a comment explaining why both conditions are required for added clarity in the future.

apps/ai-hero/src/inngest/functions/post-cohort-purchase-workflow.ts (1)

103-121: Implemented cohort entitlement assignment

This new feature assigns entitlements to users after a cohort purchase, giving them access to the cohort's resources. The implementation correctly:

  • Checks for prerequisites before processing
  • Creates entitlement records for each resource in the cohort
  • Associates the records with the proper user, organization, and membership
  • Includes resource IDs in metadata for traceability

Consider adding error handling within the loop to prevent a single resource failure from stopping the entire entitlement process.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b4101c7 and ce7e068.

📒 Files selected for processing (4)
  • apps/ai-hero/src/inngest/functions/post-cohort-purchase-workflow.ts (2 hunks)
  • apps/ai-hero/src/lib/cohort.ts (1 hunks)
  • packages/adapter-drizzle/src/lib/mysql/index.ts (1 hunks)
  • packages/commerce-next/src/pricing/pricing.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/ai-hero/src/lib/cohort.ts (1)
packages/core/src/schemas/product-schema.ts (1)
  • productSchema (9-41)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: typecheck
  • GitHub Check: build
  • GitHub Check: format
  • GitHub Check: lint
  • GitHub Check: e2e-node (course-builder-web)
🔇 Additional comments (3)
apps/ai-hero/src/lib/cohort.ts (1)

17-25: Good defensive programming with default empty array

Adding a default empty array for resourceProducts is a good practice that prevents potential null/undefined errors when iterating over this field in other parts of the codebase.

This change works well with the new entitlement assignment logic in the post-cohort-purchase workflow.

packages/adapter-drizzle/src/lib/mysql/index.ts (1)

740-743: Enhanced query to include related entities

Including organization and user data in the membership query result provides more complete data to downstream code, potentially reducing the need for additional database queries.

This enriched data is particularly valuable for the cohort entitlement assignment workflow where organization and user details are needed.

apps/ai-hero/src/inngest/functions/post-cohort-purchase-workflow.ts (1)

2-6: Updated imports to support entitlement functionality

The additional imports for entitlements and entitlementTypes are necessary for the new entitlement assignment logic.

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