lib/ditty/models/user.rb in ditty-0.8.0 vs lib/ditty/models/user.rb in ditty-0.9.0

- old
+ new

@@ -15,15 +15,24 @@ one_to_many :audit_logs one_to_many :user_login_traits def role?(check) @roles ||= Hash.new do |h, k| - h[k] = !roles_dataset.first(name: k).nil? + role_or_descendant = roles.find do |role| + role.name == k || role.descendants.map(&:name).include?(k) + end + h[k] = !role_or_descendant.nil? end @roles[check] end + def all_roles + roles.inject([]) do |memo, role| + memo + [role] + role.descendants + end.uniq + end + def method_missing(method_sym, *arguments, &block) if respond_to_missing?(method_sym) role?(method_sym[0..-2]) else super @@ -64,9 +73,13 @@ def username identity = identity_dataset.first return identity.username if identity email + end + + def display_name + name || username end class << self def anonymous_user role = ::Ditty::Role.find_or_create(name: 'anonymous')