Sha256: 2162b658aadce346e0dc8766ac96598ab640618af2b7aca607c210258060598d

Contents?: true

Size: 881 Bytes

Versions: 1

Compression:

Stored size: 881 Bytes

Contents

<%= autogenerated_model_warning %>

class Admin < ApplicationRecord
  include CanvasSync::ApiSyncable

  validates :canvas_id, uniqueness: true, presence: true
  belongs_to :user, primary_key: :canvas_id, foreign_key: :canvas_user_id, optional: true
  belongs_to :role, primary_key: :canvas_id, foreign_key: :canvas_role_id, optional: true

  api_syncable({
    canvas_id: :id,
    role_name: :role,
    canvas_role_id: :role_id,
    user_data: :user,
    canvas_user_id: ->(r) { r['user']['id'] },
    workflow_state: :workflow_state,
  }, -> (api) {
    admins = api.account_admins('self').all_pages!
    admin_data = admins.find{|admin| admin['id'] == canvas_id }
    raise Footrest::HttpError::NotFound unless admin_data.present?
    admin_data
  })

  def self.create_or_update(params); find_or_initialize_by(canvas_id: params['id']).update_from_api_params!(params); end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
canvas_sync-0.10.2 lib/canvas_sync/generators/templates/models/admin.rb