eco-helpers 2.5.2 → 2.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +62 -2
  3. data/eco-helpers.gemspec +2 -2
  4. data/lib/eco/api/common/loaders/use_case.rb +0 -2
  5. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +0 -2
  6. data/lib/eco/api/common/session/logger.rb +22 -77
  7. data/lib/eco/api/microcases/with_each.rb +0 -1
  8. data/lib/eco/api/organization/tag_tree.rb +64 -15
  9. data/lib/eco/api/session/config/tagtree.rb +32 -10
  10. data/lib/eco/api/session/config/workflow.rb +0 -1
  11. data/lib/eco/api/session/config.rb +6 -2
  12. data/lib/eco/api/session.rb +2 -2
  13. data/lib/eco/api/usecases/default_cases/abstract_policygroup_abilities_case.rb +2 -3
  14. data/lib/eco/api/usecases/default_cases/analyse_people_case.rb +2 -3
  15. data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +0 -1
  16. data/lib/eco/api/usecases/default_cases/change_email_case.rb +1 -2
  17. data/lib/eco/api/usecases/default_cases/clean_unknown_tags_case.rb +0 -5
  18. data/lib/eco/api/usecases/default_cases/clear_abilities_case.rb +2 -2
  19. data/lib/eco/api/usecases/default_cases/codes_to_tags_case.rb +5 -7
  20. data/lib/eco/api/usecases/default_cases/create_case.rb +0 -5
  21. data/lib/eco/api/usecases/default_cases/create_details_case.rb +0 -5
  22. data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +0 -5
  23. data/lib/eco/api/usecases/default_cases/csv_to_tree_case/helper.rb +1 -1
  24. data/lib/eco/api/usecases/default_cases/csv_to_tree_case.rb +0 -4
  25. data/lib/eco/api/usecases/default_cases/delete_sync_case.rb +2 -4
  26. data/lib/eco/api/usecases/default_cases/delete_trans_case.rb +2 -3
  27. data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +0 -1
  28. data/lib/eco/api/usecases/default_cases/entries_to_csv_case.rb +0 -4
  29. data/lib/eco/api/usecases/default_cases/hris_case.rb +2 -3
  30. data/lib/eco/api/usecases/default_cases/new_email_case.rb +0 -2
  31. data/lib/eco/api/usecases/default_cases/new_id_case.rb +0 -2
  32. data/lib/eco/api/usecases/default_cases/org_data_convert_case.rb +0 -5
  33. data/lib/eco/api/usecases/default_cases/refresh_case.rb +0 -1
  34. data/lib/eco/api/usecases/default_cases/reinvite_sync_case.rb +1 -3
  35. data/lib/eco/api/usecases/default_cases/reinvite_trans_case.rb +2 -2
  36. data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +1 -2
  37. data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +2 -3
  38. data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +1 -7
  39. data/lib/eco/api/usecases/default_cases/restore_db_case.rb +0 -10
  40. data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +0 -1
  41. data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +0 -1
  42. data/lib/eco/api/usecases/default_cases/supers_cyclic_identify_case.rb +2 -3
  43. data/lib/eco/api/usecases/default_cases/supers_hierarchy_case.rb +2 -3
  44. data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +2 -4
  45. data/lib/eco/api/usecases/default_cases/tagtree_case.rb +0 -2
  46. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +4 -5
  47. data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +0 -1
  48. data/lib/eco/api/usecases/default_cases/transfer_account_case.rb +0 -2
  49. data/lib/eco/api/usecases/default_cases/update_case.rb +0 -2
  50. data/lib/eco/api/usecases/default_cases/update_details_case.rb +0 -2
  51. data/lib/eco/api/usecases/default_cases/upsert_case.rb +0 -4
  52. data/lib/eco/api/usecases/graphql/base.rb +6 -18
  53. data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +15 -0
  54. data/lib/eco/api/usecases/graphql/helpers/base.rb +23 -0
  55. data/lib/eco/api/usecases/graphql/helpers/location/base.rb +87 -0
  56. data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +69 -0
  57. data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +126 -0
  58. data/lib/eco/api/usecases/graphql/helpers/location/command.rb +92 -0
  59. data/lib/eco/api/usecases/graphql/helpers/location.rb +7 -0
  60. data/lib/eco/api/usecases/graphql/helpers.rb +2 -1
  61. data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +54 -0
  62. data/lib/eco/api/usecases/graphql/samples/location/command/results.rb +125 -0
  63. data/lib/eco/api/usecases/graphql/samples/location/command.rb +10 -0
  64. data/lib/eco/api/usecases/graphql/samples/location/dsl.rb +6 -0
  65. data/lib/eco/api/usecases/graphql/samples/location.rb +10 -0
  66. data/lib/eco/api/usecases/graphql/samples.rb +6 -0
  67. data/lib/eco/api/usecases/graphql/utils/sftp.rb +74 -0
  68. data/lib/eco/api/usecases/graphql/utils.rb +6 -0
  69. data/lib/eco/api/usecases/graphql.rb +3 -1
  70. data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +0 -1
  71. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +0 -2
  72. data/lib/eco/api/usecases/ooze_samples/register_migration_case.rb +0 -2
  73. data/lib/eco/api/usecases/use_case.rb +2 -2
  74. data/lib/eco/cli/config/default/workflow.rb +2 -4
  75. data/lib/eco/cli/scripting/args_helpers.rb +0 -2
  76. data/lib/eco/csv/table.rb +39 -3
  77. data/lib/eco/data/files/helpers.rb +4 -3
  78. data/lib/eco/data/hashes/array_diff.rb +21 -61
  79. data/lib/eco/data/hashes/diff_meta.rb +52 -0
  80. data/lib/eco/data/hashes/diff_result.rb +36 -25
  81. data/lib/eco/data/hashes.rb +1 -0
  82. data/lib/eco/data/locations/convert.rb +92 -0
  83. data/lib/eco/data/locations/dsl.rb +35 -0
  84. data/lib/eco/data/locations/node_base/builder.rb +26 -0
  85. data/lib/eco/data/locations/node_base/csv_convert.rb +57 -0
  86. data/lib/eco/data/locations/node_base/parsing.rb +30 -0
  87. data/lib/eco/data/locations/node_base/serial.rb +26 -0
  88. data/lib/eco/data/locations/node_base/tag_validations.rb +52 -0
  89. data/lib/eco/data/locations/node_base/treeify.rb +150 -0
  90. data/lib/eco/data/locations/node_base.rb +48 -0
  91. data/lib/eco/data/locations/node_diff/accessors.rb +46 -0
  92. data/lib/eco/data/locations/node_diff/nodes_diff.rb +90 -0
  93. data/lib/eco/data/locations/node_diff/selectors.rb +20 -0
  94. data/lib/eco/data/locations/node_diff.rb +55 -0
  95. data/lib/eco/data/locations/node_level/builder.rb +6 -0
  96. data/lib/eco/data/locations/node_level/cleaner.rb +74 -0
  97. data/lib/eco/data/locations/node_level/parsing.rb +63 -0
  98. data/lib/eco/data/locations/node_level/serial.rb +37 -0
  99. data/lib/eco/data/locations/node_level.rb +153 -0
  100. data/lib/eco/data/locations/node_plain/builder.rb +6 -0
  101. data/lib/eco/data/locations/node_plain/parsing.rb +36 -0
  102. data/lib/eco/data/locations/node_plain/serial.rb +14 -0
  103. data/lib/eco/data/locations/node_plain.rb +31 -0
  104. data/lib/eco/data/locations.rb +13 -0
  105. data/lib/eco/data.rb +1 -0
  106. data/lib/eco/language/auxiliar_logger.rb +9 -1
  107. data/lib/eco/language/basic_logger.rb +74 -0
  108. data/lib/eco/language.rb +2 -1
  109. data/lib/eco/version.rb +1 -1
  110. metadata +45 -8
  111. data/lib/eco/api/usecases/default_cases/new_id_case0.rb +0 -14
  112. data/lib/eco/api/usecases/graphql/helpers/locations/commands.rb +0 -4
  113. data/lib/eco/api/usecases/graphql/helpers/locations.rb +0 -6
