eco-helpers 2.7.2 → 2.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -3
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api/common/loaders/base.rb +4 -3
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +2 -2
- data/lib/eco/api/common/loaders/parser.rb +1 -0
- data/lib/eco/api/common/people/default_parsers/csv_parser.rb +47 -33
- data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +1 -1
- data/lib/eco/api/common/people/default_parsers/xls_parser.rb +8 -2
- data/lib/eco/api/common/people/default_parsers.rb +0 -11
- data/lib/eco/api/common/people/person_attribute_parser.rb +2 -1
- data/lib/eco/api/common/people/person_entry.rb +4 -2
- data/lib/eco/api/session/batch/errors.rb +43 -44
- data/lib/eco/api/session.rb +9 -2
- data/lib/eco/api/usecases/default/locations/csv_to_tree_case.rb +1 -1
- data/lib/eco/api/usecases/default/people/set_default_tag_case.rb +2 -2
- data/lib/eco/api/usecases/default/people/supers_cyclic_identify_case.rb +15 -17
- data/lib/eco/api/usecases/default/people/switch_supervisor_case.rb +26 -20
- data/lib/eco/api/usecases/default/people/transfer_account_case.rb +86 -70
- data/lib/eco/api/usecases/default_cases/hris_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +7 -7
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +1 -1
- data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +73 -65
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +7 -1
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb +1 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list.rb +1 -0
- data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +1 -1
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +13 -9
- data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +4 -4
- data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +9 -6
- data/lib/eco/api/usecases/ooze_samples/register_migration_case.rb +5 -5
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +7 -5
- data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +2 -2
- data/lib/eco/api/usecases.rb +19 -13
- data/lib/eco/cli/scripting/args_helpers.rb +2 -0
- data/lib/eco/data/files/helpers.rb +25 -12
- data/lib/eco/data/hashes/sanke_camel_indifferent_access.rb +0 -5
- data/lib/eco/language/models/parser_serializer.rb +4 -2
- data/lib/eco/version.rb +1 -1
- metadata +3 -3
@@ -2,22 +2,24 @@ class Eco::API::UseCases::Default::People::SwitchSupervisorCase < Eco::API::Comm
|
|
2
2
|
name "switch-supervisor"
|
3
3
|
type :transform
|
4
4
|
|
5
|
-
def main(people, session,
|
5
|
+
def main(people, session, _options, usecase)
|
6
6
|
supers = session.new_job("main", "supers", :update, usecase, :core)
|
7
7
|
|
8
|
-
old_sup, new_sup = get_supers(people).tap do |
|
9
|
-
inform(*
|
8
|
+
old_sup, new_sup = get_supers(people).tap do |sups|
|
9
|
+
inform(*sups)
|
10
10
|
end
|
11
11
|
|
12
12
|
micro.with_each_subordinate(old_sup, people) do |subordinate|
|
13
13
|
subordinate.supervisor_id = new_sup&.id
|
14
14
|
supers.add(subordinate)
|
15
15
|
end.tap do |subordinates|
|
16
|
-
unless subordinates.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
next unless subordinates.empty?
|
17
|
+
|
18
|
+
sup_str = "#{old_sup.external_id} (#{old_sup.name} - #{old_sup.email})"
|
19
|
+
log(:error) {
|
20
|
+
"There are no subordinates for supervisor #{sup_str}. Aborting..."
|
21
|
+
}
|
22
|
+
exit(1)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
@@ -26,43 +28,47 @@ class Eco::API::UseCases::Default::People::SwitchSupervisorCase < Eco::API::Comm
|
|
26
28
|
def get_supers(people)
|
27
29
|
micro = session.micro
|
28
30
|
old_id, new_id = get_super_ids(options)
|
29
|
-
old_sup, new_sup = [nil, nil]
|
31
|
+
old_sup, new_sup = [nil, nil] # rubocop:disable Style/ParallelAssignment
|
30
32
|
|
31
33
|
micro.with_supervisor(old_id, people) do |supervisor|
|
32
|
-
unless old_sup = supervisor
|
33
|
-
|
34
|
+
unless (old_sup = supervisor)
|
35
|
+
log(:error) {
|
36
|
+
"Couldn't find any user with that id (old-super): '#{old_id}'. Aborting..."
|
37
|
+
}
|
34
38
|
exit(1)
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
42
|
micro.with_supervisor(new_id, people) do |supervisor|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
next if (new_sup = supervisor)
|
44
|
+
|
45
|
+
log(:error) {
|
46
|
+
"Couldn't find any user with that id (new-super): '#{new_id}'. Aborting..."
|
47
|
+
}
|
48
|
+
exit(1)
|
43
49
|
end
|
44
50
|
|
45
51
|
[old_sup, new_sup]
|
46
52
|
end
|
47
53
|
|
48
54
|
def get_super_ids(options)
|
49
|
-
unless old_id = options.dig(:super, :old)
|
50
|
-
|
55
|
+
unless (old_id = options.dig(:super, :old))
|
56
|
+
log(:error) { "You haven't specified the original supervisor. Aborting..." }
|
51
57
|
exit(1)
|
52
58
|
end
|
53
59
|
|
54
60
|
# we could be setting the supervisor to nil
|
55
61
|
unless options[:super].key?(:new)
|
56
|
-
|
62
|
+
log(:error) { "You haven't specified the new supervisor. Aborting..." }
|
57
63
|
exit(1)
|
58
64
|
end
|
59
65
|
|
60
66
|
[old_id, options.dig(:super, :new)]
|
61
67
|
end
|
62
68
|
|
63
|
-
def inform(old_sup, new_sup
|
69
|
+
def inform(old_sup, new_sup)
|
64
70
|
msg = "Switching supervisor '#{old_sup.name}' (#{old_sup.external_id}) "
|
65
71
|
msg += "to '#{new_sup&.name}' (#{new_sup&.external_id})"
|
66
|
-
|
72
|
+
log(:info) { msg }
|
67
73
|
end
|
68
74
|
end
|
@@ -6,7 +6,8 @@ class Eco::API::UseCases::Default::People::TransferAccountCase < Eco::API::Commo
|
|
6
6
|
# * **invocation command**: `-transfer-account-from`
|
7
7
|
#
|
8
8
|
# These are the steps and jobs it does:
|
9
|
-
# 1. **pair** person entries (note: the `destination-id` entry could not be present, it will add it
|
9
|
+
# 1. **pair** person entries (note: the `destination-id` entry could not be present, it will add it
|
10
|
+
# in such a case).
|
10
11
|
# 2. **retrieve** from server persons that were not included in `people`.
|
11
12
|
# 3. **validation**
|
12
13
|
# - a person should only receive account from just one user
|
@@ -24,7 +25,8 @@ class Eco::API::UseCases::Default::People::TransferAccountCase < Eco::API::Commo
|
|
24
25
|
# - **restore** email: sets the receiver email from the dummy address to the final email.
|
25
26
|
# * the final email inbox will receive a **notification** of _email change_
|
26
27
|
# @note
|
27
|
-
# - the `csv` should contain a column `destination-id` containing the person `id` or `external_id` of
|
28
|
+
# - the `csv` should contain a column `destination-id` containing the person `id` or `external_id` of
|
29
|
+
# the person that will be receiving the account.
|
28
30
|
# - when running this case, it is recommended to use the option `-skip-batch-policies`
|
29
31
|
# - it is highly recommended to either refresh the cache with `-get-people` or use the `-get-partial` option.
|
30
32
|
# @param entries [Eco::API::Common::People::Entries] the input entries with the data.
|
@@ -34,28 +36,29 @@ class Eco::API::UseCases::Default::People::TransferAccountCase < Eco::API::Commo
|
|
34
36
|
# @option options [Hash<Symbol, Object>] :include things that should be included.
|
35
37
|
# * `:email` (Boolean) [false] if the `email` should be transferred as well (**command option**: `-include-email`)
|
36
38
|
# @option options [Hash<Symbol, Object>] :skip things that should be excluded.
|
37
|
-
# * `:api_policies` (Boolean) [false] if the `api policies` should be skipped
|
39
|
+
# * `:api_policies` (Boolean) [false] if the `api policies` should be skipped
|
40
|
+
# (**command option**: `-skip-api-policies`)
|
38
41
|
# @return [Void]
|
39
|
-
def main(entries,
|
42
|
+
def main(entries, _people, session, options, usecase) # rubocop:disable Metrics/AbcSize
|
40
43
|
move = session.new_job("main", "move email accounts", :update, usecase, :account)
|
41
44
|
free = session.new_job("main", "free up accounts", :update, usecase, :account)
|
42
45
|
switch = session.new_job("main", "switch email", :update, usecase, :core)
|
43
46
|
invite = session.new_job("post", "invite receivers", :update, usecase, :account)
|
44
47
|
restore = session.new_job("post", "restore email", :update, usecase, :core)
|
45
48
|
|
46
|
-
with_each_person_pair(entries
|
49
|
+
with_each_person_pair(entries) do |src_person, dst_person|
|
47
50
|
# capture actual initial information
|
48
|
-
src_doc
|
49
|
-
src_email
|
50
|
-
src_dummy
|
51
|
-
dst_email
|
52
|
-
dst_dummy
|
53
|
-
copy_src_email
|
54
|
-
dst_end_email
|
51
|
+
src_doc = src_person.account.doc
|
52
|
+
src_email = src_person.email
|
53
|
+
src_dummy = dummy_email(src_person)
|
54
|
+
dst_email = dst_person.email
|
55
|
+
dst_dummy = dummy_email(dst_person)
|
56
|
+
copy_src_email = options.dig(:include, :email) || !dst_person.account
|
57
|
+
dst_end_email = copy_src_email ? src_email : dst_email
|
55
58
|
|
56
59
|
# account email renamings are necessary to avoid uncertainty and ensure no email taken error
|
57
|
-
move.add(dst_person)
|
58
|
-
move.add(src_person)
|
60
|
+
move.add(dst_person) {|dst| dst.email = dst_dummy}
|
61
|
+
move.add(src_person) {|src| src.email = src_dummy}
|
59
62
|
# free accounts up!
|
60
63
|
free.add([dst_person, src_person]) {|person| person.account = nil}
|
61
64
|
# to effectivelly transfer the user/account, email should be the same during invite
|
@@ -66,8 +69,10 @@ class Eco::API::UseCases::Default::People::TransferAccountCase < Eco::API::Commo
|
|
66
69
|
# recover the original email, if the receiver had account
|
67
70
|
restore.add(dst_person) {|dst| dst.email = dst_end_email}
|
68
71
|
end.tap do |units|
|
69
|
-
|
70
|
-
|
72
|
+
next unless options[:simulate]
|
73
|
+
|
74
|
+
units.each do |unit|
|
75
|
+
puts unit.persons.map(&:external_id).join(" --> ")
|
71
76
|
end
|
72
77
|
end
|
73
78
|
end
|
@@ -77,23 +82,24 @@ class Eco::API::UseCases::Default::People::TransferAccountCase < Eco::API::Commo
|
|
77
82
|
# if the person has account and an email different to demo+__@ecoportal.co.nz
|
78
83
|
# it transforms email to demo+__@ecoportal.co.nz
|
79
84
|
def dummy_email(person)
|
80
|
-
return nil unless email = person.email
|
85
|
+
return nil unless (email = person.email)
|
81
86
|
return email if email.start_with?("demo") && email.end_with?("@ecoportal.co.nz")
|
82
87
|
return email unless person.account
|
83
88
|
"demo+#{email.split("@").join(".")}@ecoportal.co.nz"
|
84
89
|
end
|
85
90
|
|
86
|
-
def with_each_person_pair(entries
|
87
|
-
units = paired_entries(entries
|
88
|
-
report_missing_peer!(unpaired_entries
|
91
|
+
def with_each_person_pair(entries)
|
92
|
+
units = paired_entries(entries) do |unpaired_entries|
|
93
|
+
report_missing_peer!(unpaired_entries)
|
89
94
|
end.map do |entry_pair|
|
90
|
-
person_pair = to_persons(entry_pair
|
95
|
+
person_pair = to_persons(entry_pair)
|
91
96
|
new_unit(*entry_pair, *person_pair)
|
92
97
|
end
|
93
|
-
|
98
|
+
|
99
|
+
sort_units(units).tap do |uts|
|
94
100
|
# check that there are no repeated sources or destinations, that sources have account
|
95
|
-
validate_pairs!(
|
96
|
-
|
101
|
+
validate_pairs!(uts)
|
102
|
+
uts.each do |unit|
|
97
103
|
yield(*unit.persons) if block_given?
|
98
104
|
end
|
99
105
|
end
|
@@ -111,17 +117,20 @@ class Eco::API::UseCases::Default::People::TransferAccountCase < Eco::API::Commo
|
|
111
117
|
end
|
112
118
|
|
113
119
|
# Entry helpers
|
114
|
-
def to_persons(paired_entry
|
115
|
-
micro = session.micro
|
120
|
+
def to_persons(paired_entry)
|
116
121
|
[].tap do |persons|
|
117
122
|
micro.with_each(paired_entry, people, options) do |entry, person|
|
118
123
|
next persons.push(person) unless person.new?
|
119
|
-
|
124
|
+
|
125
|
+
person = session.batch.search([entry], silent: true).people.first
|
126
|
+
if person
|
120
127
|
persons.push(person)
|
121
128
|
people << person
|
122
129
|
next
|
123
130
|
end
|
124
|
-
|
131
|
+
log(:error) {
|
132
|
+
"This person does not exist: #{entry.to_s(:identify)}"
|
133
|
+
}
|
125
134
|
exit(1)
|
126
135
|
end
|
127
136
|
end.tap do |persons|
|
@@ -129,22 +138,23 @@ class Eco::API::UseCases::Default::People::TransferAccountCase < Eco::API::Commo
|
|
129
138
|
end
|
130
139
|
end
|
131
140
|
|
132
|
-
def paired_entries(entries
|
133
|
-
expect_destination_id!(entries
|
141
|
+
def paired_entries(entries)
|
142
|
+
expect_destination_id!(entries)
|
134
143
|
missing_peer = []
|
135
144
|
entries.each_with_object([]) do |source, out|
|
136
|
-
if peer = entry_peer(source, entries)
|
145
|
+
if (peer = entry_peer(source, entries))
|
137
146
|
out.push([source, peer])
|
138
147
|
else
|
139
148
|
missing_peer.push(source)
|
140
149
|
end
|
141
|
-
end.tap do
|
150
|
+
end.tap do
|
142
151
|
yield(missing_peer) if block_given?
|
143
152
|
end
|
144
153
|
end
|
145
154
|
|
146
155
|
def entry_peer(entry, entries)
|
147
|
-
return nil unless peer_id = entry_peer_id(entry)
|
156
|
+
return nil unless (peer_id = entry_peer_id(entry))
|
157
|
+
|
148
158
|
entries.entry(id: peer_id, external_id: peer_id) || decouple_peer(entry)
|
149
159
|
end
|
150
160
|
|
@@ -159,7 +169,7 @@ class Eco::API::UseCases::Default::People::TransferAccountCase < Eco::API::Commo
|
|
159
169
|
|
160
170
|
def entry_peer_id(entry)
|
161
171
|
dest_id = entry.final_entry["destination-id"]
|
162
|
-
|
172
|
+
dest_id unless dest_id.to_s.strip.empty?
|
163
173
|
end
|
164
174
|
|
165
175
|
def entry_peer_id?(entry)
|
@@ -172,9 +182,11 @@ class Eco::API::UseCases::Default::People::TransferAccountCase < Eco::API::Commo
|
|
172
182
|
def persons
|
173
183
|
[src_person, dst_person]
|
174
184
|
end
|
175
|
-
|
176
|
-
|
185
|
+
|
186
|
+
def reversed_unit?(u_2)
|
187
|
+
(src_person == u_2.dst_person) && (dst_person == u_2.src_person)
|
177
188
|
end
|
189
|
+
|
178
190
|
# givers go first
|
179
191
|
def <=>(other)
|
180
192
|
return -1 if src_person == other.dst_person
|
@@ -184,15 +196,15 @@ class Eco::API::UseCases::Default::People::TransferAccountCase < Eco::API::Commo
|
|
184
196
|
end
|
185
197
|
end
|
186
198
|
|
187
|
-
def new_unit(
|
188
|
-
unit_type.new(
|
199
|
+
def new_unit(e_1, e_2, p_1, p_2)
|
200
|
+
unit_type.new(e_1, e_2, p_1, p_2)
|
189
201
|
end
|
190
202
|
|
191
203
|
# Units helpers
|
192
204
|
def find_repeated(units, &block)
|
193
|
-
units.group_by(&block).select do |
|
205
|
+
units.group_by(&block).select do |_k, v|
|
194
206
|
v.count > 1
|
195
|
-
end.map {|
|
207
|
+
end.map {|_k, v| v.first}
|
196
208
|
end
|
197
209
|
|
198
210
|
def uniq_array(ary, &block)
|
@@ -201,8 +213,9 @@ class Eco::API::UseCases::Default::People::TransferAccountCase < Eco::API::Commo
|
|
201
213
|
end
|
202
214
|
end
|
203
215
|
|
204
|
-
def validate_pairs!(units
|
216
|
+
def validate_pairs!(units) # rubocop:disable Metrics/AbcSize
|
205
217
|
missing_account = []
|
218
|
+
|
206
219
|
src_repeated = find_repeated(units) do |unit|
|
207
220
|
unit.src_person.tap do |src_person|
|
208
221
|
missing_account << (src_person.account ? nil : str_person_entry(unit.src_person, unit.src_entry))
|
@@ -210,32 +223,32 @@ class Eco::API::UseCases::Default::People::TransferAccountCase < Eco::API::Commo
|
|
210
223
|
end.each_with_object([]) do |unit, lines|
|
211
224
|
lines << str_person_entry(unit.src_person, unit.src_entry)
|
212
225
|
end
|
213
|
-
|
214
|
-
|
215
|
-
end.each_with_object([]) do |unit, lines|
|
226
|
+
|
227
|
+
dst_repeated = find_repeated(units, &:dst_person).each_with_object([]) do |unit, lines|
|
216
228
|
lines << str_person_entry(unit.dst_person, unit.dst_entry, unit.src_entry.idx)
|
217
229
|
end
|
218
230
|
missing_account.compact!
|
219
|
-
unless [missing_account, src_repeated, dst_repeated].all?(&:empty?)
|
220
|
-
report_missing_account(missing_account.join("\n"), logger) unless missing_account.empty?
|
221
231
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
232
|
+
return if [missing_account, src_repeated, dst_repeated].all?(&:empty?)
|
233
|
+
|
234
|
+
report_missing_account(missing_account.join("\n")) unless missing_account.empty?
|
235
|
+
|
236
|
+
msg = proc do |spot|
|
237
|
+
"Transfers should be a 1.to.1 relation. The following #{spot} entries are repeated in the csv:"
|
228
238
|
end
|
239
|
+
report_repeated(src_repeated.join("\n"), msg["SOURCE"]) unless src_repeated.empty?
|
240
|
+
report_repeated(dst_repeated.join("\n"), msg["DESTINATION"]) unless dst_repeated.empty?
|
241
|
+
exit(1)
|
229
242
|
end
|
230
243
|
|
231
244
|
# Messaging & Validation
|
232
|
-
def report_missing_peer!(unpaired_entries
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
245
|
+
def report_missing_peer!(unpaired_entries)
|
246
|
+
return if unpaired_entries.empty?
|
247
|
+
|
248
|
+
msg = "The following rows are missing 'destination-id':\n\n"
|
249
|
+
msg += unpaired_entries.map {|entry| str_missing_peer(entry)}.join("\n")
|
250
|
+
log(:error) { msg }
|
251
|
+
exit(1)
|
239
252
|
end
|
240
253
|
|
241
254
|
def str_missing_peer(entry)
|
@@ -247,22 +260,25 @@ class Eco::API::UseCases::Default::People::TransferAccountCase < Eco::API::Commo
|
|
247
260
|
"#{str_row}id: '#{person.id || person.external_id}' email:#{person.email} -> Entry #{entry.to_s(:identify)}"
|
248
261
|
end
|
249
262
|
|
250
|
-
def expect_destination_id!(entries
|
251
|
-
unless entries.
|
252
|
-
|
253
|
-
exit(1)
|
254
|
-
end
|
255
|
-
unless entry_peer_id?(entries.first)
|
256
|
-
logger.error("You haven't defined a column 'destination-id' to whom the account should be transferred")
|
263
|
+
def expect_destination_id!(entries)
|
264
|
+
unless entries.any?
|
265
|
+
log(:error) { "Your csv is empty" }
|
257
266
|
exit(1)
|
258
267
|
end
|
268
|
+
|
269
|
+
return if entry_peer_id?(entries.first)
|
270
|
+
|
271
|
+
log(:error) {
|
272
|
+
"You haven't defined a column 'destination-id' to whom the account should be transferred"
|
273
|
+
}
|
274
|
+
exit(1)
|
259
275
|
end
|
260
276
|
|
261
|
-
def report_missing_account(str
|
262
|
-
|
277
|
+
def report_missing_account(str)
|
278
|
+
log(:error) { "The following source people do not have account:\n#{str}" }
|
263
279
|
end
|
264
280
|
|
265
|
-
def report_repeated(str,
|
266
|
-
|
281
|
+
def report_repeated(str, msg = "The following entries are repeated")
|
282
|
+
log(:error) { "#{msg}\n#{str}" }
|
267
283
|
end
|
268
284
|
end
|
@@ -52,7 +52,7 @@ class Eco::API::UseCases::DefaultCases::HrisCase < Eco::API::Common::Loaders::Us
|
|
52
52
|
msg << " (as it will remove the account of all the people of other schemas"
|
53
53
|
msg << " if they are not in the input file)."
|
54
54
|
msg << "\n For example: -schema-id '#{active_schema.name.downcase}'"
|
55
|
-
|
55
|
+
log(:error) { msg }
|
56
56
|
raise msg
|
57
57
|
end
|
58
58
|
end
|
@@ -4,12 +4,12 @@ class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::U
|
|
4
4
|
|
5
5
|
attr_reader :people
|
6
6
|
|
7
|
-
def main(people,
|
7
|
+
def main(people, _session, options, _usecase)
|
8
8
|
options[:end_get] = false
|
9
9
|
@people = people
|
10
10
|
|
11
11
|
unless people && !people.empty?
|
12
|
-
|
12
|
+
log(:warn) { "No source people to create the file... aborting!" }
|
13
13
|
return false
|
14
14
|
end
|
15
15
|
|
@@ -40,7 +40,7 @@ class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::U
|
|
40
40
|
def to_row(person)
|
41
41
|
entry = to_entry_type(person)
|
42
42
|
entry.values_at(*keys(entry)).tap do |row|
|
43
|
-
row << schemas.to_name(person.details&.schema_id) || "No Schema"
|
43
|
+
row << (schemas.to_name(person.details&.schema_id) || "No Schema")
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -53,11 +53,11 @@ class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::U
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def keys(entry)
|
56
|
-
entry.keys - [
|
56
|
+
entry.keys - %w[freemium send_invites]
|
57
57
|
end
|
58
58
|
|
59
59
|
def nice_header_names?
|
60
|
-
|
60
|
+
options[:nice_header] || options.dig(:export, :options, :nice_header)
|
61
61
|
end
|
62
62
|
|
63
63
|
def nice_header_names(header, schema: nil)
|
@@ -65,7 +65,7 @@ class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::U
|
|
65
65
|
name_maps = schema.fields_by_alt_id.each_with_object({}) do |(alt_id, fld), mappings|
|
66
66
|
mappings[alt_id] = fld.name
|
67
67
|
end.merge(nice_header_maps)
|
68
|
-
header.map {|name| name_maps[name]
|
68
|
+
header.map {|name| name_maps[name] || name}
|
69
69
|
end
|
70
70
|
|
71
71
|
def to_entry_type(person)
|
@@ -89,7 +89,7 @@ class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::U
|
|
89
89
|
|
90
90
|
def by_schema
|
91
91
|
people.group_by do |person|
|
92
|
-
if details = person.details
|
92
|
+
if (details = person.details)
|
93
93
|
details.schema_id
|
94
94
|
end
|
95
95
|
end.transform_values do |persons|
|
@@ -43,7 +43,7 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
|
|
43
43
|
with_sliced_input(batch_input, size: size) do |sliced_input, page, pages, count, total|
|
44
44
|
msg = "#{dry_run_msg}Launching '#{desc}' request #{page} (of #{pages}) "
|
45
45
|
msg << "with #{count} commands (done #{done} of #{total})..."
|
46
|
-
|
46
|
+
log(:info) { msg }
|
47
47
|
|
48
48
|
response = nil
|
49
49
|
unless simulate? && !options.dig(:requests, :backup)
|
@@ -2,87 +2,95 @@ class Eco::API::UseCases::GraphQL::Samples::Location
|
|
2
2
|
module Command::Service
|
3
3
|
# Service to generate the command updates.
|
4
4
|
module TreeUpdate
|
5
|
-
include Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeDiff
|
6
|
-
include Eco::API::UseCases::GraphQL::Samples::Location::Command::DSL
|
7
|
-
include Eco::API::UseCases::GraphQL::Utils::Sftp
|
8
|
-
|
9
5
|
# Whether to stop or continue on command fail
|
10
6
|
FORCE_CONTINUE = false
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
class << self
|
9
|
+
def included(base)
|
10
|
+
super(base)
|
11
|
+
base.send :include, Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeDiff
|
12
|
+
base.send :include, Eco::API::UseCases::GraphQL::Samples::Location::Command::DSL
|
13
|
+
base.send :include, Eco::API::UseCases::GraphQL::Utils::Sftp
|
14
|
+
base.send :include, InstanceMethods
|
15
|
+
end
|
17
16
|
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
module InstanceMethods
|
19
|
+
def process
|
20
|
+
super
|
21
|
+
ensure
|
22
|
+
rescued { re_archive }
|
23
|
+
rescued { email_digest('TagTree Update') }
|
24
|
+
end
|
25
|
+
|
26
|
+
# Before closing, run RE-ARCHIVE: those that where unarchived via archivedToken
|
27
|
+
# that should remain archived.
|
28
|
+
# @note this is an additional necessary step
|
29
|
+
def re_archive
|
30
|
+
return if simulate?
|
31
|
+
stage = :rearchive
|
25
32
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
nodes_diff_class.new(
|
34
|
+
hash_list(current_tree),
|
35
|
+
file_nodes_list,
|
36
|
+
original_tree: current_tree,
|
37
|
+
logger: logger
|
38
|
+
).tap do |nodes_diff|
|
39
|
+
archive_input = input(nodes_diff.stage_commands(:archive), force_continue: true)
|
40
|
+
sliced_batches(
|
41
|
+
archive_input,
|
42
|
+
desc: stage,
|
43
|
+
track_tree_mode: :once
|
44
|
+
) do |sliced_input, response, page, pages, count, total| # rubocop:disable Metrics/ParameterLists
|
45
|
+
page_results = request_results_class.new(sliced_input, response)
|
46
|
+
(results[stage] ||= []) << page_results
|
47
|
+
self.error ||= page_errors?(page_results, page, pages, count, total, stage: stage)
|
48
|
+
end
|
41
49
|
end
|
42
50
|
end
|
43
|
-
end
|
44
51
|
|
45
|
-
|
52
|
+
private
|
46
53
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
54
|
+
# Work with adapted diff builders.
|
55
|
+
def nodes_diff_class
|
56
|
+
Eco::API::UseCases::GraphQL::Helpers::Location::Command::Diffs
|
57
|
+
end
|
51
58
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
59
|
+
def inputs(nodes_diff = comparer, force_continue: force_continue?)
|
60
|
+
{}.tap do |sequence|
|
61
|
+
nodes_diff.commands do |comms, stage|
|
62
|
+
sequence[stage] = input(comms, force_continue: force_continue)
|
63
|
+
end
|
64
|
+
end.tap do |sequence|
|
65
|
+
sequence.each do |stage, input|
|
66
|
+
yield(input, stage) if block_given?
|
67
|
+
end
|
60
68
|
end
|
61
69
|
end
|
62
|
-
end
|
63
70
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
# Generates the file and pushes to the SFTP folder
|
72
|
+
# @note this method can only work if we can run cummulative dry-runs to the back-end.
|
73
|
+
# This is only possible using a draft, which is not that desired.
|
74
|
+
# @note the SFTP push only happens if `remote_subfolder` is defined, via:
|
75
|
+
# 1. `options.dig(:sftp, :remote_subfolder)`
|
76
|
+
# 2. `REMOTE_FOLDER` const
|
77
|
+
def close_handling_tags_remap_csv
|
78
|
+
return false unless super
|
79
|
+
upload(tags_remap_csv_file) unless remote_subfolder.nil?
|
80
|
+
true
|
81
|
+
end
|
75
82
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
+
def email_digest(title)
|
84
|
+
return if simulate?
|
85
|
+
digest_msgs = logger.cache.logs(level: %i[info error warn])
|
86
|
+
exception = exception ? " - Exception!" : ''
|
87
|
+
subject = "#{config.active_enviro} - #{title}#{exception}"
|
88
|
+
session.mail(subject: subject, body: digest_msgs.join)
|
89
|
+
end
|
83
90
|
|
84
|
-
|
85
|
-
|
91
|
+
def print_diff_details?
|
92
|
+
false
|
93
|
+
end
|
86
94
|
end
|
87
95
|
end
|
88
96
|
end
|
@@ -43,7 +43,13 @@ module Eco::API::UseCases::GraphQL::Samples
|
|
43
43
|
include Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeToList
|
44
44
|
|
45
45
|
require_relative 'tree_diff/convertible'
|
46
|
-
|
46
|
+
|
47
|
+
class << self
|
48
|
+
def included(base)
|
49
|
+
super(base)
|
50
|
+
base.send :include, Convertible
|
51
|
+
end
|
52
|
+
end
|
47
53
|
|
48
54
|
def process
|
49
55
|
compare
|