Class: Virgo::User

Inherits:
ActiveRecord::Base
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loginObject

Returns the value of attribute login


14
15
16
# File 'app/models/virgo/user.rb', line 14

def 
  @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  = conditions.delete(:login)
    where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value => .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  = conditions.delete(:login)
    where(conditions.to_h).where(["lower(username) = :value OR lower(email) = :value", { :value => .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

Returns:

  • (Boolean)

48
49
50
# File 'app/models/virgo/user.rb', line 48

def admin?
  role == :admin
end

#admin_access?Boolean

Returns:

  • (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

Returns:

  • (Boolean)

60
61
62
# File 'app/models/virgo/user.rb', line 60

def admin_or_editor?
  admin? || editor?
end

#editor?Boolean

Returns:

  • (Boolean)

56
57
58
# File 'app/models/virgo/user.rb', line 56

def editor?
  role == :editor
end

#full_nameObject


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_nameObject


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

Returns:

  • (Boolean)

52
53
54
# File 'app/models/virgo/user.rb', line 52

def superuser?
  role == :superuser
end