eco-helpers 2.5.4 → 2.5.5

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: 444bec4cd18402a38eff718340932ca7d72c9959b865805964b0ec9787d94636
4
- data.tar.gz: 97291544f70b525781d81f168ffc86c1d960151e53535a540ac1b7824b9eaf28
3
+ metadata.gz: d241b7bc57bd81e9b3a6b1d71ecab5f7530b7b6df176301adc21584722f2b247
4
+ data.tar.gz: a8beafa1e6cd1e3425291121c55b78fe144f155021ab149148fcc6ce35569984
5
5
  SHA512:
6
- metadata.gz: 02360de987395d801aa1b1fb659dd4b6011c317a21058be33c3283b3a2856c69db519baf6eb85a022f7a2c7c4e826861b108c2cf09aefad3ca57b32d53b45c72
7
- data.tar.gz: 402c880d701446c072f6534d4df35b2a104704dc79480e37e5033101df63a8b10baa25257911af1cc84994efe05744b15c608798dbc1637ad268811ca2d7d926
6
+ metadata.gz: 2bad589998061077bac0f6adb500fdbb9402b77578da68bf43a84f83101a2bf862213acb00707a363f5583c47ec94a876c367360c562043865e573232b272c4c
7
+ data.tar.gz: 7c33f358f5cbb7ab0b3118d7b0b20e86a9f686f2e1f49216e23bea5ab504ca4bb0bbb2eeab8bb37daf0d11b997af0160212ff7ab2d1fe382fa05a6b354529f48
data/CHANGELOG.md CHANGED
@@ -1,12 +1,26 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.5.5] - 2023-07-xx
4
+ ## [2.5.6] - 2023-08-xx
5
5
 
6
6
  ### Added
7
7
  ### Changed
8
8
  ### Fixed
9
9
 
10
+ ## [2.5.5] - 2023-08-03
11
+
12
+ ### Added
13
+ - `Eco::API::Organization::TagTree` - **added/improved methods**
14
+ - `#as_json` new parameter `max_depth:` to be able to cut the tree
15
+ - `#active_tree` new method to exclude archived nodes.
16
+ - `#truncate` new method to obtain a tree cut to `max_depth:`
17
+ - `Eco::API::Session::Config::Tagtree`: **exposed** `include_archived:` (a.k.a. `inludeArchivedNodes`).
18
+ - This change states that `session.tagtree` does not retrieve archived nodes by default, while `session.live_tree` does retrieve archived nodes.
19
+ - This change required an update on the `ecoportal-api-graphql` **gem**
20
+
21
+ ### Fixed
22
+ - `Eco::API::Organization::TagTree#path` - dups the result (rather than exposing the internal path array)
23
+
10
24
  ## [2.5.4] - 2023-07-27
11
25
 
12
26
  ### Added
data/eco-helpers.gemspec CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.add_dependency 'ecoportal-api', '>= 0.9.4', '< 0.10'
34
34
  spec.add_dependency 'ecoportal-api-v2', '>= 1.1.3', '< 1.2'
35
- spec.add_dependency 'ecoportal-api-graphql', '>= 0.3.8', '< 0.4'
35
+ spec.add_dependency 'ecoportal-api-graphql', '>= 0.3.9', '< 0.4'
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', '< 3'
@@ -523,7 +523,6 @@ module Eco
523
523
  call_order = parsing? ? [ext, mad, int, fin] : [fin, int, mad, ext]
524
524
  call_order.each {|proc| proc.call}
525
525
  end
526
-
527
526
  end
528
527
  end
529
528
  end
@@ -76,9 +76,23 @@ module Eco
76
76
  @archived
77
77
  end
78
78
 
79
+ def active?
80
+ !archived?
81
+ end
82
+
79
83
  # @return [Eco::API::Organization::TagTree]
80
84
  def dup
81
- self.class.new(as_json)
85
+ self.class.new(as_json, name: name, id: id)
86
+ end
87
+
88
+ # @return [Eco::API::Organization::TagTree] with **non** `archived` nodes only
89
+ def active_tree
90
+ self.class.new(as_json(include_archived: false), name: name, id: id)
91
+ end
92
+
93
+ # @return [Eco::API::Organization::TagTree] with nodes up to `max_depth`
94
+ def truncate(max_depth: total_depth)
95
+ self.class.new(as_json(max_depth: max_depth), name: name, id: id)
82
96
  end
83
97
 
84
98
  # Iterate through all the nodes of this tree
@@ -161,11 +175,26 @@ module Eco
161
175
  # Returns a tree of Hashes form nested via `nodes` (or just a list of hash nodes)
162
176
  # @yield [node_json, node] block for custom output json model
163
177
  # @yiledreturn [Hash] the custom json model.
