eco-helpers 1.5.1 → 1.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +114 -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.rb +1 -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/common/version_patches/object.rb +10 -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 +95 -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 +101 -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 +104 -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.rb +1 -1
- data/lib/eco/api/usecases/use_case_io.rb +9 -10
- 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 +89 -31
- 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 +64 -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,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,99 +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
|
-
person.freemium = entry.freemium
|
44
|
-
end
|
45
|
-
|
46
|
-
unless options.dig(:exclude, :account)
|
47
|
-
#person.account = entry.account
|
48
|
-
if eaccount = entry.account
|
49
|
-
person.account ||= {}
|
50
|
-
person.account.default_tag = eaccount.default_tag unless options.dig(:exclude, :filter_tags)
|
51
|
-
|
52
|
-
unless options.dig(:exclude, :policy_groups) && person.account.policy_group_ids
|
53
|
-
person.account.policy_group_ids = eaccount.policy_group_ids
|
54
|
-
end
|
55
|
-
|
56
|
-
unless options.dig(:exclude, :abilities) && (person.account.permissions_preset || person.account.permissions_custom)
|
57
|
-
person.account.permissions_preset = eaccount.permissions_preset if eaccount.permissions_preset
|
58
|
-
person.account.permissions_custom = eaccount.permissions_custom
|
59
|
-
end
|
60
|
-
person.account.login_provider_ids = eaccount.login_provider_ids if eaccount.login_provider_ids
|
61
|
-
person.account.accept_eula = eaccount.accept_eula if eaccount.accept_eula
|
62
|
-
|
63
|
-
if eaccount.preferences
|
64
|
-
person.account.doc["preferences"] = JSON.parse((eaccount.doc["preferences"] || {}).to_json)
|
65
|
-
end
|
66
|
-
|
67
|
-
person.account.starred_ids = eaccount.starred_ids if eaccount.landing_page_id
|
68
|
-
person.account.landing_page_id = eaccount.landing_page_id if eaccount.landing_page_id
|
69
|
-
|
70
|
-
person.account&.send_invites = options[:send_invites] if options.key?(:send_invites)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
unless options.dig(:exclude, :details)
|
75
|
-
person.details = entry.details
|
76
|
-
end
|
77
|
-
|
78
|
-
creation.add(person) if create
|
79
|
-
update.add(person) unless create
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
unless not_exist.empty?
|
84
|
-
session.logger.error("There were #{not_exist.length} entries of the back up that do not exist in the (filtered?) people manager")
|
85
|
-
session.logger.error("Some examples:")
|
86
|
-
not_exist.slice(0, 4).each_with_index do |entry, i|
|
87
|
-
session.logger.error("Entry(#{i}) - this person does not exist: #{entry.name} (#{entry.email})")
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
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,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
|