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
@@ -0,0 +1,124 @@
|
|
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
|
+
creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details, :account])
|
10
|
+
update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account])
|
11
|
+
supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
|
12
|
+
leavers = session.job_group("post").new("leavers", usecase: usecase, type: :update, sets: :account)
|
13
|
+
|
14
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
15
|
+
pgs = session.policy_groups
|
16
|
+
|
17
|
+
people.each_with_index do |person, i|
|
18
|
+
if !entries.find(person, strict: strict_search)
|
19
|
+
leavers.add(person) do |person|
|
20
|
+
person.supervisor_id = nil
|
21
|
+
person.account = nil if person.account
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
if session.config.people.default_usergroup?
|
28
|
+
def_id = pgs.to_id(session.config.people.default_usergroup)
|
29
|
+
end
|
30
|
+
|
31
|
+
entries.each_with_index do |entry, i|
|
32
|
+
person = people.find(entry, strict: strict_search)
|
33
|
+
person = session.new_person if create = !person
|
34
|
+
|
35
|
+
unless options.dig(:exclude, :core) && !create
|
36
|
+
ini_tags = person.filter_tags || []
|
37
|
+
|
38
|
+
core_attrs = ["name", "external_id", "email", "filter_tags"]
|
39
|
+
core_excluded = core_attrs.map.select {|attr| options.dig(:exclude, attr.to_sym)}
|
40
|
+
core_excluded.push("supervisor_id")
|
41
|
+
|
42
|
+
entry.set_core(person, exclude: core_excluded)
|
43
|
+
if session.tagtree && !options.dig(:exclude, :filter_tags)
|
44
|
+
person.filter_tags = session.tagtree.user_tags(
|
45
|
+
initial: ini_tags,
|
46
|
+
final: person.filter_tags,
|
47
|
+
preserve_custom: true,
|
48
|
+
add_custom: true
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
entry.set_details(person) unless options.dig(:exclude, :details)
|
54
|
+
|
55
|
+
unless options.dig(:exclude, :account)
|
56
|
+
add_account = !person.account
|
57
|
+
ini_pg_ids = person.account&.policy_group_ids || []
|
58
|
+
|
59
|
+
account_excluded = []
|
60
|
+
account_excluded.push("policy_group_ids") if options.dig(:exclude, :policy_groups) && !create
|
61
|
+
|
62
|
+
entry.set_account(person, exclude: account_excluded)
|
63
|
+
|
64
|
+
person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
|
65
|
+
|
66
|
+
unless options.dig(:exclude, :policy_groups) && !create
|
67
|
+
end_pg_ids = person.account.policy_group_ids || []
|
68
|
+
|
69
|
+
if add_account && def_id && !entry.policy_group_ids?
|
70
|
+
# on account creation, if missing policy_group_ids column in the input
|
71
|
+
# use default_usergroup, if it's defined
|
72
|
+
end_pg_ids = [def_id]
|
73
|
+
end
|
74
|
+
|
75
|
+
# avoid false updates by preserving the original order
|
76
|
+
person.account.policy_group_ids = pgs.user_pg_ids(
|
77
|
+
initial: ini_pg_ids,
|
78
|
+
final: end_pg_ids
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
person.account.permissions_custom = session.new_preset(person) unless !create && options.dig(:exclude, :abilities)
|
83
|
+
|
84
|
+
unless options.dig(:exclude, :filter_tags) || entry.default_tag?
|
85
|
+
if session.tagtree
|
86
|
+
person.account.default_tag = session.tagtree.default_tag(*person.filter_tags)
|
87
|
+
else
|
88
|
+
tags = person.filter_tags || []
|
89
|
+
person.account.default_tag = tags.first unless tags.length > 1
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
creation.add(person) if create
|
95
|
+
update.add(person) unless create
|
96
|
+
|
97
|
+
# set supervisor
|
98
|
+
unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
|
99
|
+
if !(sup_id = entry.supervisor_id)
|
100
|
+
person.supervisor_id = nil
|
101
|
+
else
|
102
|
+
if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)
|
103
|
+
person.supervisor_id = supervisor.id
|
104
|
+
else
|
105
|
+
# delay setting supervisor if does not exit
|
106
|
+
supers.add(person) do |person|
|
107
|
+
person.supervisor_id = sup_id
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class UseCases
|
4
|
+
class DefaultCases
|
5
|
+
class SetDefaultTagCase < DefaultCase
|
6
|
+
# take the deepest tag (the one that is further down in the tree)
|
7
|
+
# different options (several nodes at the same depth):
|
8
|
+
# => take the common node between them (i.e. you have Hamilton and Auckland -> take New Zealand)
|
9
|
+
# => if there's no common node between them, take the `first` (unless they are at top level of the tree)
|
10
|
+
|
11
|
+
def process
|
12
|
+
@cases.define("set-default-tag", type: :transform) do |people, session, options, usecase|
|
13
|
+
if !session.tagtree
|
14
|
+
msg = "There is no tagtree definition in the configuration files\n" +
|
15
|
+
"For this usecase to work out you need to define it."
|
16
|
+
session.logger.fatal(msg)
|
17
|
+
raise msg
|
18
|
+
end
|
19
|
+
|
20
|
+
# IMPORTANT: this two lines ensure that only people to be updated is selected
|
21
|
+
all_people = people
|
22
|
+
people = people.account_present
|
23
|
+
|
24
|
+
if people.length <= 0
|
25
|
+
msg = "There are no people with account... aborting script"
|
26
|
+
session.logger.info(msg)
|
27
|
+
raise msg
|
28
|
+
end
|
29
|
+
|
30
|
+
update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :account)
|
31
|
+
|
32
|
+
people.each_with_index do |person, i|
|
33
|
+
if session.tagtree
|
34
|
+
person.account.default_tag = session.tagtree.default_tag(*person.filter_tags)
|
35
|
+
else
|
36
|
+
tags = person.filter_tags || []
|
37
|
+
person.account.default_tag = tags.first unless tags.length > 1
|
38
|
+
end
|
39
|
+
update.add(person)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class UseCases
|
4
|
+
class DefaultCases
|
5
|
+
class SetSupervisorCase < DefaultCase
|
6
|
+
|
7
|
+
def process
|
8
|
+
@cases.define("set-supervisor", type: :sync) do |entries, people, session, options, usecase|
|
9
|
+
job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :core)
|
10
|
+
|
11
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
12
|
+
|
13
|
+
entries.each.with_index do |entry, i|
|
14
|
+
person = people.find(entry, strict: strict_search)
|
15
|
+
|
16
|
+
if !person
|
17
|
+
session.logger.error("This person does not exist: #{entry.to_s(:identify)}")
|
18
|
+
else
|
19
|
+
sup_id = entry.supervisor_id
|
20
|
+
supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)
|
21
|
+
|
22
|
+
if !supervisor
|
23
|
+
if entry.supervisor_id
|
24
|
+
msg = "Entry(#{i}) - supervisor id #{entry.supervisor_id} does not exist for person: #{entry.to_s(:identify)}"
|
25
|
+
session.logger.warn(msg)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
# set internal id of the supervisor (detect if actually changed)
|
29
|
+
person.supervisor_id = supervisor.id
|
30
|
+
job.add(person)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class UseCases
|
4
|
+
class DefaultCases
|
5
|
+
class TransferAccountCase < DefaultCase
|
6
|
+
|
7
|
+
def process
|
8
|
+
@cases.define("transfer-account", type: :sync) do |entries, people, session, options, usecase|
|
9
|
+
remove_account = session.job_group("main").new("remove account", usecase: usecase, type: :update, sets: :account)
|
10
|
+
add_account = session.job_group("post").new("add account", usecase: usecase, type: :update, sets: :account)
|
11
|
+
|
12
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
13
|
+
|
14
|
+
done = []; pending = []
|
15
|
+
pairs = entries.each_with_object([]) do |source|
|
16
|
+
entry_hash = source.internal_entry
|
17
|
+
unless entry_hash.key?("destination-id")
|
18
|
+
session.logger.error("You haven't defined a column 'destination-id' to whom the account should be transferred")
|
19
|
+
exit(1)
|
20
|
+
end
|
21
|
+
if peer_id = entry_hash["destination-id"]
|
22
|
+
if peer = entries.entry(id: peer_id, external_id: peer_id)
|
23
|
+
if done.include?(peer)
|
24
|
+
session.logger.error("You paired '#{peer_id}' twice. A person can only receive account from 1 user")
|
25
|
+
exit(1)
|
26
|
+
end
|
27
|
+
pending.delete(source)
|
28
|
+
pending.delete(peer)
|
29
|
+
done.push(source).push(pair)
|
30
|
+
[source, peer]
|
31
|
+
else
|
32
|
+
pending.push(source)
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
else
|
36
|
+
pending.push(source)
|
37
|
+
end
|
38
|
+
end.compact
|
39
|
+
|
40
|
+
# Data input integrity check
|
41
|
+
unless pending.empty?
|
42
|
+
msg = "You haven't defined a pair for the following ids:"
|
43
|
+
msg += pending.each_with_object("") do |entry, str|
|
44
|
+
str << "\n#{entry.id || entry.external_id}"
|
45
|
+
end
|
46
|
+
session.logger.error(msg)
|
47
|
+
exit(1)
|
48
|
+
end
|
49
|
+
|
50
|
+
pairs.each do |pair|
|
51
|
+
src_entry, dst_entry = pair
|
52
|
+
unless src_person = people.find(src_entry, strict: strict_search)
|
53
|
+
session.logger.error("This person does not exist: #{src_entry.to_s(:identify)}")
|
54
|
+
exit(1)
|
55
|
+
end
|
56
|
+
|
57
|
+
unless dst_person = people.find(dst_entry, strict: strict_search)
|
58
|
+
session.logger.error("This person does not exist: #{dst_person.to_s(:identify)}")
|
59
|
+
exit(1)
|
60
|
+
end
|
61
|
+
|
62
|
+
unless account_doc = src_person.account&.doc
|
63
|
+
session.logger.error("You are trying to move account from a person that doesn't have: #{src_person.id | src_person.external_id}")
|
64
|
+
exit(1)
|
65
|
+
end
|
66
|
+
|
67
|
+
if dst_person.email.to_s.strip.empty?
|
68
|
+
session.logger.error("A person you are trying to add account doesn't have email: #{dst_person.id | dst_person.external_id}")
|
69
|
+
exit(1)
|
70
|
+
end
|
71
|
+
|
72
|
+
src_person.account = nil
|
73
|
+
remove_account.add(src_person)
|
74
|
+
add_account.add(dst_person) do |person|
|
75
|
+
# only if we got to remove the account of the original person
|
76
|
+
if account_doc && src_person.as_update == {}
|
77
|
+
person.account = account_doc
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,112 @@
|
|
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
|
+
update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account])
|
10
|
+
supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
|
11
|
+
|
12
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
13
|
+
pgs = session.policy_groups
|
14
|
+
|
15
|
+
if session.config.people.default_usergroup?
|
16
|
+
def_id = pgs.to_id(session.config.people.default_usergroup)
|
17
|
+
end
|
18
|
+
|
19
|
+
entries.each.with_index do |entry, i|
|
20
|
+
if person = people.find(entry, strict: strict_search)
|
21
|
+
|
22
|
+
unless options.dig(:exclude, :core)
|
23
|
+
ini_tags = person.filter_tags || []
|
24
|
+
|
25
|
+
core_attrs = ["name", "external_id", "email", "filter_tags"]
|
26
|
+
core_excluded = core_attrs.map.select {|attr| options.dig(:exclude, attr.to_sym)}
|
27
|
+
core_excluded.push("supervisor_id")
|
28
|
+
|
29
|
+
entry.set_core(person, exclude: core_excluded)
|
30
|
+
|
31
|
+
if session.tagtree && !options.dig(:exclude, :filter_tags)
|
32
|
+
person.filter_tags = session.tagtree.user_tags(
|
33
|
+
initial: ini_tags,
|
34
|
+
final: person.filter_tags,
|
35
|
+
preserve_custom: true,
|
36
|
+
add_custom: true
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
entry.set_details(person) unless options.dig(:exclude, :details)
|
42
|
+
|
43
|
+
unless options.dig(:exclude, :account)
|
44
|
+
add_account = !person.account
|
45
|
+
ini_pg_ids = person.account&.policy_group_ids || []
|
46
|
+
|
47
|
+
account_excluded = []
|
48
|
+
account_excluded.push("policy_group_ids") if options.dig(:exclude, :policy_groups)
|
49
|
+
|
50
|
+
entry.set_account(person, exclude: account_excluded)
|
51
|
+
|
52
|
+
person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
|
53
|
+
|
54
|
+
unless options.dig(:exclude, :policy_groups) && !create
|
55
|
+
end_pg_ids = person.account.policy_group_ids || []
|
56
|
+
|
57
|
+
if add_account && def_id && !entry.policy_group_ids?
|
58
|
+
# on account creation, if missing policy_group_ids column in the input
|
59
|
+
# use default_usergroup, if it's defined
|
60
|
+
end_pg_ids = [def_id]
|
61
|
+
end
|
62
|
+
|
63
|
+
# avoid false updates by preserving the original order
|
64
|
+
person.account.policy_group_ids = pgs.user_pg_ids(
|
65
|
+
initial: ini_pg_ids,
|
66
|
+
final: end_pg_ids
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
person.account.permissions_custom = session.new_preset(person) unless options.dig(:exclude, :abilities)
|
71
|
+
|
72
|
+
unless options.dig(:exclude, :filter_tags) || entry.default_tag?
|
73
|
+
if session.tagtree
|
74
|
+
person.account.default_tag = session.tagtree.default_tag(*person.filter_tags)
|
75
|
+
else
|
76
|
+
tags = person.filter_tags || []
|
77
|
+
person.account.default_tag = tags.first unless tags.length > 1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
update.add(person)
|
83
|
+
|
84
|
+
# set supervisor
|
85
|
+
unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
|
86
|
+
if !(sup_id = entry.supervisor_id)
|
87
|
+
person.supervisor_id = nil
|
88
|
+
else
|
89
|
+
if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)
|
90
|
+
person.supervisor_id = supervisor.id
|
91
|
+
else
|
92
|
+
# delay setting supervisor if does not exit
|
93
|
+
supers.add(person) do |person|
|
94
|
+
person.supervisor_id = sup_id
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
else
|
101
|
+
session.logger.error("This person does not exist: #{entry.to_s(:identify)}")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,64 @@
|
|
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
|
+
job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details])
|
10
|
+
supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
|
11
|
+
|
12
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
13
|
+
|
14
|
+
entries.each.with_index do |entry, i|
|
15
|
+
if person = people.find(entry, strict: strict_search)
|
16
|
+
unless options.dig(:exclude, :core)
|
17
|
+
core_attrs = ["name", "external_id", "email", "filter_tags"]
|
18
|
+
core_excluded = core_attrs.map.select {|attr| options.dig(:exclude, attr.to_sym)}
|
19
|
+
core_excluded.push("supervisor_id")
|
20
|
+
|
21
|
+
entry.set_core(person, exclude: core_excluded) unless options.dig(:exclude, :core)
|
22
|
+
|
23
|
+
if session.tagtree && !options.dig(:exclude, :filter_tags)
|
24
|
+
person.filter_tags = session.tagtree.user_tags(
|
25
|
+
initial: ini_tags,
|
26
|
+
final: person.filter_tags,
|
27
|
+
preserve_custom: true,
|
28
|
+
add_custom: true
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
entry.set_details(person)
|
34
|
+
|
35
|
+
job.add(person)
|
36
|
+
|
37
|
+
# set supervisor
|
38
|
+
unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
|
39
|
+
if !(sup_id = entry.supervisor_id)
|
40
|
+
person.supervisor_id = nil
|
41
|
+
else
|
42
|
+
if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)
|
43
|
+
person.supervisor_id = supervisor.id
|
44
|
+
else
|
45
|
+
# delay setting supervisor if does not exit
|
46
|
+
supers.add(person) do |person|
|
47
|
+
person.supervisor_id = sup_id
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
else
|
54
|
+
session.logger.error("This person does not exist: #{entry.to_s(:identify)}")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|