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 +4 -4
- data/CHANGELOG.md +15 -1
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api/common/people/person_entry.rb +0 -1
- data/lib/eco/api/organization/tag_tree.rb +36 -7
- data/lib/eco/api/session/config/tagtree.rb +38 -14
- data/lib/eco/api/session/config.rb +8 -2
- data/lib/eco/api/usecases/default_cases/reinvite_trans_case.rb +2 -2
- data/lib/eco/api/usecases/graphql/helpers/location/base.rb +8 -2
- data/lib/eco/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d241b7bc57bd81e9b3a6b1d71ecab5f7530b7b6df176301adc21584722f2b247
|
4
|
+
data.tar.gz: a8beafa1e6cd1e3425291121c55b78fe144f155021ab149148fcc6ce35569984
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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'
|
@@ -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
|
-
|
168
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
45
|
+
args = { id: id }.merge(kargs)
|
28
46
|
@live_tree = live_tree_get(**args, &block)
|
29
47
|
else
|
30
|
-
|
31
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
66
|
-
|
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
|
-
|
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 =
|
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 =
|
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
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
|
+
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.
|
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.
|
169
|
+
version: 0.3.9
|
170
170
|
- - "<"
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: '0.4'
|