eco-helpers 2.5.10 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/CHANGELOG.md +132 -4
  4. data/README.md +5 -0
  5. data/eco-helpers.gemspec +20 -16
  6. data/lib/eco/api/common/class_helpers.rb +1 -1
  7. data/lib/eco/api/common/loaders/base.rb +2 -9
  8. data/lib/eco/api/common/loaders/case_base.rb +0 -2
  9. data/lib/eco/api/common/loaders/config/workflow/mailer.rb +78 -0
  10. data/lib/eco/api/common/loaders/config/workflow.rb +11 -0
  11. data/lib/eco/api/common/loaders/config.rb +29 -0
  12. data/lib/eco/api/common/loaders/error_handler.rb +0 -2
  13. data/lib/eco/api/common/loaders/parser.rb +0 -1
  14. data/lib/eco/api/common/loaders/policy.rb +0 -2
  15. data/lib/eco/api/common/loaders/use_case.rb +27 -1
  16. data/lib/eco/api/common/loaders.rb +1 -0
  17. data/lib/eco/api/common/people/default_parsers.rb +2 -2
  18. data/lib/eco/api/common/people/person_entry.rb +3 -0
  19. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +111 -16
  20. data/lib/eco/api/common/session/base_session.rb +4 -0
  21. data/lib/eco/api/common/session/environment.rb +4 -0
  22. data/lib/eco/api/common/session/mailer.rb +3 -1
  23. data/lib/eco/api/common/session/sftp.rb +1 -1
  24. data/lib/eco/api/common/version_patches/exception.rb +2 -2
  25. data/lib/eco/api/common/version_patches/ruby3/object.rb +18 -0
  26. data/lib/eco/api/common/version_patches/ruby3.rb +1 -0
  27. data/lib/eco/api/common/version_patches.rb +3 -0
  28. data/lib/eco/api/custom/config.rb +10 -0
  29. data/lib/eco/api/custom/mailer.rb +9 -0
  30. data/lib/eco/api/custom/namespace.rb +2 -0
  31. data/lib/eco/api/custom/workflow.rb +9 -0
  32. data/lib/eco/api/custom.rb +3 -0
  33. data/lib/eco/api/organization/tag_tree.rb +20 -23
  34. data/lib/eco/api/session/batch/base_policy.rb +13 -5
  35. data/lib/eco/api/session/batch/job.rb +14 -11
  36. data/lib/eco/api/session/batch/jobs.rb +2 -2
  37. data/lib/eco/api/session/batch/jobs_groups.rb +2 -2
  38. data/lib/eco/api/session/config/files.rb +2 -2
  39. data/lib/eco/api/session/config/people.rb +2 -2
  40. data/lib/eco/api/session/config/sftp.rb +4 -0
  41. data/lib/eco/api/session/config/tagtree.rb +9 -8
  42. data/lib/eco/api/session/config/workflow.rb +95 -58
  43. data/lib/eco/api/session/config.rb +9 -2
  44. data/lib/eco/api/session.rb +17 -2
  45. data/lib/eco/api/usecases/base_io.rb +50 -4
  46. data/lib/eco/api/usecases/cli/dsl.rb +94 -0
  47. data/lib/eco/api/usecases/cli/option.rb +19 -0
  48. data/lib/eco/api/usecases/cli.rb +13 -0
  49. data/lib/eco/api/usecases/default/locations/cli/tagtree_extract_cli.rb +29 -0
  50. data/lib/eco/api/usecases/{default_cases → default/locations}/codes_to_tags_case.rb +1 -1
  51. data/lib/eco/api/usecases/{default_cases → default/locations}/create_tag_paths_case.rb +1 -1
  52. data/lib/eco/api/usecases/{default_cases → default/locations}/csv_to_tree_case.rb +1 -1
  53. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +181 -0
  54. data/lib/eco/api/usecases/default/locations.rb +15 -0
  55. data/lib/eco/api/usecases/{default_cases → default/people}/analyse_people_case.rb +1 -1
  56. data/lib/eco/api/usecases/{default_cases → default/people}/change_email_case.rb +1 -1
  57. data/lib/eco/api/usecases/default/people/clean_unknown_tags_case.rb +66 -0
  58. data/lib/eco/api/usecases/{default_cases → default/people}/clear_abilities_case.rb +1 -1
  59. data/lib/eco/api/usecases/{default_cases → default/people}/org_data_convert_case.rb +1 -1
  60. data/lib/eco/api/usecases/{default_cases → default/people}/refresh_case.rb +1 -1
  61. data/lib/eco/api/usecases/{default_cases → default/people}/reinvite_sync_case.rb +1 -1
  62. data/lib/eco/api/usecases/{default_cases → default/people}/reinvite_trans_case.rb +1 -1
  63. data/lib/eco/api/usecases/default/people/reinvite_trans_cli.rb +5 -0
  64. data/lib/eco/api/usecases/{default_cases → default/people}/restore_db_case.rb +1 -1
  65. data/lib/eco/api/usecases/{default_cases → default/people}/set_default_tag_case.rb +1 -1
  66. data/lib/eco/api/usecases/{default_cases → default/people}/supers_cyclic_identify_case.rb +1 -1
  67. data/lib/eco/api/usecases/{default_cases → default/people}/supers_hierarchy_case.rb +1 -1
  68. data/lib/eco/api/usecases/{default_cases → default/people}/switch_supervisor_case.rb +1 -1
  69. data/lib/eco/api/usecases/{default_cases → default/people}/transfer_account_case.rb +1 -1
  70. data/lib/eco/api/usecases/default/people.rb +25 -0
  71. data/lib/eco/api/usecases/default.rb +16 -0
  72. data/lib/eco/api/usecases/default_cases/samples/cli/sftp_cli.rb +46 -0
  73. data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +21 -9
  74. data/lib/eco/api/usecases/default_cases.rb +2 -30
  75. data/lib/eco/api/usecases/graphql/helpers/location/base.rb +1 -2
  76. data/lib/eco/api/usecases/graphql/utils/sftp.rb +1 -1
  77. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +3 -3
  78. data/lib/eco/api/usecases/use_case.rb +31 -7
  79. data/lib/eco/api/usecases/use_case_chain.rb +2 -2
  80. data/lib/eco/api/usecases.rb +4 -1
  81. data/lib/eco/assets.rb +3 -5
  82. data/lib/eco/cli/config/filters/people_filters.rb +0 -1
  83. data/lib/eco/cli/config/filters.rb +2 -6
  84. data/lib/eco/cli/config/help.rb +0 -1
  85. data/lib/eco/cli/config/input.rb +0 -1
  86. data/lib/eco/cli/config/options_set.rb +3 -4
  87. data/lib/eco/cli/config/use_cases.rb +13 -6
  88. data/lib/eco/cli/config.rb +4 -5
  89. data/lib/eco/cli/scripting/args_helpers.rb +1 -1
  90. data/lib/eco/cli/scripting/argument.rb +0 -1
  91. data/lib/eco/cli/scripting/arguments.rb +0 -2
  92. data/lib/eco/cli.rb +0 -1
  93. data/lib/eco/{cli/config/default → cli_default}/input_filters.rb +0 -1
  94. data/lib/eco/{cli/config/default → cli_default}/people_filters.rb +0 -1
  95. data/lib/eco/{cli/config/default → cli_default}/usecases.rb +2 -52
  96. data/lib/eco/cli_default/workflow.rb +171 -0
  97. data/lib/eco/cli_default.rb +13 -0
  98. data/lib/eco/csv/table.rb +0 -1
  99. data/lib/eco/data/files/encoding.rb +1 -1
  100. data/lib/eco/data/files/helpers.rb +1 -1
  101. data/lib/eco/data/locations/convert.rb +8 -4
  102. data/lib/eco/data/locations/node_base/csv_convert.rb +4 -4
  103. data/lib/eco/data/locations/node_base/tag_validations.rb +19 -9
  104. data/lib/eco/data/locations/node_base/treeify.rb +193 -18
  105. data/lib/eco/data/locations/node_level.rb +1 -1
  106. data/lib/eco/data/locations/node_plain/parsing.rb +1 -1
  107. data/lib/eco/data/locations/node_plain/serial.rb +1 -1
  108. data/lib/eco/data/locations/node_plain.rb +4 -3
  109. data/lib/eco/data/mapper.rb +6 -1
  110. data/lib/eco/language/klass/when_inherited.rb +17 -0
  111. data/lib/eco/language/klass.rb +8 -0
  112. data/lib/eco/language/methods/delegate_missing.rb +28 -0
  113. data/lib/eco/language/methods/dsl_able.rb +25 -0
  114. data/lib/eco/language/methods.rb +9 -0
  115. data/lib/eco/language.rb +2 -0
  116. data/lib/eco/version.rb +1 -1
  117. metadata +169 -79
  118. data/lib/eco/api/usecases/default_cases/abstract_policygroup_abilities_case.rb +0 -160
  119. data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +0 -14
  120. data/lib/eco/api/usecases/default_cases/clean_unknown_tags_case.rb +0 -74
  121. data/lib/eco/api/usecases/default_cases/create_details_case.rb +0 -20
  122. data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +0 -21
  123. data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +0 -12
  124. data/lib/eco/api/usecases/default_cases/new_email_case.rb +0 -13
  125. data/lib/eco/api/usecases/default_cases/new_id_case.rb +0 -12
  126. data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +0 -10
  127. data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +0 -16
  128. data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +0 -18
  129. data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +0 -16
  130. data/lib/eco/api/usecases/default_cases/tagtree_case.rb +0 -42
  131. data/lib/eco/api/usecases/default_cases/update_details_case.rb +0 -15
  132. data/lib/eco/cli/config/default/workflow.rb +0 -188
  133. data/lib/eco/cli/config/default.rb +0 -16
  134. /data/lib/eco/{cli/config/default → cli_default}/input.rb +0 -0
  135. /data/lib/eco/{cli/config/default → cli_default}/options.rb +0 -0
  136. /data/lib/eco/{cli/config/default → cli_default}/people.rb +0 -0
@@ -0,0 +1,181 @@
1
+ # Use case to export an org tree into some of the offered forms.
2
+ class Eco::API::UseCases::Default::Locations::TagtreeExtract < Eco::API::UseCases::GraphQL::Samples::Location
3
+ require_relative 'cli/tagtree_extract_cli'
4
+ #cli self::Cli
5
+
6
+ name "export-tree"
7
+ type :other
8
+
9
+ include Eco::Data::Files
10
+
11
+ OUT_FOLDER = "sftp"
12
+ OUT_TIME_FORMAT = '%Y%m%dT%H%M%S'
13
+ OUT_FILENAME = "live_tree"
14
+
15
+ def process
16
+ case format
17
+ when :excel_tree, :excel_nodes
18
+ excel(output_filename) do |workbook|
19
+ tag_trees.each do |tree|
20
+ excel_sheet(workbook, compact_name(tree.name), header: format == :excel_nodes) do |sheet|
21
+ tree_extract(tree).each_with_index do |row, idx|
22
+ sheet.append_row(row)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ when :list, :nodes, :csv_tree, :json
28
+ tag_trees.each do |tree|
29
+ file(output_filename(compact_name(tree.name))) do |fd|
30
+ fd << tree_extract(tree)
31
+ end
32
+ end
33
+ else
34
+ log(:error) { "Unknown selected output format '#{format}'. Abort..." }
35
+ exit 1
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def compact_name(str)
42
+ str.gsub(/\s+/, "_")[0..30]
43
+ end
44
+
45
+ def str_node_attrs
46
+ options.dig(:output, :attrs) || [:id]
47
+ end
48
+
49
+ def tree_extract(tree)
50
+ case format
51
+ when :list
52
+ to_indented_list(tree)
53
+ when :csv_tree
54
+ with_ancestors(csv_tree(tree, attrs: str_node_attrs)).to_csv
55
+ when :excel_tree
56
+ with_ancestors(csv_tree(tree, attrs: str_node_attrs)).to_a
57
+ when :nodes
58
+ csv_list(tree).to_csv
59
+ when :excel_nodes
60
+ csv_list(tree).to_a
61
+ when :json
62
+ hash_tree(tree).to_json
63
+ else
64
+ log(:error) { "Unsupported or must use a different function for '#{format}'. Aboart..."}
65
+ exit 1
66
+ end
67
+ rescue StandardError => err
68
+ log(:error) { "Something went wrong whene extracting '#{tree.name}':\n • #{err}" }
69
+ exit 1
70
+ end
71
+
72
+ def with_ancestors(csv)
73
+ return csv unless include_ancestors?
74
+ # TODO: transform table so it includes previous row's ancestors up to the node level
75
+ csv
76
+ end
77
+
78
+ def format
79
+ options.dig(:output, :format)&.to_sym || :list
80
+ end
81
+
82
+ def indentation
83
+ options.dig(:output, :indent) || " "
84
+ end
85
+
86
+ def output_file_format
87
+ case format
88
+ when :list; 'txt'
89
+ when :nodes; 'csv'
90
+ when :csv_tree; 'csv'
91
+ when :json; 'json'
92
+ when :excel_tree; 'xlsx'
93
+ when :excel_nodes; 'xlsx'
94
+ else
95
+ 'txt'
96
+ end
97
+ end
98
+
99
+ def tag_trees
100
+ @tag_trees ||= session.live_trees(include_archived: include_archived?).reject do |tree|
101
+ tree.empty?.tap do |rejected|
102
+ log(:warn) { "Tree '#{tree.name}' does NOT have location nodes. Skipping..." } if rejected
103
+ end
104
+ end
105
+ end
106
+
107
+ def include_ancestors?
108
+ options.dig(:output, :include, :ancestors)
109
+ end
110
+
111
+ def include_archived?
112
+ options.dig(:output, :include, :archived)
113
+ end
114
+
115
+ def output_filename(name = self.class::OUT_FILENAME)
116
+ File.join(output_folder, "#{timestamp}_#{config.active_enviro}_#{name}.#{output_file_format}")
117
+ end
118
+
119
+ def output_folder
120
+ "#{config.active_enviro}/#{self.class::OUT_FOLDER}"
121
+ end
122
+
123
+ def timestamp(date = Time.now)
124
+ date.strftime(self.class::OUT_TIME_FORMAT)
125
+ end
126
+
127
+ # Transforms the input `tree` into a String list of indented nodes
128
+ def to_indented_list(tree, level: 0, attrs: str_node_attrs, indent: indentation)
129
+ ''.tap do |result|
130
+ out_str = nil
131
+ sublevel = tree.top?? 0 : level + 1
132
+ str_ary = tree.nodes.map { |subtree| to_indented_list(subtree, level: sublevel) }
133
+ out_str = str_ary.join("\n") unless str_ary.empty?
134
+
135
+ unless tree.top?
136
+ node_name = tree.as_json(include_children: false).values_at(*attrs.map(&:to_s)).join(" ## ")
137
+ out_head = "#{indent * level}#{node_name}"
138
+ out_str = out_str ? "#{out_head}\n#{out_str}" : out_head
139
+ end
140
+ result << out_str
141
+ end
142
+ end
143
+
144
+ def csv(filename, header = [])
145
+ CSV.open(filename, "w") do |csv|
146
+ csv << header unless header.empty?
147
+ yield(csv)
148
+ end
149
+ ensure
150
+ log(:info) { "Created file: #{filename}" }
151
+ end
152
+
153
+ def file(filename)
154
+ File.open(filename, "w") do |fd|
155
+ yield(fd)
156
+ end
157
+ ensure
158
+ log(:info) { "Created file: #{filename}" }
159
+ end
160
+
161
+ def excel(filename)
162
+ require 'fast_excel'
163
+ FastExcel.open(filename, constant_memory: true).tap do |workbook|
164
+ yield(workbook)
165
+ workbook.close
166
+ end
167
+ log(:info) { "Created file: #{filename}" }
168
+ end
169
+
170
+ def excel_sheet(workbook, name, header: true)
171
+ #unless sheet = workbook.get_worksheet_by_name(name)
172
+ sheet = workbook.add_worksheet(name)
173
+ #end
174
+ sheet.auto_width = true
175
+ yield(sheet)
176
+ if header
177
+ sheet.set_row(0, 30, workbook.bold_format)
178
+ sheet.freeze_panes(1, 0)
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,15 @@
1
+ module Eco
2
+ module API
3
+ class UseCases
4
+ class Default
5
+ module Locations
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ require_relative 'locations/codes_to_tags_case'
13
+ require_relative 'locations/create_tag_paths_case'
14
+ require_relative 'locations/csv_to_tree_case'
15
+ require_relative 'locations/tagtree_extract_case'
@@ -1,4 +1,4 @@
1
- class Eco::API::UseCases::DefaultCases::AnalysePeople < Eco::API::Common::Loaders::UseCase
1
+ class Eco::API::UseCases::Default::People::Analyse < Eco::API::Common::Loaders::UseCase
2
2
  name "analyse-people"
