Sha256: b7bf05d30baefe8edb19f854de6add35137fa388f02672d537fec05b21631ad2

Contents?: true

Size: 836 Bytes

Versions: 42

Compression:

Stored size: 836 Bytes

Contents

<%= autogenerated_model_warning %>

class Admin < ApplicationRecord
  validates :canvas_admin_id, uniqueness: true, presence: true
  belongs_to :user, primary_key: :canvas_user_id, foreign_key: :canvas_user_id, optional: true
  belongs_to :role, primary_key: :canvas_role_id, foreign_key: :canvas_role_id, optional: true

  def self.create_or_update(admin_params)
    admin = Admin.find_or_initialize_by(canvas_admin_id: admin_params['id'])

    admin.assign_attributes(role_name: admin_params['role'],
                            canvas_role_id: admin_params['role_id'],
                            user_data: admin_params['user'],
                            canvas_user_id: admin_params['user']['id'],
                            workflow_state: admin_params['workflow_state'])

    admin.save! if admin.changed?
    admin
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

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