diff --git a/Gemfile.lock b/Gemfile.lock index 9ebfde10..0dc1d2f5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -523,7 +523,7 @@ GEM uber (0.1.0) unaccent (0.4.0) unicode-display_width (2.5.0) - uri (0.13.2) + uri (0.13.3) useragent (0.16.11) warden (1.2.9) rack (>= 2.0.9) diff --git a/app/controllers/judging_rounds_controller.rb b/app/controllers/judging_rounds_controller.rb index 81622f1b..0841cce0 100644 --- a/app/controllers/judging_rounds_controller.rb +++ b/app/controllers/judging_rounds_controller.rb @@ -107,12 +107,37 @@ def send_instructions return end + # Get selected judge assignment IDs, or use all if none selected + selected_assignment_ids = params[:judge_assignment_ids]&.compact_blank || [] + + if selected_assignment_ids.any? + assignments = @judging_round.round_judge_assignments.active.includes(:user).where(id: selected_assignment_ids) + else + # If no selection, send to all (backward compatibility) + assignments = @judging_round.round_judge_assignments.active.includes(:user) + end + + if assignments.empty? + redirect_to container_contest_description_contest_instance_judging_assignments_path( + @container, @contest_description, @contest_instance + ), alert: 'No judges selected.' + return + end + + # Get collection administrator emails if copy requested + admin_emails = [] + if params[:send_copy_to_admin] == '1' + admin_emails = @container.assignments.container_administrators.includes(:user).map { |a| a.user.normalize_email } + end + sent_count = 0 failed_emails = [] - @judging_round.round_judge_assignments.active.includes(:user).each do |assignment| + assignments.each do |assignment| begin - JudgingInstructionsMailer.send_instructions(assignment).deliver_later + mail = JudgingInstructionsMailer.send_instructions(assignment, cc_emails: admin_emails) + mail.deliver_later + assignment.update_column(:instructions_sent_at, Time.current) sent_count += 1 rescue => e failed_emails << assignment.user.email diff --git a/app/mailers/judging_instructions_mailer.rb b/app/mailers/judging_instructions_mailer.rb index 8fc2fb57..d407ece9 100644 --- a/app/mailers/judging_instructions_mailer.rb +++ b/app/mailers/judging_instructions_mailer.rb @@ -1,5 +1,5 @@ class JudgingInstructionsMailer < ApplicationMailer - def send_instructions(round_judge_assignment) + def send_instructions(round_judge_assignment, cc_emails: []) @round_judge_assignment = round_judge_assignment @judge = @round_judge_assignment.user @judging_round = @round_judge_assignment.judging_round @@ -23,6 +23,9 @@ def send_instructions(round_judge_assignment) subject: subject } + # Add CC to collection administrators if provided + mail_options[:cc] = cc_emails if cc_emails.any? + # Override reply_to with container's contact_email if present # If not present, the default reply-to from ApplicationMailer will be used mail_options[:reply_to] = @container.contact_email if @container.contact_email.present? diff --git a/app/models/round_judge_assignment.rb b/app/models/round_judge_assignment.rb index ef0798f8..c9d9ed23 100644 --- a/app/models/round_judge_assignment.rb +++ b/app/models/round_judge_assignment.rb @@ -2,12 +2,13 @@ # # Table name: round_judge_assignments # -# id :bigint not null, primary key -# active :boolean default(TRUE) -# created_at :datetime not null -# updated_at :datetime not null -# judging_round_id :bigint not null -# user_id :bigint not null +# id :bigint not null, primary key +# active :boolean default(TRUE) +# instructions_sent_at :datetime +# created_at :datetime not null +# updated_at :datetime not null +# judging_round_id :bigint not null +# user_id :bigint not null # # Indexes # diff --git a/app/views/contest_instances/_manage_judges.html.erb b/app/views/contest_instances/_manage_judges.html.erb index 8aff54b8..60ce1d8a 100644 --- a/app/views/contest_instances/_manage_judges.html.erb +++ b/app/views/contest_instances/_manage_judges.html.erb @@ -7,16 +7,12 @@