avo 0.5.0.beta4 → 0.5.0.beta5

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.

Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -2
  3. data/Gemfile.lock +1 -1
  4. data/app/components/avo/index/grid_item_component.html.erb +8 -8
  5. data/app/components/avo/index/grid_item_component.rb +6 -12
  6. data/app/components/avo/index/resource_table_component.html.erb +1 -1
  7. data/app/components/avo/index/table_row_component.html.erb +1 -1
  8. data/app/controllers/avo/actions_controller.rb +2 -4
  9. data/app/controllers/avo/application_controller.rb +6 -3
  10. data/app/controllers/avo/base_controller.rb +0 -3
  11. data/app/controllers/avo/relations_controller.rb +1 -1
  12. data/app/controllers/avo/search_controller.rb +1 -1
  13. data/app/frontend/packs/application.js +1 -1
  14. data/app/views/avo/base/_actions.html.erb +0 -6
  15. data/app/views/avo/base/_boolean_filter.html.erb +1 -1
  16. data/app/views/avo/base/_filters.html.erb +3 -11
  17. data/app/views/avo/base/_select_filter.html.erb +1 -1
  18. data/app/views/avo/home/_resources.html.erb +0 -1
  19. data/app/views/layouts/avo/_filter_wrapper.html.erb +1 -1
  20. data/app/views/layouts/avo/application.html.erb +5 -0
  21. data/config/webpacker.yml +10 -23
  22. data/lib/avo.rb +5 -16
  23. data/lib/avo/app.rb +190 -0
  24. data/lib/avo/base_action.rb +115 -0
  25. data/lib/avo/base_resource.rb +321 -0
  26. data/lib/avo/configuration.rb +6 -0
  27. data/lib/avo/engine.rb +12 -31
  28. data/lib/avo/{app/fields → fields}/badge_field.rb +1 -1
  29. data/lib/avo/{app/fields/field.rb → fields/base_field.rb} +3 -7
  30. data/lib/avo/{app/fields/belongs_to.rb → fields/belongs_to_field.rb} +3 -3
  31. data/lib/avo/{app/fields → fields}/boolean_field.rb +1 -1
  32. data/lib/avo/{app/fields → fields}/boolean_group_field.rb +1 -1
  33. data/lib/avo/{app/fields → fields}/code_field.rb +1 -1
  34. data/lib/avo/{app/fields → fields}/country_field.rb +1 -1
  35. data/lib/avo/{app/fields → fields}/currency_field.rb +1 -1
  36. data/lib/avo/{app/fields → fields}/date_field.rb +0 -2
  37. data/lib/avo/{app/fields → fields}/date_time_field.rb +0 -2
  38. data/lib/avo/{app/fields → fields}/external_image_field.rb +1 -1
  39. data/lib/avo/{app/fields → fields}/field_extensions/has_field_name.rb +0 -0
  40. data/lib/avo/{app/fields → fields}/field_extensions/visible_in_different_views.rb +1 -1
  41. data/lib/avo/{app/fields → fields}/file_field.rb +1 -2
  42. data/lib/avo/{app/fields → fields}/files_field.rb +1 -2
  43. data/lib/avo/{app/fields → fields}/gravatar_field.rb +1 -1
  44. data/lib/avo/{app/fields/has_and_belongs_to_many.rb → fields/has_and_belongs_to_many_field.rb} +1 -1
  45. data/lib/avo/{app/fields/has_many.rb → fields/has_many_field.rb} +1 -1
  46. data/lib/avo/{app/fields/has_one.rb → fields/has_one_field.rb} +1 -1
  47. data/lib/avo/{app/fields → fields}/heading_field.rb +1 -1
  48. data/lib/avo/{app/fields → fields}/hidden_field.rb +0 -2
  49. data/lib/avo/{app/fields → fields}/id_field.rb +1 -1
  50. data/lib/avo/{app/fields → fields}/key_value_field.rb +1 -1
  51. data/lib/avo/{app/fields → fields}/markdown_field.rb +1 -3
  52. data/lib/avo/{app/fields → fields}/number_field.rb +0 -2
  53. data/lib/avo/{app/fields → fields}/password_field.rb +0 -2
  54. data/lib/avo/{app/fields → fields}/select_field.rb +1 -1
  55. data/lib/avo/{app/fields → fields}/status_field.rb +1 -1
  56. data/lib/avo/{app/fields → fields}/text_field.rb +1 -1
  57. data/lib/avo/{app/fields → fields}/textarea_field.rb +0 -2
  58. data/lib/avo/{app/fields → fields}/trix_field.rb +1 -3
  59. data/lib/avo/filters/base_filter.rb +20 -0
  60. data/lib/avo/filters/boolean_filter.rb +7 -0
  61. data/lib/avo/filters/select_filter.rb +7 -0
  62. data/lib/avo/{app/grid_fields → grid_fields}/body_field.rb +0 -2
  63. data/lib/avo/{app/grid_fields → grid_fields}/grid_field.rb +0 -0
  64. data/lib/avo/{app/grid_fields → grid_fields}/preview_field.rb +0 -2
  65. data/lib/avo/{app/grid_fields → grid_fields}/title_field.rb +0 -2
  66. data/lib/avo/licensing/community_license.rb +6 -0
  67. data/lib/avo/licensing/h_q.rb +88 -0
  68. data/lib/avo/licensing/license.rb +50 -0
  69. data/lib/avo/licensing/license_manager.rb +22 -0
  70. data/lib/avo/licensing/null_license.rb +14 -0
  71. data/lib/avo/licensing/pro_license.rb +11 -0
  72. data/lib/avo/loaders/actions_loader.rb +6 -0
  73. data/lib/avo/loaders/fields_loader.rb +27 -0
  74. data/lib/avo/loaders/filters_loader.rb +6 -0
  75. data/lib/avo/loaders/loader.rb +15 -0
  76. data/lib/avo/services/authorization_service.rb +93 -0
  77. data/lib/avo/services/panel_service.rb +27 -0
  78. data/lib/avo/{app/tools_manager.rb → tools_manager.rb} +0 -0
  79. data/lib/avo/version.rb +1 -1
  80. data/lib/generators/avo/action_generator.rb +11 -5
  81. data/lib/generators/avo/controller_generator.rb +14 -8
  82. data/lib/generators/avo/filter_generator.rb +14 -8
  83. data/lib/generators/avo/install_generator.rb +14 -10
  84. data/lib/generators/avo/locales_generator.rb +11 -7
  85. data/lib/generators/avo/partials_generator.rb +11 -5
  86. data/lib/generators/avo/resource_generator.rb +33 -15
  87. data/lib/generators/avo/templates/{action.rb → action.tt} +2 -4
  88. data/lib/generators/avo/templates/filters/boolean_filter.tt +11 -0
  89. data/lib/generators/avo/templates/filters/select_filter.tt +11 -0
  90. data/lib/generators/avo/templates/initializer/{avo.rb → avo.tt} +6 -0
  91. data/lib/generators/avo/templates/resource/controller.tt +2 -0
  92. data/lib/generators/avo/templates/resource/resource.tt +17 -0
  93. data/public/avo-packs/css/{application-3598cfbb.css → application-c75ac28c.css} +1 -1
  94. data/public/avo-packs/css/application-c75ac28c.css.br +0 -0
  95. data/public/avo-packs/css/{application-3598cfbb.css.gz → application-c75ac28c.css.gz} +0 -0
  96. data/public/avo-packs/js/{application-6ba2bd1bca05d69b96e0.js → application-8849c6e2c8f75d55c666.js} +3 -3
  97. data/public/avo-packs/js/{application-6ba2bd1bca05d69b96e0.js.LICENSE.txt → application-8849c6e2c8f75d55c666.js.LICENSE.txt} +0 -0
  98. data/public/avo-packs/js/application-8849c6e2c8f75d55c666.js.br +0 -0
  99. data/public/avo-packs/js/application-8849c6e2c8f75d55c666.js.gz +0 -0
  100. data/public/avo-packs/js/{application-6ba2bd1bca05d69b96e0.js.map → application-8849c6e2c8f75d55c666.js.map} +1 -1
  101. data/public/avo-packs/js/application-8849c6e2c8f75d55c666.js.map.br +0 -0
  102. data/public/avo-packs/js/{application-6ba2bd1bca05d69b96e0.js.map.gz → application-8849c6e2c8f75d55c666.js.map.gz} +0 -0
  103. data/public/avo-packs/manifest.json +6 -6
  104. data/public/avo-packs/manifest.json.br +0 -0
  105. data/public/avo-packs/manifest.json.gz +0 -0
  106. metadata +72 -73
  107. data/config/webpacker_packed.yml +0 -86
  108. data/lib/avo/app/action.rb +0 -145
  109. data/lib/avo/app/actions_loader.rb +0 -11
  110. data/lib/avo/app/app.rb +0 -183
  111. data/lib/avo/app/fields_loader.rb +0 -29
  112. data/lib/avo/app/filter.rb +0 -23
  113. data/lib/avo/app/filters/boolean_filter.rb +0 -13
  114. data/lib/avo/app/filters/select_filter.rb +0 -13
  115. data/lib/avo/app/licensing/community_license.rb +0 -4
  116. data/lib/avo/app/licensing/hq.rb +0 -86
  117. data/lib/avo/app/licensing/license.rb +0 -48
  118. data/lib/avo/app/licensing/license_manager.rb +0 -25
  119. data/lib/avo/app/licensing/null_license.rb +0 -12
  120. data/lib/avo/app/licensing/pro_license.rb +0 -9
  121. data/lib/avo/app/resource.rb +0 -299
  122. data/lib/avo/app/resource_grid_fields.rb +0 -30
  123. data/lib/avo/app/services/authorization_service.rb +0 -110
  124. data/lib/avo/app/services/panel_service.rb +0 -25
  125. data/lib/avo/app/tool.rb +0 -5
  126. data/lib/generators/avo/templates/filters/boolean_filter.rb +0 -17
  127. data/lib/generators/avo/templates/filters/select_filter.rb +0 -17
  128. data/lib/generators/avo/templates/resource/%plural_name%_controller.tt +0 -2
  129. data/lib/generators/avo/templates/resource/%singular_name%.tt +0 -20
  130. data/public/avo-packs/css/application-3598cfbb.css.br +0 -0
  131. data/public/avo-packs/js/application-6ba2bd1bca05d69b96e0.js.br +0 -0
  132. data/public/avo-packs/js/application-6ba2bd1bca05d69b96e0.js.gz +0 -0
  133. data/public/avo-packs/js/application-6ba2bd1bca05d69b96e0.js.map.br +0 -0
@@ -1,30 +0,0 @@
1
- module Avo
2
- module Resources
3
- class Resource
4
- class << self
5
- @@grid_fields = {}
6
-
7
- def grid(&block)
8
- @@grid_fields[self] ||= {}
9
- yield
10
- end
11
-
12
- def get_grid_fields
13
- @@grid_fields[self] or {}
14
- end
15
-
16
- def preview(name, **args, &block)
17
- @@grid_fields[self][:preview] = Avo::GridFields::PreviewField::new(name, **args, &block)
18
- end
19
-
20
- def title(name, **args, &block)
21
- @@grid_fields[self][:title] = Avo::GridFields::TitleField::new(name, **args, &block)
22
- end
23
-
24
- def body(name, **args, &block)
25
- @@grid_fields[self][:body] = Avo::GridFields::BodyField::new(name, **args, &block)
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,110 +0,0 @@
1
- module Avo
2
- class AuthorizationService
3
- attr_accessor :user
4
- attr_accessor :record
5
-
6
- def initialize(user = nil, record = nil)
7
- @user = user
8
- @record = record
9
- end
10
-
11
- def authorize(action, **args)
12
- self.class.authorize(user, record, action, **args)
13
- end
14
-
15
- def set_record(record)
16
- @record = record
17
-
18
- self
19
- end
20
-
21
- def set_user(user)
22
- @user = user
23
-
24
- self
25
- end
26
-
27
- def authorize_action(action, **args)
28
- self.class.authorize_action(user, record, action, **args)
29
- end
30
-
31
- def apply_policy(model)
32
- self.class.apply_policy(user, model)
33
- end
34
-
35
- class << self
36
- def authorize(user, record, action, **args)
37
- return true if skip_authorization
38
- return true if user.nil?
39
-
40
- # puts '----->'.inspect
41
-
42
- begin
43
- if Pundit.policy user, record
44
- Pundit.authorize user, record, action
45
- end
46
-
47
- # puts 'true authorize'.inspect
48
- true
49
- rescue Pundit::NotDefinedError => error
50
- # puts 'not_defined'.inspect
51
- false
52
- rescue => error
53
- # puts ['general raise', args].inspect
54
- if args[:raise_exception] == false
55
- # puts 1.inspect
56
- false
57
- else
58
- # puts 2.inspect
59
- raise error
60
- end
61
- end
62
-
63
-
64
- # abort action.inspect
65
-
66
- # return true
67
- # end
68
-
69
- # false
70
- # begin
71
- # rescue Pundit::NotAuthorizedError => error
72
- # false
73
- # end
74
- end
75
-
76
- def authorize_action(user, record, action, **args)
77
- action = Avo.configuration.authorization_methods.stringify_keys[action.to_s]
78
-
79
- return true if action.nil?
80
-
81
- authorize user, record, action, **args
82
- end
83
-
84
- def apply_policy(user, model)
85
- return model if skip_authorization
86
- return model if user.nil?
87
-
88
- begin
89
- Pundit.policy_scope! user, model
90
- rescue => exception
91
- model
92
- end
93
- end
94
-
95
- def skip_authorization
96
- Avo::App.license.lacks :authorization
97
- end
98
-
99
- def authorized_methods(user, record)
100
- [:new, :edit, :update, :show, :destroy].map do |method|
101
- [method, authorize(user, record, Avo.configuration.authorization_methods[method])]
102
- end.to_h
103
- end
104
-
105
- def get_policy(user, record)
106
- Pundit.policy user, record
107
- end
108
- end
109
- end
110
- end
@@ -1,25 +0,0 @@
1
- module Avo
2
- class PanelService
3
- attr_accessor :request
4
- attr_accessor :params
5
- attr_accessor :resource
6
-
7
- def initialize(request: nil, resource: nil)
8
- @request = request
9
- @params = request.params
10
- end
11
-
12
- def default_panel_name
13
- return @request[:via_relation_param].capitalize if @request[:via_relation_param] == 'has_one'
14
-
15
- case @view
16
- when :show
17
- I18n.t('avo.resource_details', item: @resource.name.downcase, title: @resource.model_title).upcase_first
18
- when :edit
19
- I18n.t('avo.update_item', item: @resource.name.downcase, title: @resource.model_title).upcase_first
20
- when :new
21
- I18n.t('avo.create_new_item', item: @resource.name.downcase).upcase_first
22
- end
23
- end
24
- end
25
- end
data/lib/avo/app/tool.rb DELETED
@@ -1,5 +0,0 @@
1
- module Avo
2
- class Tool
3
-
4
- end
5
- end
@@ -1,17 +0,0 @@
1
- module Avo
2
- module Filters
3
- class <%= class_name.camelize %> < BooleanFilter
4
- def configure
5
- @name = '<%= name.underscore.humanize %>'
6
- end
7
-
8
- def apply(request, query, value)
9
- query
10
- end
11
-
12
- def options
13
- {}
14
- end
15
- end
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- module Avo
2
- module Filters
3
- class <%= class_name.camelize %> < SelectFilter
4
- def configure
5
- @name = '<%= name.underscore.humanize %>'
6
- end
7
-
8
- def apply(request, query, value)
9
- query
10
- end
11
-
12
- def options
13
- {}
14
- end
15
- end
16
- end
17
- end
@@ -1,2 +0,0 @@
1
- class Avo::<%= plural_name.humanize %>Controller < Avo::ResourcesController
2
- end
@@ -1,20 +0,0 @@
1
- class Avo::Resources::<%= class_name %> < Avo::Resources::Resource
2
- def configure
3
- @title = :id
4
- @search = :id
5
- end
6
-
7
- def fields(request)
8
- f.id
9
-
10
- # add fields here
11
- end
12
-
13
- def actions(request)
14
- # add actions here
15
- end
16
-
17
- def filters(request)
18
- # add filters here
19
- end
20
- end