Add StudyGroups with ExternalUsers only

This commit is contained in:
Sebastian Serth
2018-11-26 17:06:35 +01:00
parent 141450a840
commit b137e64020
12 changed files with 86 additions and 6 deletions

View File

@@ -4,11 +4,11 @@ class ExternalUser < User
validates :external_id, presence: true
def displayname
result = name
if(result == nil || result == "")
result = "User " + id.to_s
if name.blank?
"User " + id.to_s
else
name
end
result
end
end

11
app/models/study_group.rb Normal file
View File

@@ -0,0 +1,11 @@
# frozen_string_literal: true
class StudyGroup < ApplicationRecord
has_many :study_group_memberships
# Use `ExternalUser` as `source_type` for now.
# Using `User` will lead ActiveRecord to access the inexistent table `users`.
# Issue created: https://github.com/rails/rails/issues/34531
has_many :users, through: :study_group_memberships, source_type: 'ExternalUser'
has_many :submissions
belongs_to :consumer
end

View File

@@ -0,0 +1,8 @@
# frozen_string_literal: true
class StudyGroupMembership < ApplicationRecord
belongs_to :user, polymorphic: true
belongs_to :study_group
validates_uniqueness_of :user_id, :scope => [:user_type, :study_group_id]
end

View File

@@ -6,6 +6,7 @@ class Submission < ApplicationRecord
FILENAME_URL_PLACEHOLDER = '{filename}'
belongs_to :exercise
belongs_to :study_group, optional: true
has_many :testruns
has_many :structured_errors

View File

@@ -4,6 +4,8 @@ class User < ApplicationRecord
ROLES = %w(admin teacher)
belongs_to :consumer
has_many :study_group_memberships, as: :user
has_many :study_groups, through: :study_group_memberships, as: :user
has_many :exercises, as: :user
has_many :file_types, as: :user
has_many :submissions, as: :user