user.rb 763 Bytes
Newer Older
Florian Hübsch's avatar
Florian Hübsch committed
1
2
3
4
5
class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
6
7

  has_many :collections
8
9
10
  has_many :samples, through: :collections
  has_many :reactions, through: :collections
  has_many :wellplates, through: :collections
Florian Hübsch's avatar
Florian Hübsch committed
11

12
13
  validates_presence_of :first_name, :last_name, allow_blank: false

Florian Hübsch's avatar
Florian Hübsch committed
14
15
16
17
18
19
20
  def owns_collections?(collections)
    collections.pluck(:user_id).uniq == [id]
  end

  def owns_unshared_collections?(collections)
    owns_collections?(collections) && collections.pluck(:is_shared).none?
  end
21
22
23
24

  def name
    "#{first_name} #{last_name}"
  end
Florian Hübsch's avatar
Florian Hübsch committed
25
end