Class: User

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#skip_password_validationObject

Returns the value of attribute skip_password_validation.



10
11
12
# File 'app/models/user.rb', line 10

def skip_password_validation
  @skip_password_validation
end

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/user.rb', line 41

def admin?
  admin
end

#content_editor?Boolean

Returns:

  • (Boolean)


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

def content_editor?
  content_editor
end

#designer?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/user.rb', line 45

def designer?
  designer
end

#editor?Boolean

Returns:

  • (Boolean)


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

def editor?
  designer
end

#localeObject



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

def locale
  'en'
end

#nameObject



65
66
67
# File 'app/models/user.rb', line 65

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

#password_complexityObject



75
76
77
78
79
# File 'app/models/user.rb', line 75

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)


69
70
71
72
73
# File 'app/models/user.rb', line 69

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)


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

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)


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

def scoped_site?
  sites.present?
end