8000 features adding hs credit license to the teacher by smallst · Pull Request #7931 · codecombat/codecombat · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

features adding hs credit license to the teacher #7931

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 7 commits into from
May 9, 2025

Conversation

smallst
Copy link
Contributor
@smallst smallst commented Mar 5, 2025

image
image
fix ENG-1426

this pr is ready, but draft because we didn't implement server logic to redeem such license yet.

Summary by CodeRabbit

  • New Features

    • Introduced support for a new "AI HackStack" license type with customizable credit limits and durations.
    • Added UI options for admins and teachers to configure HackStack license credits when granting licenses.
    • Displayed HackStack license and credit details in enrollment and license management views.
  • Localization

    • Added new English language entries for HackStack license and credit descriptions.
  • Enhancements

    • Updated schemas to support structured credit details for HackStack licenses.
    • Included the HackStack course in course listings and orderings across products.

Copy link
Contributor
coderabbitai bot commented Mar 5, 2025

Walkthrough

This change introduces support for a new course and license type called "AI HackStack" across the application. It adds the HACKSTACK course identifier to course utilities, updates schemas to handle credit-based licensing, and enhances both backend and frontend logic to support the creation, display, and management of HackStack licenses with customizable credit details. Localization entries and UI components are updated to reflect the new license type, and admin workflows are modified to allow granting HackStack licenses with specific credit parameters.

Changes

Files/Paths Change Summary
app/core/utils.js Added HACKSTACK course ID to course ID collections and ordering for both CodeCombat and Ozaria.
app/locale/en.js Added localization keys and strings for "AI HackStack License", "Hackstack Credits", and related credit templates.
app/models/Prepaid.js Enhanced typeDescription to display HackStack license and credits when applicable.
app/schemas/models/prepaid.schema.js Added creditDetails object (with operation, durationAmount, durationKey, limit) to Prepaid schema.
app/schemas/models/user_credit.schema.js Added a licenses array property to the UserCredit schema to store license credit information.
app/templates/admin/administer-user-modal.pug Updated license-type mixin call to pass credit details for HackStack license creation.
app/templates/courses/enrollments-view.pug Updated prepaidCard mixin to detect and display HackStack licenses and their credit info.
app/templates/teachers/common/license-type-mixin.pug Added "hackstack" license type option and UI for entering credit details in the license-type mixin.
app/views/admin/AdministerUserModal.js Added logic to support HackStack license creation, parsing credit details and attaching them to the license.

Sequence Diagram(s)

sequenceDiagram
    participant AdminUser as Admin User
    participant AdminModal as AdministerUserModal
    participant Backend as Backend (Prepaid, Schemas)
    participant UI as UI Templates

    AdminUser->>AdminModal: Selects "HackStack" license type and enters credit details
    AdminModal->>AdminModal: Parses credit details and sets isHackstack flag
    AdminModal->>Backend: Creates Prepaid license with creditDetails for HACKSTACK
    Backend->>Backend: Stores license with creditDetails in Prepaid schema
    Backend-->>AdminModal: Returns created license
    AdminModal->>UI: Passes license data
    UI->>UI: Displays HackStack license and credits using localization
Loading

Assessment against linked issues

Objective Addressed Explanation
Add ability to create and grant AI HackStack course/prepaid licenses with paid credits (ENG-1426)

Possibly related PRs

Suggested reviewers

  • mrfinch

Poem

In the warren where the HackStack grows,
New credits bloom in tidy rows.
Licenses sprout with prompts to spare,
Admins grant them with thoughtful care.
From schemas deep to UI bright,
🐇 celebrates HackStack’s digital light!
Hop, hop, hooray—new features in sight!

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.

🔧 ast-grep (0.31.1)
app/locale/en.js

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.

@smallst smallst marked this pull request as ready for review April 15, 2025 13:33
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 (6)
app/templates/teachers/common/license-type-mixin.pug (2)

30-44: Comprehensive credit configuration UI.

The credit configuration section provides a complete set of inputs for configuring hackstack credits:

  • Duration amount (numeric input)
  • Duration unit (day/week/month dropdown)
  • Credit limit (numeric input)

The UI is conditionally displayed only when the hackstack license type is selected, and pre-populates values from the credit object.

Suggestion: Consider adding min/max validation for the credit limit and duration amount to prevent unreasonable values.

- <input(type="number", min=1, name="durationAmount", value=credit.amount)>
+ <input(type="number", min=1, max=365, name="durationAmount", value=credit.amount)>

- <input(type="number", min=1, name='creditLimit', value=credit.limit)>
+ <input(type="number", min=1, max=10000, name='creditLimit', value=credit.limit)>

32-44: Improve text label accessibility.

The static text elements ("Every" and "prompts") should be more descriptive or have appropriate ARIA labels to improve accessibility.

- | Every
+ span(aria-hidden="true") Every
+ span.sr-only Duration: Credits refresh every

- | prompts
+ span(aria-hidden="true") prompts
+ span.sr-only Credit limit: Maximum number of prompts per duration
app/locale/en.js (1)

4533-4533: Minor capitalization inconsistency noted.

There's a slight inconsistency in the capitalization between "HackStack" in the teacher namespace (line 2737) and "Hackstack" here in the admin namespace. Consider standardizing the capitalization across all instances for brand consistency.

-      license_type_hackstack: 'Hackstack Credits',
+      license_type_hackstack: 'HackStack Credits',
app/views/admin/AdministerUserModal.js (3)

303-312: Consider adding validation for HackStack credit parameters.

The implementation correctly handles the new HackStack license type by setting the appropriate course ID and collecting credit-related parameters. However, there's no validation to ensure positive values for durationAmount or limit.

if (attrs.licenseType === 'hackstack') {
  attrs.includedCourseIDs = [utils.courseIDs.HACKSTACK]
  isHackstack = true
  hackstackCredits.durationAmount = parseInt(attrs.durationAmount)
+ if (isNaN(hackstackCredits.durationAmount) || hackstackCredits.durationAmount <= 0) {
+   alert('Duration amount must be a positive number')
+   return
+ }
  hackstackCredits.durationKey = attrs.durationKey
  hackstackCredits.limit = parseInt(attrs.creditLimit)
+ if (isNaN(hackstackCredits.limit) || hackstackCredits.limit <= 0) {
+   alert('Credit limit must be a positive number')
+   return
+ }
  delete attrs.durationAmount
  delete attrs.durationKey
  delete attrs.creditLimit
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 309-309: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 310-310: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 311-311: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


309-311: Consider using undefined assignment instead of delete operator.

The delete operator can have a slight performance impact. Consider using undefined assignment instead.

-  delete attrs.durationAmount
-  delete attrs.durationKey
-  delete attrs.creditLimit
+  attrs.durationAmount = undefined
+  attrs.durationKey = undefined
+  attrs.creditLimit = undefined
🧰 Tools
🪛 Biome (1.9.4)

[error] 309-309: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 310-310: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 311-311: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


323-326: Small optimization: Unnecessary object reset.

Resetting hackstackCredits = {} after assignment is unnecessary since the object is no longer used.

if (isHackstack) {
  attrs.properties.creditDetails = hackstackCredits
-  hackstackCredits = {}
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5ac7e26 and b009430.

📒 Files selected for processing (9)
  • app/core/utils.js (3 hunks)
  • app/locale/en.js (2 hunks)
  • app/models/Prepaid.js (1 hunks)
  • app/schemas/models/prepaid.schema.js (1 hunks)
  • app/schemas/models/user_credit.schema.js (1 hunks)
  • app/templates/admin/administer-user-modal.pug (1 hunks)
  • app/templates/courses/enrollments-view.pug (1 hunks)
  • app/templates/teachers/common/license-type-mixin.pug (3 hunks)
  • app/views/admin/AdministerUserModal.js (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
app/core/utils.js (1)
app/models/User.js (1)
  • courseIDs (677-677)
🪛 Biome (1.9.4)
app/views/admin/AdministerUserModal.js

[error] 309-309: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 310-310: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 311-311: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🔇 Additional comments (16)
app/core/utils.js (2)

290-291: LGTM: HACKSTACK course added to orderedCourseIDs

The HACKSTACK course has been properly added to the end of the orderedCourseIDs array for CodeCombat, ensuring it will be included in course ordering and references.


361-362: LGTM: HACKSTACK course added to otherOrderedCourseIDs

The HACKSTACK course ID has been properly added to the end of the otherOrderedCourseIDs array for Ozaria, maintaining consistency between products.

app/templates/admin/administer-user-modal.pug (1)

304-304: LGTM: Credit details parameter added to license-type mixin

The view.creditDetails parameter has been added to the license-type mixin call, enabling support for the new credit-based HackStack license type.

app/schemas/models/prepaid.schema.js (1)

34-42: LGTM: Credit details schema added for HACKSTACK license type

The creditDetails schema has been added with appropriate properties for tracking duration and limits for HackStack licenses:

  • durationAmount: numeric value for time period
  • durationKey: enumerated string ('day', 'week', 'month') for time unit
  • limit: numeric value for maximum credits

This schema will allow proper validation of credit details for HackStack licenses.

app/schemas/models/user_credit.schema.js (1)

30-39: LGTM: License credits tracking added to UserCredit schema

A licenses array has been added to the UserCredit schema to track credit-based license information, with fields that align with the prepaid schema's creditDetails:

  • operation: likely indicates the credit action type
  • durationKey: time unit matching prepaid schema
  • durationAmount: time period matching prepaid schema
  • limit: credit limit matching prepaid schema

This addition enables proper tracking of HackStack license credits at the user level.

app/templates/courses/enrollments-view.pug (4)

109-110: Well-structured license detection logic.

The code correctly identifies hackstack licenses by checking three conditions:

  1. Presence of creditDetails in properties
  2. Exactly one includedCourseID
  3. That ID matches the HACKSTACK course ID

This approach ensures proper license type identification.


113-114: Proper internationalization for hackstack license display.

The code appropriately uses the i18n system for displaying the hackstack license label, maintaining consistency with how other license types are displayed.


120-123: Clear hackstack credits display with localization.

The code effectively handles the special case for hackstack licenses by displaying credits information instead of course acronyms, using proper localization by passing the credit object to the translation function.


124-125: Fallback logic for non-hackstack licenses.

The else branch correctly maintains the existing behavior for regular licenses, ensuring backward compatibility.

app/models/Prepaid.js (1)

80-83: Good use of optional chaining and license type differentiation.

The implementation correctly:

  1. Uses optional chaining (?.) to safely access nested properties
  2. Checks for the presence of credit details and the HACKSTACK course ID
  3. Returns appropriate localized text by combining the license type and credit details

This maintains consistency with the UI changes in the templates while ensuring the model layer properly supports the new license type.

app/templates/teachers/common/license-type-mixin.pug (2)

1-1: Properly updated mixin signature.

The mixin signature has been updated to include the new credit parameter, which is essential for handling the hackstack license type configuration.


11-14: Clear hackstack license option with i18n support.

The new radio button option for hackstack licenses is properly implemented and uses the i18n system for displaying the label, maintaining consistency with other license types.

app/locale/en.js (1)

2737-2738: Localization strings for HackStack license added correctly.

These new localization entries align with the PR objective of adding high school credit license functionality for teachers. The placeholder structure in hackstack_credits allows for dynamic insertion of credit limits and duration information.

app/views/admin/AdministerUserModal.js (3)

132-136: LGTM: New credit defaults look good.

The addition of the creditDetails object with sensible defaults will support the new HackStack license type.


292-294: LGTM: Clean variable declarations.

The new variables for tracking HackStack license type and its credit details are clearly defined.


303-326:

✅ Verification successful

Verify field names match between frontend and backend.

Ensure that the field names used here (durationAmount, durationKey, limit) match what the backend expects in creditDetails.


🏁 Script executed:

#!/bin/bash
# Look for references to creditDetails structure in schema files
rg -A 10 -p "creditDetails" --glob "*.schema.js" .

Length of output: 494


Field Name Mapping Verified: All field names correctly align between the frontend and backend.

  • The backend schema (app/schemas/models/prepaid.schema.js) defines the creditDetails object with properties durationAmount, durationKey, and limit.
  • The frontend code correctly maps the UI fields by:
    • Parsing and assigning attrs.durationAmount to hackstackCredits.durationAmount,
    • Passing attrs.durationKey directly to hackstackCredits.durationKey,
    • Converting attrs.creditLimit to an integer and assigning it to hackstackCredits.limit.
  • This mapping ensures that the backend receives the expected structure.
🧰 Tools
🪛 Biome (1.9.4)

[error] 309-309: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 310-310: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 311-311: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 314-314: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🪛 ESLint

[error] 320-321: Missing trailing comma.

(comma-dangle)


[error] 321-322: Missing trailing comma.

(comma-dangle)

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

♻️ Duplicate comments (1)
app/schemas/models/user_credit.schema.js (1)

30-41: Schema properly extended to support Hackstack license credits.

The addition of the licenses array to the UserCreditSchema effectively supports credit-based licensing for the new Hackstack course. The schema includes all necessary fields for tracking license credits: prepaidId, endDate, operation, durationKey, durationAmount, and limit.

Adding endDate is appropriate as previously discussed in past review comments.

🧹 Nitpick comments (1)
app/views/admin/AdministerUserModal.js (1)

292-317: Properly implemented Hackstack license type support.

The implementation correctly handles the Hackstack license type, including setting the appropriate course IDs and capturing credit parameters from the form. However, there's a performance concern with using the delete operator.

Consider using undefined assignment instead of delete for better performance:

-        delete attrs.durationAmount
-        delete attrs.durationKey
-        delete attrs.creditLimit
+        attrs.durationAmount = undefined
+        attrs.durationKey = undefined
+        attrs.creditLimit = undefined
🧰 Tools
🪛 Biome (1.9.4)

[error] 300-300: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 314-314: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 315-315: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 316-316: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b009430 and e8b5479.

📒 Files selected for processing (6)
  • app/core/utils.js (3 hunks)
  • app/locale/en.js (2 hunks)
  • app/schemas/models/prepaid.schema.js (1 hunks)
  • app/schemas/models/user_credit.schema.js (1 hunks)
  • app/templates/admin/administer-user-modal.pug (1 hunks)
  • app/views/admin/AdministerUserModal.js (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • app/templates/admin/administer-user-modal.pug
  • app/schemas/models/prepaid.schema.js
  • app/core/utils.js
  • app/locale/en.js
🧰 Additional context used
🪛 Biome (1.9.4)
app/views/admin/AdministerUserModal.js

[error] 314-314: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 315-315: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 316-316: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: ESLint CI
  • GitHub Check: Node.js CI (18.10.0)
🔇 Additional comments (2)
app/views/admin/AdministerUserModal.js (2)

132-136: Good defaults for Hackstack credit configuration.

The default values for creditDetails have been updated from using days to using weeks, and increasing the limit from 10 to 30, which is better aligned with high school credit licensing requirements.


328-331: Correctly sets creditDetails properties for Hackstack licenses.

This code properly adds the credit details to the prepaid license properties when creating a Hackstack license.

@mrfinch mrfinch merged commit 01ee227 into master May 9, 2025
2 of 3 checks passed
@mrfinch mrfinch deleted the yuqiang/license-add-hs-credits-feature branch May 9, 2025 05:01
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
0