Remove PairProgramming23Study and instead use LTI parameter

This commit is contained in:
kiragrammel
2023-10-13 14:03:00 +02:00
committed by Sebastian Serth
parent 5bbc94f1d1
commit b91a2b7ce0
7 changed files with 14 additions and 53 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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')

View File

@ -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

View File

@ -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

View File

@ -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