Migrate database and models for study-group-based authorization
This commit is contained in:

committed by
Sebastian Serth

parent
ec4c6207f0
commit
04ed45ea73
@ -4,6 +4,7 @@ require 'securerandom'
|
||||
|
||||
class AuthenticationToken < ApplicationRecord
|
||||
include Creation
|
||||
belongs_to :study_group, optional: true
|
||||
|
||||
def self.generate!(user)
|
||||
create!(
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
class Consumer < ApplicationRecord
|
||||
has_many :users
|
||||
has_many :study_groups, dependent: :destroy
|
||||
|
||||
scope :with_internal_users, -> { where('id IN (SELECT DISTINCT consumer_id FROM internal_users)') }
|
||||
scope :with_external_users, -> { where('id IN (SELECT DISTINCT consumer_id FROM external_users)') }
|
||||
|
@ -6,6 +6,8 @@ class StudyGroup < ApplicationRecord
|
||||
has_many :internal_users, through: :study_group_memberships, source_type: 'InternalUser', source: :user
|
||||
has_many :submissions, dependent: :nullify
|
||||
has_many :remote_evaluation_mappings, dependent: :nullify
|
||||
has_many :subscriptions, dependent: :nullify
|
||||
has_many :authentication_tokens, dependent: :nullify
|
||||
belongs_to :consumer
|
||||
|
||||
def users
|
||||
|
@ -4,5 +4,11 @@ class StudyGroupMembership < ApplicationRecord
|
||||
belongs_to :user, polymorphic: true
|
||||
belongs_to :study_group
|
||||
|
||||
enum role: {
|
||||
learner: 0,
|
||||
teacher: 1,
|
||||
}, _default: :learner, _prefix: true
|
||||
|
||||
validates :role, presence: true
|
||||
validates :user_id, uniqueness: {scope: %i[user_type study_group_id]}
|
||||
end
|
||||
|
@ -3,4 +3,5 @@
|
||||
class Subscription < ApplicationRecord
|
||||
belongs_to :user, polymorphic: true
|
||||
belongs_to :request_for_comment
|
||||
belongs_to :study_group, optional: true
|
||||
end
|
||||
|
Reference in New Issue
Block a user