diff --git a/app/controllers/concerns/lti.rb b/app/controllers/concerns/lti.rb index 6437b731..30735de6 100644 --- a/app/controllers/concerns/lti.rb +++ b/app/controllers/concerns/lti.rb @@ -226,6 +226,7 @@ module Lti @lti_parameters.save! session[:external_user_id] = current_user.id + session[:pair_programming] = parameters[:custom_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 81a27c31..86f4e3a2 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -305,6 +305,7 @@ class ExercisesController < ApplicationController # we are acting on behalf of a programming group if current_user.admin? session.delete(:pg_id) + session.delete(:pair_programming) @current_contributor = current_user else return redirect_back( @@ -316,9 +317,9 @@ class ExercisesController < ApplicationController # 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 79c8dacc..fc84aaab 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -19,12 +19,15 @@ class SessionsController < ApplicationController def create_through_lti return redirect_to_survey if params[:custom_survey_id] - session.delete(:pg_id) # Remove any previous pg_id from the session + # Remove any previous pg_id and pair_programming option from the session + session.delete(:pg_id) + session.delete(:pair_programming) + store_lti_session_data(params) 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[:custom_pair_programming] redirect_to(new_exercise_programming_group_path(@exercise)) else redirect_to(implement_exercise_path(@exercise), @@ -57,6 +60,7 @@ class SessionsController < ApplicationController session.delete(:study_group_id) session.delete(:embed_options) session.delete(:pg_id) + session.delete(:pair_programming) # In case we have another session as an internal user, we set the study group for this one internal_user = find_or_login_current_user @@ -98,7 +102,6 @@ class SessionsController < ApplicationController # 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 48328bae..14f483f2 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 53ed401e..00000000 --- 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 diff --git a/spec/concerns/lti_spec.rb b/spec/concerns/lti_spec.rb index 25059ba1..8ea55222 100644 --- a/spec/concerns/lti_spec.rb +++ b/spec/concerns/lti_spec.rb @@ -163,6 +163,7 @@ RSpec.describe Lti do controller.instance_variable_set(:@current_user, create(:external_user)) controller.instance_variable_set(:@exercise, create(:fibonacci)) expect(controller.session).to receive(:[]=).with(:external_user_id, anything) + expect(controller.session).to receive(:[]=).with(:pair_programming, anything) controller.send(:store_lti_session_data, parameters) end diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index 1b28c134..5a02a830 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -194,6 +194,7 @@ RSpec.describe SessionsController do expect(controller.session).to receive(:delete).with(:study_group_id) expect(controller.session).to receive(:delete).with(:embed_options) expect(controller.session).to receive(:delete).with(:pg_id) + expect(controller.session).to receive(:delete).with(:pair_programming) delete :destroy end