Sha256: 35bbd9f2fdb8e8ec8513815b2d3cfdecc1759188e7df1433cb76a9f70548bc87

Contents?: true

Size: 1.08 KB

Versions: 14

Compression:

Stored size: 1.08 KB

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, organization: organization)
  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

  def has_progress_for?(user, organization)
    user.present? && find_assignment_for(user, organization).present?
  end


end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mumuki-domain-9.23.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.22.1 app/models/concerns/with_assignments.rb
mumuki-domain-9.22.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.21.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.20.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.19.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.18.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.17.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.16.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.15.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.14.1 app/models/concerns/with_assignments.rb
mumuki-domain-9.14.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.13.1 app/models/concerns/with_assignments.rb
mumuki-domain-9.13.0 app/models/concerns/with_assignments.rb