eco-helpers 3.0.20 → 3.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/.idea/.gitignore +10 -0
  3. data/CHANGELOG.md +55 -5
  4. data/eco-helpers.gemspec +3 -3
  5. data/lib/eco/api/common/class_hierarchy.rb +6 -9
  6. data/lib/eco/api/common/loaders/case_base.rb +12 -4
  7. data/lib/eco/api/common/loaders/config/cli.rb +9 -0
  8. data/lib/eco/api/common/loaders/config/workflow/cases_extension.rb +53 -0
  9. data/lib/eco/api/common/loaders/config/workflow/mailer.rb +2 -14
  10. data/lib/eco/api/common/loaders/config/workflow.rb +4 -0
  11. data/lib/eco/api/common/loaders/config.rb +1 -0
  12. data/lib/eco/api/common/loaders/error_handler.rb +3 -2
  13. data/lib/eco/api/common/loaders/policy.rb +3 -2
  14. data/lib/eco/api/common/loaders/use_case/cli_identify.rb +28 -0
  15. data/lib/eco/api/common/loaders/use_case/target_model.rb +25 -0
  16. data/lib/eco/api/common/loaders/use_case/type.rb +37 -0
  17. data/lib/eco/api/common/loaders/use_case.rb +16 -43
  18. data/lib/eco/api/common/people/default_parsers/xls_parser.rb +1 -1
  19. data/lib/eco/api/common/session/logger/cache.rb +10 -4
  20. data/lib/eco/api/common/session/logger/channels.rb +41 -0
  21. data/lib/eco/api/common/session/logger.rb +9 -0
  22. data/lib/eco/api/error/handler.rb +6 -4
  23. data/lib/eco/api/error/handlers.rb +12 -5
  24. data/lib/eco/api/microcases/people/apply_changes/set_account/account_excluded.rb +34 -0
  25. data/lib/eco/api/microcases/people/apply_changes/set_account.rb +28 -0
  26. data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +28 -0
  27. data/lib/eco/api/microcases/people/apply_changes/set_core.rb +27 -0
  28. data/lib/eco/api/microcases/people/apply_changes/set_core_with_supervisor.rb +38 -0
  29. data/lib/eco/api/microcases/people/apply_changes/set_supervisor.rb +69 -0
  30. data/lib/eco/api/microcases/people/apply_changes.rb +19 -0
  31. data/lib/eco/api/microcases/people/fetch/with_each.rb +109 -0
  32. data/lib/eco/api/microcases/people/fetch/with_each_leaver.rb +33 -0
  33. data/lib/eco/api/microcases/people/fetch/with_each_present.rb +42 -0
  34. data/lib/eco/api/microcases/people/fetch/with_each_starter.rb +43 -0
  35. data/lib/eco/api/microcases/people/fetch/with_each_subordinate.rb +41 -0
  36. data/lib/eco/api/microcases/people/fetch/with_supervisor.rb +46 -0
  37. data/lib/eco/api/microcases/people/fetch.rb +23 -0
  38. data/lib/eco/api/microcases/people/integrity/fix_default_group.rb +39 -0
  39. data/lib/eco/api/microcases/people/integrity/fix_filter_tags.rb +55 -0
  40. data/lib/eco/api/microcases/people/integrity/refresh_default_tag.rb +32 -0
  41. data/lib/eco/api/microcases/people/integrity.rb +17 -0
  42. data/lib/eco/api/microcases/people/macro/take_email.rb +141 -0
  43. data/lib/eco/api/microcases/people/macro.rb +13 -0
  44. data/lib/eco/api/microcases/people/manage/cache.rb +36 -0
  45. data/lib/eco/api/microcases/people/manage/load.rb +90 -0
  46. data/lib/eco/api/microcases/people/manage/refresh.rb +59 -0
  47. data/lib/eco/api/microcases/people/manage/search.rb +118 -0
  48. data/lib/eco/api/microcases/people/manage.rb +19 -0
  49. data/lib/eco/api/microcases/people/preserve/default_tag.rb +29 -0
  50. data/lib/eco/api/microcases/people/preserve/filter_tags.rb +34 -0
  51. data/lib/eco/api/microcases/people/preserve/policy_groups.rb +36 -0
  52. data/lib/eco/api/microcases/people/preserve.rb +17 -0
  53. data/lib/eco/api/microcases/people.rb +21 -0
  54. data/lib/eco/api/microcases/person_update.rb +1 -1
  55. data/lib/eco/api/microcases/s3upload_targets.rb +1 -1
  56. data/lib/eco/api/microcases/with_each_contractor_present.rb +40 -0
  57. data/lib/eco/api/microcases.rb +3 -23
  58. data/lib/eco/api/organization/people/multiple_search_results.rb +48 -0
  59. data/lib/eco/api/organization/{people_similarity.rb → people/similarity.rb} +89 -72
  60. data/lib/eco/api/organization/people.rb +40 -66
  61. data/lib/eco/api/organization.rb +0 -1
  62. data/lib/eco/api/policies/policy.rb +7 -5
  63. data/lib/eco/api/policies.rb +9 -4
  64. data/lib/eco/api/session/batch/feedback/generate.rb +60 -0
  65. data/lib/eco/api/session/batch/feedback/getters.rb +28 -0
  66. data/lib/eco/api/session/batch/feedback/identifiers.rb +20 -0
  67. data/lib/eco/api/session/batch/feedback/job_dependencies.rb +45 -0
  68. data/lib/eco/api/session/batch/feedback/request_stat.rb +27 -0
  69. data/lib/eco/api/session/batch/feedback/request_stats.rb +270 -0
  70. data/lib/eco/api/session/batch/feedback.rb +45 -119
  71. data/lib/eco/api/session/batch/job/sets.rb +23 -0
  72. data/lib/eco/api/session/batch/job/type.rb +22 -0
  73. data/lib/eco/api/session/batch/job.rb +19 -18
  74. data/lib/eco/api/session/batch/jobs.rb +6 -2
  75. data/lib/eco/api/session/batch/launcher/mode_size.rb +1 -1
  76. data/lib/eco/api/session/batch/launcher/retry.rb +4 -4
  77. data/lib/eco/api/session/batch/launcher.rb +2 -2
  78. data/lib/eco/api/session/batch/policies.rb +4 -4
  79. data/lib/eco/api/session/batch/searcher.rb +2 -1
  80. data/lib/eco/api/session/batch.rb +0 -1
  81. data/lib/eco/api/session/config/workflow.rb +19 -9
  82. data/lib/eco/api/usecases/base_case/model.rb +54 -0
  83. data/lib/eco/api/usecases/base_case/type.rb +52 -0
  84. data/lib/eco/api/usecases/base_case.rb +5 -29
  85. data/lib/eco/api/usecases/base_io/chaining.rb +48 -0
  86. data/lib/eco/api/usecases/base_io/validations.rb +114 -0
  87. data/lib/eco/api/usecases/base_io.rb +65 -115
  88. data/lib/eco/api/usecases/cli/dsl.rb +3 -1
  89. data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +7 -4
  90. data/lib/eco/api/usecases/default/people/treat/supers_cyclic_identify_case.rb +1 -3
  91. data/lib/eco/api/usecases/default/people/treat/supers_hierarchy_case.rb +1 -5
  92. data/lib/eco/api/usecases/default_cases/entries_to_csv_case.rb +2 -2
  93. data/lib/eco/api/usecases/default_cases/hris_case.rb +0 -2
  94. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +3 -6
  95. data/lib/eco/api/usecases/graphql/base.rb +3 -2
  96. data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +1 -1
  97. data/lib/eco/api/usecases/graphql/helpers/base/error_handling.rb +3 -3
  98. data/lib/eco/api/usecases/graphql/helpers/contractors/base/load.rb +17 -0
  99. data/lib/eco/api/usecases/graphql/helpers/contractors/base.rb +8 -0
  100. data/lib/eco/api/usecases/graphql/helpers/contractors.rb +6 -0
  101. data/lib/eco/api/usecases/graphql/helpers/location/base.rb +5 -4
  102. data/lib/eco/api/usecases/graphql/helpers/location/command.rb +2 -2
  103. data/lib/eco/api/usecases/graphql/helpers.rb +1 -0
  104. data/lib/eco/api/usecases/graphql/samples/contractors/dsl.rb +5 -0
  105. data/lib/eco/api/usecases/graphql/samples/contractors.rb +17 -0
  106. data/lib/eco/api/usecases/graphql/samples/location/service/base.rb +1 -1
  107. data/lib/eco/api/usecases/graphql/samples/location.rb +1 -1
  108. data/lib/eco/api/usecases/graphql/samples.rb +1 -0
  109. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +0 -1
  110. data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +8 -8
  111. data/lib/eco/api/usecases/use_case/chainer.rb +12 -0
  112. data/lib/eco/api/usecases/use_case.rb +32 -23
  113. data/lib/eco/api/usecases/use_case_chain/chaining.rb +88 -0
  114. data/lib/eco/api/usecases/use_case_chain.rb +17 -62
  115. data/lib/eco/api/usecases/use_case_io/chain.rb +24 -0
  116. data/lib/eco/api/usecases/use_case_io.rb +17 -22
  117. data/lib/eco/api/usecases.rb +12 -4
  118. data/lib/eco/assets.rb +1 -1
  119. data/lib/eco/cli/config/filters/people_filters.rb +6 -5
  120. data/lib/eco/cli/config/input.rb +6 -2
  121. data/lib/eco/cli/config/use_cases.rb +4 -2
  122. data/lib/eco/cli_default/input.rb +49 -29
  123. data/lib/eco/cli_default/options.rb +4 -1
  124. data/lib/eco/cli_default/people.rb +102 -47
  125. data/lib/eco/cli_default/people_filters.rb +5 -1
  126. data/lib/eco/cli_default/workflow.rb +149 -138
  127. data/lib/eco/data/mapper.rb +51 -19
  128. data/lib/eco/language/auxiliar_logger.rb +16 -3
  129. data/lib/eco/language/basic_logger.rb +1 -0
  130. data/lib/eco/language/methods/dsl_able.rb +3 -0
  131. data/lib/eco/version.rb +1 -1
  132. metadata +68 -33
  133. data/lib/eco/api/microcases/account_excluded.rb +0 -26
  134. data/lib/eco/api/microcases/core_excluded.rb +0 -20
  135. data/lib/eco/api/microcases/fix_default_group.rb +0 -33
  136. data/lib/eco/api/microcases/fix_filter_tags.rb +0 -49
  137. data/lib/eco/api/microcases/people_cache.rb +0 -30
  138. data/lib/eco/api/microcases/people_load.rb +0 -84
  139. data/lib/eco/api/microcases/people_refresh.rb +0 -53
  140. data/lib/eco/api/microcases/people_search.rb +0 -112
  141. data/lib/eco/api/microcases/preserve_default_tag.rb +0 -23
  142. data/lib/eco/api/microcases/preserve_filter_tags.rb +0 -28
  143. data/lib/eco/api/microcases/preserve_policy_groups.rb +0 -30
  144. data/lib/eco/api/microcases/refresh_default_tag.rb +0 -26
  145. data/lib/eco/api/microcases/set_account.rb +0 -18
  146. data/lib/eco/api/microcases/set_core.rb +0 -17
  147. data/lib/eco/api/microcases/set_core_with_supervisor.rb +0 -32
  148. data/lib/eco/api/microcases/set_supervisor.rb +0 -63
  149. data/lib/eco/api/microcases/take_email_from_account.rb +0 -129
  150. data/lib/eco/api/microcases/with_each.rb +0 -103
  151. data/lib/eco/api/microcases/with_each_leaver.rb +0 -27
  152. data/lib/eco/api/microcases/with_each_present.rb +0 -36
  153. data/lib/eco/api/microcases/with_each_starter.rb +0 -37
  154. data/lib/eco/api/microcases/with_each_subordinate.rb +0 -33
  155. data/lib/eco/api/microcases/with_supervisor.rb +0 -35
  156. data/lib/eco/api/session/batch/request_stats.rb +0 -266
@@ -5,7 +5,7 @@ module Eco
5
5
  autoloads_children_of "Eco::API::Common::Loaders::ErrorHandler"
6
6
  autoload_namespace_ignore "Eco::API"
7
7
 
8
- def define(*args)
8
+ def define(*_args)
9
9
  raise "Missusage. You should use 'on' method instead"
10
10
  end
11
11
 
@@ -13,16 +13,23 @@ module Eco
13
13
  def on(klass_err, type: :error_handler, retry: true, &block)
14
14
  Eco::API::Error.validate_err_class(klass_err)
15
15
  raise "Expected block but not given" unless block
16
- Eco::API::Error::Handler.new(klass_err, type: type, root: self, &block).tap do |handler|
16
+
17
+ Eco::API::Error::Handler.new(
18
+ klass_err,
19
+ type: type,
20
+ root: self,
21
+ &block
22
+ ).tap do |handler|
17
23
  add(handler)
18
24
  end
19
25
  end
20
26
 
21
27
  def add(handler)
22
- raise "Expected Eco::API::Error::Handler object. Given: #{policy}" unless handler.is_a?(Eco::API::Error::Handler)
23
- super(handler)
24
- end
28
+ msg = "Expected Eco::API::Error::Handler object. Given: #{handler.class}"
29
+ raise ArgumentError, msg unless handler.is_a?(Eco::API::Error::Handler)
25
30
 
31
+ super
32
+ end
26
33
  end
27
34
  end
28
35
  end
@@ -0,0 +1,34 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ module People
5
+ module ApplyChanges
6
+ module SetAccount
7
+ module AccountExcluded
8
+ # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
9
+ # @param options [Hash] the options.
10
+ # @return [Array<String>] the account parameters that should not be included.
11
+ def account_excluded(person, options)
12
+ [].tap do |account_excluded|
13
+ next if person.new?
14
+
15
+ if options.dig(:exclude, :policy_groups)
16
+ account_excluded.push('policy_group_ids')
17
+ end
18
+
19
+ if options.dig(:exclude, :default_tag)
20
+ account_excluded.push('default_tag')
21
+ end
22
+
23
+ if options.dig(:exclude, :login_providers)
24
+ account_excluded.push('login_provider_ids')
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'set_account/account_excluded'
2
+
3
+ module Eco
4
+ module API
5
+ class MicroCases
6
+ module People
7
+ module ApplyChanges
8
+ module SetAccount
9
+ include AccountExcluded
10
+
11
+ # @param entry [PersonEntry] the input entry with the data we should set on person.
12
+ # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
13
+ # @param options [Hash] the options.
14
+ def set_account(entry, person, options)
15
+ return if options.dig(:exclude, :account)
16
+
17
+ entry.set_account(person, exclude: micro.account_excluded(person, options))
18
+
19
+ person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
20
+ micro.refresh_default_tag(entry, person, options)
21
+ micro.fix_default_group(entry, person, options)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ module People
5
+ module ApplyChanges
6
+ module SetCore
7
+ module CoreExcluded
8
+ # @note by default `supervisor_id` is always excluded.
9
+ # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
10
+ # @param options [Hash] the options.
11
+ # @return [Array<String>] the core parameters that should not be included.
12
+ def core_excluded(person, options)
13
+ ['supervisor_id'].tap do |core_excluded|
14
+ can_exclude = person.new?? ['filter_tags'] : %w[name external_id email filter_tags]
15
+
16
+ exclusions = can_exclude.select do |attr|
17
+ options.dig(:exclude, attr.to_sym)
18
+ end
19
+ core_excluded.concat(exclusions)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'set_core/core_excluded'
2
+
3
+ module Eco
4
+ module API
5
+ class MicroCases
6
+ module People
7
+ module ApplyChanges
8
+ module SetCore
9
+ include CoreExcluded
10
+
11
+ # Sets all the core details, but the supervisor.
12
+ # @note `supervisor_id` requires a special treatment, and therefore is always excluded.
13
+ # @param entry [PersonEntry] the input entry with the data we should set on person.
14
+ # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
15
+ # @param options [Hash] the options
16
+ def set_core(entry, person, options)
17
+ return if options.dig(:exclude, :core) && !person.new?
18
+
19
+ entry.set_core(person, exclude: micro.core_excluded(person, options))
20
+ micro.fix_filter_tags(person, options)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ module People
5
+ module ApplyChanges
6
+ module SetCoreWithSupervisor
7
+ # Sets all the core details, but the supervisor.
8
+ # @note `supervisor_id` requires a special treatment, and therefore is always excluded.
9
+ # @param entry [PersonEntry] the input entry with the data we should set on person.
10
+ # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
11
+ # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
12
+ # @param supers_job [Eco::API::Session::Batch::Job] the job that will run the supers .
13
+ # @param options [Hash] the options.
14
+ def set_core_with_supervisor(entry, person, people, supers_job, options)
15
+ return if options.dig(:exclude, :core) && !person.new?
16
+
17
+ micro.set_core(entry, person, options)
18
+
19
+ return unless entry.supervisor_id?
20
+
21
+ micro.set_supervisor(
22
+ person,
23
+ entry.supervisor_id,
24
+ people,
25
+ options
26
+ ) do |unknown_id|
27
+ # delay setting supervisor if does not exit
28
+ supers_job.add(person) do |pers|
29
+ micro.set_supervisor(pers, unknown_id, people, options)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,69 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ module People
5
+ module ApplyChanges
6
+ module SetSupervisor
7
+ # Unique access point to set the `supervisor_id` value on a person.
8
+ # @note
9
+ # - It prevents the basic cyclic supervisor case (supervisor to be supervisor of themselves)
10
+ # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
11
+ # @param sup_id [nil, String] the **supervisor id** we should set on the `person`.
12
+ # @param people [Eco::API::Organization::People] _People_ involved in the current update.
13
+ # @param options [Hash] the options.
14
+ # @yield [supervisor_id] callback when the supervisor_id is **unknown** (not `nil` nor any one's in `people`).
15
+ # @yieldparam supervisor_id [String] the **unknown** `supervisor_id`.
16
+ def set_supervisor(person, sup_id, people, options)
17
+ return false if options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
18
+ return false if sup_id && ((person.id == sup_id) || (person.external_id == sup_id))
19
+
20
+ cur_id = person.supervisor_id
21
+ cur_super = cur_id && with_supervisor(cur_id, people)
22
+
23
+ micro.with_supervisor(sup_id, people) do |new_super|
24
+ if !sup_id
25
+ person.supervisor_id = nil
26
+ descrease_subordinates(cur_super)
27
+ elsif new_super && (id = new_super.id)
28
+ set_supervisor(new_super, nil, people, options) if new_super_direct_cyclic?(person, new_super)
29
+ person.supervisor_id = id
30
+ descrease_subordinates(cur_super)
31
+ increase_subordinates(new_super)
32
+ elsif !block_given?
33
+ descrease_subordinates(cur_super)
34
+ person.supervisor_id = sup_id
35
+ elsif block_given?
36
+ yield(sup_id)
37
+ end
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def new_super_direct_cyclic?(person, new_super)
44
+ return false unless new_super.is_a?(Ecoportal::API::V1::Person)
45
+ return false if new_super.supervisor_id.nil?
46
+ return true if person.id == new_super.id
47
+ return true if new_super.supervisor_id == person.id
48
+ return true if new_super.supervisor_id == person.external_id
49
+
50
+ false
51
+ end
52
+
53
+ def descrease_subordinates(person, by = 1)
54
+ return unless person.is_a?(Ecoportal::API::V1::Person)
55
+
56
+ person.subordinates -= by
57
+ end
58
+
59
+ def increase_subordinates(person, by = 1)
60
+ return unless person.is_a?(Ecoportal::API::V1::Person)
61
+
62
+ person.subordinates += by
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'apply_changes/set_core'
2
+ require_relative 'apply_changes/set_supervisor'
3
+ require_relative 'apply_changes/set_core_with_supervisor'
4
+ require_relative 'apply_changes/set_account'
5
+
6
+ module Eco
7
+ module API
8
+ class MicroCases
9
+ module People
10
+ module ApplyChanges
11
+ include SetCore
12
+ include SetSupervisor
13
+ include SetCoreWithSupervisor
14
+ include SetAccount
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,109 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ module People
5
+ module Fetch
6
+ module WithEach
7
+ # Finds each **entry** of `entries` in `people` and runs a block.
8
+ # @note
9
+ # - it also links to `person.entry` the input data entry.
10
+ # @param entries [Eco::API::Common::People::Entries] the input entries with the data.
11
+ # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
12
+ # @param options [Hash] the options.
13
+ # @param append_created [Boolean] whether or not a new person will be added to the `people` object.
14
+ # @yield [entry, person] gives each entry, and the paired person thereof (new or existing).
15
+ # @yieldparam entry [PersonEntry] the input entry with the data we should set on person.
16
+ # @yieldparam person [Ecoportal::API::V1::Person] the found person that matches `entry`, or a new person otherwise.
17
+ # @return [Eco::API::Organization::People] all the people, including new and existing ones.
18
+ def with_each(entries, people, options, append_created: true)
19
+ @_skip_all_multiple_results = false
20
+ people_copy = people.newFrom(people.to_a)
21
+
22
+ entries.each_with_object([]) do |entry, scoped|
23
+ begin
24
+ person = people_copy.find(entry, strict: micro.strict_search?(options))
25
+ person ||= session.new_person.tap do |pers|
26
+ people << pers if append_created
27
+ end
28
+ rescue Eco::API::Organization::People::MultipleSearchResults => e
29
+ unless @_skip_all_multiple_results
30
+ msg = "\n * When searching this Entry: #{entry.to_s(:identify)}"
31
+ person = _with_each_prompt_to_select_user(e.append_message(msg), entry: entry)
32
+ end
33
+ end
34
+
35
+ next unless person
36
+
37
+ person.entry = entry
38
+ yield(entry, person) if block_given?
39
+
40
+ scoped << person
41
+ end.then do |all_people|
42
+ people.newFrom all_people.uniq
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def _with_each_prompt_to_select_user(error, entry: nil, increase_count: true) # rubocop:disable Metrics/AbcSize
49
+ unless error.is_a?(Eco::API::Organization::People::MultipleSearchResults)
50
+ raise "Expecting Eco::API::Organization::People::MultipleSearchResults. Given: #{error.class}"
51
+ end
52
+
53
+ @_with_each_prompts = 0 unless instance_variable_defined?(:@_with_each_prompts)
54
+ @_with_each_prompts += 1 if increase_count
55
+
56
+ lines = []
57
+ lines << "\n(#{@_with_each_prompts}) #{error}\n"
58
+ lines << ' #index - Select the correct person by its number index among the list above.'
59
+ lines << ' (I) - Just Skip/Ignore this one. I will deal with that input entry in another launch.'
60
+ lines << ' (A) - Ignore all the rest of input entries with this problem.'
61
+ lines << ' (C) - Create a new person.'
62
+ lines << ' (B) - Just break this script. I need to change the input file :/'
63
+
64
+ prompt_user('Type one option (#number/I/A/C/B):', explanation: lines.join("\n"), default: 'I') do |res|
65
+ res = res.upcase
66
+
67
+ if res.start_with?('I')
68
+ log(:info) { "Ignoring entry... #{entry&.to_s(:identify)}" }
69
+
70
+ nil
71
+ elsif res.start_with?('A')
72
+ log(:info) {
73
+ 'All input entries with this same issue will be ignored for this launch'
74
+ }
75
+
76
+ @_skip_all_multiple_results = true
77
+ nil
78
+ elsif res.start_with?('C')
79
+ log(:info) {
80
+ "Creating new person...#{"for entry #{entry.to_s(:identify)}" if entry}"
81
+ }
82
+
83
+ session.new_person
84
+ elsif res.start_with?('B')
85
+ raise error
86
+ elsif res && !res.empty? && (pos = res.to_i rescue nil) && (pos < error.candidates.length) # rubocop:disable Style/RescueModifier
87
+ error.candidate(pos).tap do |person|
88
+ log(:info) { "Thanks!! You selected #{person.identify}" }
89
+ sleep(1.5)
90
+ end
91
+ else
92
+ if pos.is_a?(Numeric) && (pos >= error.candidates.length)
93
+ print "#{pos} is not a number in the range. "
94
+ else
95
+ print "#{res} is not an option. "
96
+ end
97
+
98
+ puts 'Please select one of the offered options...'
99
+ sleep(1)
100
+ _with_each_prompt_to_select_user(error, increase_count: false, entry: entry)
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,33 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ module People
5
+ module Fetch
6
+ module WithEachLeaver
7
+ # Detects who has left the organization and `yield` s them one by one to the given block
8
+ # @note
9
+ # - To be used only when the input file is the full DB
10
+ # - The `Entries#find` method. If the people manager entry does not have `external_id`,
11
+ # but has a matching `email` wiht some input entry (row), it won't be identified as a leaver.
12
+ # @param entries [Eco::API::Common::People::Entries] the input entries with the data.
13
+ # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
14
+ # @param options [Hash] the options.
15
+ # @yield [person] gives each person of `people` that is not present in `entries`.
16
+ # @yieldparam person [Ecoportal::API::V1::Person] the person that leaves the org.
17
+ # @return [Eco::API::Organization::People] the leavers.
18
+ def with_each_leaver(entries, people, options)
19
+ leavers = people.map do |person|
20
+ unless entries.find(person, strict: micro.strict_search?(options))
21
+ yield(person) if block_given?
22
+ person
23
+ end
24
+ end.compact
25
+
26
+ people.newFrom leavers
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,42 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ module People
5
+ module Fetch
6
+ module WithEachPresent
7
+ # Finds those in `entries` that already exist in the organization (`people`) and `yield` s them one by one to the given block.
8
+ # @note
9
+ # - it also links to `person.entry` the input data `entry`.
10
+ # @param entries [Eco::API::Common::People::Entries] the input entries with the data.
11
+ # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
12
+ # @param options [Hash] the options.
13
+ # @param log_starter [Boolean] log error message if an `entry` does not have match in `people`.
14
+ # @yield [entry, person] gives each **found** `person` of `entries` that is not present in `people`.
15
+ # @yieldparam entry [PersonEntry] the input entry with the data we should set on person.
16
+ # @yieldparam person [Ecoportal::API::V1::Person] the **found** person.
17
+ # @return [Eco::API::Organization::People] the found people.
18
+ def with_each_present(entries, people, options, log_starter: false)
19
+ found = []
20
+ micro.with_each(entries, people, options) do |entry, person|
21
+ if person.new?
22
+ if log_starter
23
+ log(:error) {
24
+ "This person does not exist: #{entry.to_s(:identify)}"
25
+ }
26
+ end
27
+
28
+ next
29
+ end
30
+
31
+ found << person
32
+ yield(entry, person) if block_given?
33
+ end
34
+
35
+ people.newFrom found
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,43 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ module People
5
+ module Fetch
6
+ module WithEachStarter
7
+ # Detects who in the `entries` is new in the organization and `yield` s them one by one to the given block.
8
+ # @note
9
+ # - it also links to `person.entry` the input data `entry`.
10
+ # @param entries [Eco::API::Common::People::Entries] the input entries with the data.
11
+ # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
12
+ # @param options [Hash] the options.
13
+ # @param log_present [Boolean] log error message if an `entry` has match in `people`.
14
+ # @param append_created [Boolean] whether or not a new person will be added to the `people` object.
15
+ # @yield [entry, person] gives each **new** `person` of `entries` that is not present in `people`.
16
+ # @yieldparam entry [PersonEntry] the input entry with the data we should set on person.
17
+ # @yieldparam person [Ecoportal::API::V1::Person] the **new** person.
18
+ # @return [Eco::API::Organization::People] the starters.
19
+ def with_each_starter(entries, people, options, log_present: false, append_created: true)
20
+ starters = []
21
+ micro.with_each(entries, people, options, append_created: append_created) do |entry, person|
22
+ unless person.new?
23
+ if log_present
24
+ log(:error) {
25
+ "This person (id: '#{person.id}') already exists: #{entry.to_s(:identify)}"
26
+ }
27
+ end
28
+
29
+ next
30
+ end
31
+
32
+ starters << person
33
+ yield(entry, person) if block_given?
34
+ end
35
+
36
+ people.newFrom starters
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,41 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ module People
5
+ module Fetch
6
+ module WithEachSubordinate
7
+ # Finds all the subordinates of `supervisor`.
8
+ # @note if `supervisor` is `nil`, it will return all people with no supervisor.
9
+ # @param supervisor [String, Ecoportal::API::V1::Person, Hash] the `supervisor` or the `id` / `external_id` thereof.
10
+ # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
11
+ # @yield [subordinate] block that does some stuff with `subordinate`.
12
+ # @yieldparam subordinate [Ecoportal::API::V1::Person] each one of the suborinates of `supervisor`.
13
+ # @return [Eco::API::Organization::People] the **subordinates** of `supervisor`.
14
+ def with_each_subordinate(supervisor, people)
15
+ people.supervisor_id(
16
+ _person_id(supervisor, people)
17
+ ).tap do |subordinates|
18
+ subordinates.each do |subordinate|
19
+ yield(subordinate) if block_given?
20
+ end
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def _person_id(value, people)
27
+ case value
28
+ when Hash
29
+ _person_id(value['id'] || value['external_id'], people)
30
+ when Ecoportal::API::V1::Person
31
+ _person_id(value.id || value.external_id, people)
32
+ when String
33
+ micro.with_supervisor(value, people)&.id
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,46 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ module People
5
+ module Fetch
6
+ module WithSupervisor
7
+ # Finds the supervisor among `people` by using the `supervisor_id` of `value`.
8
+ # @param value [String, Ecoportal::API::V1::Person, Hash] the subordinate person,
9
+ # or the unique identifier of the supervisor to be found (preferably the `external_id`).
10
+ # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
11
+ # @param strict [Boolean] specifies if the search should be `strict` (see {Eco::API::Organization::People#person}).
12
+ # @yield [supervisor] block that does some stuff with supevisor.
13
+ # @yieldparam supervisor [Ecoportal::API::V1::Person] the person object of the supervisor, or `nil` if not found.
14
+ # @return [nil, Ecoportal::API::V1::Person] found `supervisor` of `value`.
15
+ def with_supervisor(value, people, strict: false)
16
+ if (sup_id = with_supervisor_supervisor_id(value))
17
+ people.person(
18
+ id: sup_id,
19
+ external_id: sup_id,
20
+ email: sup_id,
21
+ strict: strict
22
+ )
23
+ end.tap do |supervisor|
24
+ yield(supervisor) if block_given?
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def with_supervisor_supervisor_id(value)
31
+ return if value.to_s.strip.empty?
32
+
33
+ if value.respond_to?(:supervisor_id)
34
+ value.supervisor_id
35
+ elsif value.is_a?(Hash)
36
+ value['supervisor_id']
37
+ else
38
+ value
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'fetch/with_supervisor'
2
+ require_relative 'fetch/with_each'
3
+ require_relative 'fetch/with_each_present'
4
+ require_relative 'fetch/with_each_starter'
5
+ require_relative 'fetch/with_each_leaver'
6
+ require_relative 'fetch/with_each_subordinate'
7
+
8
+ module Eco
9
+ module API
10
+ class MicroCases
11
+ module People
12
+ module Fetch
13
+ include WithSupervisor
14
+ include WithEach
15
+ include WithEachPresent
16
+ include WithEachStarter
17
+ include WithEachLeaver
18
+ include WithEachSubordinate
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ module People
5
+ module Integrity
6
+ module FixDefaultGroup
7
+ # If defined, it sets the default usergroup, only when the `policy_group_ids` was not part of the input data.
8
+ # @param entry [PersonEntry] the input entry with the data we should set on person.
9
+ # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
10
+ # @param options [Hash] the options.
11
+ def fix_default_group(entry, person, options)
12
+ return if options.dig(:exclude, :account)
13
+ return if options.dig(:exclude, :policy_groups) && !person.new?
14
+
15
+ end_pg_ids = person.account.policy_group_ids
16
+
17
+ if person.account_added? && __def_usergroup_id && !entry.policy_group_ids?
18
+ # on account creation, if missing policy_group_ids column in the input
19
+ # use default_usergroup, if it's defined
20
+ end_pg_ids = [__def_usergroup_id]
21
+ end
22
+
23
+ person.account.policy_group_ids = end_pg_ids
24
+ end
25
+
26
+ private
27
+
28
+ def __def_usergroup_id
29
+ @__def_usergroup_id ||=
30
+ if session.config.people.default_usergroup?
31
+ session.policy_groups.to_id(session.config.people.default_usergroup)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end