eco-helpers 1.3.3 → 1.3.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: 64ffc42a60247e70fba74a45b4cdef667d9df2060e5dade03312631e41b0a91a
4
- data.tar.gz: 94dcaa78623fe11bde331bb71deb52664a87f50b397bc21b37ee91aedea0df95
3
+ metadata.gz: 1fe8fa73efd298f498da1a2dd233cb40b3c4f3810a24762d6d60ca3d29f04786
4
+ data.tar.gz: e377424f7424d88548674f29c742250d75adadcd9c9b49d96d8f9593a6d90fd5
5
5
  SHA512:
6
- metadata.gz: acf65af431eb33a3b6ba5d864b9dedf2b2cb45469354933011807d6ed8598a2b73254a07f6eaf8531c025608458e7ef211b31a324847879a93278c4029bdc322
7
- data.tar.gz: f8975080afd8acfa445e00af5665eb2d4f8ed9bb4aecbd29038a417842012ffd52c3ad53bd7197924d285ef4f27b233e09e95723ecda308f81148eac945ca867
6
+ metadata.gz: c76d0d688292fcff201bea5e447c53a97939153c1a9a65c7d840ab9dede00e9b55cc08e9feb02f8e16744f6c051737624769d34ae59d1f476c50c5ed8e57782b
7
+ data.tar.gz: 6db7c8ccfacd19e2edf056b63cb6280aed96a70c26bdef4943e89e108927e2d1f8b8ffdecea7f93e493fccf8c04096e0549ef93554be313063b07e81dc11fcf0
@@ -51,7 +51,6 @@ module Eco
51
51
  # the active environment
52
52
  def active_root_name
53
53
  active_name
54
- #active_name.split("-").first
55
54
  end
56
55
 
57
56
  def active_api
@@ -26,6 +26,7 @@ module Eco
26
26
  ReinviteCase.new(self).process
27
27
  DeleteCase.new(self).process
28
28
  RemoveAccountCase.new(self).process
29
+ TransferAccountCase.new(self).process
29
30
  RecoverDBCase.new(self).process
30
31
  RefreshPresets.new(self).process
31
32
  Refresh.new(self).process
@@ -56,6 +57,7 @@ require_relative 'default_cases/create_details_with_supervisor_case'
56
57
  require_relative 'default_cases/reinvite_case'
57
58
  require_relative 'default_cases/delete_case'
58
59
  require_relative 'default_cases/remove_account_case'
60
+ require_relative 'default_cases/transfer_account_case'
59
61
  require_relative 'default_cases/refresh_case'
60
62
  require_relative 'default_cases/refresh_presets_case'
61
63
  require_relative 'default_cases/recover_db_case'
