Sha256: 516aebe15f64abb5a1bfd701e4dd05e543b4b22b7541d3117d542fc9e030539d

Contents?: true

Size: 1.55 KB

Versions: 13

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true
require "devise"

# A person with some authoritative role (a non-Participant).
class User < ActiveRecord::Base
  include ThinkFeelDoEngine::Concerns::ValidatePassword

  devise :database_authenticatable,
         :recoverable, :trackable, :validatable, :timeoutable,
         timeout_in: 20.minutes

  has_many :coach_assignments, foreign_key: :coach_id, dependent: :destroy
  has_many :participants, through: :coach_assignments
  has_many :sent_messages,
           class_name: "Message",
           as: :sender,
           dependent: :destroy
  has_many :tasks, foreign_key: :creator_id, dependent: :nullify
  has_many :messages, as: :sender, dependent: :destroy
  has_many :received_messages,
           -> { includes :message },
           class_name: "DeliveredMessage",
           as: :recipient,
           dependent: :destroy
  has_many :created_groups,
           class_name: "Group",
           foreign_key: :creator_id,
           dependent: :nullify
  has_many :user_roles, dependent: :destroy

  accepts_nested_attributes_for :coach_assignments

  def build_sent_message(attributes = {})
    sent_messages.build(attributes)
  end

  def participants_for_group(group)
    participants.where(id: group.participant_ids)
  end

  def admin?
    is_admin
  end

  def coach?
    user_roles.map(&:role_class_name).include?("Roles::Clinician")
  end

  def researcher?
    user_roles.map(&:role_class_name).include?("Roles::Researcher")
  end

  def content_author?
    user_roles.map(&:role_class_name).include?("Roles::ContentAuthor")
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
think_feel_do_engine-3.22.9 app/models/user.rb
think_feel_do_engine-3.22.8 app/models/user.rb
think_feel_do_engine-3.22.7 app/models/user.rb
think_feel_do_engine-3.22.6 app/models/user.rb
think_feel_do_engine-3.22.5 app/models/user.rb
think_feel_do_engine-3.22.4 app/models/user.rb
think_feel_do_engine-3.22.2 app/models/user.rb
think_feel_do_engine-3.22.1 app/models/user.rb
think_feel_do_engine-3.22.0 app/models/user.rb
think_feel_do_engine-3.21.2 app/models/user.rb
think_feel_do_engine-3.21.1 app/models/user.rb
think_feel_do_engine-3.21.0 app/models/user.rb
think_feel_do_engine-3.20.1 app/models/user.rb