Allow assignment of study groups for internal users

This commit is contained in:
Sebastian Serth
2022-09-20 15:52:55 +02:00
committed by Sebastian Serth
parent 998a12e6bc
commit 4d2fe22daf
6 changed files with 79 additions and 2 deletions

View File

@ -1,9 +1,17 @@
# frozen_string_literal: true
class StudyGroupMembership < ApplicationRecord
ROLES = %w[learner teacher].freeze
belongs_to :user, polymorphic: true
belongs_to :study_group
before_save :destroy_if_empty_study_group_or_user
def destroy_if_empty_study_group_or_user
destroy if study_group.blank? || user.blank?
end
enum role: {
learner: 0,
teacher: 1,