@@ -0,0 +1,90 @@
1
+ module Eco
2
+ module API
3
+ class UseCases
4
+ class DefaultCases
5
+ class TransferAccountCase < DefaultCase
6
+
7
+ def process
8
+ @cases.define("transfer-account", type: :sync) do |entries, people, session, options, usecase|
9
+ remove_account = session.job_group("main").new("remove account", usecase: usecase, type: :update, sets: :account)
10
+ add_account = session.job_group("post").new("add account", usecase: usecase, type: :update, sets: :account)
11
+
12
+ strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
13
+
14
+ done = []; pending = []
15
+ pairs = entries.each_with_object([]) do |source|
16
+ entry_hash = source.internal_entry
17
+ unless entry_hash.key?("destination-id")
18
+ session.logger.error("You haven't defined a column 'destination-id' to whom the account should be transferred")
19
+ exit(1)
20
+ end
21
+ if peer_id = entry_hash["destination-id"]
22
+ if peer = entries.entry(id: peer_id, external_id: peer_id)
23
+ if done.include?(peer)
24
+ session.logger.error("You paired '#{peer_id}' twice. A person can only receive account from 1 user")
25
+ exit(1)
26
+ end
27
+ pending.delete(source)
28
+ pending.delete(peer)
29
+ done.push(source).push(pair)
30
+ [source, peer]
31
+ else
32
+ pending.push(source)
33
+ nil
34
+ end
35
+ else
36
+ pending.push(source)
37
+ end
38
+ end.compact
39
+
40
+ # Data input integrity check
41
+ unless pending.empty?
42
+ msg = "You haven't defined a pair for the following ids:"
43
+ msg += pending.each_with_object("") do |entry, str|
44
+ str << "\n#{entry.id || entry.external_id}"
45
+ end
46
+ session.logger.error(msg)
47
+ exit(1)
48
+ end
49
+
50
+ pairs.each do |pair|
51
+ src_entry, dst_entry = pair
52
+ unless src_person = people.find(src_entry, strict: strict_search)
53
+ session.logger.error("Entry(#{i}) - this person does not exist: #{src_entry.to_s(:identify)}")
54
+ exit(1)
55
+ end
56
+
57
+ unless dst_person = people.find(dst_entry, strict: strict_search)
58
+ session.logger.error("Entry(#{i}) - this person does not exist: #{dst_person.to_s(:identify)}")
59
+ exit(1)
60
+ end
61
+
62
+ unless account_doc = src_person.account&.doc
63
+ session.logger.error("You are trying to move account from a person that doesn't have: #{src_person.id | src_person.external_id}")
64
+ exit(1)
65
+ end
66
+
67
+ if dst_person.email.to_s.strip.empty?
68
+ session.logger.error("A person you are trying to add account doesn't have email: #{dst_person.id | dst_person.external_id}")
69
+ exit(1)
70
+ end
71
+
72
+ src_person.account = nil
73
+ remove_account.add(src_person)
74
+ add_account.add(dst_person) do |person|
75
+ # only if we got to remove the account of the original person
76
+ if account_doc && src_person.as_update == {}
77
+ person.account = account_doc
78
+ end
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+ end
85
+
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -66,6 +66,7 @@ ASSETS.cli.config do |cnf|
66
66
  cases.add("-update-from", :sync, case_name: "update")
67
67
  cases.add("-refresh", :transform, case_name: "refresh")
68
68
  cases.add("-refresh-presets", :transform, case_name: "refresh-presets")
69
+ cases.add("-transfer-account-from", :sync, case_name: "transfer-account")
69
70
  cases.add("-remove-account", :transform, case_name: "remove-account")
70
71
  cases.add("-remove-account-from", :sync, case_name: "remove-account")
71
72
  cases.add("-delete", :transform, case_name: "delete")
@@ -4,7 +4,8 @@ module Eco
4
4
 
5
5
  # it expects [[v1a, v1b], [v2a, v2b] ...]
6
6
  def initialize (array_of_arrays = [], internal: :last)
7
- @source = array_of_arrays
7
+ @internal_order = internal
8
+ @source = array_of_arrays
8
9
 
9
10
  if @source
10
11
  # internal should be always last in @source
@@ -18,6 +19,27 @@ module Eco
18
19
  end
19
20
  end
20
21
 
22
+ def as_json(internal: @internal_order)
23
+ to_a(internal: internal)
24
+ end
25
+
26
+ def to_json(internal: @internal_order)
27
+ content = as_json(internal: internal).map do |pair|
28
+ " " + pair.to_json
29
+ end.join(",\n")
30
+ "[\n#{content}\n]"
31
+ end
32
+
33
+ def to_a(internal: @internal_order)
34
+ @by_internal.map do |int, ext|
35
+ internal == :last ? [ext, int] : [int, ext]
36
+ end
37
+ end
38
+
39
+ def +(array_of_arrays)
40
+ self.class.new(array_of_arrays + to_a, internal: @internal_order)
41
+ end
42
+
21
43
  def list(type = :internal)
22
44
  return [] if !@source
23
45
  @source.map do |pair|
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "1.3.3"
2
+ VERSION = "1.3.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: 1.3.3
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -320,6 +320,7 @@ files:
320
320
  - lib/eco/api/usecases/default_cases/switch_supervisor_case.rb
321
321
  - lib/eco/api/usecases/default_cases/to_csv_case.rb
322
322
  - lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb
323
+ - lib/eco/api/usecases/default_cases/transfer_account_case.rb
323
324
  - lib/eco/api/usecases/default_cases/update_case.rb
324
325
  - lib/eco/api/usecases/default_cases/update_details_case.rb
325
326
  - lib/eco/api/usecases/default_cases/upsert_case.rb