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



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'app/controllers/concerns/glib/auth/policy.rb', line 124

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



111
112
113
114
115
116
# File 'app/controllers/concerns/glib/auth/policy.rb', line 111

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)


118
119
120
# File 'app/controllers/concerns/glib/auth/policy.rb', line 118

def glib_auth_inited?
  @@__glib_auth_init ||= false
end