Skip to content

Commit

Permalink
Merge pull request #5127 from dodona-edu/fix/remove-activities-job
Browse files Browse the repository at this point in the history
Never remove exercises that are part of an evaluation
  • Loading branch information
jorg-vr authored Nov 10, 2023
2 parents e4a4977 + a29e6e6 commit 3a2f73e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/jobs/remove_activities_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class RemoveActivitiesJob < ApplicationJob
# permanently remove activities that match all of the following criteria:
# - status is 'removed'
# - updated_at is more than 1 month ago
# - not part of an evaluation
# - one of the following is true:
# - draft is true (never published)
# - series_memberships is empty and less then 25 submissions and latest submission is more than 1 month ago
Expand All @@ -28,6 +29,8 @@ def perform
next if activity.submissions.present? && activity.submissions.reorder(:created_at).last.created_at > 1.month.ago
end

next if EvaluationExercise.exists?(exercise_id: activity.id)

# destroy submissions first explicitly, as they are dependent: :restrict_with_error
activity.submissions.destroy_all

Expand Down
9 changes: 9 additions & 0 deletions test/jobs/remove_activities_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,13 @@ class RemoveActivitiesJobTest < ActiveJob::TestCase
RemoveActivitiesJob.perform_now
end
end

test 'should not remove activities that are part of an evaluation' do
e = create :exercise, status: :removed, draft: false, updated_at: 2.months.ago
create :evaluation_exercise, exercise: e

assert_no_difference 'Exercise.count' do
RemoveActivitiesJob.perform_now
end
end
end

0 comments on commit 3a2f73e

Please sign in to comment.