eco-helpers 1.5.13 → 1.5.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -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/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/job.rb +17 -7
- data/lib/eco/version.rb +1 -1
- metadata +5 -12
- 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
data/lib/eco/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eco-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
@@ -286,6 +286,8 @@ files:
|
|
286
286
|
- lib/eco/api/common/session/environment.rb
|
287
287
|
- lib/eco/api/common/session/file_manager.rb
|
288
288
|
- lib/eco/api/common/session/logger.rb
|
289
|
+
- lib/eco/api/common/session/logger/cache.rb
|
290
|
+
- lib/eco/api/common/session/logger/log.rb
|
289
291
|
- lib/eco/api/common/session/mailer.rb
|
290
292
|
- lib/eco/api/common/session/s3_uploader.rb
|
291
293
|
- lib/eco/api/common/session/sftp.rb
|
@@ -342,6 +344,8 @@ files:
|
|
342
344
|
- lib/eco/api/organization/presets_values.json
|
343
345
|
- lib/eco/api/organization/tag_tree.rb
|
344
346
|
- lib/eco/api/policies.rb
|
347
|
+
- lib/eco/api/policies/default_policies.rb
|
348
|
+
- lib/eco/api/policies/default_policies/99_user_access_policy.rb
|
345
349
|
- lib/eco/api/policies/policy.rb
|
346
350
|
- lib/eco/api/session.rb
|
347
351
|
- lib/eco/api/session/batch.rb
|
@@ -367,17 +371,6 @@ files:
|
|
367
371
|
- lib/eco/api/session/config/sftp.rb
|
368
372
|
- lib/eco/api/session/config/workflow.rb
|
369
373
|
- lib/eco/api/usecases.rb
|
370
|
-
- lib/eco/api/usecases/backup/append_usergroups_case.rb
|
371
|
-
- lib/eco/api/usecases/backup/create_case.rb
|
372
|
-
- lib/eco/api/usecases/backup/create_details_case.rb
|
373
|
-
- lib/eco/api/usecases/backup/create_details_with_supervisor_case.rb
|
374
|
-
- lib/eco/api/usecases/backup/hris_case.rb
|
375
|
-
- lib/eco/api/usecases/backup/set_default_tag_case.rb
|
376
|
-
- lib/eco/api/usecases/backup/set_supervisor_case.rb
|
377
|
-
- lib/eco/api/usecases/backup/transfer_account_case.rb
|
378
|
-
- lib/eco/api/usecases/backup/update_case.rb
|
379
|
-
- lib/eco/api/usecases/backup/update_details_case.rb
|
380
|
-
- lib/eco/api/usecases/backup/upsert_case.rb
|
381
374
|
- lib/eco/api/usecases/base_case.rb
|
382
375
|
- lib/eco/api/usecases/base_io.rb
|
383
376
|
- lib/eco/api/usecases/default_cases.rb
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class UseCases
|
4
|
-
class DefaultCases
|
5
|
-
class AppendUsergroupsCase < DefaultCase
|
6
|
-
|
7
|
-
def process
|
8
|
-
@cases.define("append-usergroups", 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
|
-
|
11
|
-
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
12
|
-
pgs = session.policy_groups
|
13
|
-
|
14
|
-
entries.each.with_index do |entry, i|
|
15
|
-
if person = people.find(entry, strict: strict_search)
|
16
|
-
if person.account
|
17
|
-
ini_pg_ids = person.account&.policy_group_ids || []
|
18
|
-
add = entry.internal_entry["policy_group_ids"].to_s.split("|").compact
|
19
|
-
person.account.policy_group_ids = (ini_pg_ids | add).uniq
|
20
|
-
|
21
|
-
person.account.permissions_custom = session.new_preset(person) unless options.dig(:exclude, :abilities)
|
22
|
-
update.add(person)
|
23
|
-
end
|
24
|
-
else
|
25
|
-
session.logger.error("This person does not exist: #{entry.to_s(:identify)}")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class UseCases
|
4
|
-
class DefaultCases
|
5
|
-
class CreateCase < DefaultCase
|
6
|
-
|
7
|
-
def process
|
8
|
-
@cases.define("create", 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
|
-
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
|
-
session.logger.error("This person (id: '#{person.id}') already exists: #{entry.to_s(:identify)}")
|
22
|
-
else
|
23
|
-
person = session.new_person
|
24
|
-
core_excluded = ["supervisor_id"]
|
25
|
-
|
26
|
-
ini_tags = person.filter_tags || []
|
27
|
-
entry.set_core(person, exclude: core_excluded)
|
28
|
-
|
29
|
-
if session.tagtree
|
30
|
-
person.filter_tags = session.tagtree.user_tags(
|
31
|
-
initial: ini_tags,
|
32
|
-
final: person.filter_tags,
|
33
|
-
preserve_custom: true,
|
34
|
-
add_custom: true
|
35
|
-
)
|
36
|
-
end
|
37
|
-
|
38
|
-
entry.set_details(person) unless options.dig(:exclude, :details)
|
39
|
-
|
40
|
-
unless options.dig(:exclude, :account)
|
41
|
-
add_account = !person.account
|
42
|
-
ini_pg_ids = person.account&.policy_group_ids || []
|
43
|
-
|
44
|
-
account_excluded = []
|
45
|
-
account_excluded.push("policy_group_ids") if options.dig(:exclude, :policy_groups) && !create
|
46
|
-
|
47
|
-
entry.set_account(person, exclude: account_excluded)
|
48
|
-
|
49
|
-
person.account&.send_invites = options[:send_invites] if options.key?(:send_invites)
|
50
|
-
|
51
|
-
unless options.dig(:exclude, :policy_groups) && !create
|
52
|
-
end_pg_ids = person.account.policy_group_ids || []
|
53
|
-
|
54
|
-
if add_account && def_id && !entry.policy_group_ids?
|
55
|
-
# on account creation, if missing policy_group_ids column in the input
|
56
|
-
# use default_usergroup, if it's defined
|
57
|
-
end_pg_ids = [def_id]
|
58
|
-
end
|
59
|
-
|
60
|
-
# avoid false updates by preserving the original order
|
61
|
-
person.account.policy_group_ids = pgs.user_pg_ids(
|
62
|
-
initial: ini_pg_ids,
|
63
|
-
final: end_pg_ids
|
64
|
-
)
|
65
|
-
end
|
66
|
-
|
67
|
-
person.account.permissions_custom = session.new_preset(person)
|
68
|
-
|
69
|
-
if session.tagtree
|
70
|
-
person.account.default_tag = session.tagtree.default_tag(*person.filter_tags)
|
71
|
-
else
|
72
|
-
tags = person.filter_tags || []
|
73
|
-
person.account.default_tag = tags.first unless tags.length > 1
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
creation.add(person)
|
78
|
-
|
79
|
-
# set supervisor
|
80
|
-
unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
|
81
|
-
if !(sup_id = entry.supervisor_id)
|
82
|
-
person.supervisor_id = nil
|
83
|
-
else
|
84
|
-
if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)
|
85
|
-
person.supervisor_id = supervisor.id
|
86
|
-
else
|
87
|
-
# delay setting supervisor if does not exit
|
88
|
-
supers.add(person) do |person|
|
89
|
-
person.supervisor_id = sup_id
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class UseCases
|
4
|
-
class DefaultCases
|
5
|
-
class CreateDetailsCase < DefaultCase
|
6
|
-
|
7
|
-
def process
|
8
|
-
@cases.define("create-details", type: :sync) do |entries, people, session, options, usecase|
|
9
|
-
creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details])
|
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
|
-
if person = people.find(entry, strict: strict_search)
|
15
|
-
session.logger.error("This person (id: '#{person.id}') already exists: #{entry.to_s(:identify)}")
|
16
|
-
else
|
17
|
-
person = session.new_person
|
18
|
-
entry.set_core(person, exclude: "supervisor_id")
|
19
|
-
entry.set_details(person)
|
20
|
-
|
21
|
-
creation.add(person)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module Eco
|
2
|
-
module API
|
3
|
-
class UseCases
|
4
|
-
class DefaultCases
|
5
|
-
class CreateDetailsWithSupervisorCase < DefaultCase
|
6
|
-
|
7
|
-
def process
|
8
|
-
# good candidate to do @cases.case("create-details").use.chain(@cases.case("set-supervisor").use)
|
9
|
-
@cases.define("create-details-with-supervisor", type: :sync) do |entries, people, session, options, usecase|
|
10
|
-
creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details])
|
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
|
-
|
15
|
-
entries.each.with_index do |entry, i|
|
16
|
-
if person = people.find(entry, strict: strict_search)
|
17
|
-
session.logger.error("This person (id: '#{person.id}') already exists: #{entry.to_s(:identify)}")
|
18
|
-
else
|
19
|
-
person = session.new_person
|
20
|
-
entry.set_core(person, exclude: "supervisor_id")
|
21
|
-
entry.set_details(person)
|
22
|
-
|
23
|
-
creation.add(person)
|
24
|
-
|
25
|
-
# set supervisor
|
26
|
-
if !(sup_id = entry.supervisor_id)
|
27
|
-
person.supervisor_id = nil
|
28
|
-
else
|
29
|
-
if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)
|
30
|
-
person.supervisor_id = supervisor.id
|
31
|
-
else
|
32
|
-
# delay setting supervisor if does not exit
|
33
|
-
supers.add(person) do |person|
|
34
|
-
person.supervisor_id = sup_id
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,124 +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
|
-
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
|
@@ -1,49 +0,0 @@
|
|
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
|