Skip to content
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

feat: REST APIs (list/retrieve + learner-status) for DefaultEnterpriseEnrollmentIntention #2274

Merged
merged 8 commits into from
Oct 29, 2024

Conversation

adamstankiewicz
Copy link
Member

@adamstankiewicz adamstankiewicz commented Oct 25, 2024

Jira

CHANGELOG:

Introduces basic CRUD endpoints for the DefaultEnterpriseEnrollmentIntention model.

GET {LMS}/enterprise/api/v1/default-enterprise-enrollment-intentions/?enterprise_customer_uuid={enterprise_id}

Lists all DefaultEnterpriseEnrollmentIntentions for the specified enterprise customer.

{
    "next": null,
    "previous": null,
    "count": 1,
    "num_pages": 1,
    "current_page": 1,
    "start": 0,
    "results": [
        {
            "uuid": "2e1b323b-f8c5-4cee-b875-db0e3d964264",
            "content_key": "edX+DemoX",
            "enterprise_customer": "7ad8cdb9-352c-4b71-bcf1-3015103cca1f",
            "course_key": "edX+DemoX",
            "course_run_key": "course-v1:edX+DemoX+Demo_Course",
            "is_course_run_enrollable": true,
            "applicable_enterprise_catalog_uuids": [
                "1bc4dd08-2995-4952-a942-ba57efb5c378"
            ],
            "course_run_normalized_metadata": {
                "start_date": "2024-09-17T14:00:00Z",
                "end_date": "2025-09-15T22:30:00Z",
                "enroll_by_date": "2025-09-05T23:59:59Z",
                "enroll_start_date": "2024-08-17T14:00:00Z",
                "content_price": 49
            },
            "created": "2024-10-25T13:20:04.082376Z",
            "modified": "2024-10-25T15:08:18.161258Z"
        }
    ]
}

GET {LMS}/enterprise/api/v1/default-enterprise-enrollment-intentions/{intention_uuid}/?enterprise_customer_uuid={enterprise_id}

Retrieves a single instance of DefaultEnterpriseEnrollmentIntention.

{
    "uuid": "2e1b323b-f8c5-4cee-b875-db0e3d964264",
    "content_key": "edX+DemoX",
    "enterprise_customer": "7ad8cdb9-352c-4b71-bcf1-3015103cca1f",
    "course_key": "edX+DemoX",
    "course_run_key": "course-v1:edX+DemoX+Demo_Course",
    "is_course_run_enrollable": true,
    "applicable_enterprise_catalog_uuids": [
        "1bc4dd08-2995-4952-a942-ba57efb5c378"
    ],
    "course_run_normalized_metadata": {
        "start_date": "2024-09-17T14:00:00Z",
        "end_date": "2025-09-15T22:30:00Z",
        "enroll_by_date": "2025-09-05T23:59:59Z",
        "enroll_start_date": "2024-08-17T14:00:00Z",
        "content_price": 49
    },
    "created": "2024-10-25T13:20:04.082376Z",
    "modified": "2024-10-25T15:08:18.161258Z"
}

Introduces endpoint to retrieve DefaultEnterpriseEnrollmentIntentions for a given enterprise customer <> enterprise learner

GET {LMS}/enterprise/api/v1/default-enterprise-enrollment-intentions/learner-status/?enterprise_customer_uuid={enterprise_id}

Returns which enrollment intentions are already enrolled, needs enrollment (enrollable vs. not enrollable) by the request user (or, if staff, specific user as denoted by optional lms_user_id query parameter).

{
    "lms_user_id": 3,
    "user_email": "[email protected]",
    "enterprise_customer_uuid": "7ad8cdb9-352c-4b71-bcf1-3015103cca1f",
    "enrollment_statuses": {
        "needs_enrollment": {
            "enrollable": [
                {
                    "uuid": "2e1b323b-f8c5-4cee-b875-db0e3d964264",
                    "content_key": "edX+DemoX",
                    "enterprise_customer": "7ad8cdb9-352c-4b71-bcf1-3015103cca1f",
                    "course_key": "edX+DemoX",
                    "course_run_key": "course-v1:edX+DemoX+Demo_Course",
                    "is_course_run_enrollable": true,
                    "applicable_enterprise_catalog_uuids": [
                        "1bc4dd08-2995-4952-a942-ba57efb5c378"
                    ],
                    "course_run_normalized_metadata": {
                        "start_date": "2024-09-17T14:00:00Z",
                        "end_date": "2025-09-15T22:30:00Z",
                        "enroll_by_date": "2025-09-05T23:59:59Z",
                        "enroll_start_date": "2024-08-17T14:00:00Z",
                        "content_price": 49
                    },
                    "created": "2024-10-25T13:20:04.082376Z",
                    "modified": "2024-10-25T15:08:18.161258Z",
                    "has_existing_enrollment": false,
                    "is_existing_enrollment_active": null,
                    "is_existing_enrollment_audit": null
                }
            ],
            "not_enrollable": []
        },
        "already_enrolled": []
    },
    "metadata": {
        "total_default_enterprise_course_enrollments": 1,
        "total_needs_enrollment": {
            "enrollable": 1,
            "not_enrollable": 0
        },
        "total_already_enrolled": 0
    }
}

