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

@@ -11,6 +11,8 @@ class InternalUser < User
validates :password, confirmation: true, if: -> { password_void? && validate_password? }, on: :update, presence: true
validate :password_strength, if: -> { password_void? && validate_password? }, on: :update
accepts_nested_attributes_for :study_group_memberships
def activated?
activation_state == 'active'
end

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,