eco-helpers 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +82 -2
- data/LICENSE +21 -0
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api.rb +2 -0
- data/lib/eco/api/common.rb +4 -0
- 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 +3 -12
- 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 +15 -25
- 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 +24 -35
- data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +15 -25
- data/lib/eco/api/common/people/entries.rb +54 -24
- data/lib/eco/api/common/people/entry_factory.rb +10 -8
- 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 +3 -2
- data/lib/eco/api/common/people/person_parser.rb +51 -18
- 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 +1 -1
- data/lib/eco/api/common/version_patches/exception.rb +22 -0
- 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 +17 -13
- 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 +4 -4
- data/lib/eco/api/microcases/{set_default_group.rb → fix_default_group.rb} +10 -9
- data/lib/eco/api/microcases/fix_filter_tags.rb +26 -6
- 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 +7 -19
- data/lib/eco/api/microcases/set_core.rb +5 -5
- data/lib/eco/api/microcases/set_core_with_supervisor.rb +23 -0
- data/lib/eco/api/microcases/set_supervisor.rb +17 -13
- data/lib/eco/api/microcases/strict_search.rb +12 -7
- 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/policies.rb +11 -7
- data/lib/eco/api/session.rb +54 -24
- data/lib/eco/api/session/batch.rb +1 -1
- 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 +91 -58
- data/lib/eco/api/session/batch/status.rb +35 -31
- data/lib/eco/api/session/config.rb +104 -42
- data/lib/eco/api/session/config/api.rb +17 -6
- 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/table.rb +1 -1
- data/lib/eco/data/crypto/encryption.rb +3 -0
- 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 +63 -18
- data/lib/eco/api/microcases/set_default_tag.rb +0 -23
- 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 -99
- 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/api/usecases/microed_cases/hris_case.rb +0 -53
- data/lib/eco/api/usecases/microed_cases/update_case.rb +0 -33
- data/lib/eco/api/usecases/microed_cases/update_details_case.rb +0 -30
- data/lib/eco/api/usecases/microed_cases/upsert_case.rb +0 -36
- data/lib/eco/cli/config/default/filters.rb +0 -70
- data/lib/eco/cli/config/people_filters.rb +0 -38
@@ -1,26 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class UseCases
|
4
|
-
class DefaultCases
|
5
|
-
class RefreshPresets < DefaultCase
|
6
|
-
|
7
|
-
def process
|
8
|
-
@cases.define("refresh-presets", type: :transform) do |people, session, options, usecase|
|
9
|
-
job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :account)
|
10
|
-
|
11
|
-
users = people.users
|
12
|
-
session.logger.warn("There are no people with account amoung your #{people.length} people") unless users.length > 0
|
13
|
-
users.each do |person|
|
14
|
-
person.account.permissions_custom = session.new_preset(person)
|
15
|
-
job.add(person)
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class UseCases
|
4
|
-
class DefaultCases
|
5
|
-
class ReinviteCase < DefaultCase
|
6
|
-
|
7
|
-
def process
|
8
|
-
@cases.define("reinvite", type: :transform) do |people, session, options, usecase|
|
9
|
-
invite = session.job_group("main").new("invite", usecase: usecase, type: :update, sets: :account)
|
10
|
-
people.users.each do |person|
|
11
|
-
person.account.send_invites = true
|
12
|
-
invite.add(person)
|
13
|
-
end
|
14
|
-
invite
|
15
|
-
end
|
16
|
-
|
17
|
-
@cases.define("reinvite", type: :sync) do |entries, people, session, options, usecase|
|
18
|
-
invite = session.job_group("main").new("invite", usecase: usecase, type: :update, sets: :account)
|
19
|
-
|
20
|
-
users = people.users
|
21
|
-
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
22
|
-
|
23
|
-
entries.each_with_index do |entry, i|
|
24
|
-
if person = people.find(entry, strict: strict_search)
|
25
|
-
if person.account
|
26
|
-
person.account.send_invites = true
|
27
|
-
invite.add(person)
|
28
|
-
end
|
29
|
-
else
|
30
|
-
session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class UseCases
|
4
|
-
class DefaultCases
|
5
|
-
class RemoveAccountCase < DefaultCase
|
6
|
-
|
7
|
-
def process
|
8
|
-
|
9
|
-
@cases.define("remove-account", type: :transform) do |people, session, options, usecase|
|
10
|
-
update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :account])
|
11
|
-
people.users.map do |person|
|
12
|
-
person.account = nil
|
13
|
-
update.add(person)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
@cases.define("remove-account", type: :sync) do |entries, people, session, options, usecase|
|
18
|
-
update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :account])
|
19
|
-
|
20
|
-
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
21
|
-
|
22
|
-
entries.each.with_index do |entry, i|
|
23
|
-
if person = people.find(entry, strict: strict_search)
|
24
|
-
person.account = nil
|
25
|
-
update.add(person)
|
26
|
-
else
|
27
|
-
session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class UseCases
|
4
|
-
class DefaultCases
|
5
|
-
class HrisCase < DefaultCase
|
6
|
-
|
7
|
-
def process
|
8
|
-
@cases.define("hris", type: :sync) do |entries, people, session, options, usecase|
|
9
|
-
micro = session.microcases
|
10
|
-
|
11
|
-
creation = session.new_job("main", "create", :create, usecase)
|
12
|
-
update = session.new_job("main", "update", :update, usecase)
|
13
|
-
supers = session.new_job("post", "supers", :update, usecase, :core)
|
14
|
-
leavers = session.new_job("post", "leavers", :update, usecase, :account)
|
15
|
-
|
16
|
-
micro.with_leavers(entries, people, options, leavers) do |person|
|
17
|
-
person.supervisor_id = nil
|
18
|
-
person.account = nil if person.account
|
19
|
-
end
|
20
|
-
|
21
|
-
people.each_with_index do |person, i|
|
22
|
-
if person = people.find(entry, strict: micro.strict_search(options))
|
23
|
-
if !entries.find(person, strict: strict: micro.strict_search(options))
|
24
|
-
leavers.add(person) do |person|
|
25
|
-
person.supervisor_id = nil
|
26
|
-
person.account = nil if person.account
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
entries.each_with_index do |entry, i|
|
32
|
-
if person = people.find(entry, strict: micro.strict_search(options))
|
33
|
-
update.add(person)
|
34
|
-
else
|
35
|
-
person = session.new_person
|
36
|
-
creation.add(person)
|
37
|
-
end
|
38
|
-
|
39
|
-
micro.set_core(entry, person, options, people, supers)
|
40
|
-
entry.set_details(person) unless options.dig(:exclude, :details)
|
41
|
-
micro.set_account(entry, person, options)
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class UseCases
|
4
|
-
class DefaultCases
|
5
|
-
class UpdateCase < DefaultCase
|
6
|
-
|
7
|
-
def process
|
8
|
-
@cases.define("update", type: :sync) do |entries, people, session, options, usecase|
|
9
|
-
micro = session.microcases
|
10
|
-
|
11
|
-
update = session.new_job("main", "update", :update, usecase)
|
12
|
-
supers = session.new_job("post", "supers", :update, usecase, :core)
|
13
|
-
|
14
|
-
entries.each.with_index do |entry, i|
|
15
|
-
if person = people.find(entry, strict: micro.strict_search(**params))
|
16
|
-
micro.set_core(entry, person, options, people, supers)
|
17
|
-
entry.set_details(person) unless options.dig(:exclude, :details)
|
18
|
-
micro.set_account(entry, person, options)
|
19
|
-
|
20
|
-
update.add(person)
|
21
|
-
else
|
22
|
-
session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class UseCases
|
4
|
-
class DefaultCases
|
5
|
-
class UpdateDetailsCase < DefaultCase
|
6
|
-
|
7
|
-
def process
|
8
|
-
@cases.define("update-details", type: :sync) do |entries, people, session, options, usecase|
|
9
|
-
micro = session.microcases
|
10
|
-
|
11
|
-
update = session.new_job("main", "update", :update, usecase)
|
12
|
-
supers = session.new_job("post", "supers", :update, usecase, :core)
|
13
|
-
|
14
|
-
entries.each.with_index do |entry, i|
|
15
|
-
if person = people.find(entry, strict: micro.strict_search(options))
|
16
|
-
micro.set_core(entry, person, options, people, supers)
|
17
|
-
entry.set_details(person) unless options.dig(:exclude, :details)
|
18
|
-
update.add(person)
|
19
|
-
else
|
20
|
-
session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class UseCases
|
4
|
-
class DefaultCases
|
5
|
-
class UpsertCase < DefaultCase
|
6
|
-
|
7
|
-
def process
|
8
|
-
@cases.define("upsert", type: :sync) do |entries, people, session, options, usecase|
|
9
|
-
micro = session.microcases
|
10
|
-
|
11
|
-
creation = session.new_job("main", "create", :create, usecase)
|
12
|
-
update = session.new_job("main", "update", :update, usecase)
|
13
|
-
supers = session.new_job("post", "supers", :update, usecase, :core)
|
14
|
-
|
15
|
-
entries.each_with_index do |entry, i|
|
16
|
-
params = [entry, person, session, options]
|
17
|
-
|
18
|
-
if person = people.find(entry, strict: micro.strict_search(options))
|
19
|
-
update.add(person)
|
20
|
-
else
|
21
|
-
person = session.new_person
|
22
|
-
creation.add(person)
|
23
|
-
end
|
24
|
-
|
25
|
-
micro.set_core(entry, person, options, people, supers)
|
26
|
-
entry.set_details(person) unless options.dig(:exclude, :details)
|
27
|
-
micro.set_account(entry, person, options)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
ASSETS.cli.config do |cnf|
|
2
|
-
cnf.people_filters do |filters|
|
3
|
-
|
4
|
-
filters.add("-only-users") do |people, session, options|
|
5
|
-
options.deep_merge!(people: {filter: {account: true}})
|
6
|
-
people.users
|
7
|
-
end
|
8
|
-
|
9
|
-
filters.add("-no-account") do |people, session, options|
|
10
|
-
options.deep_merge!(people: {filter: {account: false}})
|
11
|
-
people.account_present(false)
|
12
|
-
end
|
13
|
-
|
14
|
-
filters.add("-with-details") do |people, session, options|
|
15
|
-
options.deep_merge!(people: {filter: {details: true}})
|
16
|
-
people.details_present
|
17
|
-
end
|
18
|
-
|
19
|
-
filters.add("-no-id") do |people, session, options|
|
20
|
-
options.deep_merge!(people: {filter: {external_id: nil}})
|
21
|
-
people.external_id_present(false)
|
22
|
-
end
|
23
|
-
|
24
|
-
filters.add("-supervisors") do |people, session, options|
|
25
|
-
options.deep_merge!(people: {filter: {subordinates: true}})
|
26
|
-
people.newFrom people.to_a.select {|person| person.subordinates > 0}
|
27
|
-
end
|
28
|
-
|
29
|
-
filters.add("-supervisor-id") do |people, session, options|
|
30
|
-
id = SCR.get_arg("-supervisor-id", with_param: true)
|
31
|
-
options.deep_merge!(people: {filter: {supervisor_id: id}})
|
32
|
-
unless sup = people.person(id: id, external_id: id, email: id, strict: true)
|
33
|
-
status = session.batch.search([{"id" => id}])
|
34
|
-
sup = status.people.first
|
35
|
-
end
|
36
|
-
raise "Supervisor with id '#{id}' does not exist" unless sup
|
37
|
-
people.supervisor_id(sup.id)
|
38
|
-
end
|
39
|
-
|
40
|
-
filters.add("-no-default-tag") do |people, session, options|
|
41
|
-
options.deep_merge!(people: {filter: {account: {default_tag: nil}}})
|
42
|
-
filtered = people.select do |person|
|
43
|
-
!person.account&.default_tag
|
44
|
-
end
|
45
|
-
people.newFrom filtered
|
46
|
-
end
|
47
|
-
|
48
|
-
filters.add("-schema-id") do |people, session, options|
|
49
|
-
sch_name = SCR.get_arg("-schema-id", with_param: true)
|
50
|
-
sch_id = session.schemas.to_id(sch_name)
|
51
|
-
|
52
|
-
unless sch_id
|
53
|
-
msg = "You need to specify the schema id"
|
54
|
-
session.logger.error(msg)
|
55
|
-
exit(1)
|
56
|
-
end
|
57
|
-
|
58
|
-
options.deep_merge!(people: {filter: {details: {schema_id: sch_id}}})
|
59
|
-
session.logger.info("Filtering people entries with schema #{session.schemas.to_name(sch_id)}")
|
60
|
-
|
61
|
-
filtered = people.select do |person|
|
62
|
-
person.details && (person.details.schema_id == sch_id)
|
63
|
-
end
|
64
|
-
session.logger.info("Filtered #{filtered.count} people out of #{people.count} total")
|
65
|
-
|
66
|
-
people.newFrom filtered
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
class CLI
|
3
|
-
class Config
|
4
|
-
class PeopleFilters
|
5
|
-
attr_reader :core_config
|
6
|
-
|
7
|
-
def initialize(core_config:)
|
8
|
-
@core_config = core_config
|
9
|
-
@filters = {}
|
10
|
-
end
|
11
|
-
|
12
|
-
def add(option)
|
13
|
-
raise "Missing block to define the filters builder" unless block_given?
|
14
|
-
callback = Proc.new
|
15
|
-
[option].flatten.compact.each do |opt|
|
16
|
-
@filters[opt] = callback
|
17
|
-
end
|
18
|
-
self
|
19
|
-
end
|
20
|
-
|
21
|
-
def process(io:)
|
22
|
-
unless io && io.is_a?(Eco::API::UseCases::BaseIO)
|
23
|
-
raise "You need to provide Eco::API::UseCases::BaseIO object. Given: #{io.class}"
|
24
|
-
end
|
25
|
-
|
26
|
-
io = io.new(type: :transform)
|
27
|
-
@filters.each do |arg, callback|
|
28
|
-
if SCR.get_arg(arg)
|
29
|
-
io = io.new(people: callback.call(*io.params))
|
30
|
-
end
|
31
|
-
end
|
32
|
-
io.people
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|