-
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
base: main
Are you sure you want to change the base?
Conversation
67d4fec
to
263e0d3
Compare
@@ -106,7 +106,9 @@ def includeme(config): # noqa: PLR0915 | |||
config.register_service_factory( | |||
"lms.services.grouping.service_factory", name="grouping" | |||
) | |||
config.register_service_factory("lms.services.file.factory", name="file") | |||
config.register_service_factory( |
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
|
||
|
||
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 comment
The 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.
""" | ||
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 comment
The 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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
By default, use the services from the factories without parameters.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Give this a better name to be imported in other modules.
263e0d3
to
ab978f7
Compare
Take application_instance and user_id on the Canvas API factory to allow creating a service for arbitrary users instead of just the one of the current request. The same modification is also made to the file service as it is a dependency of the Canvas service.
6a7bf82
to
00ee5b6
Compare
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.
LGTM
Take application_instance and user_id on the Canvas API factory
to allow creating a service for arbitrary users instead of just the one
of the current request.
The same modification is also made to the file service
as it is a dependency of the Canvas service.
Motivation
This will allow us to use the Canvas API to fetch sections rosters outside the request cycle, using any application instance we need.
Testing
https://hypothesis.instructure.com/courses/125/assignments/875