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
@@ -1,28 +0,0 @@
1
- module Eco
2
- module API
3
- class MicroCases
4
- # Helper to preserve the original filter tags.
5
- # @note
6
- # 1. It only works if the original value of `filter_tags` was **not** empty
7
- # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
8
- # @param options [Hash] the options.
9
- # @param keep_new [Boolean] tells if it should keep the new tags or get rid of them.
10
- # @return [Array<String>] the final value of `filter_tags`.
11
- def preserve_filter_tags(person, _options, keep_new: false)
12
- person.filter_tags.tap do
13
- next unless person.as_update.key?('filter_tags')
14
- next unless (original = person.original_doc['filter_tags'])
15
- next if original.empty?
16
-
17
- if keep_new
18
- person.filter_tags += original
19
- else
20
- person.filter_tags = original
21
- end
22
-
23
- return person.filter_tags
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,30 +0,0 @@
1
- module Eco
2
- module API
3
- class MicroCases
4
- # Helper to preserve the original `policy_group_ids`.
5
- # @note
6
- # 1. It only works if the original value of `policy_group_ids` was **not** empty
7
- # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
8
- # @param options [Hash] the options.
9
- # @param keep_new [Boolean] tells if it should keep the new policy groups or get rid of them.
10
- # @return [String] the final value of `policy_group_ids`.
11
- def preserve_policy_groups(person, _options, keep_new: false)
12
- return unless (account = person.account)
13
-
14
- account.policy_group_ids.tap do
15
- next unless account.as_update.key?("policy_group_ids")
16
- next unless (original = person.original_doc.dig("account", "policy_group_ids"))
17
- next if original.empty?
18
-
19
- if keep_new
20
- person.account.policy_group_ids += original
21
- else
22
- person.account.policy_group_ids = original
23
- end
24
-
25
- return account.policy_group_ids
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,26 +0,0 @@
1
- module Eco
2
- module API
3
- class MicroCases
4
- # When the input data, or `entry`, does not provide the `default_tag`,
5
- # it sets the `default_tag` of the user following some criteria
6
- # @note it assumes `default_tag` has been already set to `person.account`
7
- # @param entry [PersonEntry] the input entry with the data we should set on person.
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
- def refresh_default_tag(entry, person, options)
11
- return unless person.account
12
- return if options.dig(:exclude, :account)
13
- return if options.dig(:exclude, :filter_tags)
14
- return if options.dig(:exclude, :default_tag)
15
- return if entry&.default_tag?
16
-
17
- if session.tagtree
18
- person.account.default_tag = session.tagtree.default_tag(*person.filter_tags)
19
- else
20
- tags = person.filter_tags || []
21
- person.account.default_tag = tags.first unless tags.length > 1
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,18 +0,0 @@
1
- module Eco
2
- module API
3
- class MicroCases
4
- # @param entry [PersonEntry] the input entry with the data we should set on person.
5
- # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
6
- # @param options [Hash] the options.
7
- def set_account(entry, person, options)
8
- return if options.dig(:exclude, :account)
9
-
10
- entry.set_account(person, exclude: micro.account_excluded(person, options))
11
-
12
- person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
13
- micro.refresh_default_tag(entry, person, options)
14
- micro.fix_default_group(entry, person, options)
15
- end
16
- end
17
- end
18
- end
@@ -1,17 +0,0 @@
1
- module Eco
2
- module API
3
- class MicroCases
4
- # Sets all the core details, but the supervisor.
5
- # @note `supervisor_id` requires a special treatment, and therefore is always excluded.
6
- # @param entry [PersonEntry] the input entry with the data we should set on person.
7
- # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
8
- # @param options [Hash] the options
9
- def set_core(entry, person, options)
10
- return if options.dig(:exclude, :core) && !person.new?
11
-
12
- entry.set_core(person, exclude: micro.core_excluded(person, options))
13
- micro.fix_filter_tags(person, options)
14
- end
15
- end
16
- end
17
- end
@@ -1,32 +0,0 @@
1
- module Eco
2
- module API
3
- class MicroCases
4
- # Sets all the core details, but the supervisor.
5
- # @note `supervisor_id` requires a special treatment, and therefore is always excluded.
6
- # @param entry [PersonEntry] the input entry with the data we should set on person.
7
- # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
8
- # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
9
- # @param supers_job [Eco::API::Session::Batch::Job] the job that will run the supers .
10
- # @param options [Hash] the options.
11
- def set_core_with_supervisor(entry, person, people, supers_job, options)
12
- return if options.dig(:exclude, :core) && !person.new?
13
-
14
- micro.set_core(entry, person, options)
15
-
16
- return unless entry.supervisor_id?
17
-
18
- micro.set_supervisor(
19
- person,
20
- entry.supervisor_id,
21
- people,
22
- options
23
- ) do |unknown_id|
24
- # delay setting supervisor if does not exit
25
- supers_job.add(person) do |pers|
26
- micro.set_supervisor(pers, unknown_id, people, options)
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,63 +0,0 @@
1
- module Eco
2
- module API
3
- class MicroCases
4
- # Unique access point to set the `supervisor_id` value on a person.
5
- # @note
6
- # - It prevents the basic cyclic supervisor case (supervisor to be supervisor of themselves)
7
- # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
8
- # @param sup_id [nil, String] the **supervisor id** we should set on the `person`.
9
- # @param people [Eco::API::Organization::People] _People_ involved in the current update.
10
- # @param options [Hash] the options.
11
- # @yield [supervisor_id] callback when the supervisor_id is **unknown** (not `nil` nor any one's in `people`).
12
- # @yieldparam supervisor_id [String] the **unknown** `supervisor_id`.
13
- def set_supervisor(person, sup_id, people, options)
14
- return false if options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
15
- return false if sup_id && ((person.id == sup_id) || (person.external_id == sup_id))
16
-
17
- cur_id = person.supervisor_id
18
- cur_super = cur_id && with_supervisor(cur_id, people)
19
-
20
- micro.with_supervisor(sup_id, people) do |new_super|
21
- if !sup_id
22
- person.supervisor_id = nil
23
- descrease_subordinates(cur_super)
24
- elsif new_super && (id = new_super.id)
25
- set_supervisor(new_super, nil, people, options) if new_super_direct_cyclic?(person, new_super)
26
- person.supervisor_id = id
27
- descrease_subordinates(cur_super)
28
- increase_subordinates(new_super)
29
- elsif !block_given?
30
- descrease_subordinates(cur_super)
31
- person.supervisor_id = sup_id
32
- elsif block_given?
33
- yield(sup_id)
34
- end
35
- end
36
- end
37
-
38
- private
39
-
40
- def new_super_direct_cyclic?(person, new_super)
41
- return false unless new_super.is_a?(Ecoportal::API::V1::Person)
42
- return false if new_super.supervisor_id.nil?
43
- return true if person.id == new_super.id
44
- return true if new_super.supervisor_id == person.id
45
- return true if new_super.supervisor_id == person.external_id
46
-
47
- false
48
- end
49
-
50
- def descrease_subordinates(person, by = 1)
51
- return unless person.is_a?(Ecoportal::API::V1::Person)
52
-
53
- person.subordinates -= by
54
- end
55
-
56
- def increase_subordinates(person, by = 1)
57
- return unless person.is_a?(Ecoportal::API::V1::Person)
58
-
59
- person.subordinates += by
60
- end
61
- end
62
- end
63
- end
@@ -1,129 +0,0 @@
1
- # rubocop:disable Metrics/BlockNesting, Layout/LineLength
2
- module Eco
3
- module API
4
- class MicroCases
5
- # Frees up `target_email` from an account not present in this org.
6
- # Allows to force `target_email` on the current user's account.
7
- # - If the person does not have account, this case will not do anything.
8
- # - If `original_doc["account"]` is `nil` (no account on server side), this case will not do anything.
9
- # - If the `target_email` and the `current_email` are the same or empty, this case will not do anything.
10
- # @note
11
- # - **It does not do the final update to the server to the `target_email`**.
12
- # You will need to do this part yourself.
13
- # - You would call this function only when you got an error of `email already taken`.
14
- # - If the `target_email` is associated to a user in the same org, this will fail.
15
- # @param person [Ecoportal::API::V1::Person] the person we want to update,
16
- # carrying the changes to be done.
17
- # @param dest_email [String, Proc] the email that we will move the other account to,
18
- # when we free up `target_email`.
19
- # @param target_email [String] the email that we want to free up from another account and bring to ours.
20
- # If it's empty, the `person.email` will be used instead.
21
- # @param options [Hash] the options.
22
- # @param current_email [String] the email that the person's account is currently linked.
23
- # As the current email should be associated with this person's account on server side,
24
- # we use `original_doc["email"]`.
25
- # @param context [String] main core part of logs. Provides context to the logs.
26
- def take_email_from_account(person, dest_email:, target_email: nil, options: {}, context: "Session")
27
- return false if options.dig(:exclude, :account)
28
- return false unless (account = person.account)
29
- return false unless (had_account = person.original_doc["account"]) # rubocop:disable Lint/UselessAssignment
30
-
31
- target_email ||= person.email
32
- account_email = person.original_doc["email"]
33
-
34
- return false unless target_email != account_email
35
- return false if account_email.to_s.strip.empty?
36
- return false if target_email.to_s.strip.empty?
37
-
38
- if dest_email.is_a?(String)
39
- return false unless target_email != dest_email
40
- return false unless dest_email != account_email
41
- return false if dest_email.to_s.strip.empty?
42
- end
43
-
44
- account_json = _take_email_account_json(account)
45
- person.email = account_email
46
-
47
- if (success = _take_email_remove_account!(person, context: context))
48
- if (success = _take_email_acquire_account!(person, target_email, account: {}, context: context))
49
- if (success = _take_email_email_free_up!(person, dest_email: dest_email, context: context))
50
- if (success = _take_email_remove_account!(person, context: context))
51
- # Bring back the original account
52
- if (success = _take_email_acquire_account!(person, account_email, account: account_json, context: context)) # rubocop:disable Style/SoleNestedConditional
53
- success = true
54
- person.email = target_email
55
- end
56
- end
57
- else # free up target email
58
- # restore
59
- reverted = false
60
- if reverted ||= _take_email_remove_account!(person, context: context)
61
- reverted ||= _take_email_acquire_account!(person, account_email, account: account_json, context: context)
62
- end
63
-
64
- unless reverted
65
- msg = "Could not revert back to the original account #{person.identify}"
66
- log(:debug) { msg }
67
- puts msg
68
- end
69
-
70
- success = false
71
- end
72
- else # aquire other account
73
- # restore
74
- unless _take_email_acquire_account!(person, account_email, account: account_json, context: context)
75
- msg = "Could not bring back the original account that "
76
- msg << "we want to update the email to '#{target_email}' #{person.identify}"
77
- log(:debug) { msg }
78
- puts msg
79
- end
80
-
81
- success = false
82
- end
83
- end
84
-
85
- success
86
- end
87
-
88
- private
89
-
90
- def _take_email_account_json(account)
91
- JSON.parse(account.to_json).tap do |hash|
92
- hash.delete("user_id")
93
- hash.delete("permissions_merged")
94
- hash.delete("permissions_preset")
95
- hash.delete("prefilter")
96
-
97
- if (pref = hash["preferences"])
98
- hash["preferences"] = pref.reject do |attr, _value|
99
- attr.start_with?("kiosk")
100
- end
101
- end
102
- end
103
- end
104
-
105
- # Bring the account of the `target_email` taken, so we can change the email of this account
106
- def _take_email_acquire_account!(person, target_email, account: {}, context: "Session")
107
- person.account = account
108
- person.account.send_invites = false
109
- person.email = target_email
110
- micro.person_update!(person, reason: "bring account with email '#{target_email}'", context: context)
111
- end
112
-
113
- # Free up the email (`target_email`) of the account that has it taken to `dest_email`
114
- def _take_email_email_free_up!(person, dest_email:, target_email: nil, context: "Session")
115
- target_email ||= person.email
116
- person.email = dest_email.is_a?(Proc)? dest_email.call(target_email) : dest_email
117
- reason = "free up email '#{target_email}', by moving account to '#{person.email}'"
118
- micro.person_update!(person, reason: reason, context: context)
119
- end
120
-
121
- def _take_email_remove_account!(person, context: "Session")
122
- person.account = nil
123
- micro.person_update!(person, reason: "remove account", context: context)
124
- end
125
- end
126
- end
127
- end
128
-
129
- # rubocop:enable Metrics/BlockNesting, Layout/LineLength
@@ -1,103 +0,0 @@
1
- module Eco
2
- module API
3
- class MicroCases
4
- # Finds each **entry** of `entries` in `people` and runs a block.
5
- # @note
6
- # - it also links to `person.entry` the input data entry.
7
- # @param entries [Eco::API::Common::People::Entries] the input entries with the data.
8
- # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
9
- # @param options [Hash] the options.
10
- # @param append_created [Boolean] whether or not a new person will be added to the `people` object.
11
- # @yield [entry, person] gives each entry, and the paired person thereof (new or existing).
12
- # @yieldparam entry [PersonEntry] the input entry with the data we should set on person.
13
- # @yieldparam person [Ecoportal::API::V1::Person] the found person that matches `entry`, or a new person otherwise.
14
- # @return [Eco::API::Organization::People] all the people, including new and existing ones.
15
- def with_each(entries, people, options, append_created: true)
16
- @_skip_all_multiple_results = false
17
- people_copy = people.newFrom(people.to_a)
18
-
19
- entries.each_with_object([]) do |entry, scoped|
20
- begin
21
- person = people_copy.find(entry, strict: micro.strict_search?(options))
22
- person ||= session.new_person.tap do |pers|
23
- people << pers if append_created
24
- end
25
- rescue Eco::API::Organization::People::MultipleSearchResults => e
26
- unless @_skip_all_multiple_results
27
- msg = "\n * When searching this Entry: #{entry.to_s(:identify)}"
28
- person = _with_each_prompt_to_select_user(e.append_message(msg), entry: entry)
29
- end
30
- end
31
-
32
- next unless person
33
-
34
- person.entry = entry
35
- yield(entry, person) if block_given?
36
-
37
- scoped << person
38
- end.then do |all_people|
39
- people.newFrom all_people.uniq
40
- end
41
- end
42
-
43
- private
44
-
45
- def _with_each_prompt_to_select_user(error, entry: nil, increase_count: true) # rubocop:disable Metrics/AbcSize
46
- unless error.is_a?(Eco::API::Organization::People::MultipleSearchResults)
47
- raise "Expecting Eco::API::Organization::People::MultipleSearchResults. Given: #{error.class}"
48
- end
49
-
50
- @_with_each_prompts = 0 unless instance_variable_defined?(:@_with_each_prompts)
51
- @_with_each_prompts += 1 if increase_count
52
-
53
- lines = []
54
- lines << "\n(#{@_with_each_prompts}) #{error}\n"
55
- lines << " #index - Select the correct person by its number index among the list above."
56
- lines << " (I) - Just Skip/Ignore this one. I will deal with that input entry in another launch."
57
- lines << " (A) - Ignore all the rest of input entries with this problem."
58
- lines << " (C) - Create a new person."
59
- lines << " (B) - Just break this script. I need to change the input file :/"
60
-
61
- prompt_user("Type one option (#number/I/A/C/B):", explanation: lines.join("\n"), default: "I") do |res|
62
- res = res.upcase
63
-
64
- if res.start_with?("I")
65
- log(:info) { "Ignoring entry... #{entry&.to_s(:identify)}" }
66
-
67
- nil
68
- elsif res.start_with?("A")
69
- log(:info) {
70
- "All input entries with this same issue will be ignored for this launch"
71
- }
72
-
73
- @_skip_all_multiple_results = true
74
- nil
75
- elsif res.start_with?("C")
76
- log(:info) {
77
- "Creating new person...#{"for entry #{entry.to_s(:identify)}" if entry}"
78
- }
79
-
80
- session.new_person
81
- elsif res.start_with?("B")
82
- raise error
83
- elsif res && !res.empty? && (pos = res.to_i rescue nil) && (pos < error.candidates.length) # rubocop:disable Style/RescueModifier
84
- error.candidate(pos).tap do |person|
85
- log(:info) { "Thanks!! You selected #{person.identify}" }
86
- sleep(1.5)
87
- end
88
- else
89
- if pos.is_a?(Numeric) && (pos >= error.candidates.length)
90
- print "#{pos} is not a number in the range. "
91
- else
92
- print "#{res} is not an option. "
93
- end
94
-
95
- puts "Please select one of the offered options..."
96
- sleep(1)
97
- _with_each_prompt_to_select_user(error, increase_count: false, entry: entry)
98
- end
99
- end
100
- end
101
- end
102
- end
103
- end
@@ -1,27 +0,0 @@
1
- module Eco
2
- module API
3
- class MicroCases
4
- # Detects who has left the organization and `yield` s them one by one to the given block
5
- # @note
6
- # - To be used only when the input file is the full DB
7
- # - The `Entries#find` method. If the people manager entry does not have `external_id`,
8
- # but has a matching `email` wiht some input entry (row), it won't be identified as a leaver.
9
- # @param entries [Eco::API::Common::People::Entries] the input entries with the data.
10
- # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
11
- # @param options [Hash] the options.
12
- # @yield [person] gives each person of `people` that is not present in `entries`.
13
- # @yieldparam person [Ecoportal::API::V1::Person] the person that leaves the org.
14
- # @return [Eco::API::Organization::People] the leavers.
15
- def with_each_leaver(entries, people, options)
16
- leavers = people.map do |person|
17
- unless entries.find(person, strict: micro.strict_search?(options))
18
- yield(person) if block_given?
19
- person
20
- end
21
- end.compact
22
-
23
- people.newFrom leavers
24
- end
25
- end
26
- end
27
- end
@@ -1,36 +0,0 @@
1
- module Eco
2
- module API
3
- class MicroCases
4
- # Finds those in `entries` that already exist in the organization (`people`) and `yield` s them one by one to the given block.
5
- # @note
6
- # - it also links to `person.entry` the input data `entry`.
7
- # @param entries [Eco::API::Common::People::Entries] the input entries with the data.
8
- # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
9
- # @param options [Hash] the options.
10
- # @param log_starter [Boolean] log error message if an `entry` does not have match in `people`.
11
- # @yield [entry, person] gives each **found** `person` of `entries` that is not present in `people`.
12
- # @yieldparam entry [PersonEntry] the input entry with the data we should set on person.
13
- # @yieldparam person [Ecoportal::API::V1::Person] the **found** person.
14
- # @return [Eco::API::Organization::People] the found people.
15
- def with_each_present(entries, people, options, log_starter: false)
16
- found = []
17
- micro.with_each(entries, people, options) do |entry, person|
18
- if person.new?
19
- if log_starter
20
- log(:error) {
21
- "This person does not exist: #{entry.to_s(:identify)}"
22
- }
23
- end
24
-
25
- next
26
- end
27
-
28
- found << person
29
- yield(entry, person) if block_given?
30
- end
31
-
32
- people.newFrom found
33
- end
34
- end
35
- end
36
- end
@@ -1,37 +0,0 @@
1
- module Eco
2
- module API
3
- class MicroCases
4
- # Detects who in the `entries` is new in the organization and `yield` s them one by one to the given block.
5
- # @note
6
- # - it also links to `person.entry` the input data `entry`.
7
- # @param entries [Eco::API::Common::People::Entries] the input entries with the data.
8
- # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
9
- # @param options [Hash] the options.
10
- # @param log_present [Boolean] log error message if an `entry` has match in `people`.
11
- # @param append_created [Boolean] whether or not a new person will be added to the `people` object.
12
- # @yield [entry, person] gives each **new** `person` of `entries` that is not present in `people`.
13
- # @yieldparam entry [PersonEntry] the input entry with the data we should set on person.
14
- # @yieldparam person [Ecoportal::API::V1::Person] the **new** person.
15
- # @return [Eco::API::Organization::People] the starters.
16
- def with_each_starter(entries, people, options, log_present: false, append_created: true)
17
- starters = []
18
- micro.with_each(entries, people, options, append_created: append_created) do |entry, person|
19
- unless person.new?
20
- if log_present
21
- log(:error) {
22
- "This person (id: '#{person.id}') already exists: #{entry.to_s(:identify)}"
23
- }
24
- end
25
-
26
- next
27
- end
28
-
29
- starters << person
30
- yield(entry, person) if block_given?
31
- end
32
-
33
- people.newFrom starters
34
- end
35
- end
36
- end
37
- end
@@ -1,33 +0,0 @@
1
- module Eco
2
- module API
3
- class MicroCases
4
- # Finds all the subordinates of `supervisor`.
5
- # @note if `supervisor` is `nil`, it will return all people with no supervisor.
6
- # @param supervisor [String, Ecoportal::API::V1::Person, Hash] the `supervisor` or the `id` / `external_id` thereof.
7
- # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
8
- # @yield [subordinate] block that does some stuff with `subordinate`.
9
- # @yieldparam subordinate [Ecoportal::API::V1::Person] each one of the suborinates of `supervisor`.
10
- # @return [Eco::API::Organization::People] the **subordinates** of `supervisor`.
11
- def with_each_subordinate(supervisor, people)
12
- people.supervisor_id(_person_id(supervisor, people)).tap do |subordinates|
13
- subordinates.each do |subordinate|
14
- yield(subordinate) if block_given?
15
- end
16
- end
17
- end
18
-
19
- private
20
-
21
- def _person_id(value, people)
22
- case value
23
- when Hash
24
- _person_id(value["id"] || value["external_id"], people)
25
- when Ecoportal::API::V1::Person
26
- _person_id(value.id || value.external_id, people)
27
- when String
28
- micro.with_supervisor(value, people)&.id
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,35 +0,0 @@
1
- module Eco
2
- module API
3
- class MicroCases
4
- # Finds the supervisor among `people` by using the `supervisor_id` of `value`.
5
- # @param value [String, Ecoportal::API::V1::Person, Hash] the subordinate person,
6
- # or the unique identifier of the supervisor to be found (preferably the `external_id`).
7
- # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
8
- # @param strict [Boolean] specifies if the search should be `strict` (see {Eco::API::Organization::People#person}).
9
- # @yield [supervisor] block that does some stuff with supevisor.
10
- # @yieldparam supervisor [Ecoportal::API::V1::Person] the person object of the supervisor, or `nil` if not found.
11
- # @return [nil, Ecoportal::API::V1::Person] found `supervisor` of `value`.
12
- def with_supervisor(value, people, strict: false)
13
- if sup_id = with_supervisor_supervisor_id(value)
14
- people.person(id: sup_id, external_id: sup_id, email: sup_id, strict: strict)
15
- end.tap do |supervisor|
16
- yield(supervisor) if block_given?
17
- end
18
- end
19
-
20
- private
21
-
22
- def with_supervisor_supervisor_id(value)
23
- return nil if value.to_s.strip.empty?
24
- case
25
- when value.respond_to?(:supervisor_id)
26
- value.supervisor_id
27
- when value.is_a?(Hash)
28
- value["supervisor_id"]
29
- else
30
- value
31
- end
32
- end
33
- end
34
- end
35
- end