164
- # @include_children [Boolean] whether it should return a tree hash or just a list of hash nodes.
178
+ # @param include_children [Boolean] whether it should return a tree hash or just a list of hash nodes.
179
+ # @param include_archived [Boolean] whether it should include archived nodes.
180
+ # @param max_depth [Boolean] up to what level `depth` nodes should be included.
165
181
  # @return [Array[Hash]] where `Hash` is a `node` (i.e. `{"tag" => TAG, "nodes": Array[Hash]}`)
166
- def as_json(include_children: true, &block)
167
- return [] if top? && !include_children
168
- children_json = nodes.map {|nd| nd.as_json(include_children: true, &block)} if include_children
182
+ def as_json(include_children: true, include_archived: true, max_depth: total_depth, &block)
183
+ max_depth ||= total_depth
184
+ return nil if max_depth < depth
185
+ return [] if top? && !include_children
186
+ return nil if archived? && !include_archived
187
+
188
+ if include_children
189
+ child_nodes = nodes
190
+ child_nodes = child_nodes.select(&:active?) unless include_archived
191
+ kargs = {
192
+ include_children: include_children,
193
+ include_archived: include_archived,
194
+ max_depth: max_depth
195
+ }
196
+ children_json = child_nodes.map {|nd| nd.as_json(**kargs, &block)}.compact
197
+ end
169
198
 
170
199
  if top?
171
200
  children_json
@@ -287,8 +316,8 @@ module Eco
287
316
  # @param key [String] tag to find the path to.
288
317
  # @return [Array<String>]
289
318
  def path(key = nil)
290
- return @path if !key
291
- @hash_paths[key.upcase]
319
+ return @path.dup if !key
320
+ @hash_paths[key.upcase].dup
292
321
  end
293
322
 
294
323
  # Helper to assign tags to a person account.
@@ -3,18 +3,30 @@ module Eco
3
3
  class Session
4
4
  class Config
5
5
  class TagTree < BaseConfig
6
+ class MissingTagtree < StandardError
7
+ end
8
+
6
9
  attr_key :file
7
10
 
8
- def scope_tree(enviro: nil)
11
+ # @param include_archived [Boolean] whether or not it should include archived nodes.
12
+ # @return [Eco::API::Organization::TagTree]
13
+ def scope_tree(enviro: nil, include_archived: true, raise_on_missing: true)
9
14
  return @tagtree if instance_variable_defined?(:@tagtree) && @tagtree.enviro == enviro
10
15
  if tree_file = self.file
11
16
  if (tree = file_manager.load_json(tree_file)) && !tree.empty?
12
17
  @tagtree = Eco::API::Organization::TagTree.new(tree, enviro: enviro)
13
18
  end
14
19
  end
15
- @tagtree ||= live_tree(enviro: enviro).tap do |tree|
20
+
21
+ kargs = {
22
+ enviro: enviro,
23
+ includeArchivedNodes: include_archived
24
+ }
25
+
26
+ @tagtree ||= live_tree(**kargs).tap do |tree|
16
27
  unless tree && !tree.empty?
17
- raise "Could not find a locations structure."
28
+ msg = "Could not find a local or live locations structure."
29
+ raise MissingTagtree, msg
18
30
  end
19
31
  end
20
32
  end
@@ -23,13 +35,18 @@ module Eco
23
35
  # If `id` is provided, it only retrieves this locations structure.
24
36
  def live_tree(id: nil, enviro: nil, include_archived: false, **kargs, &block)
25
37
  return @live_tree if instance_variable_defined?(:@live_tree) && @live_tree.enviro == enviro
38
+
39
+ kargs = {
40
+ enviro: enviro,
41
+ includeArchivedNodes: include_archived
42
+ }.merge(kargs)
43
+
26
44
  if id
27
- args = {id: id, enviro: enviro, include_archived: include_archived}.merge(kargs)
45
+ args = { id: id }.merge(kargs)
28
46
  @live_tree = live_tree_get(**args, &block)
29
47
  else
30
- # note that `include_archived` nodes is NOT the same as including archived structures
31
- # => In `live_tree` the paramter refers to nodes
32
- trees = live_trees(enviro: enviro, &block)
48
+ kargs
49
+ trees = live_trees(**kargs, &block)
33
50
  @live_tree = trees.reject do |tree|
34
51
  tree.empty?
35
52
  end.max do |a,b|
@@ -45,26 +62,33 @@ module Eco
45
62
 
46
63
  # Gets a single locations structure
47
64
  # @note it does not memoize
65
+ # @param include_archived [Boolean] whether or not to include archived **nodes**
66
+ # @return [Eco::API::Organization::TagTree, NilClass]
48
67
  def live_tree_get(id: nil, enviro: nil, include_archived: false, **kargs, &block)
