-
Notifications
You must be signed in to change notification settings - Fork 14
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
Refactor the canvas API factory to take parameters #6927
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,37 @@ | |
from lms.services.canvas_api._basic import BasicClient | ||
from lms.services.canvas_api._pages import CanvasPagesClient | ||
from lms.services.canvas_api.client import CanvasAPIClient | ||
from lms.services.file import file_service_factory | ||
from lms.services.oauth2_token import oauth2_token_service_factory | ||
|
||
|
||
def canvas_api_client_factory(_context, request): | ||
def canvas_api_client_factory( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take both AI and user_id as new optional parameters in the factory. |
||
_context, request, application_instance=None, user_id=None | ||
): | ||
""" | ||
Get a CanvasAPIClient from a pyramid request. | ||
|
||
:param request: Pyramid request object | ||
:return: An instance of CanvasAPIClient | ||
""" | ||
application_instance = request.lti_user.application_instance | ||
if application_instance and user_id: | ||
oauth2_token_service = oauth2_token_service_factory( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that oauth2_token_service_factory already uses this pattern, takes AI and user_id. |
||
_context, | ||
request, | ||
application_instance=application_instance, | ||
user_id=user_id, | ||
) | ||
file_service = file_service_factory(_context, request, application_instance) | ||
|
||
else: | ||
oauth2_token_service = request.find_service(name="oauth2_token") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By default, use the services from the factories without parameters. |
||
file_service = request.find_service(name="file") | ||
|
||
if not application_instance: | ||
application_instance = request.lti_user.application_instance | ||
|
||
if not user_id: | ||
user_id = request.lti_user.user_id | ||
|
||
developer_secret = application_instance.decrypted_developer_secret( | ||
request.find_service(AESService) | ||
|
@@ -22,13 +43,11 @@ def canvas_api_client_factory(_context, request): | |
|
||
authenticated_api = AuthenticatedClient( | ||
basic_client=basic_client, | ||
oauth2_token_service=request.find_service(name="oauth2_token"), | ||
oauth2_token_service=oauth2_token_service, | ||
client_id=application_instance.developer_key, | ||
client_secret=developer_secret, | ||
redirect_uri=request.route_url("canvas_api.oauth.callback"), | ||
) | ||
file_service = request.find_service(name="file") | ||
|
||
return CanvasAPIClient( | ||
authenticated_api, | ||
file_service=file_service, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,8 @@ def _file_search_query( # noqa: PLR0913 | |
return query | ||
|
||
|
||
def factory(_context, request): | ||
return FileService( | ||
application_instance=request.lti_user.application_instance, db=request.db | ||
) | ||
def file_service_factory(_context, request, application_instance=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Give this a better name to be imported in other modules. |
||
if application_instance is None: | ||
application_instance = request.lti_user.application_instance | ||
|
||
return FileService(application_instance=application_instance, db=request.db) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new name on
register_service_factory