eco-helpers 2.4.2 → 2.4.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: d2b034981dcaa5e5ecfb1778df6fed175e4631d1244372c475bd5049e8e97c67
4
- data.tar.gz: ca64274315a6da975781f3d8198b3a58956e9f665a674392ba03090feb284488
3
+ metadata.gz: 3c2d5e728987bee135ac2297b0a84858dfb14eab79b3decebc59ced1a74ccc4a
4
+ data.tar.gz: b906c449d80dbc1440c1b7e7d91565bad53409167cae3c07b0788870f842cf5e
5
5
  SHA512:
6
- metadata.gz: 33d6ba24ecab02c3bb10d11577ed067b7eab05e4c1fa0af17c72405cb16fd135b253a0414d33a14821b0684129e921eee0cb65eec8ac88558e3931c5d3bbcb8c
7
- data.tar.gz: db51965c0d7b2a607a3cd6a1fbbdac48430be4804367d9746d448141c5fe00e04e835c202e696b42bc68e6c153b511f45c3a11b38ee7c6c1701fbb46d3cf9f23
6
+ metadata.gz: e7a9781490f01e1d9ffafdec19179d492d760c9dca676e2e6f2771b61a8f422d5c9f481bb03c71563c91df97b72f89cee0e8aa664be42dcf1dd5d99576177add
7
+ data.tar.gz: 44eed6e779b8ffdfdc1bea5913090713cc15dba649b7c2eddc9f333a8be67f92afa1ec6e1d06b0c31bcf2b29d062b92cac26c7c53b07404e50d089ae56698202
data/CHANGELOG.md CHANGED
@@ -1,12 +1,34 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.4.3] - 2023-03-xx
4
+ ## [2.4.5] - 2023-03-xx
5
5
 
6
6
  ### Added
7
7
  ### Changed
8
8
  ### Fixed
9
9
 
10
+ ## [2.4.4] - 2023-03-29
11
+
12
+ ### Added
13
+ - `Eco::API:Organization::TagTree`
14
+ - Added **methods** `#each` and `#all_nodes` allow to loop through all nodes
15
+ - Added `parent` to refer to the parent node.
16
+
17
+ ### Changed
18
+ - `Eco::API:Organization::TagTree` made **Enumerable**
19
+
20
+ ### Fixed
21
+ - `Eco:API::Session#live_tree` pass `enviro`
22
+ - `Eco::API::UseCases::OozeSamples::RegisterUpdateCase`
23
+ - Fix typo on error message.
24
+
25
+ ## [2.4.3] - 2023-03-23
26
+
27
+ ### Fixed
28
+ - `Eco::API::MicroCases#take_email_from_account` it was failing at the very (when restoring the original account)
29
+ - Comes from back-end issue. Adding account with preferences.kiosk_enabled would return:
30
+ - `{"errors"=>["account > preferences > kiosk_enabled is an unknown field"]}`
31
+
10
32
  ## [2.4.2] - 2023-03-17
11
33
 
12
34
  ### Fixed
@@ -36,27 +36,33 @@ module Eco
36
36
  return false if dest_email.to_s.strip.empty?
37
37
  end
38
38
 
39
- account_json = JSON.parse(account.to_json)
39
+ account_json = _take_email_account_json(account)
40
40
  person.email = account_email
41
41
 
42
42
  if success = _take_email_remove_account!(person, context: context)
43
43
  if success = _take_email_acquire_account!(person, target_email, account: {}, context: context)
44
44
  if success = _take_email_email_free_up!(person, dest_email: dest_email, context: context)
45
45
  if success = _take_email_remove_account!(person, context: context)
46
+ # Bring back the original account
46
47
  if success = _take_email_acquire_account!(person, account_email, account: account_json, context: context)
48
+ success = true
47
49
  person.email = target_email
48
50
  end
49
51
  end
50
52
  else # free up target email
51
53
  # restore
52
- if _take_email_remove_account!(person, context: context)
53
- _take_email_acquire_account!(person, account_email, account: account_json, context: context)
54
+ reverted = false
55
+ if reverted ||= _take_email_remove_account!(person, context: context)
56
+ reverted ||= _take_email_acquire_account!(person, account_email, account: account_json, context: context)
54
57
  end
58
+ puts "Could not revert back to the original account #{person.identify}" unless reverted
55
59
  success = false
56
60
  end
57
61
  else # aquire other account
58
62
  # restore
59
- _take_email_acquire_account!(person, account_email, account: account_json, context: context)
63
+ unless _take_email_acquire_account!(person, account_email, account: account_json, context: context)
64
+ puts "Could not bring back the original account we want to update the email to '#{target_email}' #{person.identify}"
65
+ end
60
66
  success = false
61
67
  end
62
68
  end
@@ -65,6 +71,21 @@ module Eco
65
71
 
66
72
  private
67
73
 
