eco-helpers 3.0.4 → 3.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/CHANGELOG.md +55 -4
  4. data/eco-helpers.gemspec +1 -1
  5. data/lib/eco/api/common/class_helpers.rb +24 -23
  6. data/lib/eco/api/common/class_meta_basics.rb +0 -2
  7. data/lib/eco/api/common/loaders/use_case.rb +1 -0
  8. data/lib/eco/api/common/people/entry_factory.rb +6 -4
  9. data/lib/eco/api/common/people/person_entry.rb +4 -6
  10. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +25 -12
  11. data/lib/eco/api/common/people/person_parser.rb +8 -0
  12. data/lib/eco/api/common/session/base_session.rb +1 -1
  13. data/lib/eco/api/common/session/environment.rb +7 -0
  14. data/lib/eco/api/common/session/file_manager.rb +15 -8
  15. data/lib/eco/api/common/session/logger/cache.rb +14 -10
  16. data/lib/eco/api/common/session/logger/log.rb +8 -7
  17. data/lib/eco/api/common/session/mailer.rb +22 -13
  18. data/lib/eco/api/common/session/s3_uploader.rb +29 -20
  19. data/lib/eco/api/microcases/people_search.rb +1 -1
  20. data/lib/eco/api/organization/login_providers.rb +11 -4
  21. data/lib/eco/api/organization/node_classifications.rb +3 -0
  22. data/lib/eco/api/organization/presets_factory.rb +37 -31
  23. data/lib/eco/api/organization/tag_tree.rb +14 -5
  24. data/lib/eco/api/policies/default_policies/99_user_access_policy.rb +28 -18
  25. data/lib/eco/api/session/batch/errors.rb +38 -20
  26. data/lib/eco/api/session/batch/job.rb +252 -135
  27. data/lib/eco/api/session/batch/status.rb +55 -36
  28. data/lib/eco/api/session/batch.rb +2 -2
  29. data/lib/eco/api/session/config/base_config.rb +12 -11
  30. data/lib/eco/api/session/config/tagtree.rb +10 -14
  31. data/lib/eco/api/session/config/workflow.rb +15 -3
  32. data/lib/eco/api/session/config.rb +19 -26
  33. data/lib/eco/api/session.rb +13 -4
  34. data/lib/eco/api/usecases/cli.rb +4 -0
  35. data/lib/eco/api/usecases/default/locations/cli/codes_to_tags_cli.rb +18 -0
  36. data/lib/eco/api/usecases/default/locations/cli/csv_to_tree_cli.rb +12 -0
  37. data/lib/eco/api/usecases/default/locations/cli/tagtree_paths_cli.rb +12 -0
  38. data/lib/eco/api/usecases/default/locations/codes_to_tags_case.rb +32 -13
  39. data/lib/eco/api/usecases/default/locations/csv_to_tree_case.rb +15 -5
  40. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +6 -0
  41. data/lib/eco/api/usecases/default/locations/tagtree_paths_case.rb +51 -0
  42. data/lib/eco/api/usecases/default/locations.rb +1 -1
  43. data/lib/eco/api/usecases/default/people/amend/cli/reinvite_sync_cli.rb +8 -0
  44. data/lib/eco/api/usecases/default/people/amend/cli/reinvite_trans_cli.rb +11 -0
  45. data/lib/eco/api/usecases/default/people/amend/cli/restore_db_cli.rb +26 -0
  46. data/lib/eco/api/usecases/default/people/amend/reinvite_sync_case.rb +2 -0
  47. data/lib/eco/api/usecases/default/people/amend/reinvite_trans_case.rb +2 -0
  48. data/lib/eco/api/usecases/default/people/amend/restore_db_case.rb +3 -0
  49. data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +15 -5
  50. data/lib/eco/api/usecases/default/people/treat/cli/analyse_people_cli.rb +66 -0
  51. data/lib/eco/api/usecases/default/people/treat/cli/org_data_convert_cli.rb +35 -0
  52. data/lib/eco/api/usecases/default/people/treat/cli/supers_cyclic_identify_cli.rb +15 -0
  53. data/lib/eco/api/usecases/default/people/treat/cli/supers_hierachy_cli.rb +15 -0
  54. data/lib/eco/api/usecases/default/people/treat/org_data_convert_case.rb +11 -5
  55. data/lib/eco/api/usecases/default/people/treat/supers_cyclic_identify_case.rb +28 -7
  56. data/lib/eco/api/usecases/default/people/treat/supers_hierarchy_case.rb +32 -9
  57. data/lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb +2 -1
  58. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +2 -2
  59. data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +1 -0
  60. data/lib/eco/api/usecases/graphql/helpers/base/error_handling.rb +52 -0
  61. data/lib/eco/api/usecases/graphql/helpers/base.rb +1 -0
  62. data/lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb +5 -0
  63. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +2 -0
  64. data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable.rb +2 -0
  65. data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +2 -1
  66. data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +3 -0
  67. data/lib/eco/api/usecases/graphql/helpers/location/command.rb +1 -0
  68. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +3 -0
  69. data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +19 -18
  70. data/lib/eco/api/usecases/graphql/samples/location/command/results.rb +1 -7
  71. data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +11 -6
  72. data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +3 -8
  73. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/classifications.rb +2 -0
  74. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible.rb +5 -2
  75. data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +10 -4
  76. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/parser.rb +6 -2
  77. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb +2 -0
  78. data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list.rb +5 -3
  79. data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +1 -0
  80. data/lib/eco/api/usecases/ooze_samples/helpers_migration/copying.rb +66 -29
  81. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +25 -3
  82. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +10 -0
  83. data/lib/eco/api/usecases/use_case.rb +3 -1
  84. data/lib/eco/cli/config/use_cases.rb +4 -0
  85. data/lib/eco/cli/scripting/args_helpers.rb +3 -2
  86. data/lib/eco/cli/scripting/argument.rb +2 -2
  87. data/lib/eco/cli_default/input.rb +49 -45
  88. data/lib/eco/cli_default/input_filters.rb +32 -17
  89. data/lib/eco/cli_default/options.rb +8 -4
  90. data/lib/eco/cli_default/people.rb +1 -1
  91. data/lib/eco/cli_default/people_filters.rb +32 -24
  92. data/lib/eco/cli_default/usecases.rb +8 -121
  93. data/lib/eco/cli_default/workflow.rb +6 -4
  94. data/lib/eco/csv/split.rb +2 -0
  95. data/lib/eco/csv/table.rb +13 -0
  96. data/lib/eco/data/files/encoding.rb +15 -8
  97. data/lib/eco/data/files/helpers.rb +6 -2
  98. data/lib/eco/data/hashes/diff_result.rb +5 -0
  99. data/lib/eco/data/locations/node_diff/nodes_diff.rb +13 -0
  100. data/lib/eco/data/locations/node_diff.rb +4 -0
  101. data/lib/eco/data/locations/node_level.rb +6 -0
  102. data/lib/eco/language/auxiliar_logger.rb +2 -0
  103. data/lib/eco/version.rb +1 -1
  104. data/lib/eco-helpers.rb +1 -1
  105. metadata +16 -6
  106. data/lib/eco/api/usecases/default/locations/create_tag_paths_case.rb +0 -25
  107. data/lib/eco/api/usecases/default/people/amend/reinvite_trans_cli.rb +0 -4
