Module: Alchemy::UserMethods

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/alchemy/user_methods.rb

Instance Method Summary collapse

Instance Method Details

#alchemy_admin? ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/models/concerns/alchemy/user_methods.rb', line 49

def alchemy_admin?
  has_alchemy_role?("admin")
end

#alchemy_roles ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/concerns/alchemy/user_methods.rb', line 53

def alchemy_roles
  if self.class.columns_hash["alchemy_roles"]
    read_attribute(:alchemy_roles).to_s.split(" ")
  else
    Alchemy::Logger.warn <<-WARN.strip_heredoc
      The `alchemy_roles` column is missing in the #{self.class.table_name} table!

      Please run

        rails generate alchemy:user_columns_migration

      to add it.

      Falling back to default role: `member`.
    WARN
    ["member"]
  end
end

#alchemy_roles=(roles) ⇒ Object



72
73
74
75
76
77
# File 'app/models/concerns/alchemy/user_methods.rb', line 72

def alchemy_roles=(roles)
  roles = Array(roles).map { _1.to_s.strip }
  roles.reject!(&:blank?)
  roles.uniq!
  super(roles.join(" "))
end

#has_alchemy_role?(role) ⇒ Boolean

Returns true if the user has the given role.

Returns:

  • (Boolean)


80
81
82
# File 'app/models/concerns/alchemy/user_methods.rb', line 80

def has_alchemy_role?(role)
  alchemy_roles.include?(role.to_s)
end

#human_alchemy_roles ⇒ Object



84
85
86
87
88
# File 'app/models/concerns/alchemy/user_methods.rb', line 84

def human_alchemy_roles
  alchemy_roles.map do |role|
    self.class.human_alchemy_rolename(role)
  end.to_sentence
end

#unlock_pages! ⇒ Object

Calls unlock on all locked pages



91
92
93
# File 'app/models/concerns/alchemy/user_methods.rb', line 91

def unlock_pages!
  locked_pages.each(&:unlock!)
end