Sha256: 1107d385f47fb08a84211d6729cdde2043d9881a450e1b28ad911ee619508370

Contents?: true

Size: 1005 Bytes

Versions: 4

Compression:

Stored size: 1005 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
  # TODO: Please do the same on WithAssignmentsBatch
  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

4 entries across 4 versions & 1 rubygems

Version Path
mumuki-domain-8.6.1 app/models/concerns/with_assignments.rb
mumuki-domain-8.6.0 app/models/concerns/with_assignments.rb
mumuki-domain-8.5.0 app/models/concerns/with_assignments.rb
mumuki-domain-8.4.0 app/models/concerns/with_assignments.rb