@@ -2,11 +2,13 @@ class Eco::API::UseCases::Default::Locations::CsvToTree < Eco::API::Common::Load
2
2
  name "csv-to-tree"
3
3
  type :other
4
4
 
5
+ require_relative 'cli/csv_to_tree_cli'
6
+
5
7
  include Eco::Data::Locations::DSL
6
8
 
7
9
  TIME_FORMAT = '%Y%m%dT%H%M%S'.freeze
8
10
 
9
- def main(_session, options, _usecase)
11
+ def main(*_args)
10
12
  options[:end_get] = false
11
13
  tree_struct = org_tree(input_csv)
12
14
 
@@ -18,10 +20,6 @@ class Eco::API::UseCases::Default::Locations::CsvToTree < Eco::API::Common::Load
18
20
 
19
21
  private
20
22
 
21
- def output_file
22
- @output_file ||= "#{active_enviro}_tree_#{timestamp}.json"
23
- end
24
-
25
23
  def input_csv
26
24
  @input_csv ||= Eco::CSV.read(input_file, encoding: input_encoding)
27
25
  end
@@ -34,6 +32,18 @@ class Eco::API::UseCases::Default::Locations::CsvToTree < Eco::API::Common::Load
34
32
  options.dig(:input, :file, :encoding) || 'utf-8'
35
33
  end
36
34
 
35
+ def output_file
36
+ @output_file ||= File.join(output_folder, output_base_name)
37
+ end
38
+
39
+ def output_base_name
40
+ "#{active_enviro}_tree_#{timestamp}.json"
41
+ end
42
+
43
+ def output_folder
44
+ File.dirname(input_file)
45
+ end
46
+
37
47
  def timestamp(date = Time.now)