3
3
  type :export
4
4
 
@@ -1,4 +1,4 @@
1
- class Eco::API::UseCases::DefaultCases::ChangeEMailCase < Eco::API::Common::Loaders::UseCase
1
+ class Eco::API::UseCases::Default::People::ChangeEMailCase < Eco::API::Common::Loaders::UseCase
2
2
  name "change-email"
3
3
  type :sync
4
4
 
@@ -0,0 +1,66 @@
1
+ class Eco::API::UseCases::Default::People::CleanUnknownTags < Eco::API::Common::Loaders::UseCase
2
+ name "clean-unknown-tags"
3
+ type :transform
4
+
5
+ REGISTER_TAGS = [
6
+ "EVENT", "INJURY", "RISK", "CONTRACTOR", "PERMIT",
7
+ "AUDIT", "JSEA",
8
+ "TRAINING", "INDUCTION",
9
+ "MEETING", "PPE", "CHEMICAL",
10
+ "PLANT", "ASSET",
11
+ "POLICY", "IDEA", "REPORTS"
12
+ ]
13
+
14
+ def main(people, session, options, usecase)
15
+ update = session.new_job("main", "update", :update, usecase)
16
+ people.each do |person|
17
+ unknown_tags = person.filter_tags.reject { |tag| tag?(tag) }
18
+ person.filter_tags -= unknown_tags
19
+ removed_tag!(*unknown_tags)
20
+ if (tag = default_tag(person)) && !tag?(tag)
21
+ removed_tag!(tag)
22
+ micro.refresh_default_tag(person.entry, person, options)
23
+ end
24
+ update.add(person)
25
+ end
26
+
27
+ log(:info) {
28
+ msg = "Here list of the #{removed_tags.count} removed locations..."
29
+ msg + "\n • " + removed_tags.sort.join("\n • ")
30
+ }
31
+ end
32
+
33
+ private
34
+
35
+ def default_tag(person)
36
+ return nil unless account = person.account
37
+ account.default_tag
38
+ end
39
+
40
+ def register_tags
41
+ @register_tags ||= self.class::REGISTER_TAGS.compact.map(&:upcase)
42
+ end
43
+
44
+ def removed_tag!(*tags)
45
+ @removed_tags = removed_tags | tags
46
+ end
47
+
48
+ def removed_tags
49
+ @removed_tags ||= []
50
+ end
51
+
52
+ def tag?(value)
53
+ return false if value.nil?
54
+ return true if tagtree.tag?(value)
55
+ return false if clean_register_tags?
56
+ register_tags.any? { |reg| value.upcase == reg }
57
+ end
58
+
59
+ def tagtree
60
+ @tagtree ||= session.tagtree(live: true, merge: true)
61
+ end
62
+
63
+ def clean_register_tags?
64
+ options.dig(:usecase, :clear_register_tags)
65
+ end
66
+ end
@@ -1,4 +1,4 @@
1
- class Eco::API::UseCases::DefaultCases::ClearAbilitiesTransCase < Eco::API::Common::Loaders::UseCase
1
+ class Eco::API::UseCases::Default::People::ClearAbilitiesTransCase < Eco::API::Common::Loaders::UseCase
2
2
  name "clear-abilities"
3
3
  type :transform
4
4
 
@@ -1,4 +1,4 @@
1
- class Eco::API::UseCases::DefaultCases::OrgDataConvertCase < Eco::API::Common::Loaders::UseCase
1
+ class Eco::API::UseCases::Default::People::OrgDataConvertCase < Eco::API::Common::Loaders::UseCase
2
2
  name "org-data-convert"
3
3
  type :import
4
4
 
@@ -1,4 +1,4 @@
1
- class Eco::API::UseCases::DefaultCases::RefreshCase < Eco::API::Common::Loaders::UseCase
1
+ class Eco::API::UseCases::Default::People::RefreshCase < Eco::API::Common::Loaders::UseCase
2
2
  name "refresh"
3
3
  type :transform
4
4
 
@@ -1,4 +1,4 @@
1
- class Eco::API::UseCases::DefaultCases::ReinviteSyncCase < Eco::API::UseCases::DefaultCases::ReinviteTransCase
1
+ class Eco::API::UseCases::Default::People::ReinviteSyncCase < Eco::API::UseCases::Default::People::ReinviteTransCase
2
2
  name "reinvite"
3
3
  type :sync
4
4
 
@@ -1,4 +1,4 @@
1
- class Eco::API::UseCases::DefaultCases::ReinviteTransCase < Eco::API::Common::Loaders::UseCase
1
+ class Eco::API::UseCases::Default::People::ReinviteTransCase < Eco::API::Common::Loaders::UseCase
2
2
  name "reinvite"
