eco-helpers 1.4.0 → 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 +150 -2
- 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 +91 -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
@@ -1,19 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class UseCases
|
4
|
-
class DefaultCase
|
5
|
-
|
6
|
-
def initialize(cases, **options)
|
7
|
-
raise "Expected a Eco::API::UseCases object. Given #{cases.class}" if !cases.is_a?(Eco::API::UseCases)
|
8
|
-
@cases = cases
|
9
|
-
@options = options
|
10
|
-
end
|
11
|
-
|
12
|
-
def process
|
13
|
-
raise "You should reimplement this method"
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class UseCases
|
4
|
-
class DefaultCases
|
5
|
-
class DeleteCase < DefaultCase
|
6
|
-
|
7
|
-
def process
|
8
|
-
@cases.define("delete", type: :transform) do |people, session, options, usecase|
|
9
|
-
delete = session.job_group("main").new("delete", usecase: usecase, type: :delete, sets: [:core, :details, :account])
|
10
|
-
people.each_with_index do |person, i|
|
11
|
-
delete.add(person)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
@cases.define("delete", type: :sync) do |entries, people, session, options, usecase|
|
16
|
-
delete = session.job_group("main").new("delete", usecase: usecase, type: :delete, sets: [:core, :details, :account])
|
17
|
-
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
18
|
-
entries.each_with_index do |entry, i|
|
19
|
-
if person = people.find(entry, strict: strict_search)
|
20
|
-
delete.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
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class UseCases
|
4
|
-
class DefaultCases
|
5
|
-
class RecoverDBCase < DefaultCase
|
6
|
-
|
7
|
-
def process
|
8
|
-
@cases.define("recover-db", type: :sync) do |entries, people, session, options, usecase|
|
9
|
-
unless entries.is_a?(Eco::API::Organization::People)
|
10
|
-
raise "Your input should be an 'Eco::API::Organization::People' object. Got: #{entries.class}"
|
11
|
-
end
|
12
|
-
|
13
|
-
if options.dig(:include, :create)
|
14
|
-
creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details, :account])
|
15
|
-
end
|
16
|
-
|
17
|
-
update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account])
|
18
|
-
|
19
|
-
if options.dig(:include, :delete)
|
20
|
-
remove = session.job_group("main").new("remove", usecase: usecase, type: :delete, sets: [:core, :details, :account])
|
21
|
-
people.exclude(entries).map {|person| remove.add(person)}
|
22
|
-
end
|
23
|
-
|
24
|
-
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
25
|
-
pgs = session.policy_groups
|
26
|
-
|
27
|
-
not_exist = []
|
28
|
-
|
29
|
-
entries.each.with_index do |entry, i|
|
30
|
-
create = ! (person = people.find(entry, strict: strict_search))
|
31
|
-
|
32
|
-
if create && !options.dig(:include, :create)
|
33
|
-
not_exist.push(entry);
|
34
|
-
else
|
35
|
-
person = session.new_person if create
|
36
|
-
|
37
|
-
unless options.dig(:exclude, :core)
|
38
|
-
person.external_id = entry.external_id unless options.dig(:exclude, :external_id)
|
39
|
-
person.name = entry.name unless options.dig(:exclude, :name)
|
40
|
-
person.email = entry.email unless options.dig(:exclude, :email)
|
41
|
-
person.supervisor_id = entry.supervisor_id unless options.dig(:exclude, :supervisor)
|
42
|
-
person.filter_tags = entry.filter_tags || [] unless options.dig(:exclude, :filter_tags)
|
43
|
-
end
|
44
|
-
|
45
|
-
unless options.dig(:exclude, :account)
|
46
|
-
#person.account = entry.account
|
47
|
-
if eaccount = entry.account
|
48
|
-
person.account ||= {}
|
49
|
-
person.account.default_tag = eaccount.default_tag unless options.dig(:exclude, :filter_tags)
|
50
|
-
|
51
|
-
unless options.dig(:exclude, :policy_groups) && person.account.policy_group_ids
|
52
|
-
person.account.policy_group_ids = eaccount.policy_group_ids
|
53
|
-
end
|
54
|
-
|
55
|
-
unless options.dig(:exclude, :abilities) && (person.account.permissions_preset || person.account.permissions_custom)
|
56
|
-
person.account.permissions_preset = eaccount.permissions_preset if eaccount.permissions_preset
|
57
|
-
person.account.permissions_custom = eaccount.permissions_custom
|
58
|
-
end
|
59
|
-
person.account.login_provider_ids = eaccount.login_provider_ids if eaccount.login_provider_ids
|
60
|
-
person.account.accept_eula = eaccount.accept_eula if eaccount.accept_eula
|
61
|
-
|
62
|
-
if eaccount.preferences
|
63
|
-
person.account.doc["preferences"] = JSON.parse((eaccount.doc["preferences"] || {}).to_json)
|
64
|
-
end
|
65
|
-
|
66
|
-
person.account.starred_ids = eaccount.starred_ids if eaccount.landing_page_id
|
67
|
-
person.account.landing_page_id = eaccount.landing_page_id if eaccount.landing_page_id
|
68
|
-
|
69
|
-
person.account&.send_invites = options[:send_invites] if options.key?(:send_invites)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
unless options.dig(:exclude, :details)
|
74
|
-
person.details = entry.details
|
75
|
-
end
|
76
|
-
|
77
|
-
creation.add(person) if create
|
78
|
-
update.add(person) unless create
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
unless not_exist.empty?
|
83
|
-
session.logger.error("There were #{not_exist.length} entries of the back up that do not exist in the (filtered?) people manager")
|
84
|
-
session.logger.error("Some examples:")
|
85
|
-
not_exist.slice(0, 4).each_with_index do |entry, i|
|
86
|
-
session.logger.error("Entry(#{i}) - this person does not exist: #{entry.name} (#{entry.email})")
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -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,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
|