templus_models 3.0.8 → 3.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81dd9ee79ddc913b0d324a40d8e70df9151c22a5
4
- data.tar.gz: c6213ab6097d334fd99db91e2441f428c6b644fe
3
+ metadata.gz: b531514ac31823cc29637db8216e63b519bb8cd0
4
+ data.tar.gz: 48076b17649e28cdf40022c4e9c62da7825998ce
5
5
  SHA512:
6
- metadata.gz: 9d82f807bf61673a0bedac2f387a64b4ee45bad043edaa5f41a3521095b4cb3426c9499e323ef0f5e2637255be4e1b5f5a51e442696e12ed6a3ce4a24cb4822a
7
- data.tar.gz: 8c2c8ca412a8bf279613570396641fb1e3e3e43b98b35387fa44cde5752416164241f9a9079a760be45bd77b9af666f164e1ba789bab2bba04e0cb55396018e1
6
+ metadata.gz: a49da204233098191f6e4dcd499baa0f2583c17ac3fb0f9ff5256e9e721bf8873516e3e5236fb15f69546421facd17064f81f900398fe3c9bffb11c8e6d8c987
7
+ data.tar.gz: 09c0e33ea8e3131230b5fcda03d1d7ad716367160efe509821507d5f4f7cf1dfcfd8c2be3f83ea27d505e871e2ae97a84ec51af1ebdfbbb1bbc8be36d9d813f3
@@ -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
 
@@ -188,7 +192,11 @@ class CrudController < ApplicationController
188
192
  def setup
189
193
  if params[:associacao]
190
194
  @crud_associacao = Module.const_get("#{params[:model].to_s.singularize}_crud".camelize)
191
- @model = Module.const_get(params[:model].camelize).find(params[:id]).send(params[:associacao])
195
+ if Module.const_get(params[:model].camelize).reflect_on_association(params[:associacao])
196
+ @model = Module.const_get(params[:model].camelize).find(params[:id]).send(params[:associacao])
197
+ else
198
+ raise "Ação inválida"
199
+ end
192
200
  c_helper = Module.const_get(params[:model].camelize).reflect_on_association(params[:associacao]).class_name
193
201
  @crud_helper = Module.const_get("#{c_helper}Crud") unless params[:render] == "modal" and params[:action] == "new"
194
202
  @url = crud_associacao_models_path(model: params[:model], id: params[:id], associacao: params[:associacao], page: params[:page], q: params[:q])
@@ -260,4 +268,22 @@ class CrudController < ApplicationController
260
268
  end
261
269
  group
262
270
  end
271
+
272
+ def valid_method?(method)
273
+ list_methods = []
274
+ @model.ancestors.each do |m|
275
+ list_methods << m.methods(false).reject{ |m| /^_/ =~ m.to_s }
276
+ break if ["ApplicationRecord", "ActiveRecord::Base"].include? m.superclass.to_s
277
+ end
278
+ list_methods.flatten.include? method.to_sym
279
+ end
280
+
281
+ def valid_instance_method?(method)
282
+ list_methods = []
283
+ @model.ancestors.each do |m|
284
+ list_methods << m.instance_methods(false).reject{ |m| /^_/ =~ m.to_s }
285
+ break if ["ApplicationRecord", "ActiveRecord::Base"].include? m.superclass.to_s
286
+ end
287
+ list_methods.flatten.include? method.to_sym
288
+ end
263
289
  end
@@ -176,10 +176,10 @@ module CrudHelper
176
176
  def render_field_file(field)
177
177
  if imagem?(field) && field.respond_to?(:thumb)
178
178
  if is_active_action("printing")
179
- pdf_image_tag(field)
179
+ pdf_image_tag(field, width: '100px')
180
180
  else
181
181
  link_to field.url, target: "_blank" do
182
- image_tag(field.url(:thumb))
182
+ image_tag(field.url(:thumb), width: '100px')
183
183
  end
184
184
  end
185
185
  elsif video?(field)
@@ -9,7 +9,11 @@
9
9
  <% if @crud_helper.logo_printing_field.present? %>
10
10
  <div class="col-xs-3">
11
11
  <% if @crud_helper.logo_printing_field[:field].present? %>
12
- <%= render_field_file(@record.send(@crud_helper.logo_printing_field[:field])) %>
12
+ <% if @record.send(@crud_helper.logo_printing_field[:field]).present? %>
13
+ <%= render_field_file(@record.send(@crud_helper.logo_printing_field[:field])) %>
14
+ <% else %>
15
+ <%= pdf_image_tag(Templus.logo, width: '100px') %>
16
+ <% end %>
13
17
  <% elsif @crud_helper.logo_printing_field[:url].present? %>
14
18
  <%= pdf_image_tag(@crud_helper.logo_printing_field[:url], width: '100px') %>
15
19
  <% end %>
@@ -1,3 +1,3 @@
1
1
  module TemplusModels
2
- VERSION = "3.0.8"
2
+ VERSION = "3.0.9"
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: 3.0.8
4
+ version: 3.0.9
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-03-28 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