Sha256: 2d269c9a712f8d7e12b3e51f4e5de2fd9e21e4be4feb37ff69949d69a514815b
Contents?: true
Size: 1.68 KB
Versions: 27
Compression:
Stored size: 1.68 KB
Contents
# <%= autogenerated_event_warning %> module LiveEvents class EnrollmentEvent < LiveEvents::BaseEvent # The following is provided in the live events call: # { # # enrollment_id: enrollment.global_id, # course_id: enrollment.global_course_id, # user_id: enrollment.global_user_id, # user_name: enrollment.user_name, # type: enrollment.type, # created_at: enrollment.created_at, # updated_at: enrollment.updated_at, # limit_privileges_to_course_section: enrollment.limit_privileges_to_course_section, # course_section_id: enrollment.global_course_section_id, # workflow_state: enrollment.workflow_state # } def perform(payload) super return if course.nil? || section.nil? || user.nil? attrs = { canvas_enrollment_id: local_canvas_id(payload[:enrollment_id]), canvas_course_id: course.try(:id), canvas_user_id: user.try(:id), role: payload[:type], canvas_section_id: section.try(:id), status: payload[:workflow_state], } create_or_update(attrs) end private def create_or_update(attrs) enrollment = Enrollment.where(canvas_enrollment_id: attrs[:canvas_enrollment_id]).first_or_initialize enrollment.assign_attributes(attrs) enrollment.save! enrollment end def course @course ||= Course.find_by(canvas_course_id: local_canvas_id(payload[:course_id])) end def section @section ||= Section.find_by(canvas_section_id: local_canvas_id(payload[:section_id])) end def user @user ||= User.find_by(canvas_user_id: local_canvas_id(payload[:user_id])) end end end
Version data entries
27 entries across 27 versions & 1 rubygems