Enable submit via API client
This commit is contained in:
@ -144,13 +144,12 @@ module Lti
|
|||||||
::NewRelic::Agent.add_custom_attributes({score: submission.normalized_score, session: session})
|
::NewRelic::Agent.add_custom_attributes({score: submission.normalized_score, session: session})
|
||||||
fail(Error, "Score #{submission.normalized_score} must be between 0 and #{MAXIMUM_SCORE}!") unless (0..MAXIMUM_SCORE).include?(submission.normalized_score)
|
fail(Error, "Score #{submission.normalized_score} must be between 0 and #{MAXIMUM_SCORE}!") unless (0..MAXIMUM_SCORE).include?(submission.normalized_score)
|
||||||
|
|
||||||
if session[:consumer_id]
|
if submission.user.consumer
|
||||||
lti_parameter = LtiParameter.where(consumers_id: session[:consumer_id],
|
lti_parameter = LtiParameter.where(consumers_id: submission.user.consumer.id,
|
||||||
external_users_id: submission.user_id,
|
external_users_id: submission.user_id,
|
||||||
exercises_id: submission.exercise_id).last
|
exercises_id: submission.exercise_id).last
|
||||||
|
|
||||||
consumer = Consumer.find_by(id: session[:consumer_id])
|
provider = build_tool_provider(consumer: submission.user.consumer, parameters: lti_parameter.lti_parameters)
|
||||||
provider = build_tool_provider(consumer: consumer, parameters: lti_parameter.lti_parameters)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if provider.nil?
|
if provider.nil?
|
||||||
|
@ -1,15 +1,55 @@
|
|||||||
class RemoteEvaluationController < ApplicationController
|
class RemoteEvaluationController < ApplicationController
|
||||||
include RemoteEvaluationParameters
|
include RemoteEvaluationParameters
|
||||||
include SubmissionScoring
|
include SubmissionScoring
|
||||||
|
include Lti
|
||||||
|
|
||||||
skip_after_action :verify_authorized
|
skip_after_action :verify_authorized
|
||||||
skip_before_action :verify_authenticity_token
|
skip_before_action :verify_authenticity_token
|
||||||
|
|
||||||
# POST /evaluate
|
# POST /evaluate
|
||||||
# @param validation_token
|
|
||||||
# @param files_attributes
|
|
||||||
def evaluate
|
def evaluate
|
||||||
|
result = create_and_score_submission("remoteAssess")
|
||||||
|
status = if result.is_a?(Hash) && result.has_key?(:status)
|
||||||
|
result[:status]
|
||||||
|
else
|
||||||
|
201
|
||||||
|
end
|
||||||
|
render json: result, status: status
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /submit
|
||||||
|
def submit
|
||||||
|
result = create_and_score_submission("remoteSubmit")
|
||||||
|
|
||||||
|
if @submission.present?
|
||||||
|
current_user = @submission.user
|
||||||
|
if !current_user.nil? && lti_outcome_service?(@submission.exercise_id, current_user.id, current_user.consumer_id)
|
||||||
|
lti_response = send_score(@submission)
|
||||||
|
|
||||||
|
if lti_response[:status] == 'success' and lti_response[:score_sent] != @submission.normalized_score
|
||||||
|
# Score has been reduced due to the passed deadline
|
||||||
|
result = {message: I18n.t('exercises.submit.too_late'), status: 207}
|
||||||
|
elsif lti_response[:status] == 'success'
|
||||||
|
result = {message: I18n.t('sessions.destroy_through_lti.success_with_outcome', consumer: @submission.user.consumer.name), status: 202}
|
||||||
|
else
|
||||||
|
result = {message: I18n.t('exercises.submit.failure'), status: 424}
|
||||||
|
end
|
||||||
|
# ToDo: Delete LTI parameters?
|
||||||
|
else
|
||||||
|
result = {message: "Your submission was successfully scored with #{@submission.normalized_score * 100}%. However, your score could not be sent to the e-Learning platform. Please reopen the exercise through the e-Learning platform and try again.", status: 410}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
status = if result.is_a?(Hash) && result.has_key?(:status)
|
||||||
|
result[:status]
|
||||||
|
else
|
||||||
|
201
|
||||||
|
end
|
||||||
|
|
||||||
|
render json: result, status: status
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_and_score_submission cause
|
||||||
validation_token = remote_evaluation_params[:validation_token]
|
validation_token = remote_evaluation_params[:validation_token]
|
||||||
files_attributes = remote_evaluation_params[:files_attributes] || []
|
files_attributes = remote_evaluation_params[:files_attributes] || []
|
||||||
|
|
||||||
@ -19,15 +59,16 @@ class RemoteEvaluationController < ApplicationController
|
|||||||
_params = remote_evaluation_params.except(:validation_token)
|
_params = remote_evaluation_params.except(:validation_token)
|
||||||
_params[:exercise_id] = remote_evaluation_mapping.exercise_id
|
_params[:exercise_id] = remote_evaluation_mapping.exercise_id
|
||||||
_params[:user_id] = remote_evaluation_mapping.user_id
|
_params[:user_id] = remote_evaluation_mapping.user_id
|
||||||
_params[:cause] = "remoteAssess"
|
_params[:cause] = cause
|
||||||
_params[:user_type] = remote_evaluation_mapping.user_type
|
_params[:user_type] = remote_evaluation_mapping.user_type
|
||||||
|
|
||||||
@submission = Submission.create(_params)
|
@submission = Submission.create(_params)
|
||||||
render json: score_submission(@submission)
|
score_submission(@submission)
|
||||||
else
|
else
|
||||||
# todo: better output
|
# todo: better output
|
||||||
# todo: check token expired?
|
# todo: check token expired?
|
||||||
render json: "No exercise found for this validation_token! Please keep out!"
|
{message: "No exercise found for this validation_token! Please keep out!", status: 401}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
private :create_and_score_submission
|
||||||
end
|
end
|
@ -3,7 +3,7 @@ class Submission < ApplicationRecord
|
|||||||
include Creation
|
include Creation
|
||||||
include ActionCableHelper
|
include ActionCableHelper
|
||||||
|
|
||||||
CAUSES = %w(assess download file render run save submit test autosave requestComments remoteAssess)
|
CAUSES = %w(assess download file render run save submit test autosave requestComments remoteAssess remoteSubmit)
|
||||||
FILENAME_URL_PLACEHOLDER = '{filename}'
|
FILENAME_URL_PLACEHOLDER = '{filename}'
|
||||||
MAX_COMMENTS_ON_RECOMMENDED_RFC = 5
|
MAX_COMMENTS_ON_RECOMMENDED_RFC = 5
|
||||||
OLDEST_RFC_TO_SHOW = 6.months
|
OLDEST_RFC_TO_SHOW = 6.months
|
||||||
|
@ -157,6 +157,7 @@ Rails.application.routes.draw do
|
|||||||
resources :events, only: [:create]
|
resources :events, only: [:create]
|
||||||
|
|
||||||
post "/evaluate", to: 'remote_evaluation#evaluate', via: [:post]
|
post "/evaluate", to: 'remote_evaluation#evaluate', via: [:post]
|
||||||
|
post "/submit", to: 'remote_evaluation#submit', via: [:post]
|
||||||
|
|
||||||
mount ActionCable.server => '/cable'
|
mount ActionCable.server => '/cable'
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user