Module: Glib::Auth::Policy::ClassMethods

Defined in:
app/controllers/concerns/glib/auth/policy.rb

Instance Method Summary collapse

Instance Method Details

#authorize_resource(*args) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'app/controllers/concerns/glib/auth/policy.rb', line 111

def authorize_resource(*args)
  options = args.extract_options!
  resource_name = args.first

  self.before_action(options.slice(:only, :except, :if, :unless)) do |controller|
    resource_name ||= resource_name_from_controller

    begin
      if !(resource_key = options[:class]).nil?
        resource = case resource_key
        when false
          resource_name.to_sym
        when Symbol, Class
          resource_key
        else
          raise "Invalid resource class: #{resource_key}"
        end

        authorize resource
      elsif (resource_instance = controller.instance_variable_get("@#{resource_name}"))
        authorize resource_instance
      else
        authorize resource_name.camelize.constantize
      end
    rescue Pundit::NotAuthorizedError => e
      raise_access_denied(e.record, e.policy)
    end

    verify_authorized
  end
end

#glib_auth_initObject



98
99
100
101
102
103
# File 'app/controllers/concerns/glib/auth/policy.rb', line 98

def glib_auth_init
  @@__glib_auth_init = true

  before_action :glib_load_resource
  before_action :glib_authorize_resource
end

#glib_auth_inited?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'app/controllers/concerns/glib/auth/policy.rb', line 105

def glib_auth_inited?
  @@__glib_auth_init ||= false
end