74
+ def _take_email_account_json(account)
75
+ JSON.parse(account.to_json).tap do |hash|
76
+ hash.delete("user_id")
77
+ hash.delete("permissions_merged")
78
+ hash.delete("permissions_preset")
79
+ hash.delete("prefilter")
80
+ if pref = hash["preferences"]
81
+ hash["preferences"] = pref.reject do |attr, value|
82
+ attr.start_with?("kiosk")
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ # Bring the account of the `target_email` taken, so we can change the email of this account
68
89
  def _take_email_acquire_account!(person, target_email, account: {}, context: "Session")
69
90
  person.account = account
70
91
  person.account.send_invites = false
@@ -72,6 +93,7 @@ module Eco
72
93
  micro.person_update!(person, reason: "bring account with email '#{target_email}'", context: context)
73
94
  end
74
95
 
96
+ # Free up the email (`target_email`) of the account that has it taken to `dest_email`
75
97
  def _take_email_email_free_up!(person, dest_email:, target_email: nil, context: "Session")
76
98
  target_email ||= person.email
77
99
  person.email = dest_email.is_a?(Proc)? dest_email.call(target_email) : dest_email
@@ -83,7 +105,6 @@ module Eco
83
105
  person.account = nil
84
106
  micro.person_update!(person, reason: "remove account", context: context)
85
107
  end
86
-
87
108
  end
88
109
  end
89
110
  end
@@ -7,10 +7,13 @@ module Eco
7
7
  alias_method :tag, :id
8
8
  attr_accessor :name
9
9
 
10
+ attr_reader :parent
10
11
  attr_reader :nodes, :children_count
11
12
  attr_reader :depth, :path
12
13
  attr_reader :enviro
13
14
 
15
+ include Enumerable
16
+
14
17
  # @example Node format:
15
18
  # {"tag": "NODE NAME", "nodes": subtree}
16
19
  # @example Tree/subtree format:
@@ -21,8 +24,9 @@ module Eco
21
24
  # ]}]
22
25
  # tree = TagTree.new(tree.to_json)
23
26
  # @param tagtree [String] representation of the tagtree in json.
24
- def initialize(tagtree = [], name: nil, id: nil, depth: -1, path: [], enviro: nil)
25
- @depth = depth
27
+ def initialize(tagtree = [], name: nil, id: nil, depth: -1, path: [], parent: nil, enviro: nil)
28
+ @depth = depth
29
+ @parent = parent
26
30
 
27
31
  case tagtree
28
32
  when String
@@ -48,7 +52,7 @@ module Eco
48
52
  @path.push(@id) unless top?
49
53
 
50
54
  @nodes = @row_nodes.map do |cnode|
51
- TagTree.new(cnode, depth: depth + 1, path: @path.dup, enviro: @enviro)
55
+ TagTree.new(cnode, depth: depth + 1, path: @path.dup, parent: self, enviro: @enviro)
52
56
  end
53
57
 
54
58
  init_hashes
@@ -59,6 +63,27 @@ module Eco
59
63
  self.class.new(as_json)
60
64
  end
61
65
 
66
+ # Iterate through all the nodes of this tree
67
+ # @yield [node] do some stuff with one of the nodes of the tree
68
+ # @yieldparam node [Eco::API::Organization::TagTree] a node of the tree
69
+ # @return [Enumerable<Eco::API::Organization::TagTree>]
70
+ def each(&block)
71
+ return to_enum(:each) unless block
72
+ all_nodes.each(&block)
73
+ end
74
+
75
+ # All actual nodes of this tree
76
+ # @note order is that of the parent to child relationships
77
+ # @return [Array[]]
78
+ def all_nodes(&block)
79
+ [].tap do |all_nodes|
80
+ all_nodes.push(self) unless top?
81
+ nodes.each do |node|
82
+ all_nodes.concat(node.all_nodes)
83
+ end
84
+ end
85
+ end
86
+
62
87
  # @return [Array] with the differences
63
88
  def diff(tagtree, differences: {}, level: 0, **options)
64
89
  require 'hashdiff'
@@ -46,7 +46,7 @@ module Eco
46
46
 
47
47
  # @see Eco::API::Session::Config#live_tree
48
48
  def live_tree
49
- config.live_tree
49
+ config.live_tree(enviro: enviro)
50
50
  end
51
51
 
52
52
  # @see Eco::API::Session::Config#schemas
@@ -109,7 +109,7 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
109
109
  if dirty?(pending)
110
110
  msg = "Inconsistent search results. "
111
111
  msg << "Launching update on '#{object_reference(pending)}' to be able to queue it back"
112
- console.warn msg
112
+ logger.warn msg
113
113
  update_ooze(pending)
114
114
  end
115
115
  end
@@ -118,7 +118,7 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
118
118
  yield(ooz)
119
119
  else
120
120
  @non_retrieved_oozes += 1
121
- console.warn "Could not get page #{page_result.id}"
121
+ logger.warn "Could not get page #{page_result.id}"
122
122
  end
123
123
  end
124
124
  update_oozes
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.4.2"
2
+ VERSION = "2.4.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.4.2
4
+ version: 2.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura