Skip to content

Conversation

@iloveagent57
Copy link
Contributor

@iloveagent57 iloveagent57 commented Jul 14, 2025

ENT-10629

you'll need to set ENABLE_CUSTOMER_BILLING_API = True in your settings/private.py file to use this locally.

Description:
Adds a skeleton context BFF view to support checkout contexts. Adds, but does not yet utilize, serializers for the expected response structure.

curl --location --request POST 'http://localhost:18270/api/v1/bffs/checkout/context/'

Merge checklist:

  • ./manage.py makemigrations has been run
    • 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.

Post merge:

  • Ensure that your changes went out to the stage instance
  • Deploy to prod instance

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jul 14, 2025
@openedx-webhooks
Copy link

openedx-webhooks commented Jul 14, 2025

Thanks for the pull request, @iloveagent57!

This repository is currently maintained by @openedx/2u-enterprise.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Jul 14, 2025
@iloveagent57 iloveagent57 marked this pull request as ready for review July 14, 2025 19:09
Comment on lines +61 to +82
# Eventually we'll use the BFF pattern to load and process data
# context_data, status_code = self.load_route_data_and_build_response(
# request,
# CheckoutContextHandler,
# CheckoutContextResponseBuilder
# )
Copy link
Contributor

Choose a reason for hiding this comment

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

[Note] I wonder if request.user works with this BaseUnauthenticatedBFFViewSet? I think the answer is yes, but just wanted to note that subsequent PRs to actually implement this skeleton will depend on request.user getting set to the logged-in User in order to successfully extract lms_user_id to help calculate existing_customers_for_authenticated_user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Django gives us anonymous users out of the box, here's a breakpoint on an un-auth'd request:

(Pdb) request.user
<django.contrib.auth.models.AnonymousUser object at 0xf040653af920>
(Pdb) request.user.is_authenticated
False

Copy link
Contributor

@pwnage101 pwnage101 Jul 14, 2025

Choose a reason for hiding this comment

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

Gotcha, I wonder if setting viewset auth vars like this would help:

  • authentication_classes = [JwtAuthentication]
  • permission_classes = [IsAuthenticated, AllowAny]

The idea is that unauthenticated requests would fail JwtAuthentication and get request.user = AnonymousUser but pass AllowAny permmission check, while authenticated requests would go through both JwtAuthentication -> IsAuthenticated.

Testing...

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh you only tested un-authed, so it might still work out of the box for authenticated users...I think we can address this in a separate PR.

Copy link
Contributor

@pwnage101 pwnage101 Jul 14, 2025

Choose a reason for hiding this comment

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

After local testing, it doesn't seem to work out of the box, but like I said I think we can address in a separate PR more specific to the BFF framework code.

I suspect that leveraging permission composability from DRF 3.9+ (we run 3.16 today) would make the solution quite simple with the | operator:

authentication_classes = [JwtAuthentication]
permission_classes = [IsAuthenticated | AllowAny]

But this currently breaks internal logic within edx_rest_framework_extensions:

  File "/Users/tsankey/.pyenv/versions/3.12.4/envs/enterprise-access/lib/python3.12/site-packages/edx_rest_framework_extensions/auth/jwt/middleware.py", line 333, in <genexpr>
    issubclass(current_class, base_class) for current_class in iter_classes
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: issubclass() arg 1 must be a class

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines 62 to 70
class FieldConstraintsSerializer(serializers.Serializer):
"""
Serializer for field constraints in checkout context.
"""
quantity = QuantityConstraintSerializer(help_text="Constraints for license quantity")
enterprise_slug = SlugConstraintSerializer(help_text="Constraints for enterprise slug")
Copy link
Contributor

@pwnage101 pwnage101 Jul 14, 2025

Choose a reason for hiding this comment

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

Can you add a TODO to the docstring here to suggest that the implementer should expand the field constraints to more closely match the mins/maxes within this code block: https://github.com/edx/frontend-app-enterprise-checkout/blob/main/src/constants.ts#L13-L39

Copy link
Contributor

@pwnage101 pwnage101 left a comment

Choose a reason for hiding this comment

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

Just a minor question and docstring suggestion---mostly stuff we can handle in subsequent PRs.

@iloveagent57 iloveagent57 force-pushed the aed/ssp-context-endpoint branch 2 times, most recently from e1c5c6b to 573e4a8 Compare July 14, 2025 20:33
@iloveagent57 iloveagent57 enabled auto-merge (rebase) July 14, 2025 20:35
@iloveagent57 iloveagent57 force-pushed the aed/ssp-context-endpoint branch from 579e6b3 to c3d72e9 Compare July 15, 2025 15:38
@iloveagent57 iloveagent57 merged commit 0c9adc8 into main Jul 15, 2025
4 checks passed
@iloveagent57 iloveagent57 deleted the aed/ssp-context-endpoint branch July 15, 2025 18:24
@github-project-automation github-project-automation bot moved this from Needs Triage to Done in Contributions Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants