insights-api-common 4.1.5 → 5.0.4

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
  SHA256:
3
- metadata.gz: f23ebe490e2b124e093a772ba711f5f93942725df5da610609aacb0619f57194
4
- data.tar.gz: bf033da653e5130461d092a06fc5a9b26c9e451e7e900e33a34efaf8338d07e6
3
+ metadata.gz: 27c2d8f13f5a3be044e999f5eede282412bdd00e258b21760f34c154609fa622
4
+ data.tar.gz: 46afb339ae074b46703fb268b1bbd8b76f1375ba80196632c8a803f408fcd73e
5
5
  SHA512:
6
- metadata.gz: 1abf3875849663909685e77d9d9a2b212bf52a02cf8772e6f30530c96e7b814e28ff167565dfd07908ccbb5bddb50264b6ba6f9b21dce60119ce4ae5291f84a2
7
- data.tar.gz: dab5a4c9ee7a93f7f0eaec01befe41367f3799fc1f87bd0a83855f2f12148e7070de15d4d0736969f3201f76c44ff54da711cc959b0d670695c65c41b9ca6a1a
6
+ metadata.gz: 3449d374a193f78d3d314156042ef4956a76aebd82ad9fed5481f8932bb103faf19f1f67d9bac0adf61fd4a3570f743f1625a3f37bc095cd6f31499e30117f96
7
+ data.tar.gz: 562dc832ad9d50ca6e9f3790ed989cc0a2953e0450eaa11587012e9a96383df4b29491c7cab9b2f650ced30a71ef274d4a46f34e641ac7baf8f0bce7eeb74235
data/README.md CHANGED
@@ -30,6 +30,7 @@ Or install it yourself as:
30
30
  | Supported Comparators | Comparator |
31
31
  | --------------------- | ---------- |
32
32
  | Integer | eq |
33
+ | | not_eq |
33
34
  | | gt |
34
35
  | | gte |
35
36
  | | lt |
@@ -37,12 +38,14 @@ Or install it yourself as:
37
38
  | | nil |
38
39
  | | not_nil |
39
40
  | String | eq |
41
+ | | not_eq |
40
42
  | | contains |
41
43
  | | starts_with |
42
44
  | | ends_with |
43
45
  | | nil |
44
46
  | | not_nil |
45
47
  | String (case insensitive) | eq_i |
48
+ | | not_eq_i |
46
49
  | | contains_i |
47
50
  | | starts_with_i |
48
51
  | | ends_with_i |
@@ -53,6 +56,7 @@ After implementing filtering in your application, this is the way to filter via
53
56
  | --------------- | --------------------- | ----------------- |
54
57
  | "?filter[name]=reviews" | { :filter => { :name => "reviews" } } | filter: { name: "reviews" } |
55
58
  | "?filter[name][eq]=reviews" | { :filter => { :name => { :eq => "reviews" } } } | filter: { name: { eq: "reviews" } } |
59
+ | "?filter[name][not_eq]=reviews" | { :filter => { :name => { :not_eq => "reviews" } } } | filter: { name: { not_eq: "reviews" } } |
56
60
  | "?filter[name][starts_with]=a" | { :filter => { :name => { :starts_with => "a" } } } | filter: { name: { starts_with: "a" } } |
57
61
  | "?filter[name][ends_with]=manager" | { :filter => { :name => { :ends_with => "manager" } } } | filter: { name: { ends_with: "manager" } } |
58
62
  | "?filter[name][contains]=openshift" | { :filter => { :name => { :contains => "openshift" } } } | filter: { name: { contains: "openshift" } } |
@@ -123,7 +123,8 @@ module Insights
123
123
 
124
124
  def sanctified_permit_param(api_doc_definition, attributes)
125
125
  api_doc_definition['properties'].each_with_object([]) do |(k, v), memo|
126
- next unless attributes.each { |attr| attr.include?(k) }
126
+ # only add to the permit hash if we're actually trying to update it.
127
+ next unless attributes.any? { |attr| attr.include?(k) }
127
128
 
128
129
  memo << if v['type'] == 'array'
129
130
  { k => [] }
@@ -44,10 +44,14 @@ module Insights
44
44
  private
45
45
 
46
46
  def id_regexp(primary_collection_name)
47
- @id_regexp ||= begin
47
+ @id_regexp_table ||= {}
48
+
49
+ if @id_regexp_table.empty? || @id_regexp_table[primary_collection_name].nil?
48
50
  id_parameter = id_parameter_from_api_doc(primary_collection_name)
49
- id_parameter ? id_parameter.fetch_path("schema", "pattern") : /^\d+$/
51
+ @id_regexp_table[primary_collection_name] = id_parameter ? id_parameter.fetch_path("schema", "pattern") : /^\d+$/
50
52
  end
53
+
54
+ @id_regexp_table[primary_collection_name]
51
55
  end
52
56
 
53
57
  def id_parameter_from_api_doc(primary_collection_name)
@@ -7,7 +7,8 @@ module Insights
7
7
  def self.custom_message(exception)
8
8
  case exception.class.to_s
9
9
  when "Pundit::NotAuthorizedError"
10
- "You are not authorized to #{exception.query.to_s.delete_suffix('?')} this #{exception.record.model_name.human.downcase}"
10
+ exception.policy.try(:error_message) ||
11
+ "You are not authorized to perform the #{exception.query.to_s.delete_suffix('?')} action for this #{exception.record.model_name.human.downcase}"
11
12
  end
12
13
  end
13
14
  end
@@ -4,7 +4,8 @@ module Insights
4
4
  class ErrorDocument
5
5
  def add(status = 400, message)
6
6
  @status = status
7
- errors << {"status" => status, "detail" => message}
7
+ safe_message = message.to_s.encode('UTF-8', :invalid => :replace, :undef => :replace)
8
+ errors << {"status" => status, "detail" => safe_message}
8
9
  self
9
10
  end
10
11
 
@@ -2,8 +2,8 @@ module Insights
2
2
  module API
3
3
  module Common
4
4
  class Filter
5
- INTEGER_COMPARISON_KEYWORDS = ["eq", "gt", "gte", "lt", "lte", "nil", "not_nil"].freeze
6
- STRING_COMPARISON_KEYWORDS = ["contains", "contains_i", "eq", "eq_i", "starts_with", "starts_with_i", "ends_with", "ends_with_i", "nil", "not_nil"].freeze
5
+ INTEGER_COMPARISON_KEYWORDS = ["eq", "not_eq", "gt", "gte", "lt", "lte", "nil", "not_nil"].freeze
6
+ STRING_COMPARISON_KEYWORDS = ["contains", "contains_i", "eq", "not_eq", "eq_i", "not_eq_i", "starts_with", "starts_with_i", "ends_with", "ends_with_i", "nil", "not_nil"].freeze
7
7
  ALL_COMPARISON_KEYWORDS = (INTEGER_COMPARISON_KEYWORDS + STRING_COMPARISON_KEYWORDS).uniq.freeze
8
8
 
9
9
  attr_reader :apply, :arel_table, :api_doc_definition, :extra_filterable_attributes, :model
@@ -242,6 +242,16 @@ module Insights
242
242
  self.query = query.where(model_arel_attribute(key).eq_any(Array(value)))
243
243
  end
244
244
 
245
+ def comparator_not_eq(key, value)
246
+ self.query = query.where.not(model_arel_attribute(key).eq_any(Array(value)))
247
+ end
248
+
249
+ def comparator_not_eq_i(key, value)
250
+ values = Array(value).map { |v| query.sanitize_sql_like(v.downcase) }
251
+
252
+ self.query = query.where.not(model_arel_table(key).grouping(arel_lower(key).matches_any(values)))
253
+ end
254
+
245
255
  def comparator_eq_i(key, value)
246
256
  values = Array(value).map { |v| query.sanitize_sql_like(v.downcase) }
247
257
 
@@ -20,8 +20,32 @@ module Insights
20
20
  openapi_path.split("/")[1..-1]
21
21
  end
22
22
 
23
+ def self.template_file_by(type, root_dir = __dir__)
24
+ Pathname.new(root_dir).join(File.expand_path("templates", root_dir), "#{type}.erb")
25
+ end
26
+
27
+ def self.root_dir
28
+ Rails.root
29
+ end
30
+
31
+ def self.app_name
32
+ Rails.application.class.parent.name.underscore
33
+ end
34
+
35
+ def self.pluggable_template_file_by(type)
36
+ templates_relative_path = "lib/#{app_name}/api/graphql/templates"
37
+ template_path = File.expand_path(templates_relative_path, root_dir)
38
+ Pathname.new(root_dir).join(template_path, "#{type}.erb")
39
+ end
40
+
41
+ def self.template_path_by(type)
42
+ template_path_pluggable = pluggable_template_file_by(type)
43
+ template_path_default = template_file_by(type)
44
+ template_path_pluggable.exist? ? template_path_pluggable : template_path_default
45
+ end
46
+
23
47
  def self.template(type)
24
- File.read(Pathname.new(__dir__).join(File.expand_path("templates", __dir__), "#{type}.erb").to_s)
48
+ File.read(template_path_by(type))
25
49
  end
26
50
 
27
51
  def self.graphql_type(property_name, property_format, property_type)
@@ -17,7 +17,7 @@ module Insights
17
17
 
18
18
  private_class_method def self.ensure_exporter_server
19
19
  require 'socket'
20
- TCPSocket.open("localhost", metrics_port) {}
20
+ TCPSocket.open("127.0.0.1", metrics_port) {}
21
21
  rescue Errno::ECONNREFUSED
22
22
  require 'prometheus_exporter/server'
23
23
  server = PrometheusExporter::Server::WebServer.new(port: metrics_port)
@@ -1,7 +1,7 @@
1
1
  module Insights
2
2
  module API
3
3
  module Common
4
- VERSION = "4.1.5".freeze
4
+ VERSION = "5.0.4".freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insights-api-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.5
4
+ version: 5.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Insights Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-06 00:00:00.000000000 Z
11
+ date: 2021-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_tenant
@@ -160,16 +160,16 @@ dependencies:
160
160
  name: graphql
161
161
  requirement: !ruby/object:Gem::Requirement
162
162
  requirements:
163
- - - "~>"
163
+ - - '='
164
164
  - !ruby/object:Gem::Version
165
- version: '1.9'
165
+ version: 1.11.7
166
166
  type: :runtime
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
- - - "~>"
170
+ - - '='
171
171
  - !ruby/object:Gem::Version
172
- version: '1.9'
172
+ version: 1.11.7
173
173
  - !ruby/object:Gem::Dependency
174
174
  name: graphql-batch
175
175
  requirement: !ruby/object:Gem::Requirement
@@ -246,6 +246,48 @@ dependencies:
246
246
  - - ">="
247
247
  - !ruby/object:Gem::Version
248
248
  version: 12.3.3
249
+ - !ruby/object:Gem::Dependency
250
+ name: rubocop
251
+ requirement: !ruby/object:Gem::Requirement
252
+ requirements:
253
+ - - "~>"
254
+ - !ruby/object:Gem::Version
255
+ version: 1.0.0
256
+ type: :development
257
+ prerelease: false
258
+ version_requirements: !ruby/object:Gem::Requirement
259
+ requirements:
260
+ - - "~>"
261
+ - !ruby/object:Gem::Version
262
+ version: 1.0.0
263
+ - !ruby/object:Gem::Dependency
264
+ name: rubocop-performance
265
+ requirement: !ruby/object:Gem::Requirement
266
+ requirements:
267
+ - - "~>"
268
+ - !ruby/object:Gem::Version
269
+ version: '1.8'
270
+ type: :development
271
+ prerelease: false
272
+ version_requirements: !ruby/object:Gem::Requirement
273
+ requirements:
274
+ - - "~>"
275
+ - !ruby/object:Gem::Version
276
+ version: '1.8'
277
+ - !ruby/object:Gem::Dependency
278
+ name: rubocop-rails
279
+ requirement: !ruby/object:Gem::Requirement
280
+ requirements:
281
+ - - "~>"
282
+ - !ruby/object:Gem::Version
283
+ version: '2.8'
284
+ type: :development
285
+ prerelease: false
286
+ version_requirements: !ruby/object:Gem::Requirement
287
+ requirements:
288
+ - - "~>"
289
+ - !ruby/object:Gem::Version
290
+ version: '2.8'
249
291
  - !ruby/object:Gem::Dependency
250
292
  name: rspec
251
293
  requirement: !ruby/object:Gem::Requirement
@@ -415,7 +457,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
415
457
  - !ruby/object:Gem::Version
416
458
  version: '0'
417
459
  requirements: []
418
- rubygems_version: 3.0.3
460
+ rubygems_version: 3.0.3.1
419
461
  signing_key:
420
462
  specification_version: 4
421
463
  summary: Common Utilites for Insights microservices