38
48
  date.strftime(TIME_FORMAT)
39
49
  end
@@ -116,6 +116,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
116
116
 
117
117
  def input_csv
118
118
  return unless file_as_source?
119
+
119
120
  @input_csv ||= Eco::CSV.read(file_as_source, encoding: input_encoding)
120
121
  end
121
122
 
@@ -125,6 +126,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
125
126
 
126
127
  def file_as_source?
127
128
  return true unless file_as_source.nil?
129
+
128
130
  false
129
131
  end
130
132
 
@@ -132,6 +134,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
132
134
  @file_as_source ||= options.dig(:source, :file).tap do |file|
133
135
  next if file.nil?
134
136
  next if File.exist?(file)
137
+
135
138
  log(:error) { "File '#{file}' does not exist" }
136
139
  exit 1
137
140
  end
@@ -177,6 +180,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
177
180
  def csv(filename, header = [])
178
181
  CSV.open(filename, "w") do |csv|
179
182
  csv << header unless header.empty?
183
+
180
184
  yield(csv)
181
185
  end
182
186
  ensure
@@ -203,9 +207,11 @@ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCase
203
207
  sheet = workbook.add_worksheet(name)
204
208
  #end
205
209
  sheet.auto_width = true
210
+
206
211
  yield(sheet)
207
212
 
208
213
  return unless header
214
+
209
215
  sheet.set_row(0, 30, workbook.bold_format)
210
216
  sheet.freeze_panes(1, 0)
211
217
  end
@@ -0,0 +1,51 @@
1
+ class Eco::API::UseCases::Default::Locations::TagTreePaths < Eco::API::Common::Loaders::UseCase
2
+ name "tagtree-paths"
3
+ type :other
4
+
5
+ require_relative 'cli/tagtree_paths_cli'
6
+
7
+ OUT_FOLDER = "sftp".freeze
8
+ OUT_TIME_FORMAT = '%Y%m%dT%H%M%S'.freeze
9
+ OUT_FILENAME = "tag_paths".freeze
10
+
11
+ def main(*_args)
12
+ CSV.open(output_filename, "w") do |csv|
13
+ csv << %w[Tag Path]
14
+ tag_paths.each do |values|
15
+ csv << values
16
+ end
17
+ end
18
+
19
+ log(:info) {
20
+ "Generated file '#{output_filename}'"
21
+ }
22
+ end
23
+
24
+ private
25
+
26
+ def tag_paths
27
+ @tag_paths ||= tagtree.tags.reverse.map do |tag|
28
+ [tag, tagtree.path(tag).join("|")]
29
+ end
30
+ end
31
+
32
+ def tagtree
33
+ session.tagtree
34
+ end
35
+
36
+ def output_file_format
37
+ 'csv'
38
+ end
39
+
40
+ def output_filename(name = self.class::OUT_FILENAME)
41
+ File.join(output_folder, "#{timestamp}_#{config.active_enviro}_#{name}.#{output_file_format}")
42
+ end
43
+
44
+ def output_folder
45
+ "#{config.active_enviro}/#{self.class::OUT_FOLDER}"
46
+ end
47
+
48
+ def timestamp(date = Time.now)
49
+ date.strftime(self.class::OUT_TIME_FORMAT)
50
+ end
51
+ end
@@ -10,7 +10,7 @@ module Eco
10
10
  end
11
11
 
12
12
  require_relative 'locations/codes_to_tags_case'
13
- require_relative 'locations/create_tag_paths_case'
13
+ require_relative 'locations/tagtree_paths_case'
14
14
  require_relative 'locations/csv_to_tree_case'
15
15
  require_relative 'locations/tagtree_extract_case'
16
16
  require_relative 'locations/tagtree_upload_case'
@@ -0,0 +1,8 @@
1
+ class Eco::API::UseCases::Default::People::Amend::ReinviteSyncCase
2
+ class Cli < Eco::API::UseCases::Default::People::Amend::ReinviteTransCase::Cli
3
+ str = "Re-sends invites to target users that have not accepted the invite as yet"
4
+ desc str
5
+
6
+ cli_name '-reinvite-from'
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ class Eco::API::UseCases::Default::People::Amend::ReinviteTransCase
2
+ class Cli < Eco::API::UseCases::Cli
3
+ str = "Re-sends invites to all filtered users that have not accepted the invite as yet"
4
+ desc str
5
+
6
+ str = "If also send an invite email to those that have accepted the invite"
7
+ add_option("-force", str) do |options|
8
+ options.deep_merge!(force: {invite: true})
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ class Eco::API::UseCases::Default::People::Amend::RestoreDBCase
2
+ class Cli < Eco::API::UseCases::Cli
3
+ str = "Restores the people manager by using a backup.json file"
4
+ desc str
5
+
6
+ callback do |input, session, _opts, _case|
7
+ unless input && input.is_a?(Eco::API::Organization::People)
8
+ file = SCR.get_file(cli_name, required: true)
9
+ input = Eco::API::Organization::People.new(JSON.parse(File.read(file)))
10
+ session.log(:info) {
11
+ "Source DB: loaded #{input.length} entries."
12
+ }
13
+ end
14
+ end
15
+
16
+ str = "If it should DELETE people that do not exist in the backup file"
17
+ add_option("-include-delete", str) do |options|
18
+ options.deep_merge!(include: {delete: true})
19
+ end
20
+
21
+ str = "If it should CREATE people that do not exist in the people manager"
22
+ add_option("-include-create", str) do |options|
23
+ options.deep_merge!(include: {create: true})
24
+ end
25
+ end
26
+ end
@@ -3,6 +3,8 @@ module Eco::API::UseCases::Default::People::Amend
3
3
  name "reinvite"
4
4
  type :sync
5
5
 
6
+ require_relative 'cli/reinvite_sync_cli'
7
+
6
8
  def main(entries, *_args)
7
9
  found = micro.with_each_present(entries, people, options, log_starter: true)
8
10
  reinvite(found.users)
@@ -2,6 +2,8 @@ class Eco::API::UseCases::Default::People::Amend::ReinviteTransCase < Eco::API::
2
2
  name "reinvite"
3
3
  type :transform
4
4
 
5
+ require_relative 'cli/reinvite_trans_cli'
6
+
5
7
  def main(*_args)
6
8
  reinvite(people.users)
7
9
  end
@@ -4,6 +4,8 @@ class Eco::API::UseCases::Default::People::Amend::RestoreDBCase < Eco::API::Comm
4
4
  name "restore-db"
5
5
  type :sync
6
6
 
7
+ require_relative 'cli/restore_db_cli'
8
+
7
9
  def main(entries, people, session, options, usecase) # rubocop:disable Metrics/AbcSize
8
10
  require_people_as_entries!(entries)
9
11
 
@@ -52,6 +54,7 @@ class Eco::API::UseCases::Default::People::Amend::RestoreDBCase < Eco::API::Comm
52
54
 
53
55
  def account_copy(src, dst) # rubocop:disable Metrics/AbcSize
54
56
  return unless src
57
+
55
58
  dst.default_tag = src.default_tag unless options.dig(:exclude, :filter_tags)
56
59
  dst.policy_group_ids = src.policy_group_ids unless options.dig(:exclude, :policy_groups)
57
60
  dst.permissions_custom = src.permissions_custom unless options.dig(:exclude, :abilities)
@@ -2,6 +2,8 @@ class Eco::API::UseCases::Default::People::Treat::Analyse < Eco::API::Common::Lo
2
2
  name "analyse-people"
3
3
  type :export
4
4
 
5
+ require_relative 'cli/analyse_people_cli'
6
+
5
7
  attr_reader :people
6
8
 
7
9
  def main(_people, _session, options, _usecase)
@@ -26,12 +28,14 @@ class Eco::API::UseCases::Default::People::Treat::Analyse < Eco::API::Common::Lo
26
28
  def identify_unnamed
27
29
  similarity_analytics.unnamed.tap do |unnamed|
28
30
  next unless unnamed.empty?
31
+
29
32
  log(:info) { "There were no people with no name!!" }
30
33
  end
31
34
  end
32
35
 
33
36
  def identify_duplicates
34
37
  analysed = similarity_screening
38
+
35
39
  if case_options[:ignore_matching_words]
36
40
  log(:info) { "Fine tune results by ignoring matching words..." }
37
41
  analysed = strict_similarity(analysed)
@@ -155,7 +159,9 @@ class Eco::API::UseCases::Default::People::Treat::Analyse < Eco::API::Common::Lo
155
159
 
156
160
  def save!(data)
157
161
  ext = File.extname(output_file).downcase.delete(".")
158
- session.logger.info("Generating file '#{output_file}'")
162
+
163
+ log(:info) { "Generating file '#{output_file}'" }
164
+
159
165
  File.open(output_file, "w") do |fd|
160
166
  case ext
161
167
  when "txt"
@@ -184,11 +190,15 @@ class Eco::API::UseCases::Default::People::Treat::Analyse < Eco::API::Common::Lo
184
190
  # A way to use command line to specify part
185
191
  # => i.e. person.details[first-name]
186
192
  def attribute_access(person, expression)
187
- parts = expression.split(".")
193
+ parts = expression.split('.')
194
+
188
195
  parts_to_value(person, parts).tap do |value|
189
- unless value.is_a?(String) || !value
190
- raise "Something is wrong with #{expression} to parts #{parts}. Expecting String, obtained: #{value.class}"
191
- end
196
+ next if value.is_a?(String)
197
+ next unless value
198
+
199
+ msg = "Something is wrong with #{expression} to parts #{parts}. "
200
+ msg << "Expecting String, obtained: #{value.class}"
201
+ raise msg
192
202
  end
193
203
  end
194
204
 
@@ -0,0 +1,66 @@
1
+ class Eco::API::UseCases::Default::People::Treat::Analyse
2
+ class Cli < Eco::API::UseCases::Cli
3
+ str = "Provides a set of tools to analyse a set of people (i.e. detect duplicates)"
4
+ desc str
5
+
6
+ callback do |_people, _session, options|
7
+ options.deep_merge!(output: {file: "people_analysis.txt"}) unless options.dig(:output, :file)
8
+ #unless options.dig(:usecase, :analyse_people, :use_field)
9
+ # options.deep_merge!(usecase: {analyse_people: {use_field: :name}})
10
+ #end
11
+ end
12
+
13
+ add_option("-to", "Specify the output file.") do |options|
14
+ file = SCR.get_file("-to", required: true, should_exist: false)
15
+ options.deep_merge!(output: {file: file})
16
+ end
17
+
18
+ str = "Generates a list of people with possible duplicates."
19
+ add_option("-identify-duplicates", str) do |options|
20
+ options.deep_merge!(usecase: {analyse_people: {identify_duplicates: true}})
21
+ end
22
+
23
+ str = "Works with -identify-duplicates. Sets field to be used in the comparison."
24
+ add_option("-use-field", str) do |options|
25
+ expression = SCR.get_arg("-use-field", with_param: true)
26
+ options.deep_merge!(usecase: {analyse_people: {use_field: expression}})
27
+ end
28
+
29
+ str = "Works with -identify-duplicates. Adds an additional layer of comparison."
30
+ add_option("-facet-field", str) do |options|
31
+ expression = SCR.get_arg("-facet-field", with_param: true)
32
+ options.deep_merge!(usecase: {analyse_people: {facet_field: expression}})
33
+ end
34
+
35
+ str = "Works with -identify-duplicates. Skips the rearrangement stage."
36
+ add_option("-only-screening", str) do |options|
37
+ options.deep_merge!(usecase: {analyse_people: {only_screening: true}})
38
+ end
39
+
40
+ str = "Works with -identify-duplicates. Re-adjust scores ignoring matching words."
41
+ add_option("-ignore-matching-words", str) do |options|
42
+ options.deep_merge!(usecase: {analyse_people: {ignore_matching_words: true}})
43
+ end
44
+
45
+ str = "Works with -identify-duplicates. Re-adjust the comparing strings to do not have repeated words."
46
+ add_option("-unique-words", str) do |options|
47
+ options.deep_merge!(usecase: {analyse_people: {unique_words: true}})
48
+ end
49
+
50
+ add_option("-identify-unnamed", "Identifies all people with no names.") do |options|
51
+ options.deep_merge!(usecase: {analyse_people: {identify_unnamed: true}})
52
+ end
53
+
54
+ str = "Generates a json file with all the people involved in the final results of the analysis."
55
+ add_option("-backup-people-results", str) do |options|
56
+ file = SCR.get_file("-backup-people-results", required: true, should_exist: false)
57
+ options.deep_merge!(usecase: {analyse_people: {backup_people: File.expand_path(file)}})
58
+ end
59
+
60
+ str = "Genarates a CSV file with all people of the final results."
61
+ add_option("-to-csv", str) do |options|
62
+ file = SCR.get_file("-to-csv", required: true, should_exist: false) || "Results.csv"
63
+ options.deep_merge!(usecase: {analyse_people: {csv_file: File.expand_path(file)}})
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,35 @@
1
+ class Eco::API::UseCases::Default::People::Treat::OrgDataConvertCase
2
+ class Cli < Eco::API::UseCases::Cli
3
+ str = "Usage '#{cli_name} backup.json -restore-db-from'."
4
+ str << " Transforms an input .json file to the values of the destination environment "
5
+ str << " (names missmatch won't solve: i.e. usergroups)"
6
+ desc str
7
+
8
+ callback do |input, session, options|
9
+ unless input.is_a?(Eco::API::Organization::People)
10
+ file = SCR.get_file(cli_name, required: true)
11
+ input = Eco::API::Organization::People.new(JSON.parse(File.read(file)))
12
+ session.log(:info) {
13
+ "Source DB: loaded #{input.length} entries."
14
+ }
15
+ end
16
+
17
+ unless options[:source_enviro]
18
+ session.log(:error) {
19
+ "You need to specify a -source-enviro for the conversion to work out"
20
+ }
21
+ exit(1)
22
+ end
23
+ end
24
+
25
+ str = "The defined -source-enviro API configuration that the backup file was generated from"
26
+ add_option("-source-enviro", str) do |options|
27
+ options.merge!(source_enviro: SCR.get_arg("-source-enviro", with_param: true))
28
+ end
29
+
30
+ str = "Prevents the script to crash when backup file has missing usergroups in the org"
31
+ add_option("-ignore-missing-policy-groups", str) do |options|
32
+ options.deep_merge!(ignore: {missing: {policy_groups: true}})
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ class Eco::API::UseCases::Default::People::Treat::SupersCyclicIdentify
2
+ class Cli < Eco::API::UseCases::Cli
3
+ str = "Provides a set of tools to analyse a set of people (i.e. detect duplicates)"
4
+ desc str
5
+
6
+ # callback do |_people, _session, options|
7
+ # options.deep_merge!(output: {file: "cyclic_supers.txt"}) unless options.dig(:output, :file)
8
+ # end
9
+
10
+ add_option("-to", "Specify the output file") do |options|
11
+ file = SCR.get_file("-to", required: true, should_exist: false)
12
+ options.deep_merge!(output: {file: file})
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ class Eco::API::UseCases::Default::People::Treat::SupersHierarchy
2
+ class Cli < Eco::API::UseCases::Cli
3
+ str = "Draws the Supervisors hiearchy in a file"
4
+ desc str
5
+
6
+ # callback do |_people, _session, options|
7
+ # options.deep_merge!(output: {file: "supers_hierarchy.txt"}) unless options.dig(:output, :file)
8
+ # end
9
+
10
+ add_option("-to", "Specify the output file") do |options|
11
+ file = SCR.get_file("-to", required: true, should_exist: false)
12
+ options.deep_merge!(output: {file: file})
13
+ end
14
+ end
15
+ end
@@ -2,6 +2,12 @@ class Eco::API::UseCases::Default::People::Treat::OrgDataConvertCase < Eco::API:
2
2
  name "org-data-convert"
