eco-helpers 2.2.1 → 2.2.3

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: c71f3bf20fae0dff4ec0ccd0ee8205b8af1dee3c9fabb02791f6102a84f7f9ab
4
- data.tar.gz: 81ba2c67c4653941529051d433189101e6480313447fdbe6c64da617887371b7
3
+ metadata.gz: ac9d8f190b56ad971ec86e7c51be2d8bce759b7769e11065c7a61e4b26e2c5f2
4
+ data.tar.gz: b4a0de11bae2d18e4156e4904a5ca051d070c08e8c3c213749ac83acaa326059
5
5
  SHA512:
6
- metadata.gz: b67b415da8341ab6d20a4165ef9f761777bcdb871635a33b0681a56228dae6138c779c31852ce2e748156fa41832ab1ea457ad1aa7ff9dc66c3e1c16dc016be4
7
- data.tar.gz: 53e6154974cc3db39e56a127710c1a676e34af8786012b0f3c41051fe14d0b27cc55945875843cdfa1f5fb98d64ed8afcae7eebcd2cfb0cb30da43f7aee2c16f
6
+ metadata.gz: 19cfac22cebdb7a601879a9ce3c6a897c424dceeca2e42c65d8632dcdadd7c49fe239daab17926ae6531e87fe03ca962a42cf0bc815c29c8cf24d8cbbd2fbe73
7
+ data.tar.gz: 1912c842a4f517f1977024b7337dca4ab648eb77e4d6b30ab5c28fdf1d2381e6e851107d4b1a6693e603133c70b7dd231861ab78d70d0fce5cdcbdc4ed7d6b9c
data/CHANGELOG.md CHANGED
@@ -1,11 +1,23 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.2.2] - 2023-02-xx
4
+ ## [2.2.3] - 2023-02-xx
5
5
 
6
6
  ### Added
7
+ - Logger info for live tree selected.
8
+
7
9
  ### Changed
10
+ - `Eco::API::Common::People::DefaultParsers::PolicyGroupsParser`
11
+ - Should warn of unknown policy groups
12
+
8
13
  ### Fixed
14
+ - `Eco::API:Organization::TagTree` fix `defaults_tag` scoping
15
+
16
+ ## [2.2.2] - 2023-02-27
17
+
18
+ ### Fixed
19
+ - Typo in GraphQL client (`locationsStructures` should read `locationStructures`)
20
+ - Multiple typos in new code
9
21
 
10
22
  ## [2.2.1] - 2023-02-24
11
23
 
@@ -18,7 +30,7 @@ All notable changes to this project will be documented in this file.
18
30
  ### Changed
19
31
  - **Patch** `Ecoportal::API::V1::Person::VALID_TAG_REGEX` it now allows for dot `.`
20
32
  - update gem dependencies
21
-
33
+
22
34
  ## [2.1.12] - 2022-11-30
23
35
 
24
36
  ### Fixed
data/eco-helpers.gemspec CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.add_dependency 'ecoportal-api', '>= 0.8.5', '< 0.9'
34
34
  spec.add_dependency 'ecoportal-api-v2', '>= 1.0.1', '< 1.1'
35
- spec.add_dependency 'ecoportal-api-graphql', '>= 0.2.2', '< 0.3'
35
+ spec.add_dependency 'ecoportal-api-graphql', '>= 0.2.3', '< 0.3'
36
36
  spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
37
37
  spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
38
38
  spec.add_dependency 'dotenv', '>= 2.7.6', '< 2.8'
@@ -5,7 +5,12 @@ class Eco::API::Common::People::DefaultParsers::PolicyGroupsParser < Eco::API::C
5
5
  def parser(hash, deps)
6
6
  policy_group_ids = hash["policy_group_ids"] || []
7
7
  policy_group_ids.map do |name|
8
- policy_groups.to_id(name&.downcase.strip)
8
+ policy_groups.to_id(name&.downcase.strip).tap do |known|
9
+ unless !name || known || unknown_pgs.include?(name)
10
+ unknown_pgs.push(name)
11
+ logger.warn("Unknown Policy Group: '#{name}'")
12
+ end
13
+ end
9
14
  end.compact.tap do |pg_names|
10
15
  pg_names.push(default_id) if pg_names.empty?
11
16
  end
@@ -20,6 +25,10 @@ class Eco::API::Common::People::DefaultParsers::PolicyGroupsParser < Eco::API::C
20
25
 
21
26
  private
22
27
 
28
+ def unknown_pgs
29
+ unknown_pgs ||= []
30
+ end
31
+
23
32
  def default_id
24
33
  @default_id ||= policy_groups.to_id(config.people.default_usergroup)
25
34
  end
@@ -27,5 +36,4 @@ class Eco::API::Common::People::DefaultParsers::PolicyGroupsParser < Eco::API::C
27
36
  def policy_groups
28
37
  @policy_groups ||= config.policy_groups
29
38
  end
30
-
31
39
  end
@@ -22,6 +22,8 @@ module Eco
22
22
  # tree = TagTree.new(tree.to_json)
23
23
  # @param tagtree [String] representation of the tagtree in json.
24
24
  def initialize(tagtree = [], name: nil, id: nil, depth: -1, path: [], enviro: nil)
25
+ @depth = depth
26
+
25
27
  case tagtree
26
28
  when String
27
29
  @source = JSON.parse(tagtree)
@@ -32,24 +34,22 @@ module Eco
32
34
  fatal("Expecting Environment object. Given: #{enviro}") if enviro && !enviro.is_a?(API::Common::Session::Environment)
33
35
  @enviro = enviro
34
36
 
35
- @depth = depth
36
37
  if @source.is_a?(Array)
37
38
  @id = id
38
39
  @name = name
39
- @nodes = @source
40
+ @row_nodes = @source
40
41
  else
41
42
  @id = @source.values_at('tag', 'id').compact.first&.upcase
42
43
  @name = @source['name']
43
- @nodes = @source['nodes'] || []
44
+ @row_nodes = @source['nodes'] || []
44
45
  end
45
46
 
46
47
  @path = path || []
47
48
  @path.push(@id) unless top?
48
49
 
49
- @nodes = nodes.map do |cnode|
50
- TagTree.new(cnode, depth: @depth + 1, path: @path.dup, enviro: @enviro)
50
+ @nodes = @row_nodes.map do |cnode|
51
+ TagTree.new(cnode, depth: depth + 1, path: @path.dup, enviro: @enviro)
51
52
  end
52
- @children_count = @nodes.count
53
53
 
54
54
  init_hashes
55
55
  end
@@ -84,7 +84,7 @@ module Eco
84
84
 
85
85
  # @return [Boolean] `true` if there are tags in the node, `false` otherwise.
86
86
  def empty?
87
- @has_tags.empty?
87
+ @hash_tags.empty?
88
88
  end
89
89
 
90
90
  # @return [Integer] the number of locations
@@ -94,9 +94,11 @@ module Eco
94
94
 
95
95
  # @return [Integer] the highest `depth` of all the children.
96
96
  def total_depth
97
- @total_depth ||= if children_count > 0
98
- deepest_node = nodes.max_by {|node| node.total_depth}
99
- deepest_node.depth
97
+ @total_depth ||= if has_children?
98
+ deepest_node = nodes.max_by do |node|
99
+ node.total_depth
100
+ end
101
+ deepest_node.total_depth
100
102
  else
101
103
  depth
102
104
  end
@@ -140,10 +142,20 @@ module Eco
140
142
  # @return [Array<String>]
141
143
  def leafs
142
144
  tags.select do |tag|
143
- node(tag).children_count == 0
145
+ !node(tag).has_children?
144
146
  end
145
147
  end
146
148
 
149
+ # @return [Integer]
150
+ def children_count
151
+ nodes.count
152
+ end
153
+
154
+ # @return [Boolean] it has subnodes
155
+ def has_children?
156
+ children_count > 0
157
+ end
158
+
147
159
  # Verifies if a tag exists in the tree.
148
160
  # @param key [String] tag to verify.
149
161
  # @return [Boolean]
@@ -222,14 +234,14 @@ module Eco
222
234
  # @return [String] default tag.
223
235
  def default_tag(*values)
224
236
  values = filter_tags(values)
225
- nodes = []; depth = -1
237
+ nodes = []; ddepth = -1
226
238
  values.each do |tag|
227
239
  raise("Couldn't find the node of #{tag} in the tag-tree definition") unless cnode = node(tag)
228
240
 
229
- if cnode.depth > depth
241
+ if cnode.depth > ddepth
230
242
  nodes = [cnode]
231
- depth = cnode.depth
232
- elsif cnode.depth == depth
243
+ ddepth = cnode.depth
244
+ elsif cnode.depth == ddepth
233
245
  nodes.push(cnode)
234
246
  end
235
247
  end
@@ -237,9 +249,9 @@ module Eco
237
249
  default_tag = nil
238
250
  if nodes.length > 1
239
251
  common = nodes.reduce(self.tags.reverse) {|com, cnode| com & cnode.path.reverse}
240
- default_tag = common.first if common.length > 0 && depth > 0
252
+ default_tag = common.first if common.length > 0 && ddepth > 0
241
253
  end
242
- default_tag = nodes.first&.tag if !default_tag && ( (depth > 0) || flat?)
254
+ default_tag ||= nodes.first&.tag if (ddepth > 0) || flat?
243
255
  default_tag
244
256
  end
245
257
 
@@ -258,12 +270,12 @@ module Eco
258
270
  def init_hashes
259
271
  @hash_tags = {}
260
272
  @hash_tags[@id] = self unless top?
261
- @hash_tags = @nodes.reduce(@hash_tags) do |h,n|
273
+ @hash_tags = nodes.reduce(@hash_tags) do |h,n|
262
274
  h.merge(n.hash)
263
275
  end
264
276
  @hash_paths = {}
265
277
  @hash_paths[@id] = @path unless top?
266
- @hash_paths = @nodes.reduce(@hash_paths) do |h,n|
278
+ @hash_paths = nodes.reduce(@hash_paths) do |h,n|
267
279
  h.merge(n.hash_paths)
268
280
  end
269
281
  end
@@ -38,6 +38,10 @@ module Eco
38
38
  config.apis
39
39
  end
40
40
 
41
+ def logger
42
+ config.logger
43
+ end
44
+
41
45
  def clone(config:)
42
46
  keys.each_with_object(self.class.new(config: config)) do |key, cnf|
43
47
  begin
@@ -21,23 +21,29 @@ module Eco
21
21
  trees = live_trees(enviro: enviro)
22
22
  @live_tree = trees.reject do |tree|
23
23
  tree.empty?
24
- end.max {|a,b| a.count <=> b.count}
24
+ end.max do |a,b|
25
+ a.count <=> b.count
26
+ end.tap do |tree|
27
+ if tree
28
+ logger.info("Live tree in use: '#{tree.name}'")
29
+ end
30
+ end
25
31
  end
26
32
 
27
33
  # Retrieves all the location structures of the organisation
28
34
  def live_trees(enviro: nil)
29
- [].tap do |trees|
35
+ [].tap do |eco_trees|
30
36
  next unless apis.active_api.version_available?(:graphql)
31
37
  next unless graphql = apis.api(version: :graphql)
32
38
  kargs = {
33
39
  includeArchived: false,
34
40
  includeUnpublished: false
35
41
  }
36
- next unless trees = graphql.currentOrganization.locationsStructures(**kargs)
42
+ next unless trees = graphql.currentOrganization.locationStructures(**kargs)
37
43
  trees.each do |tree|
38
44
  args = { enviro: enviro, id: tree.id, name: tree.name}
39
45
  eco_tree = Eco::API::Organization::TagTree.new(tree.treeify, **args)
40
- trees.push(eco_tree)
46
+ eco_trees.push(eco_tree)
41
47
  end
42
48
  end
43
49
  end
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.2.1"
2
+ VERSION = "2.2.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eco-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -156,7 +156,7 @@ dependencies:
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: 0.2.2
159
+ version: 0.2.3
160
160
  - - "<"
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0.3'
@@ -166,7 +166,7 @@ dependencies:
166
166
  requirements:
167
167
  - - ">="
168
168
  - !ruby/object:Gem::Version
169
- version: 0.2.2
169
+ version: 0.2.3
170
170
  - - "<"
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0.3'