Sha256: c50daafff57823244ba6471147cd6414163ba2cc7b862a6277d158402a1d476c

Contents?: true

Size: 1.65 KB

Versions: 23

Compression:

Stored size: 1.65 KB

Contents

# <%= autogenerated_event_warning %>

module LiveEvents
  class CourseSectionEvent < LiveEvents::BaseEvent
    # The following is provided in the live events call:
    # {
    #   course_section_id: section.id,
    #   sis_source_id: section.sis_source_id,
    #   sis_batch_id: section.sis_batch_id,
    #   course_id: section.course_id,
    #   root_account_id: section.root_account_id,
    #   enrollment_term_id: section.enrollment_term_id,
    #   name: section.name,
    #   default_section: section.default_section,
    #   accepting_enrollments: section.accepting_enrollments,
    #   can_manually_enroll: section.can_manually_enroll,
    #   start_at: section.start_at,
    #   end_at: section.end_at,
    #   workflow_state: section.workflow_state,
    #   restrict_enrollments_to_section_dates: section.restrict_enrollments_to_section_dates,
    #   nonxlist_course_id: section.nonxlist_course_id,
    #   stuck_sis_fields: section.stuck_sis_fields,
    #   integration_id: section.integration_id
    # }

    def perform(_event_payload)
      super
      attrs = {
        canvas_section_id: local_canvas_id(payload[:course_section_id]),
        canvas_course_id: local_canvas_id(payload[:course_id]),
        name: payload[:name],
        status: payload[:workflow_state],
        start_date: payload[:start_at],
        end_date: payload[:end_at],
        canvas_nonxlist_course_id: payload[:nonxlist_course_id],
      }
      create_or_update(attrs)
    end

    private

    def create_or_update(attrs)
      section = Section.where(canvas_section_id: attrs[:canvas_section_id]).first_or_initialize
      section.assign_attributes(attrs)
      section.save!
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
canvas_sync-0.9.4 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.9.3 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.9.2 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.9.1 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.9.0 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.8.4 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.8.3 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.8.2 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.8.1 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.8.0 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.7.3 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.7.2 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.7.1 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.7.0 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.6.4 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.6.3 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.6.2 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.6.1 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.6.0 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb
canvas_sync-0.5.4 lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb