eco-helpers 2.2.2 → 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: 9786a6c42a701c7c84fc751543cd341587f637315c48febc00f85bbb948391c3
4
- data.tar.gz: aec51b6308d345fa529acfb26db56178d09ac7397d25d7c323bc6904c793fdad
3
+ metadata.gz: ac9d8f190b56ad971ec86e7c51be2d8bce759b7769e11065c7a61e4b26e2c5f2
4
+ data.tar.gz: b4a0de11bae2d18e4156e4904a5ca051d070c08e8c3c213749ac83acaa326059
5
5
  SHA512:
6
- metadata.gz: 246d8b86360b5c5a949b85d74ca2829350c206617a7ed39f071c0d853a04cc4cba40b0298897f81de8970e76d92c8b8c995dd79ccbd1748dff8c0201f4eef961
7
- data.tar.gz: 4468a3e61ec3f5cc661fc42189f00ef676e4e99a7fb9a2adbd85eef40597f1c2787007b55d4cd14170de09cadcad7824b657ad005bab5efb4b6998073360e7e4
6
+ metadata.gz: 19cfac22cebdb7a601879a9ce3c6a897c424dceeca2e42c65d8632dcdadd7c49fe239daab17926ae6531e87fe03ca962a42cf0bc815c29c8cf24d8cbbd2fbe73
7
+ data.tar.gz: 1912c842a4f517f1977024b7337dca4ab648eb77e4d6b30ab5c28fdf1d2381e6e851107d4b1a6693e603133c70b7dd231861ab78d70d0fce5cdcbdc4ed7d6b9c
data/CHANGELOG.md CHANGED
@@ -4,8 +4,14 @@ All notable changes to this project will be documented in this file.
4
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
9
15
 
10
16
  ## [2.2.2] - 2023-02-27
11
17
 
@@ -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
@@ -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,7 +21,13 @@ 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
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.2.2"
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.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura