kono_utils 0.15.15 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +5 -5
  2. data/README.rdoc +17 -78
  3. data/app/assets/javascripts/kono_utils/core.coffee +477 -0
  4. data/app/assets/stylesheets/kono_utils/{_kono_styles.css.scss → core.css.scss} +1 -16
  5. data/app/policies/kono_utils/base_editing_policy_concern.rb +52 -3
  6. data/app/policies/kono_utils/base_search_form_policy_concern.rb +25 -0
  7. data/config/initializers/mysql.rb +2 -2
  8. data/config/locales/it.yml +3 -1
  9. data/lib/generators/kono_utils/install/install_generator.rb +44 -0
  10. data/lib/generators/templates/base_editing_controller.template +3 -0
  11. data/lib/generators/templates/base_editing_helper.template +3 -0
  12. data/lib/generators/templates/base_editing_policy.template +4 -0
  13. data/lib/generators/templates/initializer.rb +3 -1
  14. data/lib/kono_utils.rb +29 -18
  15. data/lib/kono_utils/application_core_helper.rb +524 -0
  16. data/lib/kono_utils/application_enum_helper.rb +53 -0
  17. data/lib/kono_utils/application_helper.rb +4 -578
  18. data/lib/kono_utils/base_editing_core_helper.rb +194 -0
  19. data/lib/kono_utils/base_editing_helper.rb +3 -186
  20. data/lib/kono_utils/base_search.rb +32 -19
  21. data/lib/kono_utils/concerns.rb +12 -10
  22. data/lib/kono_utils/concerns/active_record_translation.rb +8 -4
  23. data/lib/kono_utils/concerns/active_storage_remover_helper.rb +61 -0
  24. data/lib/kono_utils/concerns/base_editing.rb +199 -53
  25. data/lib/kono_utils/configuration.rb +18 -0
  26. data/lib/kono_utils/engine.rb +15 -6
  27. data/lib/kono_utils/paginate_proxer.rb +17 -0
  28. data/lib/kono_utils/search_form_builder.rb +24 -0
  29. data/lib/kono_utils/version.rb +1 -1
  30. data/spec/dummy/.gitignore +2 -0
  31. data/spec/dummy/app/assets/config/manifest.js +2 -0
  32. data/spec/dummy/app/assets/javascripts/application.js +2 -0
  33. data/spec/dummy/app/controllers/application_controller.rb +10 -0
  34. data/spec/dummy/app/controllers/base_editing_controller.rb +3 -0
  35. data/spec/dummy/app/controllers/users_controller.rb +2 -0
  36. data/spec/dummy/app/helpers/application_helper.rb +1 -0
  37. data/spec/dummy/app/helpers/base_editing_helper.rb +3 -0
  38. data/spec/dummy/app/models/application_record.rb +5 -0
  39. data/spec/dummy/app/models/user.rb +2 -0
  40. data/spec/dummy/app/policies/application_policy.rb +49 -0
  41. data/spec/dummy/app/policies/base_editing_policy.rb +4 -0
  42. data/spec/dummy/app/policies/user_policy.rb +23 -0
  43. data/spec/dummy/bin/rails +1 -1
  44. data/spec/dummy/bin/setup +20 -13
  45. data/spec/dummy/bin/update +31 -0
  46. data/spec/dummy/bin/yarn +11 -0
  47. data/spec/dummy/config/application.rb +15 -17
  48. data/spec/dummy/config/environment.rb +1 -1
  49. data/spec/dummy/config/environments/development.rb +31 -11
  50. data/spec/dummy/config/environments/production.rb +26 -16
  51. data/spec/dummy/config/environments/test.rb +10 -6
  52. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  53. data/spec/dummy/config/initializers/assets.rb +6 -3
  54. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  55. data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
  56. data/spec/dummy/config/initializers/kono_utils.rb +5 -0
  57. data/spec/dummy/config/initializers/new_framework_defaults_5_2.rb +38 -0
  58. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -2
  59. data/spec/dummy/config/locales/en.yml +10 -0
  60. data/spec/dummy/config/routes.rb +3 -52
  61. data/spec/dummy/config/storage.yml +34 -0
  62. data/spec/dummy/db/migrate/20190716093114_create_users.rb +11 -0
  63. data/spec/dummy/db/schema.rb +23 -0
  64. data/spec/dummy/package.json +5 -0
  65. data/spec/dummy/spec/models/user_spec.rb +5 -0
  66. data/spec/dummy/yarn.lock +21 -0
  67. metadata +83 -144
  68. data/app/assets/javascripts/kono_utils/utilities.coffee +0 -481
  69. data/app/assets/stylesheets/kono_utils/utils.css.scss +0 -4
  70. data/app/input/bs_aceeditor_input.rb +0 -53
  71. data/app/input/bs_autocomplete_input.rb +0 -60
  72. data/app/input/bs_datepicker_input.rb +0 -16
  73. data/app/input/bs_datetimepicker_input.rb +0 -80
  74. data/app/input/bs_file_download_input.rb +0 -35
  75. data/app/input/bs_image_input.rb +0 -35
  76. data/app/input/bs_label_with_container_input.rb +0 -22
  77. data/app/input/bs_location_picker_input.rb +0 -95
  78. data/app/input/bs_readonly_input.rb +0 -52
  79. data/app/input/bs_timepicker_input.rb +0 -14
  80. data/app/views/kono_utils/application/_search_panel.html.erb +0 -36
  81. data/app/views/kono_utils/base_editing/_edit.html.erb +0 -3
  82. data/app/views/kono_utils/base_editing/_edit_page_side_title_header.html.erb +0 -3
  83. data/app/views/kono_utils/base_editing/_edit_page_title_header.html.erb +0 -3
  84. data/app/views/kono_utils/base_editing/_form.html.erb +0 -15
  85. data/app/views/kono_utils/base_editing/_index_buttons.html.erb +0 -2
  86. data/app/views/kono_utils/base_editing/_index_page_side_title_header.html.erb +0 -3
  87. data/app/views/kono_utils/base_editing/_index_page_title_header.html.erb +0 -3
  88. data/app/views/kono_utils/base_editing/_index_tfoot.html.erb +0 -0
  89. data/app/views/kono_utils/base_editing/_new.html.erb +0 -3
  90. data/app/views/kono_utils/base_editing/_new_page_side_title_header.html.erb +0 -3
  91. data/app/views/kono_utils/base_editing/_new_page_title_header.html.erb +0 -3
  92. data/app/views/kono_utils/base_editing/_search_form.html.erb +0 -1
  93. data/app/views/kono_utils/base_editing/application/_edit_page_side_title_header.html.erb +0 -1
  94. data/app/views/kono_utils/base_editing/application/_edit_page_title_header.html.erb +0 -1
  95. data/app/views/kono_utils/base_editing/application/_index_page_side_title_header.html.erb +0 -1
  96. data/app/views/kono_utils/base_editing/application/_index_page_title_header.html.erb +0 -1
  97. data/app/views/kono_utils/base_editing/application/_new_page_side_title_header.html.erb +0 -1
  98. data/app/views/kono_utils/base_editing/application/_new_page_title_header.html.erb +0 -1
  99. data/app/views/kono_utils/base_editing/application/edit.html.erb +0 -1
  100. data/app/views/kono_utils/base_editing/application/new.html.erb +0 -1
  101. data/app/views/kono_utils/base_editing/edit.html.erb +0 -1
  102. data/app/views/kono_utils/base_editing/index.html.erb +0 -36
  103. data/app/views/kono_utils/base_editing/new.html.erb +0 -1
  104. data/lib/kono_utils/encoder.rb +0 -47
  105. data/lib/kono_utils/fiscal_code.rb +0 -47
  106. data/lib/kono_utils/params_hash_array.rb +0 -37
  107. data/lib/kono_utils/percentage.rb +0 -60
  108. data/lib/kono_utils/tmp_file.rb +0 -81
  109. data/lib/kono_utils/virtual_model.rb +0 -22
  110. data/lib/tasks/kono_utils_tasks.rake +0 -4
  111. data/spec/lib/kono_utils/fiscal_code_spec.rb +0 -56
  112. data/vendor/assets/javascripts/EventEmitter.js +0 -473
@@ -1,10 +1,12 @@
1
- module KonoUtils::Concerns
2
-
3
- extend ActiveSupport::Autoload
4
-
5
- autoload :BaseModals
6
- autoload :SuccessMessage
7
- autoload :BaseEditing
8
-
9
- end
10
-
1
+ module KonoUtils
2
+ module Concerns
3
+ extend ActiveSupport::Autoload
4
+
5
+ autoload :ActiveRecordTranslation
6
+ autoload :ActiveStorageRemoverHelper
7
+ autoload :BaseEditing
8
+ autoload :BaseModals
9
+ autoload :SuccessMessage
10
+
11
+ end
12
+ end
@@ -23,9 +23,12 @@ module KonoUtils::Concerns
23
23
  class_methods do
24
24
 
25
25
  ##
26
- # E' un'alias per il TikalCore::Registration.human_attribute_name(:isee)
27
- def han(attr)
28
- self.human_attribute_name(attr)
26
+ # E' un'alias per human_attribute_name di active record
27
+ # @param [Symbol,String] attr
28
+ # @param [Hash] options
29
+ # @return [String]
30
+ def han(attr, options = {})
31
+ self.human_attribute_name(attr, options)
29
32
  end
30
33
 
31
34
  ##
@@ -44,4 +47,5 @@ module KonoUtils::Concerns
44
47
  end
45
48
 
46
49
  end
47
- end
50
+ end
51
+
@@ -0,0 +1,61 @@
1
+ require 'active_support/concern'
2
+
3
+
4
+ module KonoUtils::Concerns
5
+ ##
6
+ # Includendo questo modulo nell'application record, possiamo andare injettare metodi necessari per la gestione
7
+ # dell'attributo virtuale per cancellare il file allegato
8
+ # Usage:
9
+ #
10
+ # class Test < ApplicationRecord
11
+ #
12
+ # has_one_attached :doc
13
+ # has_one_attached_remover :doc
14
+ #
15
+ # end
16
+ #
17
+ # Ricordarsi di aggiungere anche nella policy il nome del campo da ritornare dalla form, il nome dell'attributo
18
+ # è kono_utils_purge_NOME_ATTRIBUTO
19
+ #
20
+ #
21
+ #
22
+ module ActiveStorageRemoverHelper
23
+ extend ActiveSupport::Concern
24
+ #
25
+ # included do
26
+ #
27
+ # end
28
+
29
+ module ClassMethods
30
+
31
+ ##
32
+ # Costruisce i metodi e attributi necessari al modello per gestire la rimozione attraverso l'interfaccia del
33
+ # file allegato
34
+ # @param [String,Symbol] field_name
35
+ def has_one_attached_remover(field_name)
36
+
37
+ attr = attribute_purger_name(field_name)
38
+ callback = "make_#{attr}".to_sym
39
+ attr_accessor attr
40
+
41
+ after_save callback, if: attr
42
+
43
+ define_method(callback) do
44
+ if self.send(field_name.to_sym).attached?
45
+ self.send(field_name.to_sym).purge_later
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ ##
52
+ # Nome dell'attributo da generare
53
+ # @param [String] field
54
+ # @return [Symbol]
55
+ def attribute_purger_name(field)
56
+ "kono_utils_purge_#{field}".to_sym
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -5,9 +5,14 @@ module KonoUtils
5
5
  module BaseEditing
