Reduce usage of @current_user (use helper instead)

This commit is contained in:
Sebastian Serth
2022-11-02 12:25:53 +01:00
parent a4e791e3de
commit 4f0b8c3c42
8 changed files with 22 additions and 21 deletions

View File

@ -6,9 +6,9 @@
- if object
- current_element = object
- 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
- 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]}")
- active_action = t("shared.#{params[:action]}", model: model&.model_name&.human)
- else

View File

@ -1,12 +1,13 @@
- 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 : ''
- consumer_id = @current_user.respond_to?(:external_id) ? @current_user.consumer_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 : ''
- consumer_id = current_user.respond_to?(:external_id) ? current_user.consumer_id : ''
- show_break_interventions = @show_break_interventions || "false"
- show_rfc_interventions = @show_rfc_interventions || "false"
- show_tips_interventions = @show_tips_interventions || "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]
- additional_classes = 'sidebar-col'
- if @tips.blank?

View File

@ -52,7 +52,7 @@ div.d-grid id='output_sidebar_uncollapsed' class='d-none col-sm-12 enforce-botto
| 0
= row(label: 'exercises.implement.feedback')
= 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
span == "#{t('activerecord.attributes.submission.score')}: "
span.score

View File

@ -26,13 +26,13 @@ html lang="#{I18n.locale || I18n.default_locale}"
| release: "#{SentryJavascript.release}",
| environment: "#{SentryJavascript.environment}",
| });
- if @current_user
- if current_user
| Sentry.configureScope(function(scope) {
| scope.setUser({
| "id": "#{@current_user.id}",
| "type": "#{@current_user.class.name}",
| "username": "#{@current_user.displayname}",
| "consumer": "#{@current_user.consumer.name}"
| "id": "#{current_user.id}",
| "type": "#{current_user.class.name}",
| "username": "#{current_user.displayname}",
| "consumer": "#{current_user.consumer.name}"
| });
| });
body

View File

@ -41,7 +41,7 @@
pre= testrun.log or t('request_for_comments.no_output')
- 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 }
- if assess_runs.size > 0
h5.mt-4= t('request_for_comments.test_results')
@ -53,7 +53,7 @@
span.fa-solid.fa-chevron-down.collapse-button
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')
hr