3
3
  type :import
4
4
 
5
+ require_relative 'cli/org_data_convert_cli'
6
+
7
+ def main(people, _session, _options, _usecase)
8
+ org_data_convert(people)
9
+ end
10
+
5
11
  def org_data_convert(people)
6
12
  log(:info) {
7
13
  "Going to convert data from '#{source_enviro}' to '#{ASSETS.active_config}'"
@@ -22,14 +28,11 @@ class Eco::API::UseCases::Default::People::Treat::OrgDataConvertCase < Eco::API:
22
28
  people
23
29
  end
24
30
 
25
- def main(people, _session, _options, _usecase)
26
- org_data_convert(people)
27
- end
28
-
29
31
  private
30
32
 
31
33
  def account_convert!(person)
32
34
  return unless (account = person.account)
35
+
33
36
  account.policy_group_ids = policy_groups_convert(account.policy_group_ids)
34
37
  account.doc.tap do |doc|
35
38
  %w[login_provider_ids starred_ids landing_page_id].map do |attr|
@@ -40,6 +43,7 @@ class Eco::API::UseCases::Default::People::Treat::OrgDataConvertCase < Eco::API:
40
43
 
41
44
  def details_convert!(person)
42
45
  return unless person.details
46
+
43
47
  person.details.as_json.tap do |details_doc|
44
48
  details_doc["schema_id"] = session.schema.id
45
49
  person.add_details(session.schema)
@@ -50,11 +54,13 @@ class Eco::API::UseCases::Default::People::Treat::OrgDataConvertCase < Eco::API:
50
54
  def policy_groups_convert(ids)
51
55
  ids.map do |id|
52
56
  name = source_policy_groups.to_name(id)
57
+
53
58
  unless name || ignore_missing_policy_groups?
54
59
  msg = "Ops, do not know #{id} usergroup for source environment"
55
60
  msg << "\nUse the option -ignore-missing-policy-groups if you do not care"
56
61
  error(msg)
57
62
  end
63
+
58
64
  session.policy_groups.to_id(name).tap do |new_id|
59
65
  unless new_id || ignore_missing_policy_groups?
60
66
  msg = "Ops, do not know #{name} usergroup for destination environment"
@@ -88,7 +94,7 @@ class Eco::API::UseCases::Default::People::Treat::OrgDataConvertCase < Eco::API:
88
94
  end
89
95
 
90
96
  def error(msg)
91
- logger.error(msg)
97
+ log(:error) { msg }
92
98
  exit(1)
93
99
  end
94
100
  end
@@ -1,7 +1,13 @@
1
1
  class Eco::API::UseCases::Default::People::Treat::SupersCyclicIdentify < Eco::API::Common::Loaders::UseCase
2
- name "identify-cyclic-supers"
2
+ name 'identify-cyclic-supers'
3
3
  type :export
4
4
 
5
+ require_relative 'cli/supers_cyclic_identify_cli'
6
+
7
+ OUT_FOLDER = "sftp".freeze
8
+ OUT_TIME_FORMAT = '%Y%m%dT%H%M%S'.freeze
9
+ OUT_FILENAME = "cyclic_supers".freeze
10
+
5
11
  attr_reader :people
6
12
 
7
13
  def main(_people, _session, options, _usecase)
@@ -15,10 +21,6 @@ class Eco::API::UseCases::Default::People::Treat::SupersCyclicIdentify < Eco::AP
15
21
  Eco::API::Common::People::SupervisorHelpers.identify_cyclic_chains(people)
16
22
  end
17
23
 
18
- def file
19
- @file ||= options.dig(:output, :file) || "cyclic_supers.txt"
20
- end
21
-
22
24
  def save!(data)
23
25
  if data.empty?
24
26
  log(:info) { "There were no cyclic supervisors identified!!" }
@@ -29,7 +31,7 @@ class Eco::API::UseCases::Default::People::Treat::SupersCyclicIdentify < Eco::AP
29
31
 
30
32
  case ext
31
33
  when "txt"
32
- create_file(data, file: file, format: :txt)
34
+ create_file(data, file: output_filename(ext: 'txt'), format: :txt)
33
35
  when "html"
34
36
  log(:warn) { "html is still not supported" }
35
37
  exit(1)
@@ -45,7 +47,10 @@ class Eco::API::UseCases::Default::People::Treat::SupersCyclicIdentify < Eco::AP
45
47
  File.open(file, "w") do |fd|
46
48
  fd << sets_to_str(sets, format: format)
47
49
  end
48
- puts "Generated file #{file}"
50
+
51
+ log(:info) {
52
+ "Generated file #{file}"
53
+ }
49
54
  end
50
55
 
51
56
  def sets_to_str(sets, format: :txt)
@@ -70,4 +75,20 @@ class Eco::API::UseCases::Default::People::Treat::SupersCyclicIdentify < Eco::AP
70
75
  str << set_to_str(set, lev: lev + 1, format: format)
71
76
  end
72
77
  end
78
+
79
+ def output_filename(ext: nil)
80
+ @output_filename ||= options.dig(:output, :file) || default_output_filename(ext: ext)
81
+ end
82
+
83
+ def default_output_filename(name = self.class::OUT_FILENAME, ext: nil)
84
+ File.join(output_folder, "#{timestamp}_#{config.active_enviro}_#{name}.#{ext}")
85
+ end
86
+
87
+ def output_folder
88
+ "#{config.active_enviro}/#{self.class::OUT_FOLDER}"
89
+ end
90
+
91
+ def timestamp(date = Time.now)
92
+ date.strftime(self.class::OUT_TIME_FORMAT)
93
+ end
73
94
  end
@@ -2,13 +2,19 @@ class Eco::API::UseCases::Default::People::Treat::SupersHierarchy < Eco::API::Co
2
2
  name "supers-hierarchy"
3
3
  type :export
4
4
 
5
+ require_relative 'cli/supers_hierachy_cli'
6
+
7
+ OUT_FOLDER = "sftp".freeze
8
+ OUT_TIME_FORMAT = '%Y%m%dT%H%M%S'.freeze
9
+ OUT_FILENAME = "supers_hierarchy".freeze
10
+
5
11
  attr_reader :people
6
12
 
7
13
  def main(people, _session, options, _usecase)
8
14
  options[:end_get] = false
9
15
  @people = people
10
16
 
11
- save!(hierarchy)
17
+ save!(hierarchy, file: output_filename)
12
18
  end
13
19
 
14
20
  private
@@ -17,11 +23,7 @@ class Eco::API::UseCases::Default::People::Treat::SupersHierarchy < Eco::API::Co
17
23
  Eco::API::Common::People::SupervisorHelpers.supervisors_tree(people)
18
24
  end
19
25
 
20
- def file
21
- @file ||= options.dig(:output, :file) || "supers_hierarchy.txt"
22
- end
23
-
24
- def save!(data)
26
+ def save!(data, file:)
25
27
  ext = File.extname(file).downcase.delete(".")
26
28
 
27
29
  case ext
@@ -42,18 +44,39 @@ class Eco::API::UseCases::Default::People::Treat::SupersHierarchy < Eco::API::Co
42
44
  File.open(file, "w") do |fd|
43
45
  fd << tree_to_str(tree, format: format)
44
46
  end
45
- puts "Generated file #{file}"
47
+
48
+ log(:info) {
49
+ "Generated file #{file}"
50
+ }
46
51
  end
47
52
 
48
53
  def tree_to_str(tree, lev: 0, format: :txt)
49
- raise "Required Hash tree structure. Given: #{tree.class}" unless tree.is_a?(Hash)
54
+ msg = "Required Hash tree structure. Given: #{tree.class}"
55
+ raise msg unless tree.is_a?(Hash)
56
+
50
57
  "".tap do |str|
51
58
  tree.each do |entry, subtree|
52
59
  str << "#{" " * lev}#{lev.positive? ? "+-#{lev}- " : ""}"
53
- str << entry.name
60
+ str << (entry.name || entry.email || entry.external_id || entry.id)
54
61
  str << " (#{entry.external_id}|#{entry.email}|#{entry.id})\n"
55
62
  str << tree_to_str(subtree, lev: lev + 1, format: format) unless !subtree || subtree.empty?
56
63
  end
57
64
  end
58
65
  end
66
+
67
+ def output_filename(ext: 'txt')
68
+ @output_filename ||= options.dig(:output, :file) || default_output_filename(ext: ext)
69
+ end
70
+
71
+ def default_output_filename(name = self.class::OUT_FILENAME, ext: nil)
72
+ File.join(output_folder, "#{timestamp}_#{config.active_enviro}_#{name}.#{ext}")
73
+ end
74
+
75
+ def output_folder
76
+ "#{config.active_enviro}/#{self.class::OUT_FOLDER}"
77
+ end
78
+
79
+ def timestamp(date = Time.now)
80
+ date.strftime(self.class::OUT_TIME_FORMAT)
81
+ end
59
82
  end
@@ -23,7 +23,7 @@ class Eco::API::UseCases::Default::People::Utils::SetDefaultTagCase < Eco::API::
23
23
  return unless tagtree?
24
24
 
25
25
  msg = "There is no locs struct defined. Aborting..."
26
- logger.fatal(msg)
26
+ log(:fatal) { msg }
27
27
  raise msg
28
28
  end
29
29
 
@@ -39,6 +39,7 @@ class Eco::API::UseCases::Default::People::Utils::SetDefaultTagCase < Eco::API::
39
39
 
40
40
  def tagtree?
41
41
  return false unless (tree = session.tagtree)
42
+
42
43
  !tree.empty?
43
44
  end
44
45
  end
@@ -2,7 +2,7 @@ class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::U
2
2
  name "to-csv"
3
3
  type :export
4
4
 
5
- OUT_FILENAME = 'pm'
5
+ OUT_FILENAME = 'pm'.freeze
6
6
 
7
7
  attr_reader :people
8
8
 
@@ -30,7 +30,7 @@ class Eco::API::UseCases::DefaultCases::ToCsvCase < Eco::API::Common::Loaders::U
30
30
  private
31
31
 
32
32
  def create_file!(filename = file, data = people)
33
- logger.info("going to create file: #{filename}")
33
+ session.log(:info) { "going to create file: #{filename}" }
34
34
 
35
35
  CSV.open(filename, "w") do |csv|
36
36
  csv << spot_header(data.first)
@@ -2,6 +2,7 @@ module Eco::API::UseCases::GraphQL::Helpers::Base
2
2
  # Basic stuff you would need in any use case
3
3
  module CaseEnv
4
4
  include Eco::Language::AuxiliarLogger
5
+ include ErrorHandling
5
6
 
6
7
  private
7
8