Skip to content

Commit

Permalink
Merge pull request #1281 from mamhoff/allow-override-resource-authorize
Browse files Browse the repository at this point in the history
Resource Controller: Allow overriding authorize_resource
  • Loading branch information
mamhoff authored Jul 29, 2017
2 parents 7daea57 + ad8852b commit 41acc37
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/controllers/alchemy/admin/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class ResourcesController < Alchemy::Admin::BaseController
before_action :load_resource,
only: [:show, :edit, :update, :destroy]

before_action do
authorize!(action_name.to_sym, resource_instance_variable || resource_handler.model)
end
before_action :authorize_resource

def index
@query = resource_handler.model.ransack(params[:q])
Expand Down Expand Up @@ -112,6 +110,10 @@ def load_resource
instance_variable_set("@#{resource_handler.resource_name}", resource_handler.model.find(params[:id]))
end

def authorize_resource
authorize!(action_name.to_sym, resource_instance_variable || resource_handler.model)
end

# Permits all parameters as default!
#
# THIS IS INSECURE! Although only signed in admin users can send requests anyway, but we should change this.
Expand Down

0 comments on commit 41acc37

Please sign in to comment.