Extract Contributor concern as abstract class

During documentation of the pair programming feature, we noticed that the Contributor should be an abstract class, which is parent for the User and the ProgrammingGroup. With this commit, we perform these changes.
This commit is contained in:
Sebastian Serth
2024-02-13 14:31:45 +01:00
committed by Sebastian Serth
parent 37e5dfaba1
commit dab8f777b3
6 changed files with 53 additions and 76 deletions

48
app/models/contributor.rb Normal file
View File

@@ -0,0 +1,48 @@
# frozen_string_literal: true
class Contributor < ApplicationRecord
self.abstract_class = true
has_many :anomaly_notifications, as: :contributor, dependent: :destroy
has_many :user_exercise_interventions, as: :contributor
has_many :runners, as: :contributor, dependent: :destroy
has_many :submissions, as: :contributor
def learner?
raise NotImplementedError
end
def teacher?
raise NotImplementedError
end
def admin?
raise NotImplementedError
end
def internal_user?
is_a?(InternalUser)
end
def external_user?
is_a?(ExternalUser)
end
def programming_group?
is_a?(ProgrammingGroup)
end
def to_s
displayname
end
def to_page_context
{
id:,
type: self.class.name,
consumer: try(:consumer)&.name, # Only a user is associated with a consumer.
displayname:,
}
end
end