Skip to content

Commit 5bebac2

Browse files
committed
Drop support for CanCanCan legacy can :dashboard style dashboard ability
This reverts commit da0584a.
1 parent 6b7495f commit 5bebac2

File tree

2 files changed

+6
-44
lines changed

2 files changed

+6
-44
lines changed

lib/rails_admin/extensions/cancancan/authorization_adapter.rb

+6-21
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ def initialize(controller, ability = ::Ability)
2626
# instance if it is available.
2727
def authorize(action, abstract_model = nil, model_object = nil)
2828
return unless action
29-
subject = model_object || abstract_model && abstract_model.model
30-
if authorized_for_dashboard_in_legacy_way?(action)
31-
subject
32-
else
33-
@controller.current_ability.authorize!(*resolve_with_compatibility(action, subject))
34-
end
29+
action, subject = resolve_action_and_subject(action, abstract_model, model_object)
30+
@controller.current_ability.authorize!(action, subject)
3531
end
3632

3733
# This method is called primarily from the view to determine whether the given user
@@ -40,9 +36,8 @@ def authorize(action, abstract_model = nil, model_object = nil)
4036
# return a boolean whereas +authorize+ will raise an exception when not authorized.
4137
def authorized?(action, abstract_model = nil, model_object = nil)
4238
return unless action
43-
subject = model_object || abstract_model && abstract_model.model
44-
authorized_for_dashboard_in_legacy_way?(action, true) ||
45-
@controller.current_ability.can?(*resolve_with_compatibility(action, subject))
39+
action, subject = resolve_action_and_subject(action, abstract_model, model_object)
40+
@controller.current_ability.can?(action, subject)
4641
end
4742

4843
# This is called when needing to scope a database query. It is called within the list
@@ -61,18 +56,8 @@ def attributes_for(action, abstract_model)
6156

6257
private
6358

64-
def authorized_for_dashboard_in_legacy_way?(action, silent = false)
65-
return false unless action == :dashboard
66-
legacy_ability = @controller.current_ability.permissions[:can][:dashboard]
67-
if legacy_ability && (legacy_ability.empty? || legacy_ability.all?(&:empty?))
68-
ActiveSupport::Deprecation.warn('RailsAdmin CanCanCan Ability with `can :dashboard` is old and support will be removed in the next major release, use `can :read, :dashboard` instead. See https://github.com/sferik/rails_admin/issues/2901') unless silent
69-
true
70-
else
71-
false
72-
end
73-
end
74-
75-
def resolve_with_compatibility(action, subject)
59+
def resolve_action_and_subject(action, abstract_model, model_object)
60+
subject = model_object || abstract_model && abstract_model.model
7661
if subject
7762
[action, subject]
7863
else

spec/integration/authorization/cancancan_spec.rb

-23
Original file line numberDiff line numberDiff line change
@@ -340,27 +340,4 @@ def initialize(user)
340340
end
341341
end
342342
end
343-
344-
describe 'with existing dashboard ability which uses no subject' do
345-
class LegacyDashboardAbility
346-
include CanCan::Ability
347-
def initialize(_)
348-
can :access, :rails_admin
349-
can :dashboard
350-
end
351-
end
352-
353-
before do
354-
RailsAdmin.config { |c| c.authorize_with :cancancan, LegacyDashboardAbility }
355-
@user = FactoryBot.create :user
356-
login_as @user
357-
end
358-
359-
it 'shows dashboard with instruction on how to migrate to new ability notation' do
360-
allow(ActiveSupport::Deprecation).to receive(:warn)
361-
expect(ActiveSupport::Deprecation).to receive(:warn).with(/can :read, :dashboard/)
362-
visit dashboard_path
363-
is_expected.to have_content('Dashboard')
364-
end
365-
end if CanCan::VERSION < '3'
366343
end

0 commit comments

Comments
 (0)