Class: Virgo::User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Virgo::User
- Extended by:
- FriendlyId
- Includes:
- Search
- Defined in:
- app/models/virgo/user.rb,
app/models/concerns/virgo/user/search.rb
Defined Under Namespace
Modules: Search
Instance Attribute Summary collapse
-
#login ⇒ Object
Returns the value of attribute login.
Class Method Summary collapse
- .find_first_by_auth_conditions(warden_conditions) ⇒ Object
- .find_for_database_authentication(warden_conditions) ⇒ Object
- .role_names(opts = {}) ⇒ Object
Instance Method Summary collapse
- #admin? ⇒ Boolean
- #admin_access? ⇒ Boolean
- #admin_or_editor? ⇒ Boolean
- #editor? ⇒ Boolean
- #full_name ⇒ Object
- #pretty_name ⇒ Object
- #superuser? ⇒ Boolean
Instance Attribute Details
#login ⇒ Object
Returns the value of attribute login.
14 15 16 |
# File 'app/models/virgo/user.rb', line 14 def login @login end |
Class Method Details
.find_first_by_auth_conditions(warden_conditions) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/models/virgo/user.rb', line 107 def self.find_first_by_auth_conditions(warden_conditions) conditions = warden_conditions.dup if login = conditions.delete(:login) where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first else if conditions[:username].nil? where(conditions).first else where(username: conditions[:username]).first end end end |
.find_for_database_authentication(warden_conditions) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'app/models/virgo/user.rb', line 98 def self.find_for_database_authentication(warden_conditions) conditions = warden_conditions.dup if login = conditions.delete(:login) where(conditions.to_h).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first else where(conditions.to_h).first end end |
.role_names(opts = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/virgo/user.rb', line 64 def self.role_names(opts={}) _names = {} if opts[:superuser] _names['Superuser'] = :superuser end _names.merge!( 'Admin' => :admin, 'Editor' => :editor, 'Contributor' => :contributor, 'Normal User' => :user ) _names end |
Instance Method Details
#admin? ⇒ Boolean
48 49 50 |
# File 'app/models/virgo/user.rb', line 48 def admin? role == :admin end |
#admin_access? ⇒ Boolean
44 45 46 |
# File 'app/models/virgo/user.rb', line 44 def admin_access? role.in?([:superuser, :admin, :editor, :contributor]) end |
#admin_or_editor? ⇒ Boolean
60 61 62 |
# File 'app/models/virgo/user.rb', line 60 def admin_or_editor? admin? || editor? end |
#editor? ⇒ Boolean
56 57 58 |
# File 'app/models/virgo/user.rb', line 56 def editor? role == :editor end |
#full_name ⇒ Object
82 83 84 85 86 87 88 |
# File 'app/models/virgo/user.rb', line 82 def full_name if first_name.present? && last_name.present? "#{first_name} #{last_name}" else email end end |
#pretty_name ⇒ Object
90 91 92 93 94 95 96 |
# File 'app/models/virgo/user.rb', line 90 def pretty_name if .present? else full_name end end |
#superuser? ⇒ Boolean
52 53 54 |
# File 'app/models/virgo/user.rb', line 52 def superuser? role == :superuser end |