Class: Course::AssessmentNotifier

Inherits:
Notifier::Base
  • Object
show all
Defined in:
app/notifiers/course/assessment_notifier.rb

Instance Method Summary collapse

Instance Method Details

#assessment_attempted(user, assessment) ⇒ Object

To be called when user attempted an assessment.


4
5
6
7
8
# File 'app/notifiers/course/assessment_notifier.rb', line 4

def assessment_attempted(user, assessment)
  create_activity(actor: user, object: assessment, event: :attempted).
    notify(assessment.tab.category.course, :feed).
    save!
end

#assessment_submitted(user, course_user, submission) ⇒ Object

To be called when user submitted an assessment.


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/notifiers/course/assessment_notifier.rb', line 11

def (user, course_user, submission)
  return unless email_enabled?(submission.assessment, :new_submission)

  # TODO: Replace with a group_manager method in course_user
  managers = course_user.groups.includes(group_users: [course_user: [:user]]).
             flat_map { |g| g.group_users.select(&:manager?) }.map(&:course_user)

  # Default to course manager if the course user do not have any group manager
  managers = course_user.course.managers.includes(:user) unless managers.count > 0

  activity = create_activity(actor: user, object: submission, event: :submitted)
  managers.each { |manager| activity.notify(manager.user, :email) }
  activity.save!
end