Sha256: a67c5dfa5dda730f22b06ba53259cfb882d02276eef112933ef949514d3188cf

Contents?: true

Size: 1.52 KB

Versions: 55

Compression:

Stored size: 1.52 KB

Contents

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

55 entries across 55 versions & 1 rubygems

Version Path
think_feel_do_engine-3.19.9 app/models/user.rb
think_feel_do_engine-3.19.8 app/models/user.rb
think_feel_do_engine-3.19.7 app/models/user.rb
think_feel_do_engine-3.19.6 app/models/user.rb
think_feel_do_engine-3.19.5 app/models/user.rb
think_feel_do_engine-3.19.4 app/models/user.rb
think_feel_do_engine-3.19.3 app/models/user.rb
think_feel_do_engine-3.19.2 app/models/user.rb
think_feel_do_engine-3.19.1 app/models/user.rb
think_feel_do_engine-3.19.0 app/models/user.rb
think_feel_do_engine-3.18.0 app/models/user.rb
think_feel_do_engine-3.17.2 app/models/user.rb
think_feel_do_engine-3.17.1 app/models/user.rb
think_feel_do_engine-3.17.0 app/models/user.rb
think_feel_do_engine-3.16.3 app/models/user.rb
think_feel_do_engine-3.16.2 app/models/user.rb
think_feel_do_engine-3.16.1 app/models/user.rb
think_feel_do_engine-3.15.7 app/models/user.rb
think_feel_do_engine-3.16.0 app/models/user.rb
think_feel_do_engine-3.15.6 app/models/user.rb