Prevent new programming groups in case of existing submission for study group

This commit is contained in:
Sebastian Serth
2023-08-22 17:00:22 +02:00
committed by Sebastian Serth
parent 3f674d3687
commit dddebcca67

View File

@ -7,13 +7,18 @@ class ProgrammingGroupsController < ApplicationController
before_action :set_exercise_and_authorize before_action :set_exercise_and_authorize
def new def new
@programming_group = ProgrammingGroup.new(exercise: @exercise) if current_user.submissions.where(exercise: @exercise, study_group_id: current_user.current_study_group_id).any?
authorize! # A learner has worked on this exercise **alone** in the context of the **current study group**, so we redirect them to their progress.
existing_programming_group = current_user.programming_groups.find_by(exercise: @exercise) redirect_to_exercise
if existing_programming_group elsif (existing_programming_group = current_user.programming_groups.find_by(exercise: @exercise))
# A learner has worked on this exercise **as part of a programming group**, so we redirect them to their progress.
session[:pg_id] = existing_programming_group.id session[:pg_id] = existing_programming_group.id
redirect_to(implement_exercise_path(@exercise), redirect_to_exercise
notice: t("sessions.create_through_lti.session_#{lti_outcome_service?(@exercise, current_user) ? 'with' : 'without'}_outcome", consumer: @consumer)) else
# The learner has neither worked on this exercise alone in the context of the current study group
# nor as part of a programming group (overall), so we allow creating a new programming group.
@programming_group = ProgrammingGroup.new(exercise: @exercise)
authorize!
end end
end end
@ -40,7 +45,7 @@ class ProgrammingGroupsController < ApplicationController
private private
def authorize! def authorize!
authorize(@programming_group || @programming_groups) authorize(@programming_group)
end end
def programming_group_params def programming_group_params
@ -51,4 +56,10 @@ class ProgrammingGroupsController < ApplicationController
@exercise = Exercise.find(params[:exercise_id]) @exercise = Exercise.find(params[:exercise_id])
authorize(@exercise, :implement?) authorize(@exercise, :implement?)
end end
def redirect_to_exercise
skip_authorization
redirect_to(implement_exercise_path(@exercise),
notice: t("sessions.create_through_lti.session_#{lti_outcome_service?(@exercise, current_user) ? 'with' : 'without'}_outcome", consumer: @consumer))
end
end end