eco-helpers 2.2.2 → 2.2.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: 9786a6c42a701c7c84fc751543cd341587f637315c48febc00f85bbb948391c3
4
- data.tar.gz: aec51b6308d345fa529acfb26db56178d09ac7397d25d7c323bc6904c793fdad
3
+ metadata.gz: 22b18f6a77dccb77c810944846f1fdc470e0ee54255b2b72b0f1865d9d3b556c
4
+ data.tar.gz: 5cd2157a4feeb673598608ce04e8e8eee26d75fd7d8e58ee7f51683367a68ad3
5
5
  SHA512:
6
- metadata.gz: 246d8b86360b5c5a949b85d74ca2829350c206617a7ed39f071c0d853a04cc4cba40b0298897f81de8970e76d92c8b8c995dd79ccbd1748dff8c0201f4eef961
7
- data.tar.gz: 4468a3e61ec3f5cc661fc42189f00ef676e4e99a7fb9a2adbd85eef40597f1c2787007b55d4cd14170de09cadcad7824b657ad005bab5efb4b6998073360e7e4
6
+ metadata.gz: 32c089f361f91e2f411659150d3345717b700a693962fad99ecdd1c9311daeb8d30f78d706bb6335a67e8617493d22335808146d562da531c1c9bce98cc94b9a
7
+ data.tar.gz: c9967613a369e8672cded50133b4eb7f422f801f9b6a879e82918ec71eaa3d8d6b9798ced776d70bdc30416cf81d558b45e12c799258dfaaeffc2e06a05547a4
data/CHANGELOG.md CHANGED
@@ -1,11 +1,29 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.2.3] - 2023-02-xx
4
+ ## [2.2.5] - 2023-03-xx
5
5
 
6
6
  ### Added
7
7
  ### Changed
8
8
  ### Fixed
9
+ - Logger object when logging from config
10
+
11
+ ## [2.2.4] - 2023-03-07
12
+
13
+ ### Fixed
14
+ - Logger object when logging from config
15
+
16
+ ## [2.2.3] - 2023-03-07
17
+
18
+ ### Added
19
+ - Logger info for live tree selected.
20
+
21
+ ### Changed
22
+ - `Eco::API::Common::People::DefaultParsers::PolicyGroupsParser`
23
+ - Should warn of unknown policy groups
24
+
25
+ ### Fixed
26
+ - `Eco::API:Organization::TagTree` fix `defaults_tag` scoping
9
27
 
10
28
  ## [2.2.2] - 2023-02-27
11
29
 
@@ -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
@@ -21,7 +21,11 @@ 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
+ session_logger.info("Using LIVE LOCATIONS Structure: '#{tree.name}'") if tree
28
+ end
25
29
  end
26
30
 
27
31
  # Retrieves all the location structures of the organisation
@@ -41,6 +45,16 @@ module Eco
41
45
  end
42
46
  end
43
47
  end
48
+
49
+ private
50
+
51
+ def session
52
+ ASSETS.session
53
+ end
54
+
55
+ def session_logger
56
+ session.logger
57
+ end
44
58
  end
45
59
  end
46
60
  end
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.2.2"
2
+ VERSION = "2.2.4"
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura