app/models/adminpanel/user.rb in adminpanel-2.2.5 vs app/models/adminpanel/user.rb in adminpanel-2.3.0

- old
+ new

@@ -1,39 +1,39 @@ module Adminpanel class User < ActiveRecord::Base include Adminpanel::Base has_secure_password - belongs_to :rol + belongs_to :role, touch: true - #rol validation - validates_presence_of :rol_id + default_scope do + includes(:role) + end - #name validations + #role validation + validates_presence_of :role_id + + #name validations validates_presence_of :name - validates_length_of :name, :maximum => 25 + validates_length_of :name, maximum: 25 - #password validations - validates_confirmation_of :password, :on => :create - validates_presence_of :password, :on => :create - validates_length_of :password, :minimum => 6, :on => :create + #password validations + validates_confirmation_of :password, on: :create + validates_presence_of :password, on: :create + validates_length_of :password, minimum: 6, on: :create - #password_confirmation validations - validates_presence_of :password_confirmation, :on => :create + #password_confirmation validations + validates_presence_of :password_confirmation, on: :create - #email validations + #email validations validates_presence_of :email validates_uniqueness_of :email VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i - validates_format_of :email, :with => VALID_EMAIL_REGEX + validates_format_of :email, with: VALID_EMAIL_REGEX before_save{ email.downcase! } before_save :create_remember_token - def has_role?(role_sym) - roles.any? { |r| r.name.underscore.to_sym == role_sym } - end - def self.form_attributes [ { 'name' => { 'type' => 'text_field', @@ -63,34 +63,30 @@ 'label' => I18n.t('model.attributes.password_confirmation'), 'show' => 'false' } }, { - 'rol_id' => { + 'role_id' => { 'type' => 'belongs_to', - 'model' => 'Adminpanel::Rol', + 'model' => 'Adminpanel::Role', # 'remote_resource' => false, - 'placeholder' => I18n.t('model.attributes.rol_id'), - 'label' => I18n.t('model.attributes.rol_id') + 'placeholder' => I18n.t('model.attributes.role_id'), + 'label' => I18n.t('model.attributes.role_id') } }, ] end - def root_url - self.rol.permissions.first - end - - def self.display_name - 'Usuario' - end - - def User.new_remember_token + def self.new_remember_token SecureRandom.urlsafe_base64 end - def User.digest(token) + def self.digest(token) Digest::SHA1.hexdigest(token.to_s) + end + + def self.display_name + I18n.t('model.User') end def self.icon 'user' end