Reduce usage of @current_user (use helper instead)
This commit is contained in:
@ -108,7 +108,7 @@ module Lti
|
|||||||
@exercise = if proxy_exercise.nil?
|
@exercise = if proxy_exercise.nil?
|
||||||
Exercise.find_by(token: params[:custom_token])
|
Exercise.find_by(token: params[:custom_token])
|
||||||
else
|
else
|
||||||
proxy_exercise.get_matching_exercise(@current_user)
|
proxy_exercise.get_matching_exercise(current_user)
|
||||||
end
|
end
|
||||||
session[:lti_exercise_id] = @exercise.id if @exercise
|
session[:lti_exercise_id] = @exercise.id if @exercise
|
||||||
refuse_lti_launch(message: t('sessions.oauth.invalid_exercise_token')) unless @exercise
|
refuse_lti_launch(message: t('sessions.oauth.invalid_exercise_token')) unless @exercise
|
||||||
@ -181,7 +181,7 @@ module Lti
|
|||||||
|
|
||||||
def set_current_user
|
def set_current_user
|
||||||
@current_user = ExternalUser.find_or_create_by(consumer_id: @consumer.id, external_id: @provider.user_id)
|
@current_user = ExternalUser.find_or_create_by(consumer_id: @consumer.id, external_id: @provider.user_id)
|
||||||
@current_user.update(email: external_user_email(@provider), name: external_user_name(@provider))
|
current_user.update(email: external_user_email(@provider), name: external_user_name(@provider))
|
||||||
end
|
end
|
||||||
|
|
||||||
private :set_current_user
|
private :set_current_user
|
||||||
@ -196,7 +196,7 @@ module Lti
|
|||||||
StudyGroup.find_or_create_by(external_id: @provider.resource_link_id, consumer: @consumer)
|
StudyGroup.find_or_create_by(external_id: @provider.resource_link_id, consumer: @consumer)
|
||||||
end
|
end
|
||||||
|
|
||||||
study_group_membership = StudyGroupMembership.find_or_create_by(study_group: group, user: @current_user)
|
study_group_membership = StudyGroupMembership.find_or_create_by(study_group: group, user: current_user)
|
||||||
study_group_membership.update(role: external_user_role(@provider))
|
study_group_membership.update(role: external_user_role(@provider))
|
||||||
session[:study_group_id] = group.id
|
session[:study_group_id] = group.id
|
||||||
end
|
end
|
||||||
@ -228,14 +228,14 @@ module Lti
|
|||||||
|
|
||||||
def store_lti_session_data(options = {})
|
def store_lti_session_data(options = {})
|
||||||
lti_parameters = LtiParameter.find_or_create_by(consumers_id: options[:consumer].id,
|
lti_parameters = LtiParameter.find_or_create_by(consumers_id: options[:consumer].id,
|
||||||
external_users_id: @current_user.id,
|
external_users_id: current_user.id,
|
||||||
exercises_id: @exercise.id)
|
exercises_id: @exercise.id)
|
||||||
|
|
||||||
lti_parameters.lti_parameters = options[:parameters].slice(*SESSION_PARAMETERS).permit!.to_h
|
lti_parameters.lti_parameters = options[:parameters].slice(*SESSION_PARAMETERS).permit!.to_h
|
||||||
lti_parameters.save!
|
lti_parameters.save!
|
||||||
@lti_parameters = lti_parameters
|
@lti_parameters = lti_parameters
|
||||||
|
|
||||||
session[:external_user_id] = @current_user.id
|
session[:external_user_id] = current_user.id
|
||||||
session[:lti_parameters_id] = lti_parameters.id
|
session[:lti_parameters_id] = lti_parameters.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ class SessionsController < ApplicationController
|
|||||||
redirect_to(URI.parse(params[:custom_redirect_target].to_s).path)
|
redirect_to(URI.parse(params[:custom_redirect_target].to_s).path)
|
||||||
else
|
else
|
||||||
redirect_to(implement_exercise_path(@exercise),
|
redirect_to(implement_exercise_path(@exercise),
|
||||||
notice: t("sessions.create_through_lti.session_#{lti_outcome_service?(@exercise.id, @current_user.id) ? 'with' : 'without'}_outcome",
|
notice: t("sessions.create_through_lti.session_#{lti_outcome_service?(@exercise.id, current_user.id) ? 'with' : 'without'}_outcome",
|
||||||
consumer: @consumer))
|
consumer: @consumer))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
- if object
|
- if object
|
||||||
- current_element = object
|
- current_element = object
|
||||||
- else
|
- else
|
||||||
- root_element = link_to_if(@current_user && policy(model).index?, model.model_name.human(count: 2), send(:"#{model.model_name.collection}_path"))
|
- root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: 2), send(:"#{model.model_name.collection}_path"))
|
||||||
- if object
|
- if object
|
||||||
- current_element = link_to_if(@current_user && policy(object).show?, object, send(:"#{model.model_name.singular}_path", object))
|
- current_element = link_to_if(current_user && policy(object).show?, object, send(:"#{model.model_name.singular}_path", object))
|
||||||
- if I18n.translation_present?("shared.#{params[:action]}")
|
- if I18n.translation_present?("shared.#{params[:action]}")
|
||||||
- active_action = t("shared.#{params[:action]}", model: model&.model_name&.human)
|
- active_action = t("shared.#{params[:action]}", model: model&.model_name&.human)
|
||||||
- else
|
- else
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
- external_user_external_id = @current_user.respond_to?(:external_id) ? @current_user.external_id : ''
|
- external_user_external_id = current_user.respond_to?(:external_id) ? current_user.external_id : ''
|
||||||
- external_user_id = @current_user.respond_to?(:external_id) ? @current_user.id : ''
|
- external_user_id = current_user.respond_to?(:external_id) ? current_user.id : ''
|
||||||
- consumer_id = @current_user.respond_to?(:external_id) ? @current_user.consumer_id : ''
|
- consumer_id = current_user.respond_to?(:external_id) ? current_user.consumer_id : ''
|
||||||
- show_break_interventions = @show_break_interventions || "false"
|
- show_break_interventions = @show_break_interventions || "false"
|
||||||
- show_rfc_interventions = @show_rfc_interventions || "false"
|
- show_rfc_interventions = @show_rfc_interventions || "false"
|
||||||
- show_tips_interventions = @show_tips_interventions || "false"
|
- show_tips_interventions = @show_tips_interventions || "false"
|
||||||
- hide_rfc_button = @hide_rfc_button || false
|
- hide_rfc_button = @hide_rfc_button || false
|
||||||
|
|
||||||
#editor.row data-exercise-id=@exercise.id data-message-depleted=t('exercises.editor.depleted') data-message-timeout=t('exercises.editor.timeout', permitted_execution_time: @exercise.execution_environment.permitted_execution_time) data-message-out-of-memory=t('exercises.editor.out_of_memory', memory_limit: @exercise.execution_environment.memory_limit) data-submissions-url=submissions_path data-user-id=@current_user.id data-user-external-id=external_user_external_id data-working-times-url=working_times_exercise_path(@exercise) data-intervention-save-url=intervention_exercise_path(@exercise) data-rfc-interventions=show_rfc_interventions data-break-interventions=show_break_interventions data-tips-interventions=show_tips_interventions data-course_token=@course_token data-search-save-url=search_exercise_path(@exercise)
|
= current_user
|
||||||
|
#editor.row data-exercise-id=@exercise.id data-message-depleted=t('exercises.editor.depleted') data-message-timeout=t('exercises.editor.timeout', permitted_execution_time: @exercise.execution_environment.permitted_execution_time) data-message-out-of-memory=t('exercises.editor.out_of_memory', memory_limit: @exercise.execution_environment.memory_limit) data-submissions-url=submissions_path data-user-id=current_user.id data-user-external-id=external_user_external_id data-working-times-url=working_times_exercise_path(@exercise) data-intervention-save-url=intervention_exercise_path(@exercise) data-rfc-interventions=show_rfc_interventions data-break-interventions=show_break_interventions data-tips-interventions=show_tips_interventions data-course_token=@course_token data-search-save-url=search_exercise_path(@exercise)
|
||||||
- unless @embed_options[:hide_sidebar]
|
- unless @embed_options[:hide_sidebar]
|
||||||
- additional_classes = 'sidebar-col'
|
- additional_classes = 'sidebar-col'
|
||||||
- if @tips.blank?
|
- if @tips.blank?
|
||||||
|
@ -52,7 +52,7 @@ div.d-grid id='output_sidebar_uncollapsed' class='d-none col-sm-12 enforce-botto
|
|||||||
| 0
|
| 0
|
||||||
= row(label: 'exercises.implement.feedback')
|
= row(label: 'exercises.implement.feedback')
|
||||||
= row(label: 'exercises.implement.messages')
|
= row(label: 'exercises.implement.messages')
|
||||||
#score data-maximum-score=@exercise.maximum_score data-score=@exercise.final_submission(@current_user).try(:score)
|
#score data-maximum-score=@exercise.maximum_score data-score=@exercise.final_submission(current_user).try(:score)
|
||||||
h4
|
h4
|
||||||
span == "#{t('activerecord.attributes.submission.score')}: "
|
span == "#{t('activerecord.attributes.submission.score')}: "
|
||||||
span.score
|
span.score
|
||||||
|
@ -26,13 +26,13 @@ html lang="#{I18n.locale || I18n.default_locale}"
|
|||||||
| release: "#{SentryJavascript.release}",
|
| release: "#{SentryJavascript.release}",
|
||||||
| environment: "#{SentryJavascript.environment}",
|
| environment: "#{SentryJavascript.environment}",
|
||||||
| });
|
| });
|
||||||
- if @current_user
|
- if current_user
|
||||||
| Sentry.configureScope(function(scope) {
|
| Sentry.configureScope(function(scope) {
|
||||||
| scope.setUser({
|
| scope.setUser({
|
||||||
| "id": "#{@current_user.id}",
|
| "id": "#{current_user.id}",
|
||||||
| "type": "#{@current_user.class.name}",
|
| "type": "#{current_user.class.name}",
|
||||||
| "username": "#{@current_user.displayname}",
|
| "username": "#{current_user.displayname}",
|
||||||
| "consumer": "#{@current_user.consumer.name}"
|
| "consumer": "#{current_user.consumer.name}"
|
||||||
| });
|
| });
|
||||||
| });
|
| });
|
||||||
body
|
body
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
pre= testrun.log or t('request_for_comments.no_output')
|
pre= testrun.log or t('request_for_comments.no_output')
|
||||||
|
|
||||||
- assess_runs = testruns.select {|run| run.cause == 'assess' }
|
- assess_runs = testruns.select {|run| run.cause == 'assess' }
|
||||||
- unless @current_user.admin?
|
- unless current_user.admin?
|
||||||
- assess_runs = assess_runs.select {|run| run.file.present? ? run.file.teacher_defined_test? : true }
|
- assess_runs = assess_runs.select {|run| run.file.present? ? run.file.teacher_defined_test? : true }
|
||||||
- if assess_runs.size > 0
|
- if assess_runs.size > 0
|
||||||
h5.mt-4= t('request_for_comments.test_results')
|
h5.mt-4= t('request_for_comments.test_results')
|
||||||
@ -53,7 +53,7 @@
|
|||||||
span.fa-solid.fa-chevron-down.collapse-button
|
span.fa-solid.fa-chevron-down.collapse-button
|
||||||
pre= testrun.log or t('request_for_comments.no_output')
|
pre= testrun.log or t('request_for_comments.no_output')
|
||||||
|
|
||||||
- if @current_user.admin? && user.is_a?(ExternalUser)
|
- if current_user.admin? && user.is_a?(ExternalUser)
|
||||||
= render('admin_menu')
|
= render('admin_menu')
|
||||||
|
|
||||||
hr
|
hr
|
||||||
|
@ -8,7 +8,7 @@ describe 'exercises/implement.html.slim' do
|
|||||||
let(:non_binary_files) { files.reject {|file| file.file_type.binary? } }
|
let(:non_binary_files) { files.reject {|file| file.file_type.binary? } }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
assign(:current_user, create(:admin))
|
allow(view).to receive(:current_user).and_return(create(:admin))
|
||||||
assign(:exercise, exercise)
|
assign(:exercise, exercise)
|
||||||
assign(:files, files)
|
assign(:files, files)
|
||||||
assign(:paths, [])
|
assign(:paths, [])
|
||||||
|
Reference in New Issue
Block a user