@@ -26,12 +26,8 @@ def initialize(controller, ability = ::Ability)
26
26
# instance if it is available.
27
27
def authorize ( action , abstract_model = nil , model_object = nil )
28
28
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 )
35
31
end
36
32
37
33
# 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)
40
36
# return a boolean whereas +authorize+ will raise an exception when not authorized.
41
37
def authorized? ( action , abstract_model = nil , model_object = nil )
42
38
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 )
46
41
end
47
42
48
43
# 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)
61
56
62
57
private
63
58
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
76
61
if subject
77
62
[ action , subject ]
78
63
else
0 commit comments