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:

committed by
Sebastian Serth

parent
37e5dfaba1
commit
dab8f777b3
48
app/models/contributor.rb
Normal file
48
app/models/contributor.rb
Normal 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
|
Reference in New Issue
Block a user