Skip to content

Commit

Permalink
Fix bug to get product family while on the admin pages
Browse files Browse the repository at this point in the history
In the admin pages, where there's no LTIUSer using any of the services
that are built differently per-product we need to set the product to
UNKNOWN to get the default behaviour
  • Loading branch information
marcospri committed Apr 8, 2024
1 parent b5e204a commit a7fc09a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lms/product/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
def get_product_from_request(request) -> Product:
"""Get the correct product object from the provided request."""

# pylint:disable=import-outside-toplevel
# pylint:disable=import-outside-toplevel,redefined-variable-type
from lms.product.blackboard import Blackboard
from lms.product.canvas import Canvas
from lms.product.d2l import D2L
from lms.product.moodle import Moodle

ai = request.lti_user.application_instance
family = Family(request.lti_user.lti.product_family)
family = Family.UNKNOWN
settings = {}
if request.lti_user:
ai = request.lti_user.application_instance
family = Family(request.lti_user.lti.product_family)
settings = ai.settings

product_class = {
product.family: product for product in (Blackboard, Canvas, D2L, Moodle)
}.get(family, Product)

product = product_class.from_request(request, dict(ai.settings))
product = product_class.from_request(request, dict(settings))
product.family = family
return product
7 changes: 7 additions & 0 deletions tests/unit/lms/product/factory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ def test_from_launch(self, pyramid_request, value, family, class_):

assert isinstance(product, class_)
assert product.family == family

def test_from_launch_with_no_lti_user(self, pyramid_request):
pyramid_request.lti_user = None

product = get_product_from_request(pyramid_request)

assert product.family == Product.Family.UNKNOWN

0 comments on commit a7fc09a

Please sign in to comment.