Sha256: 2ecbb536a58d8ebe0af617d8b02b0f35377c4a0a2101def3a4722c0e7d1cfa57
Contents?: true
Size: 1.83 KB
Versions: 27
Compression:
Stored size: 1.83 KB
Contents
# # # AUTO GENERATED LIVE EVENT # This was auto generated by the CanvasSync Gem. # You can customize it as needed, but make sure you test # any changes you make to the auto generated methods. # 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