49
68
  return nil unless apis.active_api.version_available?(:graphql)
50
69
  return nil unless graphql = apis.api(version: :graphql)
51
- #kargs = { includeArchived: include_archived }.merge(kargs).slice(:includeArchived)
52
- # For now, this endpoint only accepts `id` as a parameter. It is pending to
53
- # expose further parameters via query
54
- return nil unless tree = graphql.currentOrganization.locationStructure(id: id, &block)
70
+
71
+ kargs = {
72
+ id: id,
73
+ includeArchivedNodes: include_archived
74
+ }.merge(kargs)
75
+
76
+ return nil unless tree = graphql.currentOrganization.locationStructure(**kargs, &block)
55
77
  args = { enviro: enviro, id: tree.id, name: tree.name }
56
78
  Eco::API::Organization::TagTree.new(tree.treeify, **args)
57
79
  end
58
80
 
59
81
  # Retrieves all the location structures of the organisation
82
+ # @param include_archived [Boolean] whether or not to include archived **nodes**
83
+ # @return [Array<Eco::API::Organization::TagTree>]
60
84
  def live_trees(enviro: nil, include_archived: false, **kargs, &block)
61
85
  [].tap do |eco_trees|
62
86
  next unless apis.active_api.version_available?(:graphql)
63
87
  next unless graphql = apis.api(version: :graphql)
88
+
64
89
  kargs = {
65
- includeArchived: include_archived,
66
- includeUnpublished: false
67
- }.merge(kargs).slice(:includeArchived, :includeUnpublished)
90
+ includeArchivedNodes: include_archived
91
+ }.merge(kargs)
68
92
 
69
93
  next unless trees = graphql.currentOrganization.locationStructures(**kargs, &block)
70
94
  trees.each do |tree|
@@ -235,9 +235,15 @@ module Eco
235
235
  end
236
236
 
237
237
  # It uses the `tagtree.json` file and in its absence, if `graphql` enabled, the largest `life_tagtree`
238
+ # @note it does NOT include archived nodes by default.
239
+ # - This is for legacy (most usecases don't)
240
+ # @param include_archived [Boolean] whether or not it should include archived nodes.
238
241
  # @return [Eco::API::Organization::TagTree]
239
- def tagtree(enviro: nil)
240
- @tagtree ||= tagtree_config.scope_tree(enviro: enviro)
242
+ def tagtree(enviro: nil, include_archived: false, raise_on_missing: true)
243
+ kargs = {
244
+ enviro: enviro, include_archived: include_archived, raise_on_missing: raise_on_missing
245
+ }
246
+ @tagtree ||= tagtree_config.scope_tree(**kargs)
241
247
  end
242
248
 
243
249
  # It obtains the first of the live tagtree in the org
@@ -12,9 +12,9 @@ class Eco::API::UseCases::DefaultCases::ReinviteTransCase < Eco::API::Common::Lo
12
12
  invite = session.new_job("main", "invite", :update, usecase, :account)
13
13
  users.each do |person|
14
14
  if force_invite?
15
- person.account.send_invites = true
16
- else
17
15
  person.account.force_send_invites = true
16
+ else
17
+ person.account.send_invites = true
18
18
  end
19
19
  invite.add(person)
20
20
  end
@@ -68,7 +68,7 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
68
68
  msg << "nor options(:source, :structure_id). "
69
69
  msg << "Infering active locations structure."
70
70
  log(:warn) { msg }
71
- if self.current_tree = session.live_tree
71
+ if self.current_tree = session_live_tree
72
72
  @target_structure_id = current_tree.id
73
73
  end
74
74
  end
@@ -81,7 +81,13 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
81
81
  tree_init = current_tree
82
82
  target_id = target_structure_id
83
83
  return current_tree if current_tree != tree_init
84
- self.current_tree = session.live_tree(id: target_id, include_archived: true)
84
+ self.current_tree = session_live_tree(id: target_id)
85
+ end
86
+
87
+ # Unique access point to retrieve the live tree
88
+ # @note ensures archived nodes are retrieved.
89
+ def session_live_tree(id: nil)
90
+ session.live_tree(id: id, include_archived: true)
85
91
  end
86
92
  end
87
93
  end
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.5.4"
2
+ VERSION = "2.5.5"
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.5.4
4
+ version: 2.5.5
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.3.8
159
+ version: 0.3.9
160
160
  - - "<"
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0.4'
@@ -166,7 +166,7 @@ dependencies:
166
166
  requirements:
167
167
  - - ">="
168
168
  - !ruby/object:Gem::Version
169
- version: 0.3.8
169
+ version: 0.3.9
170
170
  - - "<"
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0.4'