templus_models 2.0.6 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 800c8874f35daeb9d38c42153253e4e60087568c
4
- data.tar.gz: e29d7680ec274ac5571df3d90de31904e9b3b62d
3
+ metadata.gz: bf74bcbc672934c1f6c18c0d8622c681ebd06911
4
+ data.tar.gz: 63c43c5d92fcda0d029b9d1f354caf3e208878aa
5
5
  SHA512:
6
- metadata.gz: c1020f4029559eceb571324d6584fd431a4f9e3c5b76f7d723f90a9f1d34c7ebf984a6335aaf7dee18e96051b57f52f8c8b91527c076ac65dd7dfb00e2866571
7
- data.tar.gz: 06d301f58f08a85dd4462dbd7762be108f375fb08cb7108469e236e426039ae6e376fcaff60eb359cde6a33dbcdfec5d7defeece1bf02d46fbbd709c172c2231
6
+ metadata.gz: 0e21f038652963e54036f7cbebc83b28fac2aa8d37383e5bf7ab3970f12ee96b31a812a4a4717990803b8b36f31b27293f638a14b41c77ad269ccbee4f316882
7
+ data.tar.gz: fa6f5dcd2ac7d61e5d55f3a8ae0c0e6306e00e426774e70bb1c635839e7d19c769404d0dc0c96e1d6bcf1623c4bc3ff312f6cf5cd5437f3fc13cca49c937d198
@@ -4,7 +4,7 @@ class CrudController < ApplicationController
4
4
 
5
5
  def index
6
6
  authorize! :read, @model_permission if respond_to?(:current_usuario)
7
- if params[:scope].present?
7
+ if params[:scope].present? && valid_method?(params[:scope])
8
8
  @q = @model.send(params[:scope]).search(params[:q])
9
9
  else
10
10
  @q = @model.search(params[:q])
@@ -54,7 +54,7 @@ class CrudController < ApplicationController
54
54
  def action
55
55
  @record = @model.find(@id)
56
56
  authorize! :create_or_update, @record if respond_to?(:current_usuario)
57
- if @model.method_defined?(params[:acao])
57
+ if valid_instance_method?(params[:acao])
58
58
  if @record.send(params[:acao])
59
59
  flash.now[:success] = I18n.t("mensagem_action", acao: params[:acao])
60
60
  else
@@ -145,7 +145,11 @@ class CrudController < ApplicationController
145
145
  else
146
146
  results = @q.result.page(params[:page])
147
147
  end
148
- method_label = params[:label]
148
+ if valid_instance_method?(params[:label])
149
+ method_label = params[:label]
150
+ else
151
+ raise "Ação inválida"
152
+ end
149
153
  render json: results.map {|result| {id: result.id, label: result.send(method_label), value: result.send(method_label)} }
150
154
  end
151
155
 
@@ -199,7 +203,11 @@ class CrudController < ApplicationController
199
203
  def setup
200
204
  if params[:associacao]
201
205
  @crud_associacao = Module.const_get("#{params[:model].to_s.singularize}_crud".camelize)
202
- @model = Module.const_get(params[:model].camelize).find(params[:id]).send(params[:associacao])
206
+ if Module.const_get(params[:model].camelize).reflect_on_association(params[:associacao])
207
+ @model = Module.const_get(params[:model].camelize).find(params[:id]).send(params[:associacao])
208
+ else
209
+ raise "Ação inválida"
210
+ end
203
211
  c_helper = Module.const_get(params[:model].camelize).reflect_on_association(params[:associacao]).class_name
204
212
  @crud_helper = Module.const_get("#{c_helper}Crud") unless params[:render] == "modal" and params[:action] == "new"
205
213
  @url = crud_associacao_models_path(model: params[:model], id: params[:id], associacao: params[:associacao], page: params[:page], q: params[:q])
@@ -271,4 +279,22 @@ class CrudController < ApplicationController
271
279
  end
272
280
  group
273
281
  end
282
+
283
+ def valid_method?(method)
284
+ list_methods = []
285
+ @model.ancestors.each do |m|
286
+ list_methods << m.methods(false).reject{ |m| /^_/ =~ m.to_s }
287
+ break if m.superclass.to_s == "ActiveRecord::Base"
288
+ end
289
+ list_methods.flatten.include? method.to_sym
290
+ end
291
+
292
+ def valid_instance_method?(method)
293
+ list_methods = []
294
+ @model.ancestors.each do |m|
295
+ list_methods << m.instance_methods(false).reject{ |m| /^_/ =~ m.to_s }
296
+ break if m.superclass.to_s == "ActiveRecord::Base"
297
+ end
298
+ list_methods.flatten.include? method.to_sym
299
+ end
274
300
  end
@@ -1,3 +1,3 @@
1
1
  module TemplusModels
2
- VERSION = "2.0.6"
2
+ VERSION = "2.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: templus_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Sol
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-04-05 00:00:00.000000000 Z
13
+ date: 2017-04-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -981,7 +981,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
981
981
  version: '0'
982
982
  requirements: []
983
983
  rubyforge_project:
984
- rubygems_version: 2.6.8
984
+ rubygems_version: 2.5.1
985
985
  signing_key:
986
986
  specification_version: 4
987
987
  summary: Easy CRUD generator for Rails Projects