morhekil (owner)

Revisions

gist: 221869 Download_button fork
public
Public Clone URL: git://gist.github.com/221869.git
Embed All Files: show embed
user.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'aasm'
 
class User < ActiveRecord::Base
  acts_as_authentic
  acts_as_authorization_subject
  include AASM
  
  has_and_belongs_to_many :roles
  has_and_belongs_to_many :trackers
  
  aasm_initial_state :unconfirmed
  aasm_state :unconfirmed
  aasm_state :confirmed
  aasm_event :confirm do
    transitions :from => :unconfirmed, :to => :confirmed
  end
  alias_attribute :state, :aasm_state
 
  named_scope :unconfirmed, :conditions => [ 'aasm_state = ?', 'unconfirmed' ]
 
  # Overriding default acl9's role check to pass role checks onto auth objects
  def has_role?(role_name, object=nil)
    !! if object.nil?
      self.roles.find_by_name(role_name.to_s) ||
      self.roles.member?(get_role(role_name, nil))
    else
      method = "is_#{role_name.to_s}?".to_sym
      object.respond_to?(method) && object.send(method, self)
    end
  end
 
  def is_self?(user)
    user.id == self.id && user.class == self.class
  end
 
end