@@ -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
0 commit comments