From 26ea69eba8009814edb7c4f937160b575105e78b Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Fri, 22 Sep 2023 15:43:20 +0200 Subject: [PATCH] Require pair programming for a given set of exercises --- app/controllers/exercises_controller.rb | 2 ++ app/views/programming_groups/new.html.slim | 9 ++++---- lib/pair_programming23_study.rb | 24 ++++++++++++---------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index d938fa20..04f5f491 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -315,6 +315,8 @@ 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) + 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? 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) diff --git a/app/views/programming_groups/new.html.slim b/app/views/programming_groups/new.html.slim index 3a28a6b8..42c48a03 100644 --- a/app/views/programming_groups/new.html.slim +++ b/app/views/programming_groups/new.html.slim @@ -30,9 +30,10 @@ h1.d-inline-block = t('programming_groups.new.create_programming_pair') .col-12.d-none.d-md-block = render('form') - .row - .col-12 - h5 = t('programming_groups.new.work_alone') - == t('programming_groups.new.work_alone_description', path: implement_exercise_path(@exercise)) + - unless PairProgramming23Study.participate_in_pp?(current_user, @exercise) && PairProgramming23Study::FORCED_EXERCISE_IDS.include?(@exercise.id) + .row + .col-12 + h5 = t('programming_groups.new.work_alone') + == t('programming_groups.new.work_alone_description', path: implement_exercise_path(@exercise)) = render('shared/modal', classes: 'modal-lg', id: 'modal-info-pair-programming', template: 'programming_groups/_info_pair_programming', title: t('programming_groups.new.pair_programming_info')) diff --git a/lib/pair_programming23_study.rb b/lib/pair_programming23_study.rb index 6718dbfa..af4f46fe 100644 --- a/lib/pair_programming23_study.rb +++ b/lib/pair_programming23_study.rb @@ -3,25 +3,27 @@ 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) ENABLE || participate_in_pp?(user, exercise) end def self.participate_in_pp?(user, exercise) - # All easy tasks of the first week to be solved by the participants on their own - if experiment_course?(user.current_study_group_id) && [636, 647, 648, 649, 637, 638, 623, 639, 650, 625, 624, 651, 653, 654, 655, 664, 656].exclude?(exercise.id) - return true if user.external_user? && fixed_enrolled_users.include?([user.consumer_id.to_s, user.external_id]) + 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 - return true - else # 2 - return false - end + user_group = user.id % 3 # => 0, 1, 2 + case user_group + when 0, 1 + true + else # 2 + false end - false end def self.experiment_course?(study_group_id)