class DeepUnrest::Authorization::PunditStrategy
Public Class Methods
auth_error_message(user, scope)
click to toggle source
# File lib/deep_unrest/authorization/pundit_strategy.rb, line 19 def self.auth_error_message(user, scope) if user actor = "#{user.class.name} with id '#{user.id}' is" else actor = "Anonymous users are" end target = (scope[:type] || scope[:key]).to_s.classify unless %i[create update_all].include? scope[:scope_type] target_id = (scope[:id] || scope.dig(:query, :id)).to_s.gsub('.', '') target += " with id '#{target_id.to_s.gsub('.', '')}'" end msg = "#{actor} not authorized to #{scope[:scope_type].to_s.downcase} #{target}" [{ title: msg, source: { pointer: scope[:path] } }].to_json end
get_policy(klass)
click to toggle source
# File lib/deep_unrest/authorization/pundit_strategy.rb, line 10 def self.get_policy(klass) "#{klass}Policy".constantize end
get_policy_name(method)
click to toggle source
# File lib/deep_unrest/authorization/pundit_strategy.rb, line 6 def self.get_policy_name(method) "#{method}?".to_sym end