Sha256: 3a4e58fa50a48752885121dad5d905da85ac73d12c261d38bbc0d52db5d19e78

Contents?: true

Size: 1.97 KB

Versions: 19

Compression:

Stored size: 1.97 KB

Contents

<%= autogenerated_event_warning %>

class LiveEvents::AssignmentEvent < LiveEvents::BaseEvent
  # The following is provided in the live events call:
  # {
  #     assignment_id: assignment.global_id,
  #     context_id: assignment.global_context_id,
  #     context_type: assignment.context_type,
  #     workflow_state: assignment.workflow_state,
  #     title: LiveEvents.truncate(assignment.title),
  #     description: LiveEvents.truncate(assignment.description),
  #     due_at: assignment.due_at,
  #     unlock_at: assignment.unlock_at,
  #     lock_at: assignment.lock_at,
  #     updated_at: assignment.updated_at,
  #     points_possible: assignment.points_possible
  # }

  def perform(event_payload)
    super
    attrs = {
        canvas_assignment_id: local_canvas_id(payload[:assignment_id]),
        course_id: course.try(:id),
        name: payload[:title],
        workflow_state: payload[:workflow_state],
        description: payload[:description],
        due_at: payload[:due_at],
        unlock_at: payload[:unlock_at],
        lock_at: payload[:lock_at],
        points_possible: payload[:points_possible],
        canvas_updated_at: payload[:updated_at]
    }
    create_or_update(attrs)
  rescue => e
    log_error e
  ensure
    true
  end

  private
  def create_or_update(attrs)
    assignment = Assignment.where(canvas_assignment_id: attrs[:canvas_assignment_id]).first_or_initialize
    assignment.assign_attributes(attrs)
    assignment.save!
    assignment
  end

  # This could be nil if the context type for this assignment is not 'Course' of if a local course was not found
  def canvas_course_id
    payload[:context_type] == 'Course' ? local_canvas_id(payload[:context_id]) : nil
  end

  # This could be nil if the context type for this assignment is not 'Course' of if a local course was not found
  def course
    unless @course
      if canvas_course_id.present?
        @course = Course.find_by(canvas_course_id: canvas_course_id)
      end
    end
    @course
  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
canvas_sync-0.3.23 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.22 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.21 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.20 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.19 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.18 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.17 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.16 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.15 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.14 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.13 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.12 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.11 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.10 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.9 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.8 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.7 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.6 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
canvas_sync-0.3.5 lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb