avo 2.17.1.pre.3 → 2.17.1.pre.5.stackedlayout
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of avo might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +20 -9
- data/Gemfile.lock +78 -79
- data/app/components/avo/field_wrapper_component.html.erb +9 -11
- data/app/components/avo/field_wrapper_component.rb +10 -3
- data/app/components/avo/fields/date_field/edit_component.html.erb +6 -6
- data/app/components/avo/fields/date_time_field/edit_component.html.erb +7 -6
- data/app/components/avo/fields/date_time_field/index_component.html.erb +1 -0
- data/app/components/avo/fields/date_time_field/show_component.html.erb +1 -0
- data/app/components/avo/fields/edit_component.rb +1 -1
- data/app/components/avo/fields/show_component.rb +1 -1
- data/app/components/avo/fields/time_field/edit_component.html.erb +6 -6
- data/app/components/avo/index/resource_table_component.html.erb +1 -1
- data/app/components/avo/item_switcher_component.html.erb +4 -1
- data/app/components/avo/panel_component.html.erb +5 -2
- data/app/components/avo/views/resource_edit_component.html.erb +3 -1
- data/app/components/avo/views/resource_index_component.html.erb +4 -4
- data/app/components/avo/views/resource_show_component.html.erb +5 -2
- data/app/controllers/avo/actions_controller.rb +6 -5
- data/app/controllers/avo/application_controller.rb +9 -17
- data/app/controllers/avo/associations_controller.rb +1 -1
- data/app/controllers/avo/cards_controller.rb +12 -2
- data/app/javascript/js/controllers/fields/date_field_controller.js +34 -21
- data/app/views/avo/actions/show.html.erb +1 -1
- data/app/views/avo/cards/chartkick_missing.html.erb +14 -0
- data/avo.gemspec +2 -5
- data/db/factories.rb +5 -5
- data/lib/avo/base_action.rb +1 -1
- data/lib/avo/base_resource.rb +1 -0
- data/lib/avo/concerns/can_replace_fields.rb +36 -0
- data/lib/avo/configuration.rb +4 -0
- data/lib/avo/engine.rb +10 -1
- data/lib/avo/fields/base_field.rb +2 -0
- data/lib/avo/fields/country_field.rb +5 -1
- data/lib/avo/fields/date_time_field.rb +2 -0
- data/lib/avo/fields/time_field.rb +1 -7
- data/lib/avo/html/builder.rb +14 -0
- data/lib/avo/services/authorization_clients/pundit_client.rb +51 -0
- data/lib/avo/services/authorization_service.rb +43 -61
- data/lib/avo/version.rb +1 -1
- data/lib/avo.rb +4 -0
- data/lib/generators/avo/templates/initializer/avo.tt +2 -0
- data/public/avo-assets/avo.base.css +5 -0
- data/public/avo-assets/avo.base.js +73 -73
- data/public/avo-assets/avo.base.js.map +2 -2
- metadata +11 -50
@@ -3,29 +3,43 @@ module Avo
|
|
3
3
|
class AuthorizationService
|
4
4
|
attr_accessor :user
|
5
5
|
attr_accessor :record
|
6
|
+
attr_accessor :policy_class
|
6
7
|
|
7
8
|
class << self
|
9
|
+
def client
|
10
|
+
client = Avo.configuration.authorization_client
|
11
|
+
|
12
|
+
klass = case client
|
13
|
+
when :pundit, nil
|
14
|
+
pundit_client
|
15
|
+
else
|
16
|
+
if client.is_a?(String)
|
17
|
+
client.safe_constantize
|
18
|
+
else
|
19
|
+
client
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
klass.new
|
24
|
+
end
|
25
|
+
|
8
26
|
def authorize(user, record, action, policy_class: nil, **args)
|
9
27
|
return true if skip_authorization
|
10
28
|
return true if user.nil?
|
11
29
|
|
12
|
-
|
13
|
-
begin
|
14
|
-
if policy_class&.new(user, record)
|
15
|
-
Pundit.authorize user, record, action, policy_class: policy_class
|
16
|
-
end
|
30
|
+
client.authorize user, record, action, policy_class: policy_class
|
17
31
|
|
18
|
-
|
19
|
-
|
20
|
-
|
32
|
+
true
|
33
|
+
rescue NoPolicyError => error
|
34
|
+
# By default, Avo allows anything if you don't have a policy present.
|
35
|
+
return true unless Avo.configuration.raise_error_on_missing_policy
|
21
36
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
37
|
+
raise error
|
38
|
+
rescue => error
|
39
|
+
if args[:raise_exception] == false
|
40
|
+
false
|
41
|
+
else
|
42
|
+
raise error
|
29
43
|
end
|
30
44
|
end
|
31
45
|
|
@@ -35,7 +49,7 @@ module Avo
|
|
35
49
|
# If no action passed we should raise error if the user wants that.
|
36
50
|
# If not, just allow it.
|
37
51
|
if action.nil?
|
38
|
-
raise
|
52
|
+
raise NoPolicyError.new "Policy method is missing" if Avo.configuration.raise_error_on_missing_policy
|
39
53
|
|
40
54
|
return true
|
41
55
|
end
|
@@ -48,44 +62,27 @@ module Avo
|
|
48
62
|
def apply_policy(user, model, policy_class: nil)
|
49
63
|
return model if skip_authorization || user.nil?
|
50
64
|
|
51
|
-
|
52
|
-
|
53
|
-
|
65
|
+
client.apply_policy(user, model, policy_class: policy_class)
|
66
|
+
rescue NoPolicyError => error
|
67
|
+
return model unless Avo.configuration.raise_error_on_missing_policy
|
54
68
|
|
55
|
-
|
56
|
-
# Else fallback to pundit.
|
57
|
-
if scope_from_policy_class.present?
|
58
|
-
scope_from_policy_class.new(user, model).resolve
|
59
|
-
else
|
60
|
-
Pundit.policy_scope!(user, model)
|
61
|
-
end
|
62
|
-
rescue Pundit::NotDefinedError => e
|
63
|
-
return model unless Avo.configuration.raise_error_on_missing_policy
|
64
|
-
|
65
|
-
raise e
|
66
|
-
end
|
69
|
+
raise error
|
67
70
|
end
|
68
71
|
|
69
72
|
def skip_authorization
|
70
73
|
Avo::App.license.lacks_with_trial :authorization
|
71
74
|
end
|
72
75
|
|
73
|
-
def authorized_methods(user, record)
|
74
|
-
[:new, :edit, :update, :show, :destroy].map do |method|
|
75
|
-
[method, authorize(user, record, Avo.configuration.authorization_methods[method])]
|
76
|
-
end.to_h
|
77
|
-
end
|
78
|
-
|
79
76
|
def defined_methods(user, record, policy_class: nil, **args)
|
80
|
-
return
|
77
|
+
return client.policy!(user, record).methods if policy_class.nil?
|
81
78
|
|
82
79
|
# I'm aware this will not raise a Pundit error.
|
83
80
|
# Should the policy not exist, it will however raise an uninitialized constant error, which is probably what we want when specifying a custom policy
|
84
81
|
policy_class.new(user, record).methods
|
85
|
-
rescue
|
82
|
+
rescue NoPolicyError => error
|
86
83
|
return [] unless Avo.configuration.raise_error_on_missing_policy
|
87
84
|
|
88
|
-
raise
|
85
|
+
raise error
|
89
86
|
rescue => error
|
90
87
|
if args[:raise_exception] == false
|
91
88
|
[]
|
@@ -94,24 +91,15 @@ module Avo
|
|
94
91
|
end
|
95
92
|
end
|
96
93
|
|
97
|
-
|
98
|
-
|
99
|
-
return if policy_class.blank?
|
100
|
-
|
101
|
-
if policy_class.present? && defined?(policy_class::Scope)
|
102
|
-
policy_class::Scope
|
103
|
-
end
|
94
|
+
def pundit_client
|
95
|
+
Avo::Services::AuthorizationClients::PunditClient
|
104
96
|
end
|
105
97
|
end
|
106
98
|
|
107
99
|
def initialize(user = nil, record = nil, policy_class: nil)
|
108
100
|
@user = user
|
109
101
|
@record = record
|
110
|
-
@policy_class = policy_class ||
|
111
|
-
end
|
112
|
-
|
113
|
-
def authorize(action, **args)
|
114
|
-
self.class.authorize(user, record, action, policy_class: @policy_class, **args)
|
102
|
+
@policy_class = policy_class || self.class.client.policy(user, record)&.class
|
115
103
|
end
|
116
104
|
|
117
105
|
def set_record(record)
|
@@ -120,22 +108,16 @@ module Avo
|
|
120
108
|
self
|
121
109
|
end
|
122
110
|
|
123
|
-
def set_user(user)
|
124
|
-
@user = user
|
125
|
-
|
126
|
-
self
|
127
|
-
end
|
128
|
-
|
129
111
|
def authorize_action(action, **args)
|
130
|
-
self.class.authorize_action(user, record, action, policy_class:
|
112
|
+
self.class.authorize_action(user, record, action, policy_class: policy_class, **args)
|
131
113
|
end
|
132
114
|
|
133
115
|
def apply_policy(model)
|
134
|
-
self.class.apply_policy(user, model, policy_class:
|
116
|
+
self.class.apply_policy(user, model, policy_class: policy_class)
|
135
117
|
end
|
136
118
|
|
137
119
|
def defined_methods(model, **args)
|
138
|
-
self.class.defined_methods(user, model, policy_class:
|
120
|
+
self.class.defined_methods(user, model, policy_class: policy_class, **args)
|
139
121
|
end
|
140
122
|
|
141
123
|
def has_method?(method, **args)
|
data/lib/avo/version.rb
CHANGED
data/lib/avo.rb
CHANGED
@@ -44,6 +44,10 @@ module Avo
|
|
44
44
|
class LicenseVerificationTemperedError < StandardError; end
|
45
45
|
|
46
46
|
class LicenseInvalidError < StandardError; end
|
47
|
+
|
48
|
+
class NotAuthorizedError < StandardError; end
|
49
|
+
|
50
|
+
class NoPolicyError < StandardError; end
|
47
51
|
end
|
48
52
|
|
49
53
|
loader.eager_load
|
@@ -30,6 +30,7 @@ Avo.configure do |config|
|
|
30
30
|
# destroy: 'destroy?',
|
31
31
|
# }
|
32
32
|
# config.raise_error_on_missing_policy = false
|
33
|
+
# config.authorization_client = :pundit
|
33
34
|
|
34
35
|
## == Localization ==
|
35
36
|
# config.locale = 'en-US'
|
@@ -58,6 +59,7 @@ Avo.configure do |config|
|
|
58
59
|
# config.resource_controls = :right
|
59
60
|
# config.tabs_style = :tabs # can be :tabs or :pills
|
60
61
|
# config.buttons_on_form_footers = true
|
62
|
+
# config.field_wrapper_layout = true
|
61
63
|
|
62
64
|
## == Branding ==
|
63
65
|
# config.branding = {
|
@@ -8034,6 +8034,11 @@ trix-toolbar .trix-button-group:not(:first-child){
|
|
8034
8034
|
color:rgb(22 163 74 / var(--tw-text-opacity))
|
8035
8035
|
}
|
8036
8036
|
|
8037
|
+
.\!text-pink-600{
|
8038
|
+
--tw-text-opacity:1 !important;
|
8039
|
+
color:rgb(219 39 119 / var(--tw-text-opacity)) !important
|
8040
|
+
}
|
8041
|
+
|
8037
8042
|
.underline{
|
8038
8043
|
-webkit-text-decoration-line:underline;
|
8039
8044
|
text-decoration-line:underline
|