redirect to RFCs on max score: redirect users to their own RFCs if they are open, fixed wrong usage of user_id (external_id is not used in RFCs, normal id has to be used!).

This commit is contained in:
Ralf Teusner
2016-11-09 17:58:10 +01:00
parent e8f93cb870
commit ff7446fde6
4 changed files with 26 additions and 12 deletions

View File

@ -247,23 +247,34 @@ class ExercisesController < ApplicationController
end end
def redirect_after_submit def redirect_after_submit
Rails.logger.debug('Score ' + @submission.normalized_score.to_s) Rails.logger.debug('Redirecting user with score:s ' + @submission.normalized_score.to_s)
if @submission.normalized_score == 1.0 if @submission.normalized_score == 1.0
# if user has an own rfc, redirect to it and message him to clean up and accept the answer. # if user is external and has an own rfc, redirect to it and message him to clean up and accept the answer. (we need to check that the user is external,
# otherwise an internal user could be shown a false rfc here, since current_user.id is polymorphic, but only makes sense for external users when used with rfcs.)
if current_user.respond_to? :external_id
if rfc = RequestForComment.unsolved.where(exercise_id: @submission.exercise, user_id: current_user.id).first
# set a message that informs the user that his own RFC should be closed.
flash[:notice] = I18n.t('exercises.submit.full_score_redirect_to_own_rfc')
flash.keep(:notice)
# else: show open rfc for same exercise respond_to do |format|
if rfc = RequestForComment.unsolved.where(exercise_id: @submission.exercise).order("RANDOM()").first format.html { redirect_to(rfc) }
format.json { render(json: {redirect: url_for(rfc)}) }
end
return
# set a message that informs the user that his score was perfect and help in RFC is greatly appreciated. # else: show open rfc for same exercise if available
flash[:notice] = I18n.t('exercises.submit.full_score_redirect_to_rfc') elsif rfc = RequestForComment.unsolved.where(exercise_id: @submission.exercise).order("RANDOM()").first
flash.keep(:notice) # set a message that informs the user that his score was perfect and help in RFC is greatly appreciated.
flash[:notice] = I18n.t('exercises.submit.full_score_redirect_to_rfc')
flash.keep(:notice)
respond_to do |format| respond_to do |format|
format.html { redirect_to(rfc) } format.html { redirect_to(rfc) }
format.json { render(json: {redirect: url_for(rfc)}) } format.json { render(json: {redirect: url_for(rfc)}) }
end
return
end end
return
end end
end end
redirect_to_lti_return_path redirect_to_lti_return_path

View File

@ -82,6 +82,7 @@ class RequestForCommentsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def request_for_comment_params def request_for_comment_params
# we are using the current_user.id here, since internal users are not able to create comments. The external_user.id is a primary key and does not require the consumer_id to be unique.
params.require(:request_for_comment).permit(:exercise_id, :file_id, :question, :requested_at, :solved, :submission_id).merge(user_id: current_user.id, user_type: current_user.class.name) params.require(:request_for_comment).permit(:exercise_id, :file_id, :question, :requested_at, :solved, :submission_id).merge(user_id: current_user.id, user_type: current_user.class.name)
end end
end end

View File

@ -274,6 +274,7 @@ de:
submit: submit:
failure: Beim Übermitteln Ihrer Punktzahl ist ein Fehler aufgetreten. Bitte versuchen Sie es später erneut. failure: Beim Übermitteln Ihrer Punktzahl ist ein Fehler aufgetreten. Bitte versuchen Sie es später erneut.
full_score_redirect_to_rfc: Herzlichen Glückwunsch! Sie haben die maximale Punktzahl für diese Aufgabe an den Kurs übertragen. Ein anderer Teilnehmer hat eine Frage zu der von Ihnen gelösten Aufgabe. Er würde sich sicherlich sehr über ihre Hilfe und Kommentare freuen. full_score_redirect_to_rfc: Herzlichen Glückwunsch! Sie haben die maximale Punktzahl für diese Aufgabe an den Kurs übertragen. Ein anderer Teilnehmer hat eine Frage zu der von Ihnen gelösten Aufgabe. Er würde sich sicherlich sehr über ihre Hilfe und Kommentare freuen.
full_score_redirect_to_own_rfc: Herzlichen Glückwunsch! Sie haben die maximale Punktzahl für diese Aufgabe an den Kurs übertragen. Ihre Frage ist damit wahrscheinlich gelöst? Falls ja, fügen Sie doch den entscheidenden Kniff als Antwort hinzu und markieren die Frage als gelöst, bevor sie das Fenster schließen.
external_users: external_users:
statistics: statistics:
no_data_available: Keine Daten verfügbar. no_data_available: Keine Daten verfügbar.

View File

@ -274,6 +274,7 @@ en:
submit: submit:
failure: An error occured while transmitting your score. Please try again later. failure: An error occured while transmitting your score. Please try again later.
full_score_redirect_to_rfc: Congratulations! You achieved and submitted the highest possible score for this exercise. Another participant has a question concerning the exercise you just solved. Your help and comments will be greatly appreciated! full_score_redirect_to_rfc: Congratulations! You achieved and submitted the highest possible score for this exercise. Another participant has a question concerning the exercise you just solved. Your help and comments will be greatly appreciated!
full_score_redirect_to_own_rfc: Congratulations! You achieved and submitted the highest possible score for this exercise. Your question concerning the exercise is solved? If so, please share the essential insight with your fellows and mark the question as solved, before you close this window!
external_users: external_users:
statistics: statistics:
no_data_available: No data available. no_data_available: No data available.