Sha256: dac1b812ec0da6d6eb90ce41d3895f17edde60ec998e27204db93011c32fce5b

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 KB

Contents

class ExamRegistration < ApplicationRecord
  include WithTimedEnablement
  include TerminalNavigation

  belongs_to :organization
  has_and_belongs_to_many :exams
  has_many :authorization_requests, class_name: 'ExamAuthorizationRequest'

  enum authorization_criterion_type: %i(none passed_exercises), _prefix: :authorization_criterion

  before_save :ensure_valid_authorization_criterion!

  delegate :meets_authorization_criteria?, :process_request!, to: :authorization_criterion

  alias_attribute :name, :description

  def authorization_criterion
    @authorization_criterion ||= ExamRegistration::AuthorizationCriterion.parse(authorization_criterion_type, authorization_criterion_value)
  end

  def ensure_valid_authorization_criterion!
    authorization_criterion.ensure_valid!
  end

  def start!(users)
    users.each &method(:notify_user!)
  end

  def process_requests!
    authorization_requests.each do |it|
      process_request! it
      it.try_authorize!
    end
  end

  def authorization_request_for(user)
    authorization_requests.find_by(user: user) ||
      ExamAuthorizationRequest.new(exam_registration: self, organization: organization)
  end

  private

  def notify_user!(user)
    Notification.create! organization: organization, user: user, target: self
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mumuki-domain-9.0.5 app/models/exam_registration.rb
mumuki-domain-9.0.4 app/models/exam_registration.rb
mumuki-domain-9.0.3 app/models/exam_registration.rb
mumuki-domain-9.0.2 app/models/exam_registration.rb
mumuki-domain-9.0.0 app/models/exam_registration.rb
mumuki-domain-8.6.1 app/models/exam_registration.rb
mumuki-domain-8.6.0 app/models/exam_registration.rb