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 5 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)
| @@ -0,0 +1,334 @@ | |||
| # frozen_string_literal: true | |||
There was a problem hiding this comment.
Delete this file (as you've created a new file, app/controllers/jupyter/jupyter_submissions_controller.rb)
| def username | ||
| # Local development fallback only. | ||
| # This allows standalone JupyterLab testing where there is no JupyterHub identity endpoint. | ||
| <<<<<<< HEAD |
There was a problem hiding this comment.
These markers indicate a merge conflict that needs to be resolved
| user = find_user_from_jupyter_token!(jupyter_info) | ||
| course = find_course_from_payload!(payload) | ||
|
|
||
| student = course.roles.find_by(user_id: user.id) |
There was a problem hiding this comment.
Use course.students here to query only students
|
|
||
| module Jupyter | ||
| class SubmissionsController < ApplicationController | ||
| # Local prototype only. |
There was a problem hiding this comment.
I think this comment needs to be updated, and verify_authenticity_token only applies to Api controller methods, so won't apply here
| jupyter_path = payload['notebook_path'] | ||
|
|
||
| destination_path = sanitize_destination_path( | ||
| payload['destination_path'].presence || |
There was a problem hiding this comment.
I think there are still more options than necessary. I want to keep things slim here; please just make notebook_path required and derive the filename from that, rather than also including destination_path and notebook_name
| end | ||
| end | ||
|
|
||
| # TODO: |
There was a problem hiding this comment.
Flagging this TODO as something that still is pending
|
|
||
| uri = contents_uri | ||
|
|
||
| Rails.logger.info("[JupyterNotebookFetcher] origin=#{@origin}") |
There was a problem hiding this comment.
Delete this logging statements
| def submit | ||
| payload = params | ||
|
|
||
| jupyter_info = payload['jupyter'] || {} |
There was a problem hiding this comment.
The JupyterNotebookFetcher and JupyterIdentityFetcher are both doing the same URL normalization and validation checks. Rather than repeat them in those services, process jupyter_info here and report an error if there are issues.
| end | ||
|
|
||
| def normalize_origin(origin) | ||
| # Browser/Jupyter may report origin as http://localhost:8889. |
There was a problem hiding this comment.
This adds more complication than I think is warranted (including the environment variable).
Instead, when testing this functionality you should be able to use a domain of http://host.docker.internal:3000 directly to access MarkUs (instead of localhost:3000). Unless I'm missing something about what this is referring to?
|
|
||
| # Writes a fetched Jupyter file into the student's MarkUs repository using the | ||
| # same helper methods used by the normal MarkUs web submission flow. | ||
| class JupyterSubmissionWriter |
There was a problem hiding this comment.
Is this class still being used? If not please delete the file
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.)