Implement support for some basic embed options for work sheets via LTI
This commit also fixes an issue with the flash messages being positioned too high and displayed for too long
This commit is contained in:
@@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base
|
||||
MEMBER_ACTIONS = [:destroy, :edit, :show, :update]
|
||||
|
||||
after_action :verify_authorized, except: [:help, :welcome]
|
||||
before_action :set_locale, :allow_iframe_requests
|
||||
before_action :set_locale, :allow_iframe_requests, :load_embed_options
|
||||
protect_from_forgery(with: :exception, prepend: true)
|
||||
rescue_from Pundit::NotAuthorizedError, with: :render_not_authorized
|
||||
|
||||
@@ -38,4 +38,14 @@ class ApplicationController < ActionController::Base
|
||||
def allow_iframe_requests
|
||||
response.headers.delete('X-Frame-Options')
|
||||
end
|
||||
|
||||
def load_embed_options
|
||||
if session[:embed_options].present? && session[:embed_options].is_a?(Hash)
|
||||
@embed_options = session[:embed_options].symbolize_keys
|
||||
else
|
||||
@embed_options = {}
|
||||
end
|
||||
@embed_options
|
||||
end
|
||||
private :load_embed_options
|
||||
end
|
||||
|
@@ -22,6 +22,7 @@ module Lti
|
||||
if (exercise_id.nil?)
|
||||
session.delete(:consumer_id)
|
||||
session.delete(:external_user_id)
|
||||
session.delete(:embed_options)
|
||||
else
|
||||
LtiParameter.where(consumers_id: consumer_id,
|
||||
external_users_id: user_id,
|
||||
@@ -133,6 +134,26 @@ module Lti
|
||||
end
|
||||
private :set_current_user
|
||||
|
||||
def set_embedding_options
|
||||
@embed_options = {}
|
||||
[:hide_navbar,
|
||||
:hide_exercise_description,
|
||||
:disable_run,
|
||||
:disable_score,
|
||||
:disable_rfc,
|
||||
:disable_interventions,
|
||||
:hide_sidebar,
|
||||
:read_only,
|
||||
:hide_test_results,
|
||||
:disable_hints].each do |option|
|
||||
value = params["custom_embed_options_#{option}".to_sym] == 'true'
|
||||
# Optimize storage and save only those that are true, the session cookie is limited to 4KB
|
||||
@embed_options[option] = value if value.present?
|
||||
end
|
||||
session[:embed_options] = @embed_options
|
||||
end
|
||||
private :set_embedding_options
|
||||
|
||||
def store_lti_session_data(options = {})
|
||||
lti_parameters = LtiParameter.find_or_create_by(consumers_id: options[:consumer].id,
|
||||
external_users_id: @current_user.id,
|
||||
|
@@ -55,6 +55,11 @@ module SubmissionScoring
|
||||
}
|
||||
end
|
||||
end
|
||||
if @embed_options.present? && @embed_options[:hide_test_results] && outputs.present?
|
||||
outputs.each do |output|
|
||||
output.except!(:error_messages, :count, :failed, :filename, :message, :passed, :stderr, :stdout)
|
||||
end
|
||||
end
|
||||
outputs
|
||||
end
|
||||
end
|
||||
|
@@ -188,7 +188,15 @@ class ExercisesController < ApplicationController
|
||||
user_got_intervention_in_exercise = UserExerciseIntervention.where(user: current_user, exercise: @exercise).size >= max_intervention_count_per_exercise
|
||||
user_got_enough_interventions = count_interventions_today >= max_intervention_count_per_day or user_got_intervention_in_exercise
|
||||
|
||||
@show_rfc_interventions = (not user_solved_exercise and not user_got_enough_interventions).to_s
|
||||
unless @embed_options[:disable_interventions]
|
||||
@show_rfc_interventions = (not user_solved_exercise and not user_got_enough_interventions).to_s
|
||||
@show_break_interventions = false
|
||||
else
|
||||
@show_rfc_interventions = false
|
||||
@show_break_interventions = false
|
||||
end
|
||||
|
||||
@hide_rfc_button = @embed_options[:disable_rfc]
|
||||
|
||||
|
||||
@search = Search.new
|
||||
|
@@ -8,7 +8,7 @@ class FlowrController < ApplicationController
|
||||
.order('testruns.created_at DESC').first
|
||||
|
||||
# Return if no submission was found
|
||||
if submission.blank?
|
||||
if submission.blank? || @embed_options[:disable_hints] || @embed_options[:hide_test_results]
|
||||
skip_authorization
|
||||
render json: [], status: :ok
|
||||
return
|
||||
|
@@ -96,6 +96,10 @@ class RequestForCommentsController < ApplicationController
|
||||
# POST /request_for_comments
|
||||
# POST /request_for_comments.json
|
||||
def create
|
||||
# Consider all requests as JSON
|
||||
request.format = 'json'
|
||||
raise Pundit::NotAuthorizedError if @embed_options[:disable_rfc]
|
||||
|
||||
@request_for_comment = RequestForComment.new(request_for_comment_params)
|
||||
respond_to do |format|
|
||||
if @request_for_comment.save
|
||||
|
@@ -1,7 +1,7 @@
|
||||
class SessionsController < ApplicationController
|
||||
include Lti
|
||||
|
||||
[:require_oauth_parameters, :require_valid_consumer_key, :require_valid_oauth_signature, :require_unique_oauth_nonce, :set_current_user, :require_valid_exercise_token].each do |method_name|
|
||||
[:require_oauth_parameters, :require_valid_consumer_key, :require_valid_oauth_signature, :require_unique_oauth_nonce, :set_current_user, :require_valid_exercise_token, :set_embedding_options].each do |method_name|
|
||||
before_action(method_name, only: :create_through_lti)
|
||||
end
|
||||
|
||||
|
@@ -129,6 +129,11 @@ class SubmissionsController < ApplicationController
|
||||
# end
|
||||
|
||||
hijack do |tubesock|
|
||||
if @embed_options[:disable_run]
|
||||
kill_socket(tubesock)
|
||||
return
|
||||
end
|
||||
|
||||
# probably add:
|
||||
# ensure
|
||||
# #guarantee that the thread is releasing the DB connection after it is done
|
||||
@@ -291,6 +296,11 @@ class SubmissionsController < ApplicationController
|
||||
|
||||
def score
|
||||
hijack do |tubesock|
|
||||
if @embed_options[:disable_score]
|
||||
kill_socket(tubesock)
|
||||
return
|
||||
end
|
||||
|
||||
Thread.new { EventMachine.run } unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive?
|
||||
# tubesock is the socket to the client
|
||||
|
||||
@@ -308,6 +318,7 @@ class SubmissionsController < ApplicationController
|
||||
end
|
||||
|
||||
def send_hints(tubesock, errors)
|
||||
return if @embed_options[:disable_hints]
|
||||
errors = errors.to_a.uniq { |e| e.hint}
|
||||
errors.each do | error |
|
||||
tubesock.send_data JSON.dump({cmd: 'hint', hint: error.hint, description: error.error_template.description})
|
||||
|
Reference in New Issue
Block a user