Skip to content

Commit 66be5f3

Browse files
committed
Remove authorize_scope temporarily
1 parent 1be075d commit 66be5f3

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,
@@ -219,16 +218,7 @@ def requested_resource
219218
# @param param [ActiveSupport::Parameter]
220219
# @return [ActiveRecord::Base]
221220
def find_resource(param)
222-
authorize_scope(scoped_resource).find(param)
223-
end
224-
225-
# Override this if you want to authorize the scope.
226-
# This will be used in all actions except for the `new` and `create` actions.
227-
#
228-
# @param scope [ActiveRecord::Relation]
229-
# @return [ActiveRecord::Relation]
230-
def authorize_scope(scope)
231-
scope
221+
scoped_resource.find(param)
232222
end
233223

234224
# 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
@@ -145,7 +145,6 @@ def resource_resolver
145145

146146
before do
147147
allow(controller).to receive(:find_resource).and_call_original
148-
allow(controller).to receive(:authorize_scope).and_call_original
149148
allow(controller).to receive(:scoped_resource).with(no_args).and_call_original
150149
allow(controller).to receive(:authorize_resource).and_call_original
151150
allow(controller).to receive(:contextualize_resource).and_call_original
@@ -156,8 +155,7 @@ def resource_resolver
156155
it "passes all necessary authorization methods" do
157156
get :index, params: {}
158157
expect(controller).not_to have_received(:find_resource)
159-
expect(controller).to have_received(:authorize_scope)
160-
expect(controller).to have_received(:scoped_resource)
158+
expect(controller).to have_received(:scoped_resource).exactly(2).times
161159
expect(controller).to have_received(:authorize_resource)
162160
expect(controller).not_to have_received(:contextualize_resource)
163161
end
@@ -167,7 +165,6 @@ def resource_resolver
167165
it "passes all necessary authorization methods" do
168166
get :new, params: {}
169167
expect(controller).not_to have_received(:find_resource)
170-
expect(controller).not_to have_received(:authorize_scope)
171168
expect(controller).not_to have_received(:scoped_resource)
172169
expect(controller).to have_received(:authorize_resource)
173170
expect(controller).to have_received(:contextualize_resource)
@@ -179,7 +176,6 @@ def resource_resolver
179176
params = attributes_for(:order)
180177
post :create, params: {order: params}
181178
expect(controller).not_to have_received(:find_resource)
182-
expect(controller).not_to have_received(:authorize_scope)
183179
expect(controller).not_to have_received(:scoped_resource)
184180
expect(controller).to have_received(:authorize_resource)
185181
expect(controller).to have_received(:contextualize_resource)
@@ -191,7 +187,6 @@ def resource_resolver
191187
order = create(:order)
192188
get :show, params: {id: order.to_param}
193189
expect(controller).to have_received(:find_resource)
194-
expect(controller).to have_received(:authorize_scope)
195190
expect(controller).to have_received(:scoped_resource)
196191
expect(controller).to have_received(:authorize_resource)
197192
expect(controller).to have_received(:contextualize_resource)
@@ -203,7 +198,6 @@ def resource_resolver
203198
order = create(:order)
204199
get :edit, params: {id: order.to_param}
205200
expect(controller).to have_received(:find_resource)
206-
expect(controller).to have_received(:authorize_scope)
207201
expect(controller).to have_received(:scoped_resource)
208202
expect(controller).to have_received(:authorize_resource)
209203
expect(controller).to have_received(:contextualize_resource)
@@ -215,7 +209,6 @@ def resource_resolver
215209
order = create(:order)
216210
put :update, params: {id: order.to_param, order: {address_zip: "666"}}
217211
expect(controller).to have_received(:find_resource)
218-
expect(controller).to have_received(:authorize_scope)
219212
expect(controller).to have_received(:scoped_resource)
220213
expect(controller).to have_received(:authorize_resource)
221214
expect(controller).to have_received(:contextualize_resource)
@@ -227,7 +220,6 @@ def resource_resolver
227220
order = create(:order)
228221
delete :destroy, params: {id: order.to_param}
229222
expect(controller).to have_received(:find_resource)
230-
expect(controller).to have_received(:authorize_scope)
231223
expect(controller).to have_received(:scoped_resource)
232224
expect(controller).to have_received(:authorize_resource)
233225
expect(controller).to have_received(:contextualize_resource)

0 commit comments

Comments
 (0)