eco-helpers 1.4.1 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +145 -3
- data/LICENSE +21 -0
- data/eco-helpers.gemspec +11 -10
- data/lib/eco/api.rb +3 -0
- data/lib/eco/api/common.rb +5 -1
- data/lib/eco/api/common/base_loader.rb +54 -0
- data/lib/eco/api/common/class_auto_loader.rb +109 -0
- data/lib/eco/api/common/class_helpers.rb +33 -0
- data/lib/eco/api/common/class_hierarchy.rb +1 -1
- data/lib/eco/api/common/class_meta_basics.rb +16 -0
- data/lib/eco/api/common/loaders.rb +13 -0
- data/lib/eco/api/common/loaders/error_handler.rb +41 -0
- data/lib/eco/api/common/loaders/parser.rb +127 -0
- data/lib/eco/api/common/loaders/policy.rb +25 -0
- data/lib/eco/api/common/loaders/use_case.rb +40 -0
- data/lib/eco/api/common/people/default_parsers.rb +5 -10
- data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +13 -23
- data/lib/eco/api/common/people/default_parsers/csv_parser.rb +20 -35
- data/lib/eco/api/common/people/default_parsers/date_parser.rb +15 -26
- data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +20 -0
- data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +26 -0
- data/lib/eco/api/common/people/default_parsers/multi_parser.rb +15 -27
- data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +14 -19
- data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +31 -0
- data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +15 -24
- data/lib/eco/api/common/people/entries.rb +54 -24
- data/lib/eco/api/common/people/entry_factory.rb +18 -15
- data/lib/eco/api/common/people/person_attribute_parser.rb +29 -12
- data/lib/eco/api/common/people/person_entry.rb +308 -216
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +5 -2
- data/lib/eco/api/common/people/person_parser.rb +52 -19
- data/lib/eco/api/common/session/base_session.rb +3 -6
- data/lib/eco/api/common/session/environment.rb +2 -23
- data/lib/eco/api/common/session/logger.rb +4 -0
- data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +2 -0
- data/lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb +9 -1
- data/lib/eco/api/common/version_patches/exception.rb +24 -2
- data/lib/eco/api/custom.rb +13 -0
- data/lib/eco/api/custom/error_handler.rb +20 -0
- data/lib/eco/api/custom/namespace.rb +7 -0
- data/lib/eco/api/custom/parser.rb +50 -0
- data/lib/eco/api/custom/policy.rb +28 -0
- data/lib/eco/api/custom/use_case.rb +16 -0
- data/lib/eco/api/error.rb +1 -0
- data/lib/eco/api/error/handlers.rb +10 -3
- data/lib/eco/api/microcases.rb +35 -0
- data/lib/eco/api/microcases/account_excluded.rb +24 -0
- data/lib/eco/api/microcases/append_usergroups.rb +19 -0
- data/lib/eco/api/microcases/core_excluded.rb +20 -0
- data/lib/eco/api/microcases/fix_default_group.rb +34 -0
- data/lib/eco/api/microcases/fix_filter_tags.rb +42 -0
- data/lib/eco/api/microcases/people_cache.rb +17 -0
- data/lib/eco/api/microcases/people_load.rb +59 -0
- data/lib/eco/api/microcases/people_refresh.rb +31 -0
- data/lib/eco/api/microcases/people_search.rb +65 -0
- data/lib/eco/api/microcases/refresh_abilities.rb +19 -0
- data/lib/eco/api/microcases/refresh_default_tag.rb +27 -0
- data/lib/eco/api/microcases/s3upload_targets.rb +39 -0
- data/lib/eco/api/microcases/set_account.rb +20 -0
- data/lib/eco/api/microcases/set_core.rb +18 -0
- data/lib/eco/api/microcases/set_core_with_supervisor.rb +23 -0
- data/lib/eco/api/microcases/set_supervisor.rb +30 -0
- data/lib/eco/api/microcases/strict_search.rb +19 -0
- data/lib/eco/api/microcases/with_each.rb +27 -0
- data/lib/eco/api/microcases/with_each_leaver.rb +24 -0
- data/lib/eco/api/microcases/with_each_present.rb +30 -0
- data/lib/eco/api/microcases/with_each_starter.rb +30 -0
- data/lib/eco/api/microcases/with_each_subordinate.rb +34 -0
- data/lib/eco/api/microcases/with_supervisor.rb +36 -0
- data/lib/eco/api/organization/people.rb +72 -35
- data/lib/eco/api/organization/presets_factory.rb +13 -4
- data/lib/eco/api/organization/presets_reference.json +9 -1
- data/lib/eco/api/organization/presets_values.json +4 -1
- data/lib/eco/api/policies.rb +11 -7
- data/lib/eco/api/session.rb +62 -29
- data/lib/eco/api/session/batch.rb +2 -45
- data/lib/eco/api/session/batch/base_policy.rb +7 -6
- data/lib/eco/api/session/batch/errors.rb +28 -4
- data/lib/eco/api/session/batch/feedback.rb +7 -1
- data/lib/eco/api/session/batch/job.rb +40 -23
- data/lib/eco/api/session/batch/jobs.rb +9 -4
- data/lib/eco/api/session/batch/jobs_groups.rb +1 -1
- data/lib/eco/api/session/batch/request_stats.rb +95 -58
- data/lib/eco/api/session/batch/status.rb +35 -31
- data/lib/eco/api/session/config.rb +106 -44
- data/lib/eco/api/session/config/api.rb +132 -7
- data/lib/eco/api/session/config/apis.rb +24 -25
- data/lib/eco/api/session/config/logger.rb +2 -2
- data/lib/eco/api/session/config/post_launch.rb +1 -1
- data/lib/eco/api/session/config/workflow.rb +8 -7
- data/lib/eco/api/usecases.rb +47 -33
- data/lib/eco/api/usecases/backup/append_usergroups_case.rb +36 -0
- data/lib/eco/api/usecases/backup/create_case.rb +104 -0
- data/lib/eco/api/usecases/backup/create_details_case.rb +31 -0
- data/lib/eco/api/usecases/backup/create_details_with_supervisor_case.rb +48 -0
- data/lib/eco/api/usecases/backup/hris_case.rb +124 -0
- data/lib/eco/api/usecases/backup/set_default_tag_case.rb +49 -0
- data/lib/eco/api/usecases/backup/set_supervisor_case.rb +41 -0
- data/lib/eco/api/usecases/backup/transfer_account_case.rb +90 -0
- data/lib/eco/api/usecases/backup/update_case.rb +112 -0
- data/lib/eco/api/usecases/backup/update_details_case.rb +64 -0
- data/lib/eco/api/usecases/backup/upsert_case.rb +114 -0
- data/lib/eco/api/usecases/base_case.rb +2 -0
- data/lib/eco/api/usecases/base_io.rb +3 -3
- data/lib/eco/api/usecases/default_cases.rb +23 -53
- data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +10 -31
- data/lib/eco/api/usecases/default_cases/change_email_case.rb +23 -47
- data/lib/eco/api/usecases/default_cases/codes_to_tags_case.rb +56 -43
- data/lib/eco/api/usecases/default_cases/create_case.rb +15 -101
- data/lib/eco/api/usecases/default_cases/create_details_case.rb +11 -26
- data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +12 -43
- data/lib/eco/api/usecases/default_cases/delete_sync_case.rb +11 -0
- data/lib/eco/api/usecases/default_cases/delete_trans_case.rb +14 -0
- data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +10 -21
- data/lib/eco/api/usecases/default_cases/hris_case.rb +23 -120
- data/lib/eco/api/usecases/default_cases/new_email_case.rb +10 -23
- data/lib/eco/api/usecases/default_cases/new_id_case.rb +11 -25
- data/lib/eco/api/usecases/default_cases/new_id_case0.rb +14 -0
- data/lib/eco/api/usecases/default_cases/org_data_convert_case.rb +83 -0
- data/lib/eco/api/usecases/default_cases/refresh_abilities_case.rb +30 -0
- data/lib/eco/api/usecases/default_cases/refresh_case.rb +7 -20
- data/lib/eco/api/usecases/default_cases/reinvite_sync_case.rb +11 -0
- data/lib/eco/api/usecases/default_cases/reinvite_trans_case.rb +17 -0
- data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +11 -0
- data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +17 -0
- data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +9 -19
- data/lib/eco/api/usecases/default_cases/restore_db_case.rb +92 -0
- data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +32 -40
- data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +15 -33
- data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +66 -57
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +36 -44
- data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +40 -55
- data/lib/eco/api/usecases/default_cases/transfer_account_case.rb +264 -84
- data/lib/eco/api/usecases/default_cases/update_case.rb +15 -109
- data/lib/eco/api/usecases/default_cases/update_details_case.rb +14 -61
- data/lib/eco/api/usecases/default_cases/upsert_case.rb +16 -111
- data/lib/eco/api/usecases/use_case_io.rb +9 -9
- data/lib/eco/cli/config.rb +10 -2
- data/lib/eco/cli/config/default.rb +2 -1
- data/lib/eco/cli/config/default/input_filters.rb +58 -0
- data/lib/eco/cli/config/default/options.rb +60 -25
- data/lib/eco/cli/config/default/people.rb +4 -4
- data/lib/eco/cli/config/default/people_filters.rb +108 -0
- data/lib/eco/cli/config/default/usecases.rb +69 -32
- data/lib/eco/cli/config/default/workflow.rb +37 -27
- data/lib/eco/cli/config/filters.rb +50 -0
- data/lib/eco/cli/config/filters/input_filters.rb +29 -0
- data/lib/eco/cli/config/filters/people_filters.rb +29 -0
- data/lib/eco/cli/config/help.rb +49 -0
- data/lib/eco/cli/config/options_set.rb +17 -1
- data/lib/eco/cli/config/use_cases.rb +79 -53
- data/lib/eco/cli/scripting.rb +10 -2
- data/lib/eco/cli/scripting/args_helpers.rb +25 -15
- data/lib/eco/cli/scripting/argument.rb +1 -0
- data/lib/eco/cli/scripting/arguments.rb +1 -1
- data/lib/eco/csv.rb +8 -3
- data/lib/eco/csv/table.rb +1 -1
- data/lib/eco/data/crypto/encryption.rb +3 -0
- data/lib/eco/data/files/helpers.rb +6 -1
- data/lib/eco/language/match.rb +19 -9
- data/lib/eco/language/match_modifier.rb +13 -5
- data/lib/eco/language/models/collection.rb +77 -56
- data/lib/eco/language/models/parser_serializer.rb +39 -15
- data/lib/eco/version.rb +1 -1
- metadata +149 -63
- data/lib/eco/api/session/task.rb +0 -175
- data/lib/eco/api/usecases/default_case.rb +0 -19
- data/lib/eco/api/usecases/default_cases/delete_case.rb +0 -32
- data/lib/eco/api/usecases/default_cases/recover_db_case.rb +0 -98
- data/lib/eco/api/usecases/default_cases/refresh_presets_case.rb +0 -26
- data/lib/eco/api/usecases/default_cases/reinvite_case.rb +0 -41
- data/lib/eco/api/usecases/default_cases/remove_account_case.rb +0 -38
- data/lib/eco/cli/config/default/filters.rb +0 -70
- data/lib/eco/cli/config/people_filters.rb +0 -38
@@ -0,0 +1,39 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# Helper to upload target files to `S3`.
|
5
|
+
# @return [Array<String>] the paths in `S3` of the uploaded files.
|
6
|
+
def s3upload_targets
|
7
|
+
[].tap do |paths|
|
8
|
+
session.config.s3storage.target_files.each_with_object(paths) do |file, arr|
|
9
|
+
arr.push(session.s3upload(file: file))
|
10
|
+
end
|
11
|
+
session.config.s3storage.target_directories.each_with_object(paths) do |folder, arr|
|
12
|
+
arr.concat(session.s3upload(directory: folder))
|
13
|
+
end
|
14
|
+
session.config.s3storage.target_file_patterns.each_with_object(paths) do |pattern, arr|
|
15
|
+
filenames = []
|
16
|
+
case pattern
|
17
|
+
when Regexp
|
18
|
+
Dir.entries(".").sort.each do |file|
|
19
|
+
next unless File.file?(file) # Skip directories
|
20
|
+
filenames.push(file) if file =~ pattern
|
21
|
+
end
|
22
|
+
when String
|
23
|
+
Dir.glob(pattern).sort.each do |file|
|
24
|
+
next unless File.file?(file) # Skip directories
|
25
|
+
filenames.push(file)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
# missconfiguration
|
29
|
+
end
|
30
|
+
filenames.each do |file|
|
31
|
+
arr.push(session.s3upload(file: file))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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
|
+
unless options.dig(:exclude, :account)
|
9
|
+
entry.set_account(person, exclude: micro.account_excluded(person, options))
|
10
|
+
|
11
|
+
person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
|
12
|
+
micro.refresh_default_tag(entry, person, options)
|
13
|
+
micro.fix_default_group(entry, person, options)
|
14
|
+
micro.refresh_abilities(person, options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
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
|
+
unless options.dig(:exclude, :core) && !person.new?
|
11
|
+
entry.set_core(person, exclude: micro.core_excluded(person, options))
|
12
|
+
micro.fix_filter_tags(person, options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
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
|
+
unless options.dig(:exclude, :core) && !person.new?
|
13
|
+
micro.set_core(entry, person, options)
|
14
|
+
micro.set_supervisor(entry.supervisor_id, person, people, options) do |unkown_id|
|
15
|
+
# delay setting supervisor if does not exit
|
16
|
+
supers_job.add(person) {|person| person.supervisor_id = unkown_id}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# Special snippet to decide if the `supervisor_id` is set now or in a later batch job `supers_job`.
|
5
|
+
# @note delaying the setting of a `supervisor_id` can save errors when the supervisor still does not exit.
|
6
|
+
# @param sup_id [nil, String] the **supervisor id** we should set on the `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 options [Hash] the options.
|
10
|
+
# @yield [supervisor_id] callback when the supervisor_id is **unknown** (not `nil` nor any one's in `people`).
|
11
|
+
# @yieldparam supervisor_id [String] the **unknown** `supervisor_id`.
|
12
|
+
def set_supervisor(sup_id, person, people, options)
|
13
|
+
unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
|
14
|
+
micro.with_supervisor(sup_id, people) do |supervisor|
|
15
|
+
if !sup_id
|
16
|
+
person.supervisor_id = nil
|
17
|
+
elsif supervisor
|
18
|
+
person.supervisor_id = supervisor.id
|
19
|
+
elsif !block_given?
|
20
|
+
person.supervisor_id = sup_id
|
21
|
+
else
|
22
|
+
yield(sup_id) if block_given?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# When trying to find an `person` with given a source `entry`, it states if such a search should be `strict` or `soft`.
|
5
|
+
# @note
|
6
|
+
# - `strict` searches ignore the email when the source `entry` has an `external_id` specified.
|
7
|
+
# - see related command line options `-search-strict` and `-search-soft`
|
8
|
+
# @param options [Hash] the options.
|
9
|
+
# @return [Boolean] `true` if the search should be `strict` only, and `false` otherwise.
|
10
|
+
def strict_search?(options)
|
11
|
+
strict_config = session.config.people.strict_search?
|
12
|
+
strict_option = options.dig(:search, :strict)
|
13
|
+
soft_option = options.dig(:search, :soft) && !strict_option
|
14
|
+
(strict_config || strict_option) && !soft_option
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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
|
+
# @yield [entry, person] gives each entry, and the paired person thereof (new or existing).
|
11
|
+
# @yieldparam entry [PersonEntry] the input entry with the data we should set on person.
|
12
|
+
# @yieldparam person [Ecoportal::API::V1::Person] the found person that matches `entry`, or a new person otherwise.
|
13
|
+
# @return [Eco::API::Organization::People] all the people, including new and existing ones.
|
14
|
+
def with_each(entries, people, options)
|
15
|
+
entries.map do |entry|
|
16
|
+
unless person = people.find(entry, strict: micro.strict_search?(options))
|
17
|
+
person = session.new_person
|
18
|
+
end
|
19
|
+
person.entry = entry
|
20
|
+
yield(entry, person) if block_given?
|
21
|
+
person
|
22
|
+
end.yield_self {|all_people| people.newFrom all_people.uniq}
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
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 to be used only when the input file is the full DB
|
6
|
+
# @param entries [Eco::API::Common::People::Entries] the input entries with the data.
|
7
|
+
# @param people [Eco::API::Organization::People] target existing _People_ of the current update.
|
8
|
+
# @param options [Hash] the options.
|
9
|
+
# @yield [person] gives each person of `people` that is not present in `entries`.
|
10
|
+
# @yieldparam person [Ecoportal::API::V1::Person] the person that leaves the org.
|
11
|
+
# @return [Eco::API::Organization::People] the leavers.
|
12
|
+
def with_each_leaver(entries, people, options)
|
13
|
+
leavers = people.map do |person|
|
14
|
+
unless entries.find(person, strict: micro.strict_search?(options))
|
15
|
+
yield(person) if block_given?
|
16
|
+
person
|
17
|
+
end
|
18
|
+
end.compact
|
19
|
+
people.newFrom leavers
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
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? && log_starter
|
19
|
+
session.logger.error("This person does not exist: #{entry.to_s(:identify)}")
|
20
|
+
next
|
21
|
+
end
|
22
|
+
found << person
|
23
|
+
yield(entry, person) if block_given?
|
24
|
+
end
|
25
|
+
people.newFrom found
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
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
|
+
# @yield [entry, person] gives each **new** `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 **new** person.
|
14
|
+
# @return [Eco::API::Organization::People] the starters.
|
15
|
+
def with_each_starter(entries, people, options, log_present: false)
|
16
|
+
starters = []
|
17
|
+
micro.with_each(entries, people, options) do |entry, person|
|
18
|
+
if !person.new? && log_present
|
19
|
+
session.logger.error("This person (id: '#{person.id}') already exists: #{entry.to_s(:identify)}")
|
20
|
+
next
|
21
|
+
end
|
22
|
+
starters << person
|
23
|
+
yield(entry, person) if block_given?
|
24
|
+
end
|
25
|
+
people.newFrom starters
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,36 @@
|
|
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
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -3,24 +3,18 @@ module Eco
|
|
3
3
|
module Organization
|
4
4
|
class People < Eco::Language::Models::Collection
|
5
5
|
# build the shortcuts of Collection
|
6
|
-
attr_collection :id, :external_id, :email, :name, :supervisor_id
|
7
6
|
attr_presence :account, :details
|
7
|
+
attr_collection :id, :external_id, :email, :name, :supervisor_id
|
8
8
|
|
9
9
|
alias_method :people, :to_a
|
10
10
|
|
11
|
-
def initialize(people = [], klass: Ecoportal::API::Internal::Person
|
11
|
+
def initialize(people = [], klass: Ecoportal::API::Internal::Person)
|
12
12
|
@klass = Ecoportal::API::Internal::Person unless klass == Ecoportal::API::V1::Person
|
13
13
|
super(people, klass: @klass)
|
14
14
|
@caches_init = false
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
to_a.to_json
|
19
|
-
end
|
20
|
-
|
21
|
-
def [](id_or_ext)
|
22
|
-
id(id_or_ext) || external_id(id_or_ext)
|
23
|
-
end
|
17
|
+
# @!group Main identifier helpers
|
24
18
|
|
25
19
|
def id(*args)
|
26
20
|
attr('id', *args).first
|
@@ -30,6 +24,13 @@ module Eco
|
|
30
24
|
attr('external_id', *args).first
|
31
25
|
end
|
32
26
|
|
27
|
+
def [](id_or_ext)
|
28
|
+
id(id_or_ext) || external_id(id_or_ext)
|
29
|
+
end
|
30
|
+
# @!endgroup
|
31
|
+
|
32
|
+
# @!group Special filters
|
33
|
+
|
33
34
|
def users
|
34
35
|
account_present(true)
|
35
36
|
end
|
@@ -42,7 +43,41 @@ module Eco
|
|
42
43
|
account_present(false)
|
43
44
|
end
|
44
45
|
|
45
|
-
|
46
|
+
def supervisors
|
47
|
+
sup_ids = self.ids & self.supervisor_ids
|
48
|
+
sup_ids.map do |id|
|
49
|
+
person(id: id, strict: true)
|
50
|
+
end.yield_self do |supervisors|
|
51
|
+
newFrom supervisors
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def missing_supervisors_ids
|
56
|
+
sup_ids = self.supervisor_ids
|
57
|
+
sup_ids - (sup_ids & self.ids)
|
58
|
+
end
|
59
|
+
|
60
|
+
def filter_tags_any(tags)
|
61
|
+
attr("filter_tags", tags, default_modifier.any.insensitive)
|
62
|
+
end
|
63
|
+
|
64
|
+
def filter_tags_all(tags)
|
65
|
+
attr("filter_tags", tags, default_modifier.all.insensitive)
|
66
|
+
end
|
67
|
+
|
68
|
+
def policy_group_ids_any(ids)
|
69
|
+
attr("policy_group_ids", tags, default_modifier.any.insensitive)
|
70
|
+
end
|
71
|
+
|
72
|
+
def policy_group_ids_all(ids)
|
73
|
+
attr("policy_group_ids", tags, default_modifier.all.insensitive)
|
74
|
+
end
|
75
|
+
|
76
|
+
# @!endgroup
|
77
|
+
|
78
|
+
# @!group Searchers
|
79
|
+
|
80
|
+
# It searches a person using the parameters given.
|
46
81
|
# @param id [String] the `internal id` of the person
|
47
82
|
# @param external_id [String] the `exernal_id` of the person
|
48
83
|
# @param email [String] the `email` of the person
|
@@ -72,23 +107,34 @@ module Eco
|
|
72
107
|
end
|
73
108
|
|
74
109
|
def find(object, strict: false)
|
75
|
-
id =
|
76
|
-
external_id = object
|
77
|
-
email =
|
110
|
+
id = attr_value(object, "id")
|
111
|
+
external_id = attr_value(object, "external_id")
|
112
|
+
email = attr_value(object, "email")
|
78
113
|
person(id: id, external_id: external_id, email: email, strict: strict)
|
79
114
|
end
|
115
|
+
# @!endgroup
|
116
|
+
|
117
|
+
# @!group Basic Collection Methods
|
118
|
+
|
119
|
+
def to_json
|
120
|
+
to_a.to_json
|
121
|
+
end
|
122
|
+
|
123
|
+
def newFrom(data)
|
124
|
+
self.class.new(data, klass: @klass)
|
125
|
+
end
|
80
126
|
|
81
127
|
def uniq(strict: false, include_unsearchable: false)
|
82
|
-
init_caches
|
83
128
|
unsearchable = []
|
84
|
-
|
129
|
+
to_a.each_with_object([]) do |person, people|
|
85
130
|
if found = find(person, strict: strict)
|
86
131
|
people << found
|
87
132
|
else
|
88
133
|
unsearchable << person
|
89
134
|
end
|
90
|
-
end.
|
91
|
-
|
135
|
+
end.yield_self do |found|
|
136
|
+
found += unsearchable if include_unsearchable
|
137
|
+
newFrom found
|
92
138
|
end
|
93
139
|
end
|
94
140
|
|
@@ -103,15 +149,19 @@ module Eco
|
|
103
149
|
end
|
104
150
|
|
105
151
|
def exclude!(object, strict: false)
|
106
|
-
self < exclude(object, strict: strict)
|
152
|
+
self < exclude(object, strict: strict)
|
107
153
|
end
|
108
154
|
|
109
155
|
def exclude_people(list, strict: false)
|
110
|
-
|
156
|
+
list.map do |person|
|
111
157
|
find(person, strict: strict)
|
112
|
-
end.compact
|
113
|
-
|
158
|
+
end.compact.yield_self do |discarded|
|
159
|
+
newFrom to_a - discarded
|
160
|
+
end
|
114
161
|
end
|
162
|
+
# @!endgroup
|
163
|
+
|
164
|
+
# @!group Groupping methods
|
115
165
|
|
116
166
|
def email_id_maps
|
117
167
|
users.group_by(:email).transform_values { |person| person.id }
|
@@ -121,23 +171,10 @@ module Eco
|
|
121
171
|
to_h(:supervisor_id)
|
122
172
|
end
|
123
173
|
|
124
|
-
# only those that are present
|
125
|
-
def supervisors
|
126
|
-
h_all = self.to_h
|
127
|
-
sup_ids = h_all.keys & self.supervisor_ids
|
128
|
-
newFrom h_all.select do |id, person|
|
129
|
-
sup_ids.include?(id)
|
130
|
-
end.values
|
131
|
-
end
|
132
|
-
|
133
|
-
def missing_supervisors_ids
|
134
|
-
sup_ids = self.supervisor_ids
|
135
|
-
sup_ids - (sup_ids & self.ids)
|
136
|
-
end
|
137
|
-
|
138
174
|
def to_h(attr = "id")
|
139
175
|
super(attr || "id")
|
140
176
|
end
|
177
|
+
# @!endgroup
|
141
178
|
|
142
179
|
protected
|
143
180
|
|