Skip to content

Conversation

@JosephKS10
Copy link

Description

This PR implements a comprehensive Student Tutorial Self-Enrollment feature for the OnTrack/Doubtfire API, enabling students to self-enroll in tutorials for specific tasks. This feature enhances user autonomy and reduces administrative overhead while maintaining proper authorization and validation controls.

The implementation consists of four integrated components delivered through a systematic development approach:

1. Database Schema Foundation (Task 1)

  • Migration File:
    20250912012227_add_tutorial_self_enrolment_to_task_definitions.rb
  • New Fields Added to task_definitions table:
    • tutorial_self_enrolment_enabled (boolean, default: false) - Feature toggle flag
    • tutorial_self_enrolment_stream_id (foreign key to tutorial_streams) - Target stream for enrollment
  • Performance Optimization: Added database indexes for query optimization
  • Validation: Column existence checks prevent duplicate migrations

2. ActiveRecord Model Updates (Task 2)

  • TaskDefinition Model Enhancements:

    • Added association: belongs_to :tutorial_self_enrolment_stream
    • Implemented validation: self_enrolment_stream_unit_must_match
    • Added helper method: tutorial_self_enrolment_enabled?
    • Added method: available_tutorials_for_self_enrolment
  • TutorialStream Model Updates:

    • Added reverse association: has_many :self_enrolment_task_definitions
  • Comprehensive Testing: Model validation tests ensure data integrity

3. API Entity Exposure (Task 3)

  • TaskDefinitionEntity Updates:

    • Exposed tutorial_self_enrolment_enabled field
    • Exposed tutorial_self_enrolment_stream_id field
    • Exposed tutorial_self_enrolment_stream_abbr field with safe navigation
  • Frontend Integration: API entities provide necessary data for frontend implementation

  • Testing Coverage: API entity tests verify correct field exposure

4. Complete API Controller Implementation (Task 4)

  • New API Controller: StudentTutorialEnrolmentApi

    • POST /api/projects/:project_id/tutorial_enrolments - Create/update enrollment
    • GET /api/projects/:project_id/tutorial_enrolments - Check enrollment status
  • TaskDefinitionsApi Updates:

  • Added support for tutorial_self_enrolment_enabled parameter

  • Added support for tutorial_self_enrolment_stream_abbr parameter

  • Enhanced upload_requirements handling with improved JSON parsing

Authorization & Validation:

  • Student authorization checks
  • Task definition validation (self-enrollment enabled)
  • Tutorial availability validation
  • Capacity checks with graceful handling

Type of change

  • New feature (non-breaking change which adds functionality)
  • Enhancement (improves existing functionality without breaking changes)

How Has This Been Tested?

  • Comprehensive Test Suite

  • Model Tests (test/models/task_definition_test.rb, test/models/task_definition_self_enrolment_test.rb):

    • Valid self-enrollment configurations save successfully
    • Cross-unit validation prevents invalid stream assignments
    • Available tutorials filtering works correctly
    • Feature toggle behavior functions as expected
  • API Tests (test/api/student_tutorial_enrolment_api_test.rb, test/api/tasks_api_test.rb):

    • POST enrollment creates new tutorial enrollments
    • POST enrollment updates existing enrollments
    • Authorization prevents unauthorized access
    • Validation rejects disabled self-enrollment attempts
    • GET endpoint returns correct enrollment status
    • Entity exposure provides correct field values
  • Manual Testing

  • Database Migration: Successfully runs rails db:migrate with no conflicts

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation if appropriate
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have created or extended unit tests to address my new additions
  • New and existing unit tests pass locally with my changes

If you have any questions, please contact @macite or @jakerenzella.

Copy link

@gauravmyana2002 gauravmyana2002 left a comment

Choose a reason for hiding this comment

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

The code looks good and all the features are working.

Copy link

@nouri-devv nouri-devv left a comment

Choose a reason for hiding this comment

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

I ran this code and it looks good.

Copy link

@ibi420 ibi420 left a comment

Choose a reason for hiding this comment

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

Hey, looking through this, it looks good, the code is well implemented and works as expected. Good job on this

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.

4 participants