Sha256: d9f30fb354528cb84631ad9682e94e8d49874c53a32dc16c2045130056167078

Contents?: true

Size: 952 Bytes

Versions: 24

Compression:

Stored size: 952 Bytes

Contents

module WithAssignments
  extend ActiveSupport::Concern

  # TODO we must avoid _for(user) methods when they
  # are hidden the assignment object, since an assignment already encapsulates
  # the exercise-user pair, and many times they impose a performance hit,
  # since in the normal scenario the assignment object already exists

  included do
    has_many :assignments, dependent: :destroy
  end

  def messages_for(user)
    assignment_for(user).messages
  end

  def has_messages_for?(user)
    messages_for(user).present?
  end

  # TODO: When the organization is used in this one, please change guide.pending_exercises
  def find_assignment_for(user, _organization)
    assignments.find_by(submitter: user)
  end

  def status_for(user)
    assignment_for(user).status if user
  end

  def assignment_for(user, organization=Organization.current)
    find_assignment_for(user, organization) || user.build_assignment(self, organization)
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
mumuki-domain-8.3.1 app/models/concerns/with_assignments.rb
mumuki-domain-8.2.0 app/models/concerns/with_assignments.rb
mumuki-domain-8.1.3 app/models/concerns/with_assignments.rb
mumuki-domain-8.1.2 app/models/concerns/with_assignments.rb
mumuki-domain-8.1.1 app/models/concerns/with_assignments.rb
mumuki-domain-8.1.0 app/models/concerns/with_assignments.rb
mumuki-domain-8.0.0 app/models/concerns/with_assignments.rb
mumuki-domain-7.12.2 app/models/concerns/with_assignments.rb
mumuki-domain-7.12.1 app/models/concerns/with_assignments.rb
mumuki-domain-7.12.0 app/models/concerns/with_assignments.rb
mumuki-domain-7.11.1 app/models/concerns/with_assignments.rb
mumuki-laboratory-7.11.1 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-c92f2a7212e2/app/models/concerns/with_assignments.rb
mumuki-laboratory-7.11.0 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-2e15c3330133/app/models/concerns/with_assignments.rb
mumuki-domain-7.11.0 app/models/concerns/with_assignments.rb
mumuki-domain-7.10.1 app/models/concerns/with_assignments.rb
mumuki-domain-7.10.0 app/models/concerns/with_assignments.rb
mumuki-laboratory-7.9.2 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-7082a83493eb/app/models/concerns/with_assignments.rb
mumuki-domain-7.9.2 app/models/concerns/with_assignments.rb
mumuki-laboratory-7.9.1 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-b162dc91aa77/app/models/concerns/with_assignments.rb
mumuki-domain-7.9.1 app/models/concerns/with_assignments.rb