Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#skip_password_validationObject

Returns the value of attribute skip_password_validation.



12
13
14
# File 'app/models/user.rb', line 12

def skip_password_validation
  @skip_password_validation
end

Class Method Details

.serialize_from_session(key, salt) ⇒ Object

Observe-only instrument for the intermittent logout bug (issue #1040). This keeps Devise's exact (site-scoped) behavior — it returns the scoped lookup unchanged, so a mismatch still logs the user out exactly as before — and only reports when a valid user was excluded by the site scope. See TrustyCms::SiteScopeAuthReporter. The behavior-change fix is separate (PR #1041).



88
89
90
91
92
# File 'app/models/user.rb', line 88

def self.serialize_from_session(key, salt)
  record = to_adapter.get(key)
  TrustyCms::SiteScopeAuthReporter.report_miss(key) if record.nil?
  record if record && record.authenticatable_salt == salt
end

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/models/user.rb', line 43

def admin?
  admin
end

#content_editor?Boolean

Returns:

  • (Boolean)


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

def content_editor?
  content_editor
end

#designer?Boolean

Returns:

  • (Boolean)


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

def designer?
  designer
end

#editor?Boolean

Returns:

  • (Boolean)


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

def editor?
  designer
end

#localeObject



63
64
65
# File 'app/models/user.rb', line 63

def locale
  'en'
end

#nameObject



67
68
69
# File 'app/models/user.rb', line 67

def name
  "#{first_name} #{last_name}"
end

#password_complexityObject



77
78
79
80
81
# File 'app/models/user.rb', line 77

def password_complexity
  return false if password.blank? || password =~ /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,70}$/

  errors.add :password, 'Complexity requirement not met. Length should be 12 characters and include: 1 uppercase, 1 lowercase, 1 digit and 1 special character.'
end

#password_required?Boolean

Returns:

  • (Boolean)


71
72
73
74
75
# File 'app/models/user.rb', line 71

def password_required?
  return false if skip_password_validation

  super
end

#role?(role) ⇒ Boolean

Roles Admin - all permissions Editor - all permissions except for users, sites editing Content Editor - all permissions except for users, sites, publishing and deleting

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/user.rb', line 30

def role?(role)
  case role
  when :admin
    admin?
  when :designer
    designer?
  when :content_editor
    content_editor?
  else
    false
  end
end

#scoped_site?Boolean

Returns:

  • (Boolean)


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

def scoped_site?
  sites.present?
end