3
3
  type :transform
4
4
 
@@ -0,0 +1,5 @@
1
+ class Eco::API::UseCases::Default::People::ReinviteTransCase
2
+ class Cli < Eco::API::UseCases::Cli
3
+
4
+ end
5
+ end
@@ -1,4 +1,4 @@
1
- class Eco::API::UseCases::DefaultCases::RestoreDBCase < Eco::API::Common::Loaders::UseCase
1
+ class Eco::API::UseCases::Default::People::RestoreDBCase < Eco::API::Common::Loaders::UseCase
2
2
  name "restore-db"
3
3
  type :sync
4
4
 
@@ -1,4 +1,4 @@
1
- class Eco::API::UseCases::DefaultCases::SetDefaultTagCase < Eco::API::Common::Loaders::UseCase
1
+ class Eco::API::UseCases::Default::People::SetDefaultTagCase < Eco::API::Common::Loaders::UseCase
2
2
  name "set-default-tag"
3
3
  type :transform
4
4
 
@@ -1,4 +1,4 @@
1
- class Eco::API::UseCases::DefaultCases::SupersCyclicIdentify < Eco::API::Common::Loaders::UseCase
1
+ class Eco::API::UseCases::Default::People::SupersCyclicIdentify < Eco::API::Common::Loaders::UseCase
2
2
  name "identify-cyclic-supers"