6
6
  extend ActiveSupport::Concern
7
7
 
8
+
8
9
  included do
9
10
 
10
- before_action :append_view_paths
11
+ include Pundit
12
+ include KonoUtils::Concerns::SuccessMessage
13
+
14
+ after_action :verify_authorized, except: :index
15
+ after_action :verify_policy_scoped, only: :index
11
16
 
12
17
  before_action :load_object, except: [:index, :new, :create]
13
18
  helper_method :base_class
@@ -16,7 +21,9 @@ module KonoUtils
16
21
  helper_method :new_custom_polymorphic_path
17
22
  helper_method :edit_custom_polymorphic_path
18
23
  helper_method :index_custom_polymorphic_path
19
- after_action :check_errors, only: [:create, :update]
24
+ after_action :check_errors, only: [:create, :update], if: -> { ::Rails.env.development? }
25
+
26
+ rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
20
27
 
21
28
  ##
22
29
  # E' possibile passare una callback per poter
@@ -27,11 +34,11 @@ module KonoUtils
27
34
  def index(respond_to_call: nil)
28
35
  @objects = policy_scope(base_scope).all
29
36
  @objects = yield(@objects) if block_given?
30
- @objects = @objects.paginate(:page => params[:page])
37
+ @objects = KonoUtils.configuration.pagination_proxer.new(@objects).paginate(params)
31
38
 
32
39
  respond_to do |format|
33
40
  format.html # index.html.erb
34
- format.xml {render :xml => @objects}
41
+ format.xml { render :xml => @objects }
35
42
  unless respond_to_call.nil?
36
43
  respond_to_call.call(format)
37
44
  end
@@ -40,15 +47,19 @@ module KonoUtils
40
47
 
41
48
  # GET /utenti/new
42
49
  # GET /utenti/new.xml
50
+ # GET /utenti/new.inject -> javascript che si occupa di avere un js che injetta il risultato in un
51
+ # determinato target che deve essere passato tramite params,
52
+ # se non presente il target viene scritto un warning in console
43
53
  def new
44
54
  @object = base_class.new
45
55
  authorize @object
46
56
  @object = yield(@object) if block_given?
47
- logger.debug {"Nuovo oggetto #{@object.inspect}"}
57
+ logger.debug { "Nuovo oggetto #{@object.inspect}" }
48
58
 
49
59
  respond_to do |format|
50
60
  format.html
51
- format.xml {render :xml => @object}
61
+ format.xml { render :xml => @object }
62
+ format.inject { render :layout => false }
52
63
  end
53
64
  end
54
65
 
@@ -62,7 +73,7 @@ module KonoUtils
62
73
  def update
63
74
  @object = yield(@object) if block_given?
64
75
  respond_to do |format|
65
- if @object.update_attributes(clean_params)
76
+ if @object.update(clean_params(@object))
66
77
  _successful_update(format)
67
78
  else
68
79
  _failed_update(format)
@@ -76,7 +87,7 @@ module KonoUtils
76
87
  @object = base_class.new(clean_params)
77
88
  authorize @object
78
89
  @object = yield(@object) if block_given?
79
- logger.debug {"Nuovo oggetto #{@object.inspect}"}
90
+ logger.debug { "Nuovo oggetto #{@object.inspect}" }
80
91
 
81
92
  respond_to do |format|
82
93
  if @object.save
@@ -105,61 +116,104 @@ module KonoUtils
105
116
  ##
106
117
  # Elenco degli attributi da visualizzare nella form
107
118
  def form_attributes(model = base_class.new)
119
+ ActiveSupport::Deprecation.warn('Utilizzato solo nel vecchio sistema')
108
120
  policy(model).permitted_attributes
109
121
  end
110
122
 
111
123
  ##
112
124
  # Elenco ordinato dei campi da utilizzare nella visualizzazione della tabella index
113
125
  def table_columns
126
+ ActiveSupport::Deprecation.warn('Utilizzato solo nel vecchio sistema')
114
127
  policy(base_class.new).permitted_attributes
115
128
  end
116
129
 
117
- private
118
- def load_object
119
- @object = base_class.find(params[:id])
120
- authorize @object
121
- logger.debug {"Oggetto #{@object.inspect}"}
122
-
123
- end
130
+ protected
124
131
 
125
132
  def base_class
133
+ return @_base_class if @_base_class
126
134
  controller = controller_name
127
135
  modello = controller.singularize.camelize.safe_constantize
128
- logger.debug {"Editazione del controller:#{controller} per modello: #{modello.to_s}"}
136
+ logger.debug { "Editazione del controller:#{controller} per modello: #{modello.to_s}" }
129
137
 
130
138
  raise "Non riesco a restituire la classe base per il controller #{controller}" if modello.nil?
131
139
 
132
- modello
140
+ @_base_class = modello
133
141
  end
134
142
 
143
+ private
144
+
145
+ def user_not_authorized
146
+ flash[:alert] = t('.user_not_authorized', :model => @object.mn,
147
+ default: t('kono_utils.user_not_authorized', :model => @object.mn, default: "You are not authorized to perform this action."))
148
+ redirect_to(request.referrer || root_path)
149
+ end
150
+
151
+ def load_object
152
+ @object = base_class.find(params[:id])
153
+ authorize @object
154
+ logger.debug { "Oggetto #{@object.inspect}" }
155
+
156
+ end
157
+
158
+
135
159
  ##
136
- # Scope iniziale per index, sovrascrivibile per poter inizializzare ricerca,
137
- # viene passato al policy_scope in index
160
+ # Scope iniziale per index, viene passato al policy_scope in index.
161
+ # nel caso sia stata attivata la ricerca, lo scope viene filtrato
138
162
  def base_scope
139
- base_class
163
+ if @search
164
+ @search.make_query
165
+ else
166
+ base_class
167
+ end
168
+ end
169
+
170
+ ##
171
+ # Metodo per il load della ricerca, precaricherà la classe per la ricerca
172
+ # e andrà a modificare il comportamento di base_scope in modo che sia utilizzato
173
+ # la ricerca come scope iniziale dei records
174
+ def load_search
175
+ # search_class non esiste, deve essere implementata dall'utente o settata durante il settaggio della classe
176
+ #@type [KonoUtils::BaseSearch]
177
+ #noinspection RubyResolve
178
+ @search = search_class.new
179
+ permitted = policy(@search).permitted_attributes
180
+ dati = require_params_for(search_class).permit(permitted)
181
+ ::Rails.logger.info { "Permitted Attributes: #{permitted.inspect}" }
182
+ ::Rails.logger.info { "Parametri puliti: #{dati.inspect}" }
183
+ @search.update_attributes(dati)
184
+
140
185
  end
141
186
 
142
- def clean_params
143
- permitted = policy(base_class.new).permitted_attributes
144
- dati = params.required(base_class.name.underscore.gsub('/', '_').to_sym).permit(permitted)
145
- ::Rails.logger.info {"Permitted Attributes: #{permitted.inspect}"}
146
- ::Rails.logger.info {"Parametri puliti: #{dati.inspect}"}
187
+ # @param object [ActiveRecord::Base] oggetto per cui estrapolare gli attributi ripuliti, di default utilizza
188
+ # la classe base
189
+ # @return [ActionController::Parameters]
190
+ def clean_params(object = base_class.new)
191
+ permitted = policy(object).permitted_attributes
192
+ dati = require_params_for!(object.class).permit(permitted)
193
+ ::Rails.logger.info { "Permitted Attributes: #{permitted.inspect}" }
194
+ ::Rails.logger.info { "Parametri puliti: #{dati.inspect}" }
147
195
  dati
148
196
  end
149
197
 
150
- def check_errors
151
- unless @object.valid?
152
- logger.debug {"Invalid Obj:"}
153
- logger.debug {@object.errors.inspect}
154
- end
198
+ ##
199
+ # Estrapola i parametri dalla classe in questione, partendo da params, fancendo un require
200
+ def require_params_for!(klass)
201
+ required_params_name = klass.name.underscore.gsub('/', '_').to_sym
202
+ Rails.logger.info { "Required attibute: #{required_params_name}" }
203
+ params.required(required_params_name)
155
204
  end
156
205
 
157
206
  ##
158
- # Aggiungo una path alla vista del base editing controller,
159
- # nel caso non siamo derivati dal controller ma ho solamente incluso il concern
160
- def append_view_paths
161
- append_view_path KonoUtils::Engine.root.join("app", "views", "kono_utils")
162
- append_view_path KonoUtils::Engine.root.join("app", "views", "kono_utils", "base_editing")
207
+ # Come sopra. ma fallendo su un ActionController::Parameters vuoto
208
+ def require_params_for(klass)
209
+ require_params_for!(klass) rescue ActionController::Parameters.new({})
210
+ end
211
+
212
+ def check_errors
213
+ unless @object.valid?
214
+ logger.debug { "Invalid Obj:" }
215
+ logger.debug { @object.errors.inspect }
216
+ end
163
217
  end
164
218
 
165
219
 
@@ -175,43 +229,135 @@ module KonoUtils
175
229
  polymorphic_path(*rec)
176
230
  end
177
231
 
232
+ def destroy_custom_polymorphic_path(*rec)
233
+ polymorphic_path(*rec)
234
+ end
235
+
178
236
  def _failed_destroy(format)
179
- format.html {redirect_to index_custom_polymorphic_path(base_class),
180
- :flash => {:error => @object.errors.full_messages.join(',')}}
181
- format.xml {head :ko}
237
+ format.html { redirect_to index_custom_polymorphic_path(base_class),
238
+ :flash => {:error => @object.errors.full_messages.join(',')} }
239
+ format.xml { head :ko }
240
+ format.json { render json: {success: false, errors: @object.errors.to_json}, status: 422 }
182
241
  end
183
242
 
184
243
  def _successful_destroy(format)
185
- format.html {redirect_to index_custom_polymorphic_path(base_class),
186
- :notice => success_destroy_message(@object)}
187
- format.xml {head :ok}
244
+ format.html { redirect_to index_custom_polymorphic_path(base_class),
245
+ :notice => success_destroy_message(@object) }
246
+ format.xml { head :ok }
247
+ format.json { render json: {success: true} }
188
248
  end
189
249
 
190
250
  def _failed_create(format)
191
- format.html {render :action => :new}
192
- format.xml {render :xml => @object.errors, :status => :unprocessable_entity}
251
+ format.html do
252
+ flash.now[:error] = @object.errors.full_messages.join(',')
253
+ render :action => :new
254
+ end
255
+ format.xml { render :xml => @object.errors, :status => :unprocessable_entity }
256
+ format.inject { render :action => :edit, :layout => false }
193
257
  end
194
258
 
195
259
  def _successful_create(format)
196
- format.html {redirect_to edit_custom_polymorphic_path(@object), :notice => success_create_message(@object)}
197
- format.xml {render :xml => @object, :status => :created, :location => @object}
260
+ format.html { redirect_to edit_custom_polymorphic_path(@object), :notice => success_create_message(@object) }
261
+ format.xml { render :xml => @object, :status => :created, :location => @object }
262
+ format.inject { render :action => :success_create_show, :layout => false }
198
263
  end
199
264
 
200
265
  def _failed_update(format)
201
- format.html {render :action => :edit}
202
- format.xml {render :xml => @object.errors, :status => :unprocessable_entity}
266
+ format.html do
267
+ flash.now[:error] = @object.errors.full_messages.join(',')
268
+ render :action => :edit
269
+ end
270
+ format.xml { render :xml => @object.errors, :status => :unprocessable_entity }
271
+ format.inject { render :action => :edit, :layout => false }
203
272
  end
204
273
 
205
274
  def _successful_update(format)
206
- format.html {redirect_to edit_custom_polymorphic_path(@object), :notice => success_update_message(@object)}
207
- format.xml {head :ok}
275
+ format.html { redirect_to edit_custom_polymorphic_path(@object), :notice => success_update_message(@object) }
276
+ format.xml { head :ok }
277
+ format.inject { render :action => :success_update_show, :layout => false }
208
278
  end
209
279
  end
210
280
 
211
- # module ClassMethods
212
- #
213
- #
214
- # end
281
+ module ClassMethods
282
+
283
+ #@!attribute search_class
284
+ # @return [KonoUtils::BaseSearch]
285
+
286
+ # @param [String] search_class
287
+ def setup_search(search_class: nil)
288
+
289
+ install_search_class(search_class)
290
+ development_search_setup_checks
291
+
292
+ before_action :load_search, only: [:index]
293
+ end
294
+
295
+
296
+ def setup_search_controller(search_class: nil)
297
+ install_search_class(search_class)
298
+ development_search_setup_checks
299
+
300
+ # Sul controller della ricerca, ridefiniamo la classe base, im modo che vada a trovare il modello della
301
+ # classe di ricerca
302
+ redefine_method :base_class do
303
+ self.search_class.search_model
304
+ end
305
+
306
+ end
307
+
308
+ protected
309
+
310
+ def install_search_class(search_class_name = nil)
311
+ # se passata la classe,
312
+ if search_class_name
313
+ define_singleton_method :search_class do
314
+ search_class_name.to_s.constantize
315
+ end
316
+ delegate :search_class, to: :class
317
+ end
318
+ end
319
+
320
+ ##
321
+ # Funzione che esegue un check generale sulle configurazioni del setup della ricerca
322
+ # per semplificare la vita allo sviluppatore.
323
+ # Vengono fatti i controlli solamente nell'env di sviluppo
324
+ def development_search_setup_checks
325
+ if ::Rails.env.development?
326
+ out = []
327
+ if self.respond_to?(:search_class)
328
+ # controlliamo le rotte:
329
+ unless self.search_class.new.search_form_builder.search_path
330
+ out << "- Non hai definito la rotta per il controller della ricerca, inserisci nelle rotte del progetto:
331
+ namespace :#{self.search_class.search_model.name.to_s.pluralize.downcase } do
332
+ resources :searches, :only => [:index, :create]
333
+ end
334
+ ATTENZIONE deve essere sopra alla rotta della risorsa, altrimenti verrà mechata prima la
335
+ show del controller principale
336
+ ------------------
337
+ Oppure la classe specializzata del search_form_builder non ritorna correttamente una path"
338
+ end
339
+ #controlliamo pundit
340
+ policy = Pundit::PolicyFinder.new(self.search_class).policy
341
+ if policy
342
+ unless policy.included_modules.include?(KonoUtils::BaseSearchFormPolicyConcern)
343
+ out << "- Nella policy #{policy.name} non hai incluso il concern: KonoUtils::BaseSearchFormPolicyConcern"
344
+ end
345
+ else
346
+ out << "- Non hai definito la policy per la classe #{self.search_class.name}"
347
+ end
348
+
349
+
350
+ else
351
+ out << "- Il controller deve rispondere al methodo search_class ritornando una classe figlia di
352
+ KonoUtils::BaseSearch oppure configurarlo con il setup passato il valore al parametro
353
+ search_class"
354
+ end
355
+
356
+ raise out.join("\n") unless out.empty?
357
+ end
358
+ end
359
+
360
+ end
215
361
  end
216
362
  end
217
363
  end