Merge checklist:

  • Any new requirements are in the right place (do not manually modify the requirements/*.txt files)
    • base.in if needed in production but edx-platform doesn't install it
    • test-master.in if edx-platform pins it, with a matching version
    • make upgrade && make requirements have been run to regenerate requirements
  • make static has been run to update webpack bundling if any static content was updated
  • ./manage.py makemigrations has been run
    • Checkout the Database Migration Confluence page for helpful tips on creating migrations.
    • Note: This must be run if you modified any models.
      • It may or may not make a migration depending on exactly what you modified, but it should still be run.
    • This should be run from either a venv with all the lms/edx-enterprise requirements installed or if you checked out edx-enterprise into the src directory used by lms, you can run this command through an lms shell.
      • It would be ./manage.py lms makemigrations in the shell.
  • Version bumped
  • Changelog record added
  • Translations updated (see docs/internationalization.rst but also this isn't blocking for merge atm)

Post merge:

  • Tag pushed and a new version released
    • Note: Assets will be added automatically. You just need to provide a tag (should match your version number) and title and description.
  • After versioned build finishes in GitHub Actions, verify version has been pushed to PyPI
    • Each step in the release build has a condition flag that checks if the rest of the steps are done and if so will deploy to PyPi.
      (so basically once your build finishes, after maybe a minute you should see the new version in PyPi automatically (on refresh))
  • PR created in edx-platform to upgrade dependencies (including edx-enterprise)
    • Trigger the 'Upgrade one Python dependency' action against master in edx-platform with new version number to generate version bump PR
    • This must be done after the version is visible in PyPi as make upgrade in edx-platform will look for the latest version in PyPi.
    • Note: the edx-enterprise constraint in edx-platform must also be bumped to the latest version in PyPi.

@adamstankiewicz adamstankiewicz marked this pull request as ready for review October 28, 2024 19:49
@adamstankiewicz adamstankiewicz changed the title feat: REST APIs (CRUD + learner-status) for default enterprise-enrollment intentions feat: REST APIs (list/retrieve + learner-status) for DefaultEnterpriseEnrollmentIntentions Oct 28, 2024
@adamstankiewicz adamstankiewicz changed the title feat: REST APIs (list/retrieve + learner-status) for DefaultEnterpriseEnrollmentIntentions feat: REST APIs (list/retrieve + learner-status) for DefaultEnterpriseEnrollmentIntention Oct 28, 2024
Copy link
Contributor

@iloveagent57 iloveagent57 left a comment

Choose a reason for hiding this comment

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

I'm about 30% done, enjoy these two tiny pieces of feedback! ;)

For list actions, some non-strict subset of this is what's returned by `get_queryset()`.
"""
kwargs = {}
if self.requested_enterprise_customer_uuid:
Copy link
Contributor

Choose a reason for hiding this comment

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

You made the requested_enterprise_customer_uuid property pretty defensive against false-iness, I think it's fine for this to be a one-liner:

return models.DefaultEnterpriseEnrollmentIntention.objects.filter(
    enterprise_customer=self.requested_enterprise_customer_uuid,
)


# Validate the user for learner status exists and is associated
# with the enterprise customer.
if not (user_for_learner_status := self.user_for_learner_status):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you could make self.user_for_learner_status a cached_property to avoid storing its value in a variable here.

Copy link
Member

@brobro10000 brobro10000 left a comment

Choose a reason for hiding this comment

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

Couple of nits, great job 👍🏽

enterprise/api/v1/views/default_enterprise_enrollments.py Outdated Show resolved Hide resolved
tests/test_enterprise/api/test_views.py Outdated Show resolved Hide resolved
Copy link
Contributor

@iloveagent57 iloveagent57 left a comment

Choose a reason for hiding this comment

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

This is great, I have a few more small suggestions, but it's ready to go.

tests/test_enterprise/api/test_views.py Outdated Show resolved Hide resolved
tests/test_enterprise/api/test_views.py Outdated Show resolved Hide resolved
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