eco-helpers 2.5.2 → 2.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +46 -1
- data/eco-helpers.gemspec +2 -2
- data/lib/eco/api/common/loaders/use_case.rb +0 -2
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +0 -2
- data/lib/eco/api/common/session/logger.rb +22 -77
- data/lib/eco/api/microcases/with_each.rb +0 -1
- data/lib/eco/api/organization/tag_tree.rb +64 -15
- data/lib/eco/api/session/config/tagtree.rb +32 -10
- data/lib/eco/api/session/config/workflow.rb +0 -1
- data/lib/eco/api/session/config.rb +6 -2
- data/lib/eco/api/session.rb +2 -2
- data/lib/eco/api/usecases/default_cases/abstract_policygroup_abilities_case.rb +2 -3
- data/lib/eco/api/usecases/default_cases/analyse_people_case.rb +2 -3
- data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +0 -1
- data/lib/eco/api/usecases/default_cases/change_email_case.rb +1 -2
- data/lib/eco/api/usecases/default_cases/clean_unknown_tags_case.rb +0 -5
- data/lib/eco/api/usecases/default_cases/clear_abilities_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/codes_to_tags_case.rb +5 -7
- data/lib/eco/api/usecases/default_cases/create_case.rb +0 -5
- data/lib/eco/api/usecases/default_cases/create_details_case.rb +0 -5
- data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +0 -5
- data/lib/eco/api/usecases/default_cases/csv_to_tree_case/helper.rb +1 -1
- data/lib/eco/api/usecases/default_cases/csv_to_tree_case.rb +0 -4
- data/lib/eco/api/usecases/default_cases/delete_sync_case.rb +2 -4
- data/lib/eco/api/usecases/default_cases/delete_trans_case.rb +2 -3
- data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +0 -1
- data/lib/eco/api/usecases/default_cases/entries_to_csv_case.rb +0 -4
- data/lib/eco/api/usecases/default_cases/hris_case.rb +2 -3
- data/lib/eco/api/usecases/default_cases/new_email_case.rb +0 -2
- data/lib/eco/api/usecases/default_cases/new_id_case.rb +0 -2
- data/lib/eco/api/usecases/default_cases/org_data_convert_case.rb +0 -5
- data/lib/eco/api/usecases/default_cases/refresh_case.rb +0 -1
- data/lib/eco/api/usecases/default_cases/reinvite_sync_case.rb +1 -3
- data/lib/eco/api/usecases/default_cases/reinvite_trans_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +1 -2
- data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +2 -3
- data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +1 -7
- data/lib/eco/api/usecases/default_cases/restore_db_case.rb +0 -10
- data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +0 -1
- data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +0 -1
- data/lib/eco/api/usecases/default_cases/supers_cyclic_identify_case.rb +2 -3
- data/lib/eco/api/usecases/default_cases/supers_hierarchy_case.rb +2 -3
- data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +2 -4
- data/lib/eco/api/usecases/default_cases/tagtree_case.rb +0 -2
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +4 -5
- data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +0 -1
- data/lib/eco/api/usecases/default_cases/transfer_account_case.rb +0 -2
- data/lib/eco/api/usecases/default_cases/update_case.rb +0 -2
- data/lib/eco/api/usecases/default_cases/update_details_case.rb +0 -2
- data/lib/eco/api/usecases/default_cases/upsert_case.rb +0 -4
- data/lib/eco/api/usecases/graphql/base.rb +6 -18
- data/lib/eco/api/usecases/graphql/helpers/base.rb +31 -0
- data/lib/eco/api/usecases/graphql/helpers/location/base.rb +87 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +69 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +126 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +84 -0
- data/lib/eco/api/usecases/graphql/helpers/location.rb +7 -0
- data/lib/eco/api/usecases/graphql/helpers.rb +2 -1
- data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +54 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/results.rb +125 -0
- data/lib/eco/api/usecases/graphql/samples/location/command.rb +10 -0
- data/lib/eco/api/usecases/graphql/samples/location/dsl.rb +6 -0
- data/lib/eco/api/usecases/graphql/samples/location.rb +10 -0
- data/lib/eco/api/usecases/graphql/samples.rb +6 -0
- data/lib/eco/api/usecases/graphql.rb +2 -1
- data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +0 -1
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +0 -2
- data/lib/eco/api/usecases/ooze_samples/register_migration_case.rb +0 -2
- data/lib/eco/api/usecases/use_case.rb +2 -2
- data/lib/eco/cli/config/default/workflow.rb +2 -4
- data/lib/eco/cli/scripting/args_helpers.rb +0 -2
- data/lib/eco/csv/table.rb +39 -3
- data/lib/eco/data/files/helpers.rb +1 -0
- data/lib/eco/data/hashes/array_diff.rb +12 -6
- data/lib/eco/data/hashes/diff_result.rb +1 -2
- data/lib/eco/data/locations/convert.rb +92 -0
- data/lib/eco/data/locations/dsl.rb +35 -0
- data/lib/eco/data/locations/node_base/builder.rb +26 -0
- data/lib/eco/data/locations/node_base/csv_convert.rb +57 -0
- data/lib/eco/data/locations/node_base/parsing.rb +30 -0
- data/lib/eco/data/locations/node_base/serial.rb +26 -0
- data/lib/eco/data/locations/node_base/tag_validations.rb +52 -0
- data/lib/eco/data/locations/node_base/treeify.rb +150 -0
- data/lib/eco/data/locations/node_base.rb +48 -0
- data/lib/eco/data/locations/node_level/builder.rb +6 -0
- data/lib/eco/data/locations/node_level/cleaner.rb +74 -0
- data/lib/eco/data/locations/node_level/parsing.rb +63 -0
- data/lib/eco/data/locations/node_level/serial.rb +37 -0
- data/lib/eco/data/locations/node_level.rb +156 -0
- data/lib/eco/data/locations/node_plain/builder.rb +6 -0
- data/lib/eco/data/locations/node_plain/parsing.rb +36 -0
- data/lib/eco/data/locations/node_plain/serial.rb +14 -0
- data/lib/eco/data/locations/node_plain.rb +34 -0
- data/lib/eco/data/locations.rb +12 -0
- data/lib/eco/data.rb +1 -0
- data/lib/eco/language/auxiliar_logger.rb +9 -1
- data/lib/eco/language/basic_logger.rb +74 -0
- data/lib/eco/language.rb +2 -1
- data/lib/eco/version.rb +1 -1
- metadata +37 -8
- data/lib/eco/api/usecases/default_cases/new_id_case0.rb +0 -14
- data/lib/eco/api/usecases/graphql/helpers/locations/commands.rb +0 -4
- data/lib/eco/api/usecases/graphql/helpers/locations.rb +0 -6
@@ -2,11 +2,7 @@ class Eco::API::UseCases::DefaultCases::CreateDetailsCase < Eco::API::Common::Lo
|
|
2
2
|
name "create-details"
|
3
3
|
type :sync
|
4
4
|
|
5
|
-
attr_reader :options
|
6
|
-
|
7
5
|
def main(entries, people, session, options, usecase)
|
8
|
-
@options = options
|
9
|
-
micro = session.micro
|
10
6
|
creation = session.new_job("main", "create", :create, usecase)
|
11
7
|
|
12
8
|
micro.with_each_starter(entries, people, options, log_present: true, append_created: append_created) do |entry, person|
|
@@ -21,5 +17,4 @@ class Eco::API::UseCases::DefaultCases::CreateDetailsCase < Eco::API::Common::Lo
|
|
21
17
|
def append_created
|
22
18
|
options.dig(:people, :append_created)
|
23
19
|
end
|
24
|
-
|
25
20
|
end
|
@@ -2,11 +2,7 @@ class Eco::API::UseCases::DefaultCases::CreateDetailsWithSupervisorCase < Eco::A
|
|
2
2
|
name "create-details-with-supervisor"
|
3
3
|
type :sync
|
4
4
|
|
5
|
-
attr_reader :options
|
6
|
-
|
7
5
|
def main(entries, people, session, options, usecase)
|
8
|
-
@options = options
|
9
|
-
micro = session.micro
|
10
6
|
creation = session.new_job("main", "create", :create, usecase)
|
11
7
|
supers = session.new_job("post", "supers", :update, usecase, :core)
|
12
8
|
|
@@ -22,5 +18,4 @@ class Eco::API::UseCases::DefaultCases::CreateDetailsWithSupervisorCase < Eco::A
|
|
22
18
|
def append_created
|
23
19
|
options.dig(:people, :append_created)
|
24
20
|
end
|
25
|
-
|
26
21
|
end
|
@@ -26,7 +26,7 @@ class Eco::API::UseCases::DefaultCases::CsvToTree
|
|
26
26
|
prev_node ||= node
|
27
27
|
|
28
28
|
# If node is nested in prev_node or is a sibling thereof
|
29
|
-
if prev_node.raw_level <= node.raw_level
|
29
|
+
if prev_node.raw_level <= node.raw_level
|
30
30
|
# Make sure parent is among upper level tags
|
31
31
|
node.set_high_levels(prev_node)
|
32
32
|
else
|
@@ -4,12 +4,8 @@ class Eco::API::UseCases::DefaultCases::CsvToTree < Eco::API::Common::Loaders::U
|
|
4
4
|
|
5
5
|
TIME_FORMAT = '%Y%m%dT%H%M%S'
|
6
6
|
|
7
|
-
attr_reader :session, :options
|
8
|
-
|
9
7
|
def main(session, options, usecase)
|
10
8
|
options[:end_get] = false
|
11
|
-
@session = session; @options = options
|
12
|
-
|
13
9
|
tree_struct = Helper.treeify(Helper.csv_nodes(input_file))
|
14
10
|
|
15
11
|
File.open(output_file, "w") do |fd|
|
@@ -3,9 +3,7 @@ class Eco::API::UseCases::DefaultCases::DeleteSyncCase < Eco::API::UseCases::Def
|
|
3
3
|
type :sync
|
4
4
|
|
5
5
|
def main(entries, people, session, options, usecase)
|
6
|
-
|
7
|
-
found
|
8
|
-
delete(found, session, options, usecase)
|
6
|
+
found = micro.with_each_present(entries, people, options, log_starter: true)
|
7
|
+
delete(found)
|
9
8
|
end
|
10
|
-
|
11
9
|
end
|
@@ -2,13 +2,12 @@ class Eco::API::UseCases::DefaultCases::DeleteTransCase < Eco::API::Common::Load
|
|
2
2
|
name "delete"
|
3
3
|
type :transform
|
4
4
|
|
5
|
-
def delete(people
|
5
|
+
def delete(people)
|
6
6
|
delete = session.new_job("main", "delete", :delete, usecase)
|
7
7
|
people.each {|person| delete.add(person)}
|
8
8
|
end
|
9
9
|
|
10
10
|
def main(people, session, options, usecase)
|
11
|
-
delete(people
|
11
|
+
delete(people)
|
12
12
|
end
|
13
|
-
|
14
13
|
end
|
@@ -2,11 +2,7 @@ class Eco::API::UseCases::DefaultCases::EntriesToCsv < Eco::API::Common::Loaders
|
|
2
2
|
name "entries-to-csv"
|
3
3
|
type :import
|
4
4
|
|
5
|
-
attr_reader :session, :options
|
6
|
-
|
7
5
|
def main(entries, session, options, usecase)
|
8
|
-
@options = options
|
9
|
-
@session = session
|
10
6
|
entries.export(filename)
|
11
7
|
end
|
12
8
|
|
@@ -3,10 +3,10 @@ class Eco::API::UseCases::DefaultCases::HrisCase < Eco::API::Common::Loaders::Us
|
|
3
3
|
type :sync
|
4
4
|
|
5
5
|
attr_reader :creation, :update, :supers, :leavers
|
6
|
-
attr_reader :people
|
6
|
+
attr_reader :people
|
7
7
|
|
8
8
|
def main(entries, people, session, options, usecase)
|
9
|
-
@
|
9
|
+
@people = people
|
10
10
|
require_only_one_schema!
|
11
11
|
micro = session.micro
|
12
12
|
@leavers = session.new_job("pre", "leavers", :update, usecase, :account)
|
@@ -53,5 +53,4 @@ class Eco::API::UseCases::DefaultCases::HrisCase < Eco::API::Common::Loaders::Us
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
57
56
|
end
|
@@ -3,7 +3,6 @@ class Eco::API::UseCases::DefaultCases::NewEmailCase < Eco::API::Common::Loaders
|
|
3
3
|
type :sync
|
4
4
|
|
5
5
|
def main(entries, people, session, options, usecase)
|
6
|
-
micro = session.micro
|
7
6
|
update = session.new_job("main", "update", :update, usecase, :core)
|
8
7
|
|
9
8
|
micro.with_each_present(entries, people, options, log_starter: true) do |entry, person|
|
@@ -11,5 +10,4 @@ class Eco::API::UseCases::DefaultCases::NewEmailCase < Eco::API::Common::Loaders
|
|
11
10
|
person.email = entry.email
|
12
11
|
end
|
13
12
|
end
|
14
|
-
|
15
13
|
end
|
@@ -3,12 +3,10 @@ class Eco::API::UseCases::DefaultCases::NewIdCase < Eco::API::Common::Loaders::U
|
|
3
3
|
type :sync
|
4
4
|
|
5
5
|
def main(entries, people, session, options, usecase)
|
6
|
-
micro = session.micro
|
7
6
|
update = session.new_job("main", "update", :update, usecase, :core)
|
8
7
|
micro.with_each_present(entries, people, options, log_starter: true) do |entry, person|
|
9
8
|
update.add(person)
|
10
9
|
person.external_id = entry.external_id
|
11
10
|
end
|
12
11
|
end
|
13
|
-
|
14
12
|
end
|
@@ -2,8 +2,6 @@ class Eco::API::UseCases::DefaultCases::OrgDataConvertCase < Eco::API::Common::L
|
|
2
2
|
name "org-data-convert"
|
3
3
|
type :import
|
4
4
|
|
5
|
-
attr_reader :session, :options
|
6
|
-
|
7
5
|
def org_data_convert(people)
|
8
6
|
pp "Going to convert data from '#{source_enviro}' to '#{ASSETS.active_config}'"
|
9
7
|
puts "\n"
|
@@ -22,8 +20,6 @@ class Eco::API::UseCases::DefaultCases::OrgDataConvertCase < Eco::API::Common::L
|
|
22
20
|
end
|
23
21
|
|
24
22
|
def main(people, session, options, usecase)
|
25
|
-
@options = options
|
26
|
-
@session = session
|
27
23
|
org_data_convert(people)
|
28
24
|
end
|
29
25
|
|
@@ -97,5 +93,4 @@ class Eco::API::UseCases::DefaultCases::OrgDataConvertCase < Eco::API::Common::L
|
|
97
93
|
logger.error(msg)
|
98
94
|
exit(1)
|
99
95
|
end
|
100
|
-
|
101
96
|
end
|
@@ -3,9 +3,7 @@ class Eco::API::UseCases::DefaultCases::ReinviteSyncCase < Eco::API::UseCases::D
|
|
3
3
|
type :sync
|
4
4
|
|
5
5
|
def main(entries, people, session, options, usecase)
|
6
|
-
|
7
|
-
found = micro.with_each_present(entries, people, options, log_starter: true)
|
6
|
+
found = micro.with_each_present(entries, people, options, log_starter: true)
|
8
7
|
reinvite(found.users, session, options, usecase)
|
9
8
|
end
|
10
|
-
|
11
9
|
end
|
@@ -3,12 +3,12 @@ class Eco::API::UseCases::DefaultCases::ReinviteTransCase < Eco::API::Common::Lo
|
|
3
3
|
type :transform
|
4
4
|
|
5
5
|
def main(people, session, options, usecase)
|
6
|
-
reinvite(people.users
|
6
|
+
reinvite(people.users)
|
7
7
|
end
|
8
8
|
|
9
9
|
private
|
10
10
|
|
11
|
-
def reinvite(users
|
11
|
+
def reinvite(users)
|
12
12
|
invite = session.new_job("main", "invite", :update, usecase, :account)
|
13
13
|
users.each do |person|
|
14
14
|
if force_invite?
|
@@ -5,7 +5,6 @@ class Eco::API::UseCases::DefaultCases::RemoveAccountSyncCase < Eco::API::UseCas
|
|
5
5
|
def main(entries, people, session, options, usecase)
|
6
6
|
micro = session.micro
|
7
7
|
found = micro.with_each_present(entries, people, options, log_starter: true)
|
8
|
-
remove_account(found.users
|
8
|
+
remove_account(found.users)
|
9
9
|
end
|
10
|
-
|
11
10
|
end
|
@@ -2,7 +2,7 @@ class Eco::API::UseCases::DefaultCases::RemoveAccountTransCase < Eco::API::Commo
|
|
2
2
|
name "remove-account"
|
3
3
|
type :transform
|
4
4
|
|
5
|
-
def remove_account(users
|
5
|
+
def remove_account(users)
|
6
6
|
update = session.new_job("main", "update", :update, usecase, :account)
|
7
7
|
users.each do |user|
|
8
8
|
user.account = nil
|
@@ -11,7 +11,6 @@ class Eco::API::UseCases::DefaultCases::RemoveAccountTransCase < Eco::API::Commo
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def main(people, session, options, usecase)
|
14
|
-
remove_account(people.users
|
14
|
+
remove_account(people.users)
|
15
15
|
end
|
16
|
-
|
17
16
|
end
|
@@ -2,12 +2,8 @@ class Eco::API::UseCases::DefaultCases::ResetLandingPageCase < Eco::API::Common:
|
|
2
2
|
name "reset-landing-page"
|
3
3
|
type :transform
|
4
4
|
|
5
|
-
attr_reader :session, :options
|
6
|
-
|
7
5
|
def main(people, session, options, usecase)
|
8
|
-
|
9
|
-
update = session.new_job("main", "update", :update, usecase, :core)
|
10
|
-
|
6
|
+
update = session.new_job("main", "update", :update, usecase, :core)
|
11
7
|
people.users.each do |user|
|
12
8
|
user.account.landing_page_id = page_id
|
13
9
|
update.add(user)
|
@@ -19,6 +15,4 @@ class Eco::API::UseCases::DefaultCases::ResetLandingPageCase < Eco::API::Common:
|
|
19
15
|
def page_id
|
20
16
|
options[:page_id]
|
21
17
|
end
|
22
|
-
|
23
|
-
|
24
18
|
end
|
@@ -2,12 +2,7 @@ class Eco::API::UseCases::DefaultCases::RestoreDBCase < Eco::API::Common::Loader
|
|
2
2
|
name "restore-db"
|
3
3
|
type :sync
|
4
4
|
|
5
|
-
attr_reader :session, :options
|
6
|
-
|
7
5
|
def main(entries, people, session, options, usecase)
|
8
|
-
@session = session; @options = options
|
9
|
-
|
10
|
-
micro = session.micro
|
11
6
|
require_people_as_entries!(entries)
|
12
7
|
|
13
8
|
restart = session.new_job("main", "restart", :create, usecase) if options.dig(:include, :create)
|
@@ -95,9 +90,4 @@ class Eco::API::UseCases::DefaultCases::RestoreDBCase < Eco::API::Common::Loader
|
|
95
90
|
end
|
96
91
|
end
|
97
92
|
end
|
98
|
-
|
99
|
-
def logger
|
100
|
-
session.logger
|
101
|
-
end
|
102
|
-
|
103
93
|
end
|
@@ -7,7 +7,6 @@ class Eco::API::UseCases::DefaultCases::SetDefaultTagCase < Eco::API::Common::Lo
|
|
7
7
|
# => take the common node between them (i.e. you have Hamilton and Auckland -> take New Zealand)
|
8
8
|
# => if there's no common node between them, take the `first` (unless they are at top level of the tree)
|
9
9
|
def main(people, session, options, usecase)
|
10
|
-
micro = session.micro
|
11
10
|
tagtree_present!(session)
|
12
11
|
users = users_present!(people, session)
|
13
12
|
update = session.new_job("main", "update", :update, usecase, :account)
|
@@ -3,7 +3,6 @@ class Eco::API::UseCases::DefaultCases::SetSupervisorCase < Eco::API::Common::Lo
|
|
3
3
|
type :sync
|
4
4
|
|
5
5
|
def main(entries, people, session, options, usecase)
|
6
|
-
micro = session.micro
|
7
6
|
update = session.new_job("main", "update", :update, usecase)
|
8
7
|
|
9
8
|
micro.with_each_present(entries, people, options, log_starter: true) do |entry, person|
|
@@ -2,11 +2,11 @@ class Eco::API::UseCases::DefaultCases::SupersCyclicIdentify < Eco::API::Common:
|
|
2
2
|
name "identify-cyclic-supers"
|
3
3
|
type :export
|
4
4
|
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :people
|
6
6
|
|
7
7
|
def main(people, session, options, usecase)
|
8
8
|
options[:end_get] = false
|
9
|
-
@
|
9
|
+
@people = people
|
10
10
|
|
11
11
|
save!(cyclic_sets)
|
12
12
|
end
|
@@ -68,5 +68,4 @@ class Eco::API::UseCases::DefaultCases::SupersCyclicIdentify < Eco::API::Common:
|
|
68
68
|
str << set_to_str(set, lev: lev + 1, format: format) unless !set || set.empty?
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
72
71
|
end
|
@@ -2,11 +2,11 @@ class Eco::API::UseCases::DefaultCases::SupersHierarchy < Eco::API::Common::Load
|
|
2
2
|
name "supers-hierarchy"
|
3
3
|
type :export
|
4
4
|
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :people
|
6
6
|
|
7
7
|
def main(people, session, options, usecase)
|
8
8
|
options[:end_get] = false
|
9
|
-
@
|
9
|
+
@people = people
|
10
10
|
|
11
11
|
save!(hierarchy)
|
12
12
|
end
|
@@ -55,5 +55,4 @@ class Eco::API::UseCases::DefaultCases::SupersHierarchy < Eco::API::Common::Load
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
59
58
|
end
|
@@ -3,10 +3,9 @@ class Eco::API::UseCases::DefaultCases::SwitchSupervisorCase < Eco::API::Common:
|
|
3
3
|
type :transform
|
4
4
|
|
5
5
|
def main(people, session, options, usecase)
|
6
|
-
micro = session.micro
|
7
6
|
supers = session.new_job("main", "supers", :update, usecase, :core)
|
8
7
|
|
9
|
-
old_sup, new_sup = get_supers(people
|
8
|
+
old_sup, new_sup = get_supers(people).tap do |supers|
|
10
9
|
inform(*supers, session.logger)
|
11
10
|
end
|
12
11
|
|
@@ -24,7 +23,7 @@ class Eco::API::UseCases::DefaultCases::SwitchSupervisorCase < Eco::API::Common:
|
|
24
23
|
|
25
24
|
private
|
26
25
|
|
27
|
-
def get_supers(people
|
26
|
+
def get_supers(people)
|
28
27
|
micro = session.micro
|
29
28
|
old_id, new_id = get_super_ids(options)
|
30
29
|
old_sup, new_sup = [nil, nil]
|
@@ -66,5 +65,4 @@ class Eco::API::UseCases::DefaultCases::SwitchSupervisorCase < Eco::API::Common:
|
|
66
65
|
msg += "to '#{new_sup&.name}' (#{new_sup&.external_id})"
|
67
66
|
logger.info(msg)
|
68
67
|
end
|
69
|
-
|
70
68
|
end
|
@@ -2,12 +2,10 @@ class Eco::API::UseCases::DefaultCases::TagTree < Eco::API::Common::Loaders::Use
|
|
2
2
|
name "tagtree"
|
3
3
|
type :other
|
4
4
|
|
5
|
-
attr_reader :session, :options
|
6
5
|
def main(session, options, usecase)
|
7
6
|
puts "Use case still in development"
|
8
7
|
exit
|
9
8
|
options[:end_get] = false
|
10
|
-
@session = session; @options = options
|
11
9
|
operations.keys.each do |key|
|
12
10
|
process(key)
|
13
11
|
end
|
@@ -2,14 +2,14 @@ class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::U
|
|
2
2
|
name "to-csv"
|
3
3
|
type :export
|
4
4
|
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :people
|
6
6
|
|
7
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
|
+
logger.warn("No source people to create the file... aborting!")
|
13
13
|
return false
|
14
14
|
end
|
15
15
|
|
@@ -27,7 +27,7 @@ class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::U
|
|
27
27
|
private
|
28
28
|
|
29
29
|
def create_file!(filename = file, data = people)
|
30
|
-
|
30
|
+
logger.info("going to create file: #{filename}")
|
31
31
|
|
32
32
|
CSV.open(filename, "w") do |csv|
|
33
33
|
csv << spot_header(data.first)
|
@@ -128,5 +128,4 @@ class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::U
|
|
128
128
|
"landing_page_id" => "Landing Page ID"
|
129
129
|
}
|
130
130
|
end
|
131
|
-
|
132
131
|
end
|
@@ -37,7 +37,6 @@ class Eco::API::UseCases::DefaultCases::TransferAccountCase < Eco::API::Common::
|
|
37
37
|
# * `:api_policies` (Boolean) [false] if the `api policies` should be skipped (**command option**: `-skip-api-policies`)
|
38
38
|
# @return [Void]
|
39
39
|
def main(entries, people, session, options, usecase)
|
40
|
-
micro = session.micro
|
41
40
|
move = session.new_job("main", "move email accounts", :update, usecase, :account)
|
42
41
|
free = session.new_job("main", "free up accounts", :update, usecase, :account)
|
43
42
|
switch = session.new_job("main", "switch email", :update, usecase, :core)
|
@@ -266,5 +265,4 @@ class Eco::API::UseCases::DefaultCases::TransferAccountCase < Eco::API::Common::
|
|
266
265
|
def report_repeated(str, logger, msg = "The following entries are repeated")
|
267
266
|
logger.error("#{msg}\n#{str}")
|
268
267
|
end
|
269
|
-
|
270
268
|
end
|
@@ -3,7 +3,6 @@ class Eco::API::UseCases::DefaultCases::UpdateCase < Eco::API::Common::Loaders::
|
|
3
3
|
type :sync
|
4
4
|
|
5
5
|
def main(entries, people, session, options, usecase)
|
6
|
-
micro = session.micro
|
7
6
|
update = session.new_job("main", "update", :update, usecase)
|
8
7
|
supers = session.new_job("post", "supers", :update, usecase, :core)
|
9
8
|
|
@@ -14,5 +13,4 @@ class Eco::API::UseCases::DefaultCases::UpdateCase < Eco::API::Common::Loaders::
|
|
14
13
|
micro.set_account(entry, person, options)
|
15
14
|
end
|
16
15
|
end
|
17
|
-
|
18
16
|
end
|
@@ -3,7 +3,6 @@ class Eco::API::UseCases::DefaultCases::UpdateDetailsCase < Eco::API::Common::Lo
|
|
3
3
|
type :sync
|
4
4
|
|
5
5
|
def main(entries, people, session, options, usecase)
|
6
|
-
micro = session.micro
|
7
6
|
update = session.new_job("main", "update", :update, usecase)
|
8
7
|
supers = session.new_job("post", "supers", :update, usecase, :core)
|
9
8
|
|
@@ -13,5 +12,4 @@ class Eco::API::UseCases::DefaultCases::UpdateDetailsCase < Eco::API::Common::Lo
|
|
13
12
|
entry.set_details(person) unless options.dig(:exclude, :details)
|
14
13
|
end
|
15
14
|
end
|
16
|
-
|
17
15
|
end
|
@@ -2,10 +2,7 @@ class Eco::API::UseCases::DefaultCases::UpsertCase < Eco::API::Common::Loaders::
|
|
2
2
|
name "upsert"
|
3
3
|
type :sync
|
4
4
|
|
5
|
-
attr_reader :options
|
6
|
-
|
7
5
|
def main(entries, people, session, options, usecase)
|
8
|
-
@options = options
|
9
6
|
micro = session.micro
|
10
7
|
creation = session.new_job("main", "create", :create, usecase)
|
11
8
|
update = session.new_job("main", "update", :update, usecase)
|
@@ -24,5 +21,4 @@ class Eco::API::UseCases::DefaultCases::UpsertCase < Eco::API::Common::Loaders::
|
|
24
21
|
def append_created
|
25
22
|
options.dig(:people, :append_created)
|
26
23
|
end
|
27
|
-
|
28
24
|
end
|
@@ -1,32 +1,20 @@
|
|
1
1
|
class Eco::API::UseCases::GraphQL::Base < Eco::API::Common::Loaders::UseCase
|
2
|
+
class NotImplementedMethod < StandardError
|
3
|
+
end
|
4
|
+
|
2
5
|
name "graphql-base"
|
3
6
|
type :other
|
4
7
|
|
5
|
-
|
8
|
+
include Eco::API::UseCases::GraphQL::Helpers::Base
|
6
9
|
|
7
10
|
def main(session, options, usecase)
|
11
|
+
options.deep_merge!(workflow: {no_email: true}) # prevent the default mailer to quick in
|
8
12
|
options[:end_get] = false
|
9
|
-
@session = session; @options = options; @usecase = usecase
|
10
13
|
process
|
11
14
|
end
|
12
15
|
|
13
16
|
# Write here your script
|
14
17
|
def process
|
15
|
-
raise "You need to inherit from this class ('#{self.class}') and call super with a block"
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def graphql
|
21
|
-
@graphql ||= session.api(version: :graphql)
|
22
|
-
end
|
23
|
-
|
24
|
-
def simulate?
|
25
|
-
options.dig(:simulate)
|
26
|
-
end
|
27
|
-
|
28
|
-
def exit_error(msg)
|
29
|
-
logger.error(msg)
|
30
|
-
exit(1)
|
18
|
+
raise NotImplementedMethod, "You need to inherit from this class ('#{self.class}') and call super with a block"
|
31
19
|
end
|
32
20
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Eco::API::UseCases::GraphQL::Helpers
|
2
|
+
module Base
|
3
|
+
include Eco::Language::AuxiliarLogger
|
4
|
+
attr_reader :session, :options
|
5
|
+
|
6
|
+
def graphql
|
7
|
+
@graphql ||= session.api(version: :graphql)
|
8
|
+
end
|
9
|
+
|
10
|
+
def config
|
11
|
+
session.config
|
12
|
+
end
|
13
|
+
|
14
|
+
def simulate?
|
15
|
+
options.dig(:simulate)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Keep a copy of the requests/responses for future reference
|
19
|
+
def backup(data, type:)
|
20
|
+
dry_run = simulate? ? "_dry_run" : ""
|
21
|
+
dir = config.people.requests_folder
|
22
|
+
file = File.join(dir, "#{type}#{dry_run}.json")
|
23
|
+
session.file_manager.save_json(data, file, :timestamp)
|
24
|
+
end
|
25
|
+
|
26
|
+
def exit_error(msg)
|
27
|
+
logger.error(msg)
|
28
|
+
exit(1)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Eco::API::UseCases::GraphQL::Helpers::Location
|
2
|
+
module Base
|
3
|
+
include Eco::API::UseCases::GraphQL::Helpers::Base
|
4
|
+
|
5
|
+
TAGTREE_BACKUP = 'cache/tagtree.json'.freeze
|
6
|
+
|
7
|
+
attr_reader :current_tree
|
8
|
+
attr_accessor :previous_tree
|
9
|
+
|
10
|
+
# Back-up the tree everytime that it is retrieved anew.
|
11
|
+
def current_tree=(value)
|
12
|
+
return current_tree if current_tree == value
|
13
|
+
@current_tree = value
|
14
|
+
backup_tree(current_tree)
|
15
|
+
value
|
16
|
+
end
|
17
|
+
|
18
|
+
# At any moment we want to know how the live tree is
|
19
|
+
# @note it also does a backup
|
20
|
+
# @return [Eco::API::Organization::TagTree] the latest tree (`current_tree`)
|
21
|
+
def track_current_tree(tree)
|
22
|
+
return if simulate?
|
23
|
+
return unless tree
|
24
|
+
latest_tree = tree if tree.is_a?(Eco::API::Organization::TagTree)
|
25
|
+
if tree.respond_to?(:treeify)
|
26
|
+
args = { enviro: session.enviro, id: tree.id, name: tree.name}
|
27
|
+
latest_tree ||= Eco::API::Organization::TagTree.new(tree.treeify, **args)
|
28
|
+
end
|
29
|
+
latest_tree.tap do |_tree|
|
30
|
+
next unless latest_tree
|
31
|
+
@previous_tree = @current_tree
|
32
|
+
self.current_tree = latest_tree
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# @param tree [Eco::API::Organization::TagTree, Hash, Array]
|
37
|
+
# @return [Boolean] whether or not the backup was created
|
38
|
+
def backup_tree(tree = current_tree || live_tree)
|
39
|
+
return false if simulate?
|
40
|
+
case tree
|
41
|
+
when Eco::API::Organization::TagTree
|
42
|
+
tagtree = tree.source
|
43
|
+
when Hash, Array
|
44
|
+
# that's allright
|
45
|
+
else
|
46
|
+
log(:error) {
|
47
|
+
"Can't back up tagtree. Expecting TagTree, Hash or Array. Given: #{tree.class}"
|
48
|
+
}
|
49
|
+
return false
|
50
|
+
end
|
51
|
+
file = session.file_manager.save_json(tree, self.class::TAGTREE_BACKUP, :timestamp)
|
52
|
+
logger.debug("Backed up tagtree saved locally to #{file}.")
|
53
|
+
true
|
54
|
+
end
|
55
|
+
|
56
|
+
def tagtree_id
|
57
|
+
%i[target_structure_id tagtree_id structure_id].find {|key| options.dig(:source, key)}
|
58
|
+
end
|
59
|
+
|
60
|
+
# Scopes the target structure `id`.
|
61
|
+
# @note it is basic that the `id` is correctly identified.
|
62
|
+
def target_structure_id
|
63
|
+
@target_structure_id ||= tagtree_id
|
64
|
+
@target_structure_id ||= self.class.const_get(:TARGET_STRUCTURE_ID) if self.class.const_defined?(:TARGET_STRUCTURE_ID)
|
65
|
+
@target_structure_id ||= current_tree.id if current_tree.respond_to?(:id)
|
66
|
+
return @target_structure_id if @target_structure_id
|
67
|
+
msg = "Const TARGET_STRUCTURE_ID has not been defined, "
|
68
|
+
msg << "nor options(:source, :structure_id). "
|
69
|
+
msg << "Infering active locations structure."
|
70
|
+
log(:warn) { msg }
|
71
|
+
if self.current_tree = session.live_tree
|
72
|
+
@target_structure_id = current_tree.id
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Retrieves the live tree only if `current_tree` hasn't been just retrieved.
|
77
|
+
# @note that `target_structure_id` can retrive the live tree (when `id` is not defined)
|
78
|
+
# By checking if the current_tree changed after calling `target_structure_id` we
|
79
|
+
# prevent unnecessary requests.
|
80
|
+
def live_tree
|
81
|
+
tree_init = current_tree
|
82
|
+
target_id = target_structure_id
|
83
|
+
return current_tree if current_tree != tree_init
|
84
|
+
self.current_tree = session.live_tree(id: target_id, include_archived: true)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|