3
3
  type :export
4
4
 
@@ -1,4 +1,4 @@
1
- class Eco::API::UseCases::DefaultCases::SupersHierarchy < Eco::API::Common::Loaders::UseCase
1
+ class Eco::API::UseCases::Default::People::SupersHierarchy < Eco::API::Common::Loaders::UseCase
2
2
  name "supers-hierarchy"
3
3
  type :export
4
4
 
@@ -1,4 +1,4 @@
1
- class Eco::API::UseCases::DefaultCases::SwitchSupervisorCase < Eco::API::Common::Loaders::UseCase
1
+ class Eco::API::UseCases::Default::People::SwitchSupervisorCase < Eco::API::Common::Loaders::UseCase
2
2
  name "switch-supervisor"
3
3
  type :transform
4
4
 
@@ -1,4 +1,4 @@
1
- class Eco::API::UseCases::DefaultCases::TransferAccountCase < Eco::API::Common::Loaders::UseCase
1
+ class Eco::API::UseCases::Default::People::TransferAccountCase < Eco::API::Common::Loaders::UseCase
2
2
  name "transfer-account"
3
3
  type :sync
4
4
 
@@ -0,0 +1,25 @@
1
+ module Eco
2
+ module API
3
+ class UseCases
4
+ class Default
5
+ module People
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ require_relative 'people/analyse_people_case'
13
+ require_relative 'people/change_email_case'
14
+ require_relative 'people/clean_unknown_tags_case'
15
+ require_relative 'people/clear_abilities_case'
16
+ require_relative 'people/reinvite_trans_case'
17
+ require_relative 'people/reinvite_sync_case'
18
+ require_relative 'people/org_data_convert_case'
19
+ require_relative 'people/refresh_case'
20
+ require_relative 'people/restore_db_case'
21
+ require_relative 'people/set_default_tag_case'
22
+ require_relative 'people/supers_hierarchy_case'
23
+ require_relative 'people/supers_cyclic_identify_case'
24
+ require_relative 'people/switch_supervisor_case'
25
+ require_relative 'people/transfer_account_case'
@@ -0,0 +1,16 @@
1
+ module Eco
2
+ module API
3
+ class UseCases
4
+ class Default < Eco::API::UseCases
5
+ # autoloads_children_of "Eco::API::Common::Loaders::UseCase"
6
+ # autoload_namespace "Eco::API::UseCases::Default"
7
+ # autoload_namespace "Eco::API::UseCases::DefaultCases"
8
+ # autoload_namespace "Eco::API::UseCases::OozeCases"
9
+ # autoload_namespace "Eco::API::UseCases::GraphQL::Cases"
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ require_relative 'default/people'
16
+ require_relative 'default/locations'
@@ -0,0 +1,46 @@
1
+ class Eco::API::UseCases::DefaultCases::Samples::Sftp
2
+ class Cli < Eco::API::UseCases::Cli
3
+ desc "SFTP case: manages remote files that match a file pattern"
4
+
5
+ add_option("-file-pattern-const", "Constant that should be used as a pattern") do |options|
6
+ pattern_const = SCR.get_arg("-file-pattern-const", with_param: true)
7
+ options.deep_merge!(sftp: {file_pattern_const: pattern_const})
8
+ end
9
+
10
+ add_option("-list", "It lists all the files present in the remote folder for the current environment.") do |options|
11
+ options.deep_merge!(sftp: {command: :list})
12
+ end
13
+
14
+ add_option("-get-last", "It gets the last file present in the remote folder for the current environment.") do |options|
15
+ options.deep_merge!(sftp: {command: :get_last})
16
+ end
17
+
18
+ add_option("-get", "It gets all the files present in the remote folder for the current environment.") do |options|
19
+ options.deep_merge!(sftp: {command: :get})
20
+ end
21
+
22
+ add_option("-archive", "It moves all the files present in the remote folder to the archive subfolder.") do |options|
23
+ options.deep_merge!(sftp: {command: :archive})
24
+ end
25
+
26
+ add_option("-local-folder", "Local folder to pull the remote files to.") do |options|
27
+ local_folder = SCR.get_file("-local-folder", required: true, should_exist: true)
28
+ options.deep_merge!(sftp: {local_folder: local_folder})
29
+ end
30
+
31
+ add_option("-remote-subfolder", "Remote sub folder to pull the remote files from.") do |options|
32
+ remote_subfolder = SCR.get_arg("-remote-subfolder", with_param: true)
33
+ options.deep_merge!(sftp: {remote_subfolder: remote_subfolder})
34
+ end
35
+
36
+ add_option("-remote-target-folder", "Overrides -remote-subfolder and -remote-folder.") do |options|
37
+ remote_target_folder = SCR.get_arg("-remote-target-folder", with_param: true)
38
+ options.deep_merge!(sftp: {remote_target_folder: remote_target_folder})
39
+ end
40
+
41
+ add_option("-remote-folder", "Overrides -remote-folder (but not -remote-subfolder).") do |options|
42
+ remote_folder = SCR.get_arg("-remote-folder", with_param: true)
43
+ options.deep_merge!(sftp: {remote_folder: remote_folder})
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,9 @@
1
1
  class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loaders::UseCase
2
- name "sftp-sample"
2
+ class WrongConst < ArgumentError; end
3
+ class MissRemoteFolder < ArgumentError; end
4
+
5
+ require_relative 'cli/sftp_cli'
6
+ name "sftp"
3
7
  type :other
4
8
 
5
9
  CONST_REFERRAL = /^(?:::)?(?:[A-Z][a-zA-Z0-9_]*(?:::[A-Z][a-zA-Z0-9_]*)*)$/
@@ -22,24 +26,30 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
22
26
  private
23
27
 
24
28
  # Can't pass this via CLI option, as it breaks the regular expression
25
- def file_pattern
29
+ def file_pattern(require: true)
26
30
  fpc = file_pattern_const
27
31
  return fpc if fpc
28
- raise "You should redefine the file_pattern function as a RegEx expression that matches the target remote file"
32
+ raise WrongConst, "(#{self.class}) You should redefine the file_pattern function as a RegEx expression that matches the target remote file" if require
29
33
  end
30
34
 
31
35
  def file_pattern_const
32
36
  if fpc = options.dig(:sftp, :file_pattern_const)
33
- raise "Invalid file pattern const referral: #{fpc}" unless fpc.match(CONST_REFERRAL)
34
- self.eval(fpc)
37
+ raise WrongConst, "(#{self.class}) Invalid file pattern const referral: #{fpc}" unless fpc.match(CONST_REFERRAL)
38
+ begin
39
+ self.eval(fpc)
40
+ rescue NameError
41
+ self.class.const_get(fpc)
42
+ end
35
43
  end
44
+ rescue NameError
45
+ raise WrongConst, "(#{self.class}) Unknown constant: #{fpc}"
36
46
  end
37
47
 
38
48
  # Ex: "/IN/Personnel"
39
- def remote_subfolder
49
+ def remote_subfolder(require: true)
40
50
  rm_sf = options.dig(:sftp, :remote_subfolder)
41
51
  return rm_sf if rm_sf
42
- raise "You should redefine remote_subfolder as the folder where the target file sits. Ex: /IN/Personnel"
52
+ raise MissRemoteFolder, "(#{self.class}) You should redefine remote_subfolder as the folder where the target file sits. Ex: /IN/Personnel" if require
43
53
  end
44
54
 
45
55
  # `remote_target_folder` overrides `sftp_config.remote_folder` as well as `remote_subfolder`
@@ -63,8 +73,10 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
63
73
  sftp.files(remote_folder, pattern: file_pattern).each do |remote_file|
64
74
  yield(remote_file) if block_given?
65
75
  end
66
- rescue Net::SFTP::StatusException => e
67
- logger.error("SFTP samplecase: There was an error trying to access the remote folder '#{remote_folder}'")
76
+ rescue ArgumentError
77
+ raise
78
+ rescue ::Net::SFTP::StatusException => e
79
+ logger.error("(#{self.class}) There was an error trying to access the remote folder '#{remote_folder}'")
68
80
  []
69
81
  end
70
82
  end
@@ -3,50 +3,22 @@ module Eco
3
3
  class UseCases
4
4
  class DefaultCases < Eco::API::UseCases
5
5
  autoloads_children_of "Eco::API::Common::Loaders::UseCase"
6
+ autoload_namespace "Eco::API::UseCases::Default"
6
7
  autoload_namespace "Eco::API::UseCases::DefaultCases"
7
8
  autoload_namespace "Eco::API::UseCases::OozeCases"
9
+ autoload_namespace "Eco::API::UseCases::GraphQL::Cases"
8
10
  end
9
11
  end
10
12
  end
11
13
  end
12
14
 
13
15
  require_relative 'default_cases/samples'
14
- require_relative 'default_cases/abstract_policygroup_abilities_case.rb'
15
- require_relative 'default_cases/analyse_people_case'
16
- require_relative 'default_cases/append_usergroups_case'
17
- require_relative 'default_cases/change_email_case'
18
- require_relative 'default_cases/clean_unknown_tags_case'
19
- require_relative 'default_cases/clear_abilities_case'
20
- require_relative 'default_cases/codes_to_tags_case'
21
16
  require_relative 'default_cases/create_case'
22
- require_relative 'default_cases/create_details_case'
23
- require_relative 'default_cases/create_details_with_supervisor_case'
24
- require_relative 'default_cases/create_tag_paths_case'
25
- require_relative 'default_cases/csv_to_tree_case'
26
17
  require_relative 'default_cases/delete_trans_case'
27
18
  require_relative 'default_cases/delete_sync_case'
28
- require_relative 'default_cases/email_as_id_case'
29
19
  require_relative 'default_cases/hris_case'
30
- require_relative 'default_cases/new_id_case'
31
- require_relative 'default_cases/new_email_case'
32
20
  require_relative 'default_cases/entries_to_csv_case'
33
- require_relative 'default_cases/org_data_convert_case'
34
- require_relative 'default_cases/refresh_case'
35
- require_relative 'default_cases/reinvite_trans_case'
36
- require_relative 'default_cases/reinvite_sync_case'
37
- require_relative 'default_cases/remove_account_trans_case'
38
- require_relative 'default_cases/remove_account_sync_case'
39
- require_relative 'default_cases/reset_landing_page_case'
40
- require_relative 'default_cases/restore_db_case'
41
- require_relative 'default_cases/set_default_tag_case'
42
- require_relative 'default_cases/set_supervisor_case'
43
- require_relative 'default_cases/supers_hierarchy_case'
44
- require_relative 'default_cases/supers_cyclic_identify_case'
45
- require_relative 'default_cases/switch_supervisor_case'
46
- require_relative 'default_cases/tagtree_case'
47
21
  require_relative 'default_cases/to_csv_case'
48
22
  require_relative 'default_cases/to_csv_detailed_case'
49
- require_relative 'default_cases/transfer_account_case'
50
23
  require_relative 'default_cases/update_case'
51
- require_relative 'default_cases/update_details_case'
52
24
  require_relative 'default_cases/upsert_case'
@@ -23,8 +23,7 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
23
23
  return unless tree
24
24
  latest_tree = tree if tree.is_a?(Eco::API::Organization::TagTree)
25
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)
26
+ latest_tree ||= Eco::API::Organization::TagTree.new(tree.treeify, id: tree.id, name: tree.name)
28
27
  end
29
28
  latest_tree.tap do |_tree|
30
29
  next unless latest_tree
@@ -20,7 +20,7 @@ module Eco::API::UseCases::GraphQL::Utils
20
20
  end
21
21
 
22
22
  def upload(local_file, remote_folder: self.remote_folder, gid: sftp_group_id)
23
- return false unless local_file && File.exists?(local_file)
23
+ return false unless local_file && File.exist?(local_file)
24
24
  dest_file = "#{remote_folder}/#{File.basename(local_file)}"
25
25
  res = sftp_session.upload!(local_file, dest_file)
26
26
  attrs = sftp_session.stat!(dest_file)
@@ -55,13 +55,13 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
55
55
  begin
56
56
  yield
57
57
  rescue StandardError => e
58
- logger.error([reference, e.message].join(' => \n'))
58
+ logger.error([reference, e.message].join(" => \n"))
59
59
  lines = []
60
- lines << '\nThere was an error. Choose one option:\n'
60
+ lines << "\nThere was an error. Choose one option:\n"
61
61
  lines << ' (C) - Continue/resume. Just ignore this one.'
62
62
  lines << ' (A) - Abort. Just break this run.'
63
63
 
64
- session.prompt_user('Type one option (C/a):', explanation: lines.join('\n'), default: 'C') do |res|
64
+ session.prompt_user('Type one option (C/a):', explanation: lines.join("\n"), default: 'C') do |res|
65
65
  res = res.upcase
66
66
  case
67
67
  when res.start_with?("A")