Skip to content

Commit ce182cf

Browse files
committed
Remove authorize_scope temporarily
1 parent 1dea5c3 commit ce182cf

File tree

4 files changed

+7
-33
lines changed

4 files changed

+7
-33
lines changed

app/controllers/administrate/application_controller.rb

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ class ApplicationController < ActionController::Base
55
def index
66
authorize_resource(resource_class)
77
search_term = params[:search].to_s.strip
8-
authorized_scope = authorize_scope(scoped_resource)
9-
resources = filter_resources(authorized_scope, search_term: search_term)
8+
resources = filter_resources(scoped_resource, search_term: search_term)
109
resources = apply_collection_includes(resources)
1110
resources = order.apply(resources)
1211
resources = paginate_resources(resources)
1312
page = Administrate::Page::Collection.new(dashboard, order: order)
1413
page.context = self
15-
filters = Administrate::Search.new(authorized_scope, dashboard, search_term).valid_filters
14+
filters = Administrate::Search.new(scoped_resource, dashboard, search_term).valid_filters
1615

1716
render locals: {
1817
resources: resources,
@@ -210,16 +209,7 @@ def requested_resource
210209
# @param param [ActiveSupport::Parameter]
211210
# @return [ActiveRecord::Base]
212211
def find_resource(param)
213-
authorize_scope(scoped_resource).find(param)
214-
end
215-
216-
# Override this if you want to authorize the scope.
217-
# This will be used in all actions except for the `new` and `create` actions.
218-
#
219-
# @param scope [ActiveRecord::Relation]
220-
# @return [ActiveRecord::Relation]
221-
def authorize_scope(scope)
222-
scope
212+
scoped_resource.find(param)
223213
end
224214

225215
# Override this if you have certain roles that require a subset.

app/controllers/concerns/administrate/punditize.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def policy_namespace
1515
[]
1616
end
1717

18-
def authorize_scope(scope)
19-
namespaced_scope = policy_namespace + [scope]
18+
def scoped_resource
19+
namespaced_scope = policy_namespace + [super]
2020
policy_scope!(pundit_user, namespaced_scope)
2121
end
2222

docs/customizing_controller_actions.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,7 @@ class Admin::FoosController < Admin::ApplicationController
2727
# This will be used to set the resource for the `show`, `edit`, `update` and `destroy` actions.
2828
#
2929
# def find_resource(param)
30-
# authorize_scope(scoped_resource).find_by!(slug: param)
31-
# end
32-
33-
# Override this if you want to authorize the scope.
34-
# This will be used in all actions except for the `new` and `create` actions.
35-
#
36-
# def authorize_scope(scope)
37-
# namespaced_scope = policy_namespace + [scope]
38-
# policy_scope!(pundit_user, namespaced_scope)
30+
# Foo.find_by!(slug: param)
3931
# end
4032

4133
# Override this if you have certain roles that require a subset.

spec/controllers/admin/application_controller_spec.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ def resource_resolver
111111

112112
before do
113113
allow(controller).to receive(:find_resource).and_call_original
114-
allow(controller).to receive(:authorize_scope).and_call_original
115114
allow(controller).to receive(:scoped_resource).with(no_args).and_call_original
116115
allow(controller).to receive(:authorize_resource).and_call_original
117116
allow(controller).to receive(:contextualize_resource).and_call_original
@@ -122,8 +121,7 @@ def resource_resolver
122121
it "passes all necessary authorization methods" do
123122
get :index, params: {}
124123
expect(controller).not_to have_received(:find_resource)
125-
expect(controller).to have_received(:authorize_scope)
126-
expect(controller).to have_received(:scoped_resource)
124+
expect(controller).to have_received(:scoped_resource).exactly(2).times
127125
expect(controller).to have_received(:authorize_resource)
128126
expect(controller).not_to have_received(:contextualize_resource)
129127
end
@@ -133,7 +131,6 @@ def resource_resolver
133131
it "passes all necessary authorization methods" do
134132
get :new, params: {}
135133
expect(controller).not_to have_received(:find_resource)
136-
expect(controller).not_to have_received(:authorize_scope)
137134
expect(controller).not_to have_received(:scoped_resource)
138135
expect(controller).to have_received(:authorize_resource)
139136
expect(controller).to have_received(:contextualize_resource)
@@ -145,7 +142,6 @@ def resource_resolver
145142
params = attributes_for(:order)
146143
post :create, params: {order: params}
147144
expect(controller).not_to have_received(:find_resource)
148-
expect(controller).not_to have_received(:authorize_scope)
149145
expect(controller).not_to have_received(:scoped_resource)
150146
expect(controller).to have_received(:authorize_resource)
151147
expect(controller).to have_received(:contextualize_resource)
@@ -157,7 +153,6 @@ def resource_resolver
157153
order = create(:order)
158154
get :show, params: {id: order.to_param}
159155
expect(controller).to have_received(:find_resource)
160-
expect(controller).to have_received(:authorize_scope)
161156
expect(controller).to have_received(:scoped_resource)
162157
expect(controller).to have_received(:authorize_resource)
163158
expect(controller).to have_received(:contextualize_resource)
@@ -169,7 +164,6 @@ def resource_resolver
169164
order = create(:order)
170165
get :edit, params: {id: order.to_param}
171166
expect(controller).to have_received(:find_resource)
172-
expect(controller).to have_received(:authorize_scope)
173167
expect(controller).to have_received(:scoped_resource)
174168
expect(controller).to have_received(:authorize_resource)
175169
expect(controller).to have_received(:contextualize_resource)
@@ -181,7 +175,6 @@ def resource_resolver
181175
order = create(:order)
182176
put :update, params: {id: order.to_param, order: {address_zip: "666"}}
183177
expect(controller).to have_received(:find_resource)
184-
expect(controller).to have_received(:authorize_scope)
185178
expect(controller).to have_received(:scoped_resource)
186179
expect(controller).to have_received(:authorize_resource)
187180
expect(controller).to have_received(:contextualize_resource)
@@ -193,7 +186,6 @@ def resource_resolver
193186
order = create(:order)
194187
delete :destroy, params: {id: order.to_param}
195188
expect(controller).to have_received(:find_resource)
196-
expect(controller).to have_received(:authorize_scope)
197189
expect(controller).to have_received(:scoped_resource)
198190
expect(controller).to have_received(:authorize_resource)
199191
expect(controller).to have_received(:contextualize_resource)

0 commit comments

Comments
 (0)