@@ -2,11 +2,7 @@ class Eco::API::UseCases::DefaultCases::CreateCase < Eco::API::Common::Loaders::
2
2
  name "create"
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
 
@@ -23,5 +19,4 @@ class Eco::API::UseCases::DefaultCases::CreateCase < Eco::API::Common::Loaders::
23
19
  def append_created
24
20
  options.dig(:people, :append_created)
25
21
  end
26
-
27
22
  end
@@ -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
- micro = session.micro
7
- found = micro.with_each_present(entries, people, options, log_starter: true)
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, session, options, usecase)
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, session, options, usecase)
11
+ delete(people)
12
12
  end
13
-
14
13
  end
@@ -9,5 +9,4 @@ class Eco::API::UseCases::DefaultCases::EmailAsIdCase < Eco::API::Common::Loader
9
9
  update.add(person)
10
10
  end
11
11
  end
12
-
13
12
  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, :session, :options
6
+ attr_reader :people
7
7
 
8
8
  def main(entries, people, session, options, usecase)
9
- @session = session; @options = options; @people = people
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
@@ -6,5 +6,4 @@ class Eco::API::UseCases::DefaultCases::RefreshCase < Eco::API::Common::Loaders:
6
6
  update = session.new_job("main", "update", :update, usecase)
7
7
  people.each {|person| update.add(person)}
