diff --git a/app/controllers/concerns/lti.rb b/app/controllers/concerns/lti.rb index 6437b731e..8b5df57a7 100644 --- a/app/controllers/concerns/lti.rb +++ b/app/controllers/concerns/lti.rb @@ -226,6 +226,7 @@ def store_lti_session_data(parameters) @lti_parameters.save! session[:external_user_id] = current_user.id + session[:pair_programming] = params[:pair_programming] || false rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid retry end diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 04f5f4910..2a1b3cca4 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -315,9 +315,9 @@ def implement # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedC # we are just acting on behalf of a single user who has already worked on this exercise as part of a programming group **in the context of the current study group** session[:pg_id] = pg.id @current_contributor = pg - elsif session[:pg_id].blank? && PairProgramming23Study.participate_in_pp?(current_user, @exercise) && PairProgramming23Study::FORCED_EXERCISE_IDS.include?(@exercise.id) + elsif session[:pg_id].blank? && session[:pair_programming] == 'mandatory' return redirect_back(fallback_location: new_exercise_programming_group_path(@exercise)) - elsif session[:pg_id].blank? && PairProgramming23Study.participate?(current_user, @exercise) && current_user.submissions.where(study_group_id: current_user.current_study_group_id, exercise: @exercise).none? + elsif session[:pg_id].blank? && session[:pair_programming] == 'optional' && current_user.submissions.where(study_group_id: current_user.current_study_group_id, exercise: @exercise).none? Event.find_or_create_by(category: 'pp_work_alone', user: current_user, exercise: @exercise, data: nil, file_id: nil) current_user.pair_programming_waiting_users&.find_by(exercise: @exercise)&.update(status: :worked_alone) end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 79c8dacc5..d4cbef7dd 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -24,7 +24,7 @@ def create_through_lti store_nonce(params[:oauth_nonce]) if params[:custom_redirect_target] redirect_to(URI.parse(params[:custom_redirect_target].to_s).path) - elsif PairProgramming23Study.participate?(current_user, @exercise) + elsif params[:pair_programming] redirect_to(new_exercise_programming_group_path(@exercise)) else redirect_to(implement_exercise_path(@exercise), @@ -98,7 +98,6 @@ def redirect_to_survey # add a user pseudo ID if applicable qp[:xi_pseudo_id] = Digest::SHA256.hexdigest(current_user.external_id) qp[:co_study_group_id] = current_user.current_study_group_id - qp[:co_pair_programming23_study] = PairProgramming23Study.participate_in_pp?(current_user, @exercise).to_s qp[:co_rfcs] = current_user.request_for_comments.includes(:submission).where(submission: {study_group_id: current_user.current_study_group_id}).size.to_s qp[:co_comments] = current_user.comments.includes(:submission).where(submission: {study_group_id: current_user.current_study_group_id}).size.to_s end diff --git a/app/views/programming_groups/new.html.slim b/app/views/programming_groups/new.html.slim index 48328bae7..14f483f2e 100644 --- a/app/views/programming_groups/new.html.slim +++ b/app/views/programming_groups/new.html.slim @@ -5,7 +5,7 @@ h1.d-inline-block = t('programming_groups.new.create_programming_pair') #matching data-exercise-id=@exercise.id.to_s .row .col-12.mt-2.mb-4 - - if PairProgramming23Study.participate_in_pp?(current_user, @exercise) && PairProgramming23Study::FORCED_EXERCISE_IDS.include?(@exercise.id) + - if session[:pair_programming] == 'mandatory' p = t('programming_groups.new.info_forced_work_together', exercise_title: @exercise.title) - else p = t('programming_groups.new.info_work_together', exercise_title: @exercise.title) @@ -32,7 +32,7 @@ h1.d-inline-block = t('programming_groups.new.create_programming_pair') .col-12.d-none.d-md-block = render('form') - - unless PairProgramming23Study.participate_in_pp?(current_user, @exercise) && PairProgramming23Study::FORCED_EXERCISE_IDS.include?(@exercise.id) + - unless session[:pair_programming] == 'mandatory' .row .col-12 h5 = t('programming_groups.new.work_alone') diff --git a/lib/pair_programming23_study.rb b/lib/pair_programming23_study.rb deleted file mode 100644 index 53ed401ea..000000000 --- a/lib/pair_programming23_study.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -class PairProgramming23Study - ENABLE = ENV.fetch('PAIR_PROGRAMMING_23_STUDY', nil) == 'true' - STUDY_GROUP_IDS = [368, 451].freeze - # All easy tasks of the first week to be solved by the participants on their own - EXCLUDED_EXERCISE_IDS = [636, 647, 648, 649, 637, 638, 623, 639, 650, 625, 624, 651, 653, 654, 655, 664, 656].freeze - # The participants are forced to work in pairs on these tasks - FORCED_EXERCISE_IDS = [723].freeze - - def self.participate?(user, exercise) - return false if Rails.env.test? - - ENABLE || participate_in_pp?(user, exercise) - end - - def self.participate_in_pp?(user, exercise) - return false unless experiment_course?(user.current_study_group_id) - return false if EXCLUDED_EXERCISE_IDS.include?(exercise.id) - return true if user.external_user? && fixed_enrolled_users.include?([user.consumer_id.to_s, user.external_id]) - - user_group = user.id % 3 # => 0, 1, 2 - case user_group - when 0, 1 - true - else # 2 - false - end - end - - def self.experiment_course?(study_group_id) - STUDY_GROUP_IDS.include? study_group_id - end - - def self.csv - @csv ||= CSV.read(Rails.root.join('config/pair_programming23_study.csv'), headers: true) - rescue Errno::ENOENT - [] - end - - def self.fixed_enrolled_users - @fixed_enrolled_users ||= csv.map do |row| - [row['consumer_id'], row['external_id']] - end - end -end