Adding files that are required for jupyterlab submit button extension…#7986
Adding files that are required for jupyterlab submit button extension…#7986TianshuLuan-UofT wants to merge 2 commits into
Conversation
…. Linked to pull request at MarkUsProject/markus-jupyter-extension#3
for more information, see https://pre-commit.ci
Coverage Report for CI Build 26897103316Coverage decreased (-0.2%) to 90.005%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
|
|
||
| require 'json' | ||
|
|
||
| module Api |
There was a problem hiding this comment.
About naming and organization:
- The new route and controller method should be under a new namespace. I suggest
app/controllers/jupyter/submissions_controller.rb, with a corresponding route under thejupyter(notapi). - I suggest calling the route
submitrather thancreate(though it can still be aPOSTaction).
| skip_verify_authorized only: :create | ||
|
|
||
| def create | ||
| payload = request.request_parameters.presence || params.to_unsafe_h |
| # Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin Ajax requests. | ||
|
|
||
| # Read more: https://github.com/cyu/rack-cors | ||
| # frozen_string_literal: true |
| # Add hosts running jupyterhub to the Settings.jupyter_server.hosts settings option. | ||
| origins(*Settings.jupyter_server.hosts) | ||
| resource %r{/api/courses/\d+/assignments/\d+/submit_file}, | ||
| origins 'http://localhost:8889', 'http://127.0.0.1:8889' |
There was a problem hiding this comment.
This should not be changed. Instead you can change the actual setting value, which is stored in settings.yml
| @@ -0,0 +1,102 @@ | |||
| # frozen_string_literal: true | |||
|
|
|||
| require 'tempfile' | |||
There was a problem hiding this comment.
This require is unnecessary (Tempfile is already loaded and accessible)
| 'Could not find or create a grouping for this student and assignment.' | ||
| end | ||
|
|
||
| def notebook_content_as_string(content) |
There was a problem hiding this comment.
This is unnecessary (and somewhat overly restrictive). Whatever file data is returned from JupyterHub should be streamed directly into a tempfile that's stored as a submitted file in MarkUs. No parsing is necessary, and in fact undesirable. In the future we may wish to allow other types of files to be submitted to MarkUs from JupyterHub.
|
|
||
| raise ArgumentError, 'Destination filename is missing.' if filename.blank? | ||
|
|
||
| unless filename.end_with?('.ipynb') |
There was a problem hiding this comment.
remove this check (see my above comment)
| # SubmissionsHelper#upload_file expects this helper method to exist. | ||
| # MainApiController has it, but this controller inherits from ApplicationController | ||
| # to avoid the MarkUs API permission layer for the local prototype. | ||
| def has_missing_params?(required_params) |
There was a problem hiding this comment.
Delete this method (see my above comment about not using upload_file
| end | ||
|
|
||
| def hub_user_uri | ||
| hub_origin = ENV.fetch('JUPYTERHUB_API_ORIGIN', nil).presence || @origin |
There was a problem hiding this comment.
Don't using an environment variable; instead, create a new setting (under the jupyter_server namespace)
| end | ||
|
|
||
| def normalize_origin(origin) | ||
| overridden = ENV.fetch('JUPYTER_FETCH_ORIGIN', nil) |
There was a problem hiding this comment.
See above comment (though right now I'm not sure why there are two different environment variables)
Linked to pull request at MarkUsProject/markus-jupyter-extension#3
Proposed Changes
Added necessary files for the JupyterLab extension (submit button) to work in the MarkUs server
Type of Change
(Write an
Xor a brief description next to the type or types that best describe your changes.)Checklist
(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the
[ ]into a[x]in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)Before opening your pull request:
After opening your pull request:
Questions and Comments
(Include any questions or comments you have regarding your changes.)