Skip to content

Commit

Permalink
Merge branch 'release/6.8.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed May 23, 2023
2 parents 2720b48 + e37a9f1 commit 1045d66
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/models/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ def activity_status_for(user, series = nil)
def activity_status_for!(user, series = nil)
first_try = true
begin
ActivityStatus.create_or_find_by(activity: self, series: series, user: user)
ActivityStatus.find_or_create_by(activity: self, series: series, user: user)
rescue StandardError
# https://github.com/dodona-edu/dodona/pull/4547
# https://github.com/dodona-edu/dodona/issues/1877
raise unless first_try

first_try = false
Expand Down
4 changes: 3 additions & 1 deletion app/models/activity_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ class ActivityStatus < ApplicationRecord
belongs_to :series, optional: true
belongs_to :user

validates :series_id_non_nil, uniqueness: { scope: %i[user_id activity_id] }, on: :create

scope :in_series, ->(series) { where(series: series) }
scope :for_user, ->(user) { where(user: user) }

before_create :initialise_series_id_non_nil
before_validation :initialise_series_id_non_nil, if: -> { new_record? }
before_create :initialise_values_for_content_page, if: -> { activity.content_page? }
before_create :initialise_values_for_exercise, if: -> { activity.exercise? }

Expand Down
4 changes: 2 additions & 2 deletions app/models/series_membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def add_activity_statuses_delayed
def add_activity_statuses
if activity.is_a? Exercise
activity.submissions.where(course: series.course).distinct(:user_id).find_each do |submission|
ActivityStatus.create_or_find_by(series: series, activity: activity, user: submission.user)
ActivityStatus.create(series: series, activity: activity, user: submission.user)
end
else
activity.activity_read_states.where(course: series.course).distinct(:user_id).find_each do |ars|
ActivityStatus.create_or_find_by(series: series, activity: activity, user: ars.user)
ActivityStatus.create(series: series, activity: activity, user: ars.user)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/00_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Application
module Version
MAJOR = 6
MINOR = 8
PATCH = 5
PATCH = 6

STRING = [MAJOR, MINOR, PATCH].compact.join('.')
end
Expand Down
5 changes: 1 addition & 4 deletions test/models/activity_status_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ class ActivityStatusTest < ActiveSupport::TestCase
activity = exercises(:python_exercise)
user = users(:student)
ActivityStatus.create(user: user, activity: activity, series: nil)
assert_equal 1, ActivityStatus.count
assert_raises ActiveRecord::RecordNotUnique do
ActivityStatus.create(user: user, activity: activity, series: nil)
end
ActivityStatus.create(user: user, activity: activity, series: nil)
assert_equal 1, ActivityStatus.count
end

Expand Down

0 comments on commit 1045d66

Please sign in to comment.