eco-helpers 3.0.21 → 3.0.23
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.
- checksums.yaml +4 -4
- data/.idea/.gitignore +10 -0
- data/CHANGELOG.md +44 -2
- data/eco-helpers.gemspec +5 -3
- data/lib/eco/api/common/class_helpers.rb +2 -1
- data/lib/eco/api/common/class_hierarchy.rb +6 -9
- data/lib/eco/api/common/loaders/case_base.rb +12 -4
- data/lib/eco/api/common/loaders/config/workflow/cases_extension.rb +53 -0
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +2 -14
- data/lib/eco/api/common/loaders/config/workflow.rb +4 -0
- data/lib/eco/api/common/loaders/error_handler.rb +3 -2
- data/lib/eco/api/common/loaders/policy.rb +3 -2
- data/lib/eco/api/common/loaders/use_case/cli_identify.rb +28 -0
- data/lib/eco/api/common/loaders/use_case/target_model.rb +25 -0
- data/lib/eco/api/common/loaders/use_case/type.rb +37 -0
- data/lib/eco/api/common/loaders/use_case.rb +16 -43
- data/lib/eco/api/error/handler.rb +6 -4
- data/lib/eco/api/error/handlers.rb +12 -5
- data/lib/eco/api/microcases/people/apply_changes/set_account/account_excluded.rb +34 -0
- data/lib/eco/api/microcases/people/apply_changes/set_account.rb +28 -0
- data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +28 -0
- data/lib/eco/api/microcases/people/apply_changes/set_core.rb +27 -0
- data/lib/eco/api/microcases/people/apply_changes/set_core_with_supervisor.rb +38 -0
- data/lib/eco/api/microcases/people/apply_changes/set_supervisor.rb +69 -0
- data/lib/eco/api/microcases/people/apply_changes.rb +19 -0
- data/lib/eco/api/microcases/people/fetch/with_each.rb +109 -0
- data/lib/eco/api/microcases/people/fetch/with_each_leaver.rb +33 -0
- data/lib/eco/api/microcases/people/fetch/with_each_present.rb +42 -0
- data/lib/eco/api/microcases/people/fetch/with_each_starter.rb +43 -0
- data/lib/eco/api/microcases/people/fetch/with_each_subordinate.rb +41 -0
- data/lib/eco/api/microcases/people/fetch/with_supervisor.rb +46 -0
- data/lib/eco/api/microcases/people/fetch.rb +23 -0
- data/lib/eco/api/microcases/people/integrity/fix_default_group.rb +39 -0
- data/lib/eco/api/microcases/people/integrity/fix_filter_tags.rb +55 -0
- data/lib/eco/api/microcases/people/integrity/refresh_default_tag.rb +32 -0
- data/lib/eco/api/microcases/people/integrity.rb +17 -0
- data/lib/eco/api/microcases/people/macro/take_email.rb +141 -0
- data/lib/eco/api/microcases/people/macro.rb +13 -0
- data/lib/eco/api/microcases/people/manage/cache.rb +36 -0
- data/lib/eco/api/microcases/people/manage/load.rb +90 -0
- data/lib/eco/api/microcases/people/manage/refresh.rb +59 -0
- data/lib/eco/api/microcases/people/manage/search.rb +118 -0
- data/lib/eco/api/microcases/people/manage.rb +19 -0
- data/lib/eco/api/microcases/people/preserve/default_tag.rb +29 -0
- data/lib/eco/api/microcases/people/preserve/filter_tags.rb +34 -0
- data/lib/eco/api/microcases/people/preserve/policy_groups.rb +36 -0
- data/lib/eco/api/microcases/people/preserve.rb +17 -0
- data/lib/eco/api/microcases/people.rb +21 -0
- data/lib/eco/api/microcases/person_update.rb +1 -1
- data/lib/eco/api/microcases/s3upload_targets.rb +1 -1
- data/lib/eco/api/microcases/with_each_contractor_present.rb +40 -0
- data/lib/eco/api/microcases.rb +3 -23
- data/lib/eco/api/organization/people/multiple_search_results.rb +48 -0
- data/lib/eco/api/organization/{people_similarity.rb → people/similarity.rb} +89 -72
- data/lib/eco/api/organization/people.rb +40 -66
- data/lib/eco/api/organization.rb +0 -1
- data/lib/eco/api/policies/policy.rb +7 -5
- data/lib/eco/api/policies.rb +9 -4
- data/lib/eco/api/session/batch/feedback/generate.rb +60 -0
- data/lib/eco/api/session/batch/feedback/getters.rb +28 -0
- data/lib/eco/api/session/batch/feedback/identifiers.rb +20 -0
- data/lib/eco/api/session/batch/feedback/job_dependencies.rb +45 -0
- data/lib/eco/api/session/batch/feedback/request_stat.rb +27 -0
- data/lib/eco/api/session/batch/feedback/request_stats.rb +270 -0
- data/lib/eco/api/session/batch/feedback.rb +45 -119
- data/lib/eco/api/session/batch/job/sets.rb +23 -0
- data/lib/eco/api/session/batch/job/type.rb +22 -0
- data/lib/eco/api/session/batch/job.rb +8 -18
- data/lib/eco/api/session/batch/jobs.rb +6 -2
- data/lib/eco/api/session/batch/launcher/mode_size.rb +1 -1
- data/lib/eco/api/session/batch/launcher/retry.rb +4 -4
- data/lib/eco/api/session/batch/launcher.rb +2 -2
- data/lib/eco/api/session/batch/policies.rb +4 -4
- data/lib/eco/api/session/batch/searcher.rb +2 -1
- data/lib/eco/api/session/batch.rb +0 -1
- data/lib/eco/api/session/config/workflow.rb +19 -9
- data/lib/eco/api/usecases/base_case/model.rb +54 -0
- data/lib/eco/api/usecases/base_case/type.rb +52 -0
- data/lib/eco/api/usecases/base_case.rb +5 -29
- data/lib/eco/api/usecases/base_io/chaining.rb +48 -0
- data/lib/eco/api/usecases/base_io/validations.rb +114 -0
- data/lib/eco/api/usecases/base_io.rb +65 -115
- data/lib/eco/api/usecases/cli/dsl.rb +3 -1
- data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +7 -4
- data/lib/eco/api/usecases/default/people/treat/supers_cyclic_identify_case.rb +1 -3
- data/lib/eco/api/usecases/default/people/treat/supers_hierarchy_case.rb +1 -5
- data/lib/eco/api/usecases/default_cases/entries_to_csv_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/hris_case.rb +0 -2
- data/lib/eco/api/usecases/default_cases/samples/sftp.rb +3 -0
- data/lib/eco/api/usecases/default_cases/samples.rb +1 -1
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +3 -6
- data/lib/eco/api/usecases/graphql/base.rb +3 -2
- data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +1 -1
- data/lib/eco/api/usecases/graphql/helpers/base/error_handling.rb +3 -3
- data/lib/eco/api/usecases/graphql/helpers/contractors/base/load.rb +17 -0
- data/lib/eco/api/usecases/graphql/helpers/contractors/base.rb +8 -0
- data/lib/eco/api/usecases/graphql/helpers/contractors.rb +6 -0
- data/lib/eco/api/usecases/graphql/helpers/location/base.rb +5 -4
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +2 -2
- data/lib/eco/api/usecases/graphql/helpers.rb +1 -0
- data/lib/eco/api/usecases/graphql/samples/contractors/dsl.rb +5 -0
- data/lib/eco/api/usecases/graphql/samples/contractors.rb +17 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/base.rb +1 -1
- data/lib/eco/api/usecases/graphql/samples/location.rb +1 -1
- data/lib/eco/api/usecases/graphql/samples.rb +1 -0
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +0 -1
- data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +8 -8
- data/lib/eco/api/usecases/{default_cases/samples → samples/drivers}/cli/sftp_cli.rb +1 -1
- data/lib/eco/api/usecases/samples/drivers/cli/url_pull_cli.rb +15 -0
- data/lib/eco/api/usecases/{default_cases/samples/sftp_case.rb → samples/drivers/sftp_sample.rb} +8 -8
- data/lib/eco/api/usecases/samples/drivers/url_pull_sample.rb +110 -0
- data/lib/eco/api/usecases/samples/drivers.rb +13 -0
- data/lib/eco/api/usecases/samples.rb +11 -0
- data/lib/eco/api/usecases/use_case/chainer.rb +12 -0
- data/lib/eco/api/usecases/use_case.rb +32 -23
- data/lib/eco/api/usecases/use_case_chain/chaining.rb +88 -0
- data/lib/eco/api/usecases/use_case_chain.rb +17 -62
- data/lib/eco/api/usecases/use_case_io/chain.rb +24 -0
- data/lib/eco/api/usecases/use_case_io.rb +17 -22
- data/lib/eco/api/usecases.rb +15 -6
- data/lib/eco/assets.rb +1 -1
- data/lib/eco/cli/config/filters/people_filters.rb +6 -5
- data/lib/eco/cli/config/input.rb +6 -2
- data/lib/eco/cli/config/use_cases.rb +4 -2
- data/lib/eco/cli_default/people_filters.rb +1 -0
- data/lib/eco/cli_default/workflow.rb +149 -138
- data/lib/eco/data/mapper.rb +51 -19
- data/lib/eco/language/methods/dsl_able.rb +10 -0
- data/lib/eco/version.rb +1 -1
- metadata +87 -35
- data/lib/eco/api/microcases/account_excluded.rb +0 -26
- data/lib/eco/api/microcases/core_excluded.rb +0 -20
- data/lib/eco/api/microcases/fix_default_group.rb +0 -33
- data/lib/eco/api/microcases/fix_filter_tags.rb +0 -49
- data/lib/eco/api/microcases/people_cache.rb +0 -30
- data/lib/eco/api/microcases/people_load.rb +0 -84
- data/lib/eco/api/microcases/people_refresh.rb +0 -53
- data/lib/eco/api/microcases/people_search.rb +0 -112
- data/lib/eco/api/microcases/preserve_default_tag.rb +0 -23
- data/lib/eco/api/microcases/preserve_filter_tags.rb +0 -28
- data/lib/eco/api/microcases/preserve_policy_groups.rb +0 -30
- data/lib/eco/api/microcases/refresh_default_tag.rb +0 -26
- data/lib/eco/api/microcases/set_account.rb +0 -18
- data/lib/eco/api/microcases/set_core.rb +0 -17
- data/lib/eco/api/microcases/set_core_with_supervisor.rb +0 -32
- data/lib/eco/api/microcases/set_supervisor.rb +0 -63
- data/lib/eco/api/microcases/take_email_from_account.rb +0 -129
- data/lib/eco/api/microcases/with_each.rb +0 -103
- data/lib/eco/api/microcases/with_each_leaver.rb +0 -27
- data/lib/eco/api/microcases/with_each_present.rb +0 -36
- data/lib/eco/api/microcases/with_each_starter.rb +0 -37
- data/lib/eco/api/microcases/with_each_subordinate.rb +0 -33
- data/lib/eco/api/microcases/with_supervisor.rb +0 -35
- data/lib/eco/api/session/batch/request_stats.rb +0 -266
@@ -1,112 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class MicroCases
|
4
|
-
# Helper to search/obtain people from `data` against the server (_People Manager_).
|
5
|
-
# @note
|
6
|
-
# - this helper is normally used to **get partial** part of the people manager.
|
7
|
-
# - therefore, normally used with _**delta** input files_ (files with only the differences).
|
8
|
-
# @param data [Eco::API::Organization::People, Enumerable<Person>, Enumerable<Hash>]
|
9
|
-
# `People` to search against the server.
|
10
|
-
# @param options [Hash] the options.
|
11
|
-
# @param silent [Boolean] `false` if low level search messages should be shown.
|
12
|
-
# @return [Eco::API::Organization::People] the `People` object with the found persons.
|
13
|
-
def people_search(data, options: {}, silent: false) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
14
|
-
log(:info) { "Going to api get #{data.length} entries..." }
|
15
|
-
|
16
|
-
silent &&= data.count <= 500
|
17
|
-
|
18
|
-
start = Time.now
|
19
|
-
people = session.batch.search(data, silent: silent).then do |status|
|
20
|
-
secs = (Time.now - start).round(3)
|
21
|
-
|
22
|
-
Eco::API::Organization::People.new(status.people).tap do |people| # rubocop:disable Lint/ShadowingOuterLocalVariable
|
23
|
-
cnt = people.count
|
24
|
-
per_sec = (cnt.to_f / secs).round(2)
|
25
|
-
|
26
|
-
msg = "... could get #{cnt} people "
|
27
|
-
msg << "(out of #{data.length} entries) in #{secs} seconds (#{per_sec} people/sec)"
|
28
|
-
|
29
|
-
log(:info) { msg }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# get the supervisors of found people (current supervisors)
|
34
|
-
supers = people_search_prepare_supers_request(people)
|
35
|
-
if supers.length.positive?
|
36
|
-
log(:info) {
|
37
|
-
" Going to api get #{supers.length} current supervisors..."
|
38
|
-
}
|
39
|
-
|
40
|
-
start = Time.now
|
41
|
-
people = session.batch.search(supers, silent: silent).then do |status|
|
42
|
-
secs = (Time.now - start).round(3)
|
43
|
-
found = status.people
|
44
|
-
cnt = found.count
|
45
|
-
per_sec = (cnt.to_f / secs).round(2)
|
46
|
-
|
47
|
-
msg = "... could find #{cnt} current supers "
|
48
|
-
msg << "(out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)"
|
49
|
-
log(:info) { msg }
|
50
|
-
|
51
|
-
people.merge(found, strict: micro.strict_search?(options))
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# get the supervisors referred in the input data (future supervisors)
|
56
|
-
supers = people_search_prepare_supers_request(data, people)
|
57
|
-
if supers.length.positive?
|
58
|
-
log(:info) {
|
59
|
-
" Going to api get #{supers.length} supervisors as per input entries..."
|
60
|
-
}
|
61
|
-
|
62
|
-
start = Time.now
|
63
|
-
people = session.batch.search(supers, silent: silent).then do |status|
|
64
|
-
secs = (Time.now - start).round(3)
|
65
|
-
found = status.people
|
66
|
-
cnt = found.count
|
67
|
-
per_sec = (cnt.to_f / secs).round(2)
|
68
|
-
|
69
|
-
msg = "... could find #{cnt} input supers "
|
70
|
-
msg << "(out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)"
|
71
|
-
log(:info) { msg }
|
72
|
-
|
73
|
-
people.merge(found, strict: micro.strict_search?(options))
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
log(:info) {
|
78
|
-
"Finally got #{people.length} people (out of #{data.length} entries)"
|
79
|
-
}
|
80
|
-
|
81
|
-
people
|
82
|
-
end
|
83
|
-
|
84
|
-
private
|
85
|
-
|
86
|
-
# Prepares a unique request with only the supervisor ids missing in `people`
|
87
|
-
def people_search_prepare_supers_request(data, people = data)
|
88
|
-
data.each_with_object([]) do |entry, request|
|
89
|
-
spr = {"id" => (sup_id = people_search_super_id(entry))}
|
90
|
-
next if !sup_id || request.include?(spr)
|
91
|
-
|
92
|
-
micro.with_supervisor(sup_id, people) do |supervisor|
|
93
|
-
request.push(spr) unless supervisor
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# Gets the `supervisor_id` from `value`
|
99
|
-
def people_search_super_id(value)
|
100
|
-
sup_id =
|
101
|
-
if value.respond_to?(:supervisor_id)
|
102
|
-
value.supervisor_id
|
103
|
-
elsif value.is_a?(Hash) && value.key("supervisor_id")
|
104
|
-
value["supervisor_id"]
|
105
|
-
end
|
106
|
-
|
107
|
-
sup_id = nil if sup_id.to_s.strip.empty?
|
108
|
-
sup_id
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class MicroCases
|
4
|
-
# Helper to preserve the original `default_tag`.
|
5
|
-
# @note
|
6
|
-
# 1. It only works if the original value of `default_tag` 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
|
-
# @return [String] the final value of `default_tag`.
|
10
|
-
def preserve_default_tag(person, _options)
|
11
|
-
return unless (account = person.account)
|
12
|
-
|
13
|
-
account.default_tag.tap do
|
14
|
-
next unless account.as_update.key?("default_tag")
|
15
|
-
next unless (original = person.original_doc.dig("account", "default_tag"))
|
16
|
-
|
17
|
-
person.account.default_tag = original
|
18
|
-
return original
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -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
|