Skip to content
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

Merge Numbas Integration feature into 8.0.x #443

Merged
merged 130 commits into from
Aug 9, 2024
Merged

Conversation

satikaj
Copy link
Contributor

@satikaj satikaj commented Jul 3, 2024

Description

This pull request contains the Numbas (SCORM) API and related backend changes.

Summary of key features:

  • Launch Numbas (SCORM 2004) tests
  • Upload test zip file for task and configure related properties (attempt limit, review, etc.)
  • Save and resume tests
  • Review completed attempts
  • Override attempt pass status
  • Delete attempts
  • Request more attempts if none left
  • Prevent file upload if test not passed

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Corresponding unit tests have been added.

  • scorm_api_test.rb [new]
  • test_attempts_test.rb [new]
  • scorm_extension_test.rb [new]
  • task_definitions_api_test.rb [+]
  • auth_test.rb [+]

In order to test the full feature set (e.g. answering and saving tests), the frontend must be used with the related doubtfire-web/add-numbas-integration changes. Make sure to disable browser web security or CORS for the test viewing functionality to work.

Login as convenor to configure tests and manage test attempts. Login as student to launch and view tests and make test attempts.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation if appropriate
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have created or extended unit tests to address my new additions
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

This is ready for review, @macite @maddernd

maddernd and others added 30 commits June 24, 2024 21:55
first commit containing endpoints and DB changes

new faeture
first commit containing endpoints and DB changes

new faeture
- Implement methods in task_definition model for numbas data management
- Implement routes in task_definition_api for numbas data managemnt
- Remove unused upload API in numbas_api
Copy link
Member

@macite macite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good - just a few things for us to work on...

error!({ error: 'You cannot get SCORM tokens' }, 403)
end

token = current_user.auth_tokens.find_by(token_type: 'scorm')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What can a scorm token access? It looks like there is not scope applied to these at the moment... where are they used in the auth process?

params do
requires :task_def_id, type: Integer, desc: 'Task Definition ID to get SCORM test data for'
end
get '/scorm/:task_def_id/:username/:auth_token/*file_path' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should any of the api calls here be limited to scorm tokens?

app/api/entities/scorm_entity.rb Outdated Show resolved Hide resolved
@@ -0,0 +1,5 @@
class AddAuthTokenType < ActiveRecord::Migration[7.1]
def change
add_column :auth_tokens, :token_type, :string, null: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a default here - null is not allowed... so all current tokens should have what value?

"cmi.learner_name": learner_name,
"cmi.learner_id": learner_id
}
self.cmi_datamodel = init_state.to_json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can change this to use the serialize :cmi_datamodel, coder: JSON

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See task definition

end

def review
dm = JSON.parse(self.cmi_datamodel)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serializer can do this JSON.parse


# when review is requested change the mode to review
dm['cmi.mode'] = 'review'
self[:cmi_datamodel] = dm.to_json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serializer can do this to_json

end

def override_success_status(new_success_status)
dm = JSON.parse(self.cmi_datamodel)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serializer can do this JSON.parse

def override_success_status(new_success_status)
dm = JSON.parse(self.cmi_datamodel)
dm['cmi.success_status'] = (new_success_status ? 'passed' : 'failed')
self[:cmi_datamodel] = dm.to_json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_json


# Add a scorm extension to the task
def grant_scorm_extension(by_user)
if update(scorm_extensions: self.scorm_extensions + task_definition.scorm_attempt_limit)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just return response from update


if task_definition.scorm_attempt_limit == 0
error!({ message: 'This task allows unlimited attempts to complete the test' }, 400)
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error! throws an exception - so this is unreachable... we should look and remove these unnecessary return statements

end

# Handle common exceptions
rescue_from :all do |e|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are handled by the API at the moment... so we should be able to remove these

@macite macite merged commit 8059213 into doubtfire-lms:8.0.x Aug 9, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants