From 8b23f9da6e1f1274d5cdf4bd982f72566e150415 Mon Sep 17 00:00:00 2001 From: Pranav Rao <56097527+pranavrao145@users.noreply.github.com> Date: Thu, 3 Oct 2024 21:51:11 -0400 Subject: [PATCH] Fix: Make sure released submissions are not recollectable (#7254) --- Changelog.md | 1 + app/controllers/submissions_controller.rb | 11 ++++++ config/locales/views/submissions/en.yml | 1 + .../submissions_controller_spec.rb | 36 +++++++++++++++++-- 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index dcf68d29ba..8baae3d36b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,6 +11,7 @@ ### 🐛 Bug fixes - Fix incorrect calculation of token penalties when submissions are on time (#7216) +- Ensured submissions that have been released cannot be recollected from the repo browser (#7254) - Fix bug where renaming a group to an existing group in a different assignment resulted in incorrect repository mapping (#7224) ### 🔧 Internal changes diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 59f15dfbe9..e6227aad9e 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -153,6 +153,17 @@ def populate_file_manager def manually_collect_and_begin_grading assignment = Assignment.find_by(id: params[:assignment_id]) @grouping = assignment.groupings.find(params[:grouping_id]) + + unless @grouping.current_submission_used.nil? + released = @grouping.current_submission_used.results.exists?(released_to_students: true) + + if released + flash_message(:error, I18n.t('submissions.collect.could_not_collect_released')) + return redirect_to repo_browser_course_assignment_submissions_path(current_course, assignment, + grouping_id: @grouping.id) + end + end + @revision_identifier = params[:current_revision_identifier] apply_late_penalty = if params[:apply_late_penalty].nil? false diff --git a/config/locales/views/submissions/en.yml b/config/locales/views/submissions/en.yml index e03b675a4c..6e00f3f13e 100644 --- a/config/locales/views/submissions/en.yml +++ b/config/locales/views/submissions/en.yml @@ -13,6 +13,7 @@ en: collect_due_date: Collect most recent files submitted before the due date, including any late period. collection_options: Collection options collection_time: Collection time + could_not_collect_released: Could not collect submission because it has already been released. could_not_collect_some_due: Could not collect submissions for some groupings and assignment %{assignment_identifier} - the collection date has not been reached for these groupings. could_not_collect_some_released: Could not collect submissions for some groupings and assignment %{assignment_identifier} - the submission has already been released. manual_collection: Manual Collection diff --git a/spec/controllers/submissions_controller_spec.rb b/spec/controllers/submissions_controller_spec.rb index 609cf36550..5b82cc705e 100644 --- a/spec/controllers/submissions_controller_spec.rb +++ b/spec/controllers/submissions_controller_spec.rb @@ -854,13 +854,45 @@ end describe '#manually_collect_and_begin_grading' do - before do + it 'should respond with 302' do post_as grader, :manually_collect_and_begin_grading, params: { course_id: course.id, assignment_id: @assignment.id, grouping_id: @grouping.id, current_revision_identifier: revision_identifier } + + expect(response).to have_http_status :found + end + + it 'should not flash any error messages' do + post_as grader, :manually_collect_and_begin_grading, + params: { course_id: course.id, assignment_id: @assignment.id, grouping_id: @grouping.id, + current_revision_identifier: revision_identifier } + + expect(flash[:error]).to be_nil end - it('should respond with 302') { expect(response).to have_http_status :found } + context 'When a grouping\'s submission has already been released' do + before do + # mark the existing submission as released + last_result = @grouping1.current_submission_used.get_latest_result + last_result.update!(released_to_students: true) + end + + it 'should respond with 302' do + post_as grader, :manually_collect_and_begin_grading, + params: { course_id: course.id, assignment_id: @assignment.id, grouping_id: @grouping1.id, + current_revision_identifier: revision_identifier } + + expect(response).to have_http_status :found + end + + it 'should flash an error message' do + post_as grader, :manually_collect_and_begin_grading, + params: { course_id: course.id, assignment_id: @assignment.id, grouping_id: @grouping1.id, + current_revision_identifier: revision_identifier } + + expect(flash[:error]).to eq(["

#{I18n.t('submissions.collect.could_not_collect_released')}

"]) + end + end end describe '#update submissions' do