Migrate AnomalyNotification to contributor

* Also, this commit aims to fix the (broken) anomaly notifications.
This commit is contained in:
Sebastian Serth
2023-08-21 09:08:24 +02:00
committed by Sebastian Serth
parent a1941336d9
commit 9d1be1eeff
10 changed files with 142 additions and 65 deletions

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
class AnomalyNotification < ApplicationRecord
include Creation
include ContributorCreation
belongs_to :exercise
belongs_to :exercise_collection
end

View File

@ -14,6 +14,7 @@ class Exercise < ApplicationRecord
belongs_to :execution_environment, optional: true
has_many :submissions
has_many :anomaly_notifications, as: :contributor, dependent: :destroy
has_and_belongs_to_many :proxy_exercises
has_many :user_proxy_exercise_exercises
has_many :exercise_collection_items, dependent: :delete_all
@ -596,14 +597,14 @@ class Exercise < ApplicationRecord
end
end
def last_submission_per_user
def last_submission_per_contributor
Submission.joins("JOIN (
SELECT
contributor_id,
contributor_type,
first_value(id) OVER (PARTITION BY contributor_id ORDER BY created_at DESC) AS fv
first_value(id) OVER (PARTITION BY contributor_id, contributor_type ORDER BY created_at DESC) AS fv
FROM submissions
WHERE exercise_id = #{id}
WHERE #{Submission.sanitize_sql(['exercise_id = ?', id])}
) AS t ON t.fv = submissions.id").distinct
end

View File

@ -4,6 +4,7 @@ class ExerciseCollection < ApplicationRecord
include Creation
include TimeHelper
has_many :anomaly_notifications, dependent: :destroy
has_many :exercise_collection_items, dependent: :delete_all
alias items exercise_collection_items
has_many :exercises, through: :exercise_collection_items, inverse_of: :exercise_collections

View File

@ -3,6 +3,7 @@
class ProgrammingGroup < ApplicationRecord
include Contributor
has_many :anomaly_notifications, as: :contributor, dependent: :destroy
has_many :programming_group_memberships, dependent: :destroy
has_many :external_users, through: :programming_group_memberships, source_type: 'ExternalUser', source: :user
has_many :internal_users, through: :programming_group_memberships, source_type: 'InternalUser', source: :user

View File

@ -6,6 +6,7 @@ class User < ApplicationRecord
attr_reader :current_study_group_id
belongs_to :consumer
has_many :anomaly_notifications, as: :contributor, dependent: :destroy
has_many :authentication_token, dependent: :destroy
has_many :study_group_memberships, as: :user
has_many :study_groups, through: :study_group_memberships, as: :user