8
8
  end
9
-
10
9
  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
- micro = session.micro
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, session, options, usecase)
6
+ reinvite(people.users)
7
7
  end
8
8
 
9
9
  private
10
10
 
11
- def reinvite(users, session, options, usecase)
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, session, options, usecase)
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, session, options, usecase)
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, session, options, usecase)
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
- @session = session; @options = options
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 :session, :people, :options
5
+ attr_reader :people
6
6
 
7
7
  def main(people, session, options, usecase)
8
8
  options[:end_get] = false
9
- @session = session; @options = options; @people = people
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 :session, :people, :options
5
+ attr_reader :people
6
6
 
7
7
  def main(people, session, options, usecase)
8
8
  options[:end_get] = false
9
- @session = session; @options = options; @people = people
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, session, options).tap do |supers|
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, session, options)
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 :session, :options, :people
5
+ attr_reader :people
6
6
 
7
7
  def main(people, session, options, usecase)
8
8
  options[:end_get] = false
9
- @session = session; @options = options; @people = people
9
+ @people = people
10
10
 
11
11
  unless people && !people.empty?
12
- session.logger.warn("No source people to create the file... aborting!")
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
- session.logger.info("going to create file: #{filename}")
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
@@ -116,5 +116,4 @@ class Eco::API::UseCases::DefaultCases::ToCsvDetailedCase < Eco::API::UseCases::
116
116
  "custom_person_abilities" => "(min) on Users' Abilities"
117
117
  })
118
118
  end
119
-
120
119
  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
- attr_reader :session, :options, :usecase
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,15 @@
1
+ module Eco::API::UseCases::GraphQL::Helpers::Base
2
+ # Basic stuff you would need in any use case
3
+ module CaseEnv
4
+ include Eco::Language::AuxiliarLogger
5
+ attr_reader :session, :options
6
+
7
+ def config
8
+ session.config
9
+ end
10
+
11
+ def simulate?
12
+ options.dig(:simulate)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module Eco::API::UseCases::GraphQL::Helpers
2
+ module Base
3
+ require_relative 'base/case_env'
4
+ include Eco::API::UseCases::GraphQL::Helpers::Base::CaseEnv
5
+
6
+ def graphql
7
+ @graphql ||= session.api(version: :graphql)
8
+ end
9
+
10
+ # Keep a copy of the requests/responses for future reference
11
+ def backup(data, type:)
12
+ dry_run = simulate? ? "_dry_run" : ""
13
+ dir = config.people.requests_folder
14
+ file = File.join(dir, "#{type}#{dry_run}.json")
15
+ session.file_manager.save_json(data, file, :timestamp)
16
+ end
17
+
18
+ def exit_error(msg)
19
+ log(:error) { msg }
20
+ exit(1)
21
+ end
22
+ end
23
+ end