Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User < ActiveRecord::Base
- # Associations
- belongs_to :website
- # Filters
- before_validation :confirm_website
- before_save :confirm_website
- # Authentication Module
- devise :all, :except => [:confirmable]
- # Attribute
- attr_accessible :email, :password, :firstname, :initials, :lastname
- # External User Model Files
- concerned_with :class_methods, :instance_methods
- def is_admin?
- true if role.eql?("admin")
- end
- def is_user?
- true if role.eql?("user")
- end
- def has_permission?(current_user, action)
- return true if current_user.eql?(self) if action.eql?(:edit)
- return true if current_user.eql?(self) unless action.eql?(:destroy)
- return true if current_user.is_admin? and action.eql?(:edit) unless self.is_admin?
- return true if current_user.is_admin? and action.eql?(:destroy) unless current_user.eql?(self) or self.is_admin?
- raise "No Access"
- end
- private
- def confirm_website
- strip_domain
- self.email = "#{email}@#{website.url}"
- end
- def strip_domain
- self.email = email.slice(0, email.index('@')) if self.email.include?('@')
- end
- end
Add Comment
Please, Sign In to add comment