-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include sync_grade in the generic LTIGrading interface
This allows us to use the generic service in the grading task instead of manually instantiating the LTI1.3 version. We still can't use `find_service` to create the service as the celery task placeholder request is not scoped to any application instance. Added a new parameter to the factory to explicitly pass an application instance to base the LTI version decision on. This commit doesn't implement sync_grade on LTI1.1 yet.
- Loading branch information
Showing
7 changed files
with
97 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,48 @@ | ||
from lms.services.lti_grading._v11 import LTI11GradingService | ||
from lms.services.lti_grading._v13 import LTI13GradingService | ||
from lms.services.lti_grading.interface import LTIGradingService | ||
from lms.services.ltia_http import LTIAHTTPService | ||
|
||
|
||
def service_factory(_context, request): | ||
application_instance = request.lti_user.application_instance | ||
def service_factory(_context, request, application_instance=None) -> LTIGradingService: | ||
"""Create a new LTIGradingService. | ||
if application_instance.lti_version == "1.3.0": | ||
When called via pyramid services (ie request.find_service) the LTI version is selected | ||
depending on the current request's application_instance. | ||
For other uses cases (e.g. from a Celery task) the passed application_instance will be used instead. | ||
""" | ||
|
||
if not application_instance: | ||
application_instance = request.lti_user.application_instance | ||
|
||
lti_version = application_instance.lti_version | ||
lis_outcome_service_url = _get_lis_outcome_service_url(request) | ||
|
||
if lti_version == "1.3.0": | ||
return LTI13GradingService( | ||
# Pick the value from the right dictionary depending on the context we are running | ||
# either an API call from the frontend (parsed_params) or inside an LTI launch (lti_params). | ||
line_item_url=request.parsed_params.get("lis_outcome_service_url") | ||
or request.lti_params.get("lis_outcome_service_url"), | ||
line_item_url=lis_outcome_service_url, | ||
line_item_container_url=request.lti_params.get("lineitems"), | ||
ltia_service=request.find_service(LTIAHTTPService), | ||
product_family=request.product.family, | ||
misc_plugin=request.product.plugin.misc, | ||
lti_registration=request.lti_user.application_instance.lti_registration, | ||
lti_registration=application_instance.lti_registration, | ||
) | ||
|
||
return LTI11GradingService( | ||
line_item_url=request.parsed_params.get("lis_outcome_service_url"), | ||
line_item_url=lis_outcome_service_url, | ||
http_service=request.find_service(name="http"), | ||
oauth1_service=request.find_service(name="oauth1"), | ||
application_instance=request.lti_user.application_instance, | ||
) | ||
|
||
|
||
def _get_lis_outcome_service_url(request) -> str | None: | ||
# Pick the value from the right dictionary depending on the context we are running | ||
# either an API call from the frontend (parsed_params) or inside an LTI launch (lti_params). | ||
if hasattr(request, "parsed_params") and ( | ||
lis_outcome_service_url := request.parsed_params.get("lis_outcome_service_url") | ||
): | ||
return lis_outcome_service_url | ||
|
||
return request.lti_params.get("lis_outcome_service_url") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters