Sha256: 4a5d85d161cdc900934cda7c97d713204e52232d8cc7627231a6028de22ef8bf

Contents?: true

Size: 977 Bytes

Versions: 22

Compression:

Stored size: 977 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.assignments.build(exercise: self, organization: organization)
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
mumuki-domain-7.7.3 app/models/concerns/with_assignments.rb
mumuki-domain-7.7.2 app/models/concerns/with_assignments.rb
mumuki-domain-7.7.1 app/models/concerns/with_assignments.rb
mumuki-laboratory-7.7.1 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-cb7a9018bb94/app/models/concerns/with_assignments.rb
mumuki-laboratory-7.7.0 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-cb7a9018bb94/app/models/concerns/with_assignments.rb
mumuki-domain-7.7.0 app/models/concerns/with_assignments.rb
mumuki-domain-7.6.1 app/models/concerns/with_assignments.rb
mumuki-domain-7.6.0 app/models/concerns/with_assignments.rb
mumuki-laboratory-7.5.2 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-ad16a5930cec/app/models/concerns/with_assignments.rb
mumuki-laboratory-7.5.1 vendor/bundle/ruby/2.3.0/bundler/gems/mumuki-domain-a059418e5fd8/app/models/concerns/with_assignments.rb
mumuki-domain-7.5.1 app/models/concerns/with_assignments.rb
mumuki-laboratory-7.5.0 vendor/bundle/ruby/2.6.0/bundler/gems/mumuki-domain-acb12583b793/app/models/concerns/with_assignments.rb
mumuki-domain-7.5.0 app/models/concerns/with_assignments.rb
mumuki-domain-7.4.1 app/models/concerns/with_assignments.rb
mumuki-domain-7.4.0 app/models/concerns/with_assignments.rb
mumuki-domain-7.3.2 app/models/concerns/with_assignments.rb
mumuki-domain-7.3.1 app/models/concerns/with_assignments.rb
mumuki-domain-7.2.3 app/models/concerns/with_assignments.rb
mumuki-domain-7.3.0 app/models/concerns/with_assignments.rb
mumuki-domain-7.2.2 app/models/concerns/with_assignments.rb