Sha256: 295b6006fe0723b3666f5ad0e386d0e3ec77926244442919212bafb98c2be933

Contents?: true

Size: 1.43 KB

Versions: 61

Compression:

Stored size: 1.43 KB

Contents

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me

  has_one :user_has_role
  has_one :role, :through => :user_has_role
  belongs_to :user_group
  belongs_to :required_role, :class_name => 'Role', :foreign_key => 'required_role_id'
  has_many :sent_messages, :foreign_key => 'sender_id', :class_name => 'Message'
  has_many :received_messages, :foreign_key => 'receiver_id', :class_name => 'Message'

  extend FriendlyId
  friendly_id :username

  def send_message(status, options = {})
    MessageRequest.transaction do
      request = MessageRequest.new
      request.sender = User.find(1)
      request.receiver = self
      request.message_template = MessageTemplate.localized_template(status, self.locale)
      request.save_message_body(options)
      request.sm_send_message!
    end
  end

  def has_role?(role_in_question)
    return false unless role
    return true if role.name == role_in_question
    case role.name
    when 'Administrator'
      return true
    when 'Librarian'
      return true if role_in_question == 'User'
    else
      false
    end
  end
end

Version data entries

61 entries across 61 versions & 3 rubygems

Version Path
enju_subject-0.1.0.pre25 spec/dummy/app/models/user.rb
enju_trunk_subject-1.0.4 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre24 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre23 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre22 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre21 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre20 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre19 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre18 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre17 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre16 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre15 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre14 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre13 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre12 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre11 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre10 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre9 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre8 spec/dummy/app/models/user.rb
enju_subject-0.1.0.pre7 spec/dummy/app/models/user.rb