eco-helpers 1.3.9 → 1.3.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 +46 -1
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api/common/people/default_parsers/date_parser.rb +1 -1
- data/lib/eco/api/common/people/supervisor_helpers.rb +110 -100
- data/lib/eco/api/organization/people.rb +1 -1
- data/lib/eco/api/organization/policy_groups.rb +10 -2
- data/lib/eco/api/organization/tag_tree.rb +1 -1
- data/lib/eco/api/usecases/default_cases/create_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/hris_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/update_case.rb +10 -2
- data/lib/eco/api/usecases/default_cases/upsert_case.rb +1 -1
- data/lib/eco/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01ec2727fdeee5bc360e417faefdafdb8bf69078cecc17ead881047e8df17cd2
|
4
|
+
data.tar.gz: 67e46501f166224248d6d92e6607cddcbce3806dbd05f41e485d0ca2139f1105
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd26851249e2c8557f9da3399f72292cb46a2c12db530f12e3da2a88120dc08a6e0a6ee053527b91685cd60e532d2bbd76e156f1fc803dc6bf2c1246a21fac27
|
7
|
+
data.tar.gz: 4f199963c86259bb5a210dca09aa1af2b83c9489308afd200986d6d5c13f32d3479fb2eeaad19c397882359dd3ef16892dc7449860879e2a71fdbf8f73e34943
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,51 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [1.3.14] - 2020-06-10
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- `Eco::API::Common::People::SupervisorHelpers` now has its methods as class methods
|
8
|
+
### Changed
|
9
|
+
- upgraded `ecoportal-api` gem dependency to minimum version `0.5.6`
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
|
13
|
+
## [1.3.13] - 2020-05-29
|
14
|
+
|
15
|
+
### Added
|
16
|
+
### Changed
|
17
|
+
### Fixed
|
18
|
+
- `Eco::API::Organization::TagTree#tag?` to accept `nil` by returning `false`
|
19
|
+
- `Eco::API::Common::People::DefaultParsers::DateParser` will parse to `Date` class
|
20
|
+
* it was parsing to `Time` class, while the native gem `ecoportal-api` parses as `Date` ([reference](https://gitlab.com/ecoPortal/ecoportal-api/-/blob/master/lib/ecoportal/api/v1/schema_field.rb))
|
21
|
+
## [1.3.11] - 2020-05-19
|
22
|
+
|
23
|
+
### Added
|
24
|
+
### Changed
|
25
|
+
- stop using `email` as `external_id` on `People#person` & `People#find`
|
26
|
+
* this should result in more accurate searches when using `:strict` options
|
27
|
+
### Fixed
|
28
|
+
|
29
|
+
|
30
|
+
## [1.3.11] - 2020-05-12
|
31
|
+
|
32
|
+
### Added
|
33
|
+
### Changed
|
34
|
+
- remove popping up comments on `Eco::API::Organization::PolicyGroups#`
|
35
|
+
### Fixed
|
36
|
+
|
37
|
+
|
38
|
+
## [1.3.10] - 2020-05-12
|
39
|
+
|
40
|
+
### Added
|
41
|
+
- `Eco::API::Organization::PolicyGroups#to_name` added support for `Array` input
|
42
|
+
- `config.people.default_usergroup`, when defined, will have effect on usecases: `update` (this case was missing the change)
|
43
|
+
* on account creation, if the input file did not specify `policy_group_ids`
|
44
|
+
|
45
|
+
### Changed
|
46
|
+
### Fixed
|
47
|
+
- `upsert`, `hris` and `create` usecases: fixed condition for use of default_usergroup
|
48
|
+
|
4
49
|
## [1.3.9] - 2020-05-12
|
5
50
|
|
6
51
|
### Added
|
@@ -8,7 +53,7 @@ All notable changes to this project will be documented in this file.
|
|
8
53
|
### Fixed
|
9
54
|
|
10
55
|
- `usecase` callback was not receiving `usecase` paramater
|
11
|
-
* as a consequence `Batch
|
56
|
+
* as a consequence `Batch::Job` created were missing the `usecase`
|
12
57
|
|
13
58
|
## [1.3.8] - 2020-05-07
|
14
59
|
|
data/eco-helpers.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.add_development_dependency "yard", "~> 0.9", ">= 0.9.18"
|
29
29
|
s.add_development_dependency "redcarpet", "~> 3.5", ">= 3.5.0"
|
30
30
|
|
31
|
-
s.add_dependency 'ecoportal-api', '~> 0.5', '>= 0.5.
|
31
|
+
s.add_dependency 'ecoportal-api', '~> 0.5', '>= 0.5.6'
|
32
32
|
s.add_dependency 'aws-sdk-s3', '~> 1.30', '>= 1.30.1'
|
33
33
|
s.add_dependency 'aws-sdk-ses', '~> 1.14', '>= 1.14.0'
|
34
34
|
s.add_dependency 'dotenv', '~> 2.6', '>= 2.6.0'
|
@@ -7,134 +7,144 @@ module Eco
|
|
7
7
|
# * `external_id`
|
8
8
|
# * `id`
|
9
9
|
module SupervisorHelpers
|
10
|
+
def self.included(base)
|
11
|
+
base.send(:include, ClassMethods)
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
14
|
+
module ClassMethods
|
15
|
+
# Reorders as follows:
|
16
|
+
# 1. supervisors, people with no supervisor or where their supervisor not present
|
17
|
+
# 2. subordinates
|
18
|
+
def sort_by_supervisors(values, supervisors_first: true)
|
19
|
+
raise "Expected non hash Enumerable. Given: #{values.class}" if values.is_a?(Hash)
|
20
|
+
return [] unless values && values.is_a?(Enumerable)
|
21
|
+
roam = Proc.new do |tree|
|
22
|
+
[].tap do |out|
|
23
|
+
sub_outs = tree.empty?? [] : tree.map {|sup, subtree| roam.call(subtree)}
|
24
|
+
tree.each do |sup, subtree|
|
25
|
+
sout = subtree.empty?? [] :roam.call(subtree)
|
26
|
+
supervisors_first ? sout.unshift(sup) : sout.push(sup)
|
27
|
+
out.concat(sout)
|
28
|
+
end
|
24
29
|
end
|
25
30
|
end
|
26
|
-
end
|
27
31
|
|
28
|
-
|
29
|
-
|
32
|
+
roam.call(supervisors_tree(values))
|
33
|
+
end
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
def tree_to_str(tree, lev: 0)
|
36
|
+
raise "Required Hash tree structure. Given: #{tree.class}" unless tree.is_a?(Hash)
|
37
|
+
"".tap do |str|
|
38
|
+
tree.each do |entry, subtree|
|
39
|
+
str << "#{" " * lev}+-- #{entry.id || entry.external_id}\n"
|
40
|
+
str << tree_to_str(subtree, lev: lev + 1) unless !subtree || subtree.empty?
|
41
|
+
end
|
37
42
|
end
|
38
43
|
end
|
39
|
-
end
|
40
44
|
|
41
|
-
|
42
|
-
|
43
|
-
|
45
|
+
def print_tree(tree, lev: 0)
|
46
|
+
puts tree_to_str(tree)
|
47
|
+
end
|
44
48
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
49
|
+
# Generates a `Hash` tree structure, where:
|
50
|
+
# * **keys** are nodes
|
51
|
+
# * **values** are `Hash` subtree structures of `key` subordinates
|
52
|
+
# @note it is resilient to cyclic supervisors (it will just add the last at the top)
|
53
|
+
# @param values [Enumerable<Object>] of objects with methods:
|
54
|
+
# `id`, `external_id` and `supervisor_id`
|
55
|
+
# @return [Hash] the tree structure
|
56
|
+
def supervisors_tree(values)
|
57
|
+
raise "Expected non hash Enumerable. Given: #{values.class}" if values.is_a?(Hash)
|
58
|
+
return {} unless values && values.is_a?(Enumerable)
|
59
|
+
idx = get_super_indexes(values)
|
60
|
+
|
61
|
+
processed = []
|
62
|
+
subtree = Proc.new do |entry, level, toptree|
|
63
|
+
if processed.include?(entry)
|
64
|
+
next {} unless toptree.key?(entry) && level > 0
|
65
|
+
# needs to be moved as a child
|
66
|
+
subnodes = toptree.delete(entry)
|
67
|
+
processed.delete(entry)
|
68
|
+
end
|
65
69
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
subnodes ||= {}.tap do |tree|
|
71
|
+
subs = idx[:subordinates].call(entry)
|
72
|
+
processed.push(entry)
|
73
|
+
next nil unless subs && !subs.empty?
|
74
|
+
subs.each do |sub|
|
75
|
+
sub_tree = subtree.call(sub, level + 1, toptree)
|
76
|
+
tree.merge!(sub_tree)
|
77
|
+
end
|
73
78
|
end
|
74
|
-
end
|
75
79
|
|
76
|
-
|
77
|
-
|
80
|
+
{entry => subnodes}
|
81
|
+
end
|
78
82
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
83
|
+
{}.tap do |tree|
|
84
|
+
idx[:by_sup].keys.each do |sup_id|
|
85
|
+
if sup = idx[:supers][sup_id]
|
86
|
+
tree.merge!(subtree.call(sup, 0, tree))
|
87
|
+
else
|
88
|
+
idx[:by_sup][sup_id].each do |sub|
|
89
|
+
tree.merge!(subtree.call(sub, 0, tree))
|
90
|
+
end
|
86
91
|
end
|
87
92
|
end
|
88
93
|
end
|
89
94
|
end
|
90
|
-
end
|
91
95
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
96
|
+
private
|
97
|
+
|
98
|
+
def get_super_indexes(values)
|
99
|
+
raise "Expected non hash Enumerable. Given: #{values.class}" if values.is_a?(Hash)
|
100
|
+
{}.tap do |indexes|
|
101
|
+
indexes[:by_id] = values.map do |e|
|
102
|
+
e.id && [e.id, e]
|
103
|
+
end.compact.to_h
|
104
|
+
indexes[:by_ext] = values.map do |e|
|
105
|
+
e.external_id && [e.external_id, e]
|
106
|
+
end.compact.to_h
|
107
|
+
|
108
|
+
indexes[:by_sup] = {}.tap do |by_s|
|
109
|
+
values.group_by do |e|
|
110
|
+
e.supervisor_id
|
111
|
+
end.tap do |by_sup|
|
112
|
+
by_s[nil] = by_sup.delete(nil) if by_sup.key?(nil)
|
113
|
+
by_s.merge!(by_sup)
|
114
|
+
end
|
110
115
|
end
|
111
|
-
end
|
112
116
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
117
|
+
indexes[:supers] = {}.tap do |sups|
|
118
|
+
indexes[:by_ext].select do |ext, e|
|
119
|
+
ext && indexes[:by_sup].key?(ext)
|
120
|
+
end.tap {|found| sups.merge!(found)}
|
121
|
+
indexes[:by_id].select do |id, e|
|
122
|
+
id && indexes[:by_sup].key?(id)
|
123
|
+
end.tap {|found| sups.merge!(found)}
|
124
|
+
end
|
121
125
|
|
122
|
-
|
123
|
-
|
124
|
-
|
126
|
+
indexes[:is_super] = Proc.new do |entry|
|
127
|
+
!!(indexes[:supers][entry.id] || indexes[:supers][entry.external_id])
|
128
|
+
end
|
125
129
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
130
|
+
indexes[:subordinates] = Proc.new do |entry|
|
131
|
+
subs = nil
|
132
|
+
if sup = indexes[:supers][entry.id] || indexes[:supers][entry.external_id]
|
133
|
+
subs ||= indexes[:by_sup][sup.id] unless !sup.id
|
134
|
+
subs ||= indexes[:by_sup][sup.external_id] unless !sup.external_id
|
135
|
+
end
|
136
|
+
subs
|
131
137
|
end
|
132
|
-
subs
|
133
138
|
end
|
139
|
+
|
134
140
|
end
|
135
141
|
|
136
142
|
end
|
137
143
|
|
144
|
+
class << self
|
145
|
+
include SupervisorHelpers::ClassMethods
|
146
|
+
end
|
147
|
+
|
138
148
|
end
|
139
149
|
end
|
140
150
|
end
|
@@ -65,8 +65,8 @@ module Eco
|
|
65
65
|
pers = candidates.first
|
66
66
|
end
|
67
67
|
|
68
|
+
pers = @by_external_id[email&.downcase.strip]&.first if !pers && !email.to_s.strip.empty?
|
68
69
|
end
|
69
|
-
pers = @by_external_id[email&.downcase.strip]&.first if !pers && !email.to_s.strip.empty?
|
70
70
|
|
71
71
|
pers
|
72
72
|
end
|
@@ -19,7 +19,7 @@ module Eco
|
|
19
19
|
def names
|
20
20
|
@by_name.keys
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def to_id(name)
|
24
24
|
case name
|
25
25
|
when Enumerable
|
@@ -32,7 +32,15 @@ module Eco
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def to_name(id)
|
35
|
-
|
35
|
+
case id
|
36
|
+
when Enumerable
|
37
|
+
id.map do |n|
|
38
|
+
policy_group(n)&.name
|
39
|
+
end.compact
|
40
|
+
else
|
41
|
+
policy_group(id)&.name
|
42
|
+
end
|
43
|
+
|
36
44
|
end
|
37
45
|
|
38
46
|
def policy_group(id_name)
|
@@ -51,7 +51,7 @@ module Eco
|
|
51
51
|
unless options.dig(:exclude, :policy_groups) && !create
|
52
52
|
end_pg_ids = person.account.policy_group_ids || []
|
53
53
|
|
54
|
-
|
54
|
+
if add_account && def_id && !entry.policy_group_ids?
|
55
55
|
# on account creation, if missing policy_group_ids column in the input
|
56
56
|
# use default_usergroup, if it's defined
|
57
57
|
end_pg_ids = [def_id]
|
@@ -65,7 +65,7 @@ module Eco
|
|
65
65
|
unless options.dig(:exclude, :policy_groups) && !create
|
66
66
|
end_pg_ids = person.account.policy_group_ids || []
|
67
67
|
|
68
|
-
|
68
|
+
if add_account && def_id && !entry.policy_group_ids?
|
69
69
|
# on account creation, if missing policy_group_ids column in the input
|
70
70
|
# use default_usergroup, if it's defined
|
71
71
|
end_pg_ids = [def_id]
|
@@ -46,11 +46,19 @@ module Eco
|
|
46
46
|
|
47
47
|
person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
|
48
48
|
|
49
|
-
unless options.dig(:exclude, :policy_groups)
|
49
|
+
unless options.dig(:exclude, :policy_groups) && !create
|
50
|
+
end_pg_ids = person.account.policy_group_ids || []
|
51
|
+
|
52
|
+
if add_account && def_id && !entry.policy_group_ids?
|
53
|
+
# on account creation, if missing policy_group_ids column in the input
|
54
|
+
# use default_usergroup, if it's defined
|
55
|
+
end_pg_ids = [def_id]
|
56
|
+
end
|
57
|
+
|
50
58
|
# avoid false updates by preserving the original order
|
51
59
|
person.account.policy_group_ids = pgs.user_pg_ids(
|
52
60
|
initial: ini_pg_ids,
|
53
|
-
final:
|
61
|
+
final: end_pg_ids
|
54
62
|
)
|
55
63
|
end
|
56
64
|
|
@@ -58,7 +58,7 @@ module Eco
|
|
58
58
|
unless options.dig(:exclude, :policy_groups) && !create
|
59
59
|
end_pg_ids = person.account.policy_group_ids || []
|
60
60
|
|
61
|
-
|
61
|
+
if add_account && def_id && !entry.policy_group_ids?
|
62
62
|
# on account creation, if missing policy_group_ids column in the input
|
63
63
|
# use default_usergroup, if it's defined
|
64
64
|
end_pg_ids = [def_id]
|
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.3.
|
4
|
+
version: 1.3.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
@@ -107,7 +107,7 @@ dependencies:
|
|
107
107
|
version: '0.5'
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.5.
|
110
|
+
version: 0.5.6
|
111
111
|
type: :runtime
|
112
112
|
prerelease: false
|
113
113
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -117,7 +117,7 @@ dependencies:
|
|
117
117
|
version: '0.5'
|
118
118
|
- - ">="
|
119
119
|
- !ruby/object:Gem::Version
|
120
|
-
version: 0.5.
|
120
|
+
version: 0.5.6
|
121
121
|
- !ruby/object:Gem::Dependency
|
122
122
|
name: aws-sdk-s3
|
123
123
|
requirement: !ruby/object:Gem::Requirement
|