8000 Fix pundit policy retrieving on an edge case · activeadmin/activeadmin@6b077d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6b077d1

Browse files
kwentdeivid-rodriguez
authored andcommitted
Fix pundit policy retrieving on an edge case
When retrieving the policy for an `ActiveAdmin::Page`, and the pundit namespace is `:active_admin`, we need an extra check so that the right policy is properly picked up.
1 parent 64baed6 commit 6b077d1

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Bug Fixes
6+
7+
* Fix pundit policy retrieving for static pages when the pundit namespace is :active_admin. [#5777] by [@kwent]
8+
59
## 2.1.0 [](https://github.com/activeadmin/activeadmin/compare/v2.0.0..v2.1.0)
610

711
### Bug Fixes
@@ -454,6 +458,7 @@ Please check [0-6-stable] for previous changes.
454458
[#5740]: https://github.com/activeadmin/activeadmin/pull/5740
455459
[#5751]: https://github.com/activeadmin/activeadmin/pull/5751
456460
[#5758]: https://github.com/activeadmin/activeadmin/pull/5758
461+
[#5777]: https://github.com/activeadmin/activeadmin/pull/5777
457462

458463
[@5t111111]: https://github.com/5t111111
459464
[@aarek]: https://github.com/aarek
@@ -490,6 +495,7 @@ Please check [0-6-stable] for previous changes.
490495
[@johnnyshields]: https://github.com/johnnyshields
491496
[@kjeldahl]: https://github.com/kjeldahl
492497
[@kobeumut]: https://github.com/kobeumut
498+
[@kwent]: https://github.com/kwent
493499
[@leio10]: https://github.com/leio10
494500
[@markstory]: https://github.com/markstory
495501
[@mauriciopasquier]: https://github.com/mauriciopasquier

lib/active_admin/pundit_adapter.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def format_action(action, subject)
5757
private
5858

5959
def namespace(object)
60-
if ActiveAdmin.application.pundit_policy_namespace
61-
[ActiveAdmin.application.pundit_policy_namespace.to_sym, object]
60+
if default_policy_namespace && !object.class.to_s.include?(default_policy_namespace.to_s.camelize)
61+
[default_policy_namespace.to_sym, object]
6262
else
6363
object
6464
end
@@ -72,6 +72,10 @@ def default_policy(user, subject)
7272
default_policy_class.new(user, subject)
7373
end
7474

8000
75+
def default_policy_namespace
76+
ActiveAdmin.application.pundit_policy_namespace
77+
end
78+
7579
end
7680

7781
end

spec/unit/pundit_adapter_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,17 @@ def resolve
130130
end
131131
end
132132
end
133+
134+
context "when retrieve_policy is given a page and namespace is :active_admin" do
135+
let(:page) { namespace.register_page "Dashboard" }
136+
137+
subject(:policy) { auth.retrieve_policy(page) }
138+
139+
before do
140+
allow(ActiveAdmin.application).to receive(:pundit_policy_namespace).and_return :active_admin
141+
end
142+
143+
it("should return page policy instance") { is_expected.to be_instance_of(ActiveAdmin::PagePolicy) }
144+
end
133145
end
134146
end

0 commit comments

Comments
 (0)
0