eco-helpers 1.5.12 → 2.0.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 +65 -1
- data/eco-helpers.gemspec +31 -29
- data/lib/eco/api.rb +1 -1
- data/lib/eco/api/common/class_helpers.rb +45 -1
- data/lib/eco/api/common/loaders/error_handler.rb +2 -0
- data/lib/eco/api/common/loaders/parser.rb +4 -0
- data/lib/eco/api/common/loaders/use_case.rb +2 -0
- data/lib/eco/api/common/people/person_entry.rb +15 -3
- data/lib/eco/api/common/session/logger.rb +9 -1
- data/lib/eco/api/common/session/logger/cache.rb +91 -0
- data/lib/eco/api/common/session/logger/log.rb +48 -0
- data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +9 -0
- data/lib/eco/api/microcases/people_cache.rb +7 -0
- data/lib/eco/api/microcases/people_load.rb +29 -21
- data/lib/eco/api/microcases/people_refresh.rb +6 -0
- data/lib/eco/api/microcases/people_search.rb +33 -8
- data/lib/eco/api/policies.rb +1 -0
- data/lib/eco/api/policies/default_policies.rb +12 -0
- data/lib/eco/api/policies/default_policies/99_user_access_policy.rb +100 -0
- data/lib/eco/api/session.rb +13 -0
- data/lib/eco/api/session/batch.rb +0 -3
- data/lib/eco/api/session/batch/job.rb +17 -7
- data/lib/eco/api/session/config/api.rb +1 -1
- data/lib/eco/api/usecases.rb +1 -0
- data/lib/eco/api/usecases/ooze_samples.rb +11 -0
- data/lib/eco/api/usecases/ooze_samples/ooze_update_case.rb +85 -0
- data/lib/eco/version.rb +1 -1
- metadata +42 -47
- data/lib/eco/api/usecases/backup/append_usergroups_case.rb +0 -36
- data/lib/eco/api/usecases/backup/create_case.rb +0 -104
- data/lib/eco/api/usecases/backup/create_details_case.rb +0 -31
- data/lib/eco/api/usecases/backup/create_details_with_supervisor_case.rb +0 -48
- data/lib/eco/api/usecases/backup/hris_case.rb +0 -124
- data/lib/eco/api/usecases/backup/set_default_tag_case.rb +0 -49
- data/lib/eco/api/usecases/backup/set_supervisor_case.rb +0 -41
- data/lib/eco/api/usecases/backup/transfer_account_case.rb +0 -90
- data/lib/eco/api/usecases/backup/update_case.rb +0 -112
- data/lib/eco/api/usecases/backup/update_details_case.rb +0 -64
- data/lib/eco/api/usecases/backup/upsert_case.rb +0 -114
@@ -1,64 +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
|
-
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
|
@@ -1,114 +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
|
-
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
|
-
|
13
|
-
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
14
|
-
pgs = session.policy_groups
|
15
|
-
|
16
|
-
if session.config.people.default_usergroup?
|
17
|
-
def_id = pgs.to_id(session.config.people.default_usergroup)
|
18
|
-
end
|
19
|
-
|
20
|
-
entries.each_with_index do |entry, i|
|
21
|
-
person = people.find(entry, strict: strict_search)
|
22
|
-
person = session.new_person if create = !person
|
23
|
-
|
24
|
-
unless options.dig(:exclude, :core) && !create
|
25
|
-
ini_tags = person.filter_tags || []
|
26
|
-
|
27
|
-
core_excluded = ["supervisor_id"]
|
28
|
-
|
29
|
-
unless create
|
30
|
-
core_attrs = ["name", "external_id", "email", "filter_tags"]
|
31
|
-
core_excluded += core_attrs.map.select {|attr| options.dig(:exclude, attr.to_sym)}
|
32
|
-
end
|
33
|
-
|
34
|
-
entry.set_core(person, exclude: core_excluded)
|
35
|
-
if session.tagtree && !options.dig(:exclude, :filter_tags)
|
36
|
-
person.filter_tags = session.tagtree.user_tags(
|
37
|
-
initial: ini_tags,
|
38
|
-
final: person.filter_tags,
|
39
|
-
preserve_custom: true,
|
40
|
-
add_custom: true
|
41
|
-
)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
entry.set_details(person) unless options.dig(:exclude, :details)
|
46
|
-
|
47
|
-
unless options.dig(:exclude, :account)
|
48
|
-
add_account = !person.account
|
49
|
-
ini_pg_ids = person.account&.policy_group_ids || []
|
50
|
-
|
51
|
-
account_excluded = []
|
52
|
-
account_excluded.push("policy_group_ids") if options.dig(:exclude, :policy_groups) && !create
|
53
|
-
|
54
|
-
entry.set_account(person, exclude: account_excluded)
|
55
|
-
|
56
|
-
person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
|
57
|
-
|
58
|
-
unless options.dig(:exclude, :policy_groups) && !create
|
59
|
-
end_pg_ids = person.account.policy_group_ids || []
|
60
|
-
|
61
|
-
if add_account && def_id && !entry.policy_group_ids?
|
62
|
-
# on account creation, if missing policy_group_ids column in the input
|
63
|
-
# use default_usergroup, if it's defined
|
64
|
-
end_pg_ids = [def_id]
|
65
|
-
end
|
66
|
-
|
67
|
-
# avoid false updates by preserving the original order
|
68
|
-
person.account.policy_group_ids = pgs.user_pg_ids(
|
69
|
-
initial: ini_pg_ids,
|
70
|
-
final: end_pg_ids
|
71
|
-
)
|
72
|
-
end
|
73
|
-
|
74
|
-
person.account.permissions_custom = session.new_preset(person) unless !create && options.dig(:exclude, :abilities)
|
75
|
-
|
76
|
-
unless options.dig(:exclude, :filter_tags) || entry.default_tag?
|
77
|
-
if session.tagtree
|
78
|
-
person.account.default_tag = session.tagtree.default_tag(*person.filter_tags)
|
79
|
-
else
|
80
|
-
tags = person.filter_tags || []
|
81
|
-
person.account.default_tag = tags.first unless tags.length > 1
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
creation.add(person) if create
|
88
|
-
update.add(person) unless create
|
89
|
-
|
90
|
-
# set supervisor
|
91
|
-
unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
|
92
|
-
if !(sup_id = entry.supervisor_id)
|
93
|
-
person.supervisor_id = nil
|
94
|
-
else
|
95
|
-
if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)
|
96
|
-
person.supervisor_id = supervisor.id
|
97
|
-
else
|
98
|
-
# delay setting supervisor if does not exit
|
99
|
-
supers.add(person) do |person|
|
100
|
-
person.supervisor_id = sup_id
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|