madmin 3.1.1 → 3.1.2

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
  SHA256:
3
- metadata.gz: f115a8b369e2c84e6eda3dd65cd7734f9fc3ba4ec6c49679552202af4b651d66
4
- data.tar.gz: 18b426fbe6ae3f17945d57b9bf6be94d7e063ea4f6fb71669443cce95ec38b02
3
+ metadata.gz: dde4d963db323d7d26197c454095beed2eff86ff40dcd9359e85ee480dd3bc13
4
+ data.tar.gz: 68566f86e2163ce2b7bf2fd12f6289d786fa118639936eff1aeef5f84feea616
5
5
  SHA512:
6
- metadata.gz: a044fdc4cd021c9bb2d68586a07f2fbb446ac8722ffba771278a8778171b99172cafa97ccc05871cfbef7a95cc3b779ea4a78bb823b90aafc56fbabd52a217a3
7
- data.tar.gz: 6b287859f38758d12edb7a4dcc50161b1f7147c233fc8ffc3aed30cfc9c6dd9d71c55d82edf258096210c6001b5b476a9e0350cdbe32b23233a79162ba668383
6
+ metadata.gz: 0c2206a2935ec06380389dbca3109acabf2a3f0af8d84105d964b9551bde50c30c8746403aa718b0acd9e397efecb7fe70e74f9b8704d5a2c3d7d8474898305f
7
+ data.tar.gz: eb2128311c6fd923d69f3d58955e7c9e0bdf322a8949532fc156ec8fec6bba4ab6afd6771d4b06df584a3939ef67ba5879dad16da75611d37816857b92d9582f
data/lib/madmin/filter.rb CHANGED
@@ -12,6 +12,9 @@ module Madmin
12
12
 
13
13
  WITHOUT_VALUE = %w[blank present true false].freeze
14
14
 
15
+ # Operators that match the value as text instead of casting it to the column's type
16
+ MATCHING_OPERATORS = %w[contains starts_with].freeze
17
+
15
18
  attr_reader :field, :operator, :value
16
19
 
17
20
  # Skips conditions for unknown columns or operators, and values that don't
@@ -45,15 +48,16 @@ module Madmin
45
48
  end
46
49
 
47
50
  def valid?
48
- field&.filter_type.present? && OPERATORS[type].include?(operator) && (typed_value.present? || !value?)
51
+ field&.filter_type.present? && OPERATORS[type].include?(operator) &&
52
+ (!value? || (matching_operator? ? value.present? : typed_value.present?))
49
53
  end
50
54
 
51
55
  def apply(scope)
52
56
  attribute = scope.arel_table[column]
53
57
 
54
58
  case operator
55
- when "contains" then scope.where(attribute.matches("%#{escaped_value}%"))
56
- when "starts_with" then scope.where(attribute.matches("#{escaped_value}%"))
59
+ when "contains" then scope.where(as_text(attribute).matches("%#{escaped_value}%"))
60
+ when "starts_with" then scope.where(as_text(attribute).matches("#{escaped_value}%"))
57
61
  when "eq" then scope.where(column => typed_value)
58
62
  when "gt" then scope.where(attribute.gt(typed_value))
59
63
  when "gte" then scope.where(attribute.gteq(typed_value))
@@ -85,12 +89,25 @@ module Madmin
85
89
  (type == :array) ? attribute_type.subtype : attribute_type
86
90
  end
87
91
 
92
+ def matching_operator?
93
+ MATCHING_OPERATORS.include?(operator)
94
+ end
95
+
96
+ def uuid?
97
+ value_type.type == :uuid
98
+ end
99
+
100
+ def as_text(attribute)
101
+ uuid? ? Arel::Nodes::NamedFunction.new("CAST", [attribute.as("CHAR(36)")]) : attribute
102
+ end
103
+
88
104
  def escaped_value
89
105
  field.model.sanitize_sql_like(value)
90
106
  end
91
107
 
92
108
  def blank_values
93
- (type == :string) ? [nil, ""] : nil
109
+ # UUIDs cast "" to NULL, which would match nothing
110
+ (type == :string && !uuid?) ? [nil, ""] : nil
94
111
  end
95
112
  end
96
113
  end
@@ -1,3 +1,3 @@
1
1
  module Madmin
2
- VERSION = "3.1.1"
2
+ VERSION = "3.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver