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
@ -1,12 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class User < ApplicationRecord
|
||||
class User < Contributor
|
||||
self.abstract_class = true
|
||||
|
||||
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 :comments, as: :user
|
||||
has_many :study_group_memberships, as: :user
|
||||
@ -15,15 +14,12 @@ class User < ApplicationRecord
|
||||
has_many :programming_groups, through: :programming_group_memberships, as: :user
|
||||
has_many :exercises, as: :user
|
||||
has_many :file_types, as: :user
|
||||
has_many :submissions, as: :contributor
|
||||
has_many :participations, through: :submissions, source: :exercise, as: :user
|
||||
has_many :user_proxy_exercise_exercises, as: :user
|
||||
has_many :user_exercise_interventions, as: :contributor
|
||||
has_many :testruns, as: :user
|
||||
has_many :interventions, through: :user_exercise_interventions
|
||||
has_many :remote_evaluation_mappings, as: :user
|
||||
has_many :request_for_comments, as: :user
|
||||
has_many :runners, as: :contributor
|
||||
has_many :events
|
||||
has_many :events_synchronized_editor, class_name: 'Event::SynchronizedEditor'
|
||||
has_many :pair_programming_exercise_feedbacks
|
||||
@ -31,8 +27,6 @@ class User < ApplicationRecord
|
||||
has_one :codeharbor_link, dependent: :destroy
|
||||
accepts_nested_attributes_for :user_proxy_exercise_exercises
|
||||
|
||||
scope :with_submissions, -> { where('id IN (SELECT user_id FROM submissions)') }
|
||||
|
||||
scope :in_study_group_of, lambda {|user|
|
||||
unless user.admin?
|
||||
joins(:study_group_memberships)
|
||||
@ -46,18 +40,6 @@ class User < ApplicationRecord
|
||||
|
||||
validates :platform_admin, inclusion: [true, false]
|
||||
|
||||
def internal_user?
|
||||
is_a?(InternalUser)
|
||||
end
|
||||
|
||||
def external_user?
|
||||
is_a?(ExternalUser)
|
||||
end
|
||||
|
||||
def programming_group?
|
||||
false
|
||||
end
|
||||
|
||||
def learner?
|
||||
return true if current_study_group_id.nil?
|
||||
|
||||
@ -86,19 +68,6 @@ class User < ApplicationRecord
|
||||
study_group_memberships.where(study_group: current_study_group_id).limit(1)
|
||||
end
|
||||
|
||||
def to_s
|
||||
displayname
|
||||
end
|
||||
|
||||
def to_page_context
|
||||
{
|
||||
id:,
|
||||
type: self.class.name,
|
||||
consumer: consumer.name,
|
||||
displayname:,
|
||||
}
|
||||
end
|
||||
|
||||
def self.find_by_id_with_type(id_with_type)
|
||||
if id_with_type[0].casecmp('e').zero?
|
||||
ExternalUser.find(id_with_type[1..])
|
||||
|
Reference in New Issue
Block a user