eco-helpers 1.3.10 → 1.3.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 861fdc294bb8624a1cebd3a880a94ae5c0067adb8b61b7e4467afd6b52e0c87a
4
- data.tar.gz: e3db0ea2abda25621738bbe3cb7e50ebae1b68e7daaf16344ae1a74aa200aa9c
3
+ metadata.gz: 1527493b64563ca009c0338bc5e3b5311371a4c59947526ad60fa453d577abfd
4
+ data.tar.gz: cabc02e6a45958ff8cfa46fc7ff76e451074d492f42a3091f28e6633c131b64b
5
5
  SHA512:
6
- metadata.gz: d815d693a7208363238c96adb14250f6010c55b85158c236b157982754e73438f657e2d7639f4801a2530e1ba9952ec6496a6998b3a758a9728c056956fb4688
7
- data.tar.gz: 10e1fdab93ce81884d01d474a82b41274c75bd168b52e1b525f53d127b15f8a9fa15759ac5b1b27de2b90997fe883628fec66dcffd443296f2abdb58d881065f
6
+ metadata.gz: 6c8eaa3f1a56daaee787c26dd5c2681aea73e689fa55636c946a46441e8b894adb63922584d69f292176ffe35f05da3878dd0a410e0fd3bbf0d906937bca774b
7
+ data.tar.gz: 345b6faa4aa18aaf0db1930eddcf45bf228a1ed2f6246efe7f839c86f8af396d81513209fa2a6e04e36734da28842b6b193d2269d7aee5be1b2c7be23e120eaf
@@ -1,6 +1,47 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.3.15] - 2020-06-11
5
+
6
+ ### Added
7
+ - default usecase to export to `csv` (`-detailed`) now includes `"Supervisor Name"` column
8
+ ### Changed
9
+ ### Fixed
10
+
11
+ ## [1.3.14] - 2020-06-10
12
+
13
+ ### Added
14
+ - `Eco::API::Common::People::SupervisorHelpers` now has its methods as class methods
15
+ ### Changed
16
+ - upgraded `ecoportal-api` gem dependency to minimum version `0.5.6`
17
+ ### Fixed
18
+
19
+
20
+ ## [1.3.13] - 2020-05-29
21
+
22
+ ### Added
23
+ ### Changed
24
+ ### Fixed
25
+ - `Eco::API::Organization::TagTree#tag?` to accept `nil` by returning `false`
26
+ - `Eco::API::Common::People::DefaultParsers::DateParser` will parse to `Date` class
27
+ * 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))
28
+ ## [1.3.11] - 2020-05-19
29
+
30
+ ### Added
31
+ ### Changed
32
+ - stop using `email` as `external_id` on `People#person` & `People#find`
33
+ * this should result in more accurate searches when using `:strict` options
34
+ ### Fixed
35
+
36
+
37
+ ## [1.3.11] - 2020-05-12
38
+
39
+ ### Added
40
+ ### Changed
41
+ - remove popping up comments on `Eco::API::Organization::PolicyGroups#`
42
+ ### Fixed
43
+
44
+
4
45
  ## [1.3.10] - 2020-05-12
5
46
 
6
47
  ### Added
@@ -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.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'
@@ -19,7 +19,7 @@ module Eco
19
19
 
20
20
  def parse_date(value)
21
21
  begin
22
- (value.to_s.empty?) ? nil : Time.parse(value)
22
+ (value.to_s.empty?) ? nil : Date.parse(value)
23
23
  rescue
24
24
  nil
25
25
  end
@@ -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
- # Reorders as follows:
12
- # 1. supervisors, people with no supervisor or where their supervisor not present
13
- # 2. subordinates
14
- def sort_by_supervisors(values, supervisors_first: true)
15
- raise "Expected non hash Enumerable. Given: #{values.class}" if values.is_a?(Hash)
16
- return [] unless values && values.is_a?(Enumerable)
17
- roam = Proc.new do |tree|
18
- [].tap do |out|
19
- sub_outs = tree.empty?? [] : tree.map {|sup, subtree| roam.call(subtree)}
20
- tree.each do |sup, subtree|
21
- sout = subtree.empty?? [] :roam.call(subtree)
22
- supervisors_first ? sout.unshift(sup) : sout.push(sup)
23
- out.concat(sout)
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
- roam.call(supervisors_tree(values))
29
- end
32
+ roam.call(supervisors_tree(values))
33
+ end
30
34
 
31
- def tree_to_str(tree, lev: 0)
32
- raise "Required Hash tree structure. Given: #{tree.class}" unless tree.is_a?(Hash)
33
- "".tap do |str|
34
- tree.each do |entry, subtree|
35
- str << "#{" " * lev}+-- #{entry.id || entry.external_id}\n"
36
- str << tree_to_str(subtree, lev: lev + 1) unless !subtree || subtree.empty?
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
- def print_tree(tree, lev: 0)
42
- puts tree_to_str(tree)
43
- end
45
+ def print_tree(tree, lev: 0)
46
+ puts tree_to_str(tree)
47
+ end
44
48
 
45
- # Generates a `Hash` tree structure, where:
46
- # * **keys** are nodes
47
- # * **values** are `Hash` subtree structures of `key` subordinates
48
- # @note it is resilient to cyclic supervisors (it will just add the last at the top)
49
- # @param values [Enumerable<Object>] of objects with methods:
50
- # `id`, `external_id` and `supervisor_id`
51
- # @return [Hash] the tree structure
52
- def supervisors_tree(values)
53
- raise "Expected non hash Enumerable. Given: #{values.class}" if values.is_a?(Hash)
54
- return {} unless values && values.is_a?(Enumerable)
55
- idx = get_super_indexes(values)
56
-
57
- processed = []
58
- subtree = Proc.new do |entry, level, toptree|
59
- if processed.include?(entry)
60
- next {} unless toptree.key?(entry) && level > 0
61
- # needs to be moved as a child
62
- subnodes = toptree.delete(entry)
63
- processed.delete(entry)
64
- end
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
- subnodes ||= {}.tap do |tree|
67
- subs = idx[:subordinates].call(entry)
68
- processed.push(entry)
69
- next nil unless subs && !subs.empty?
70
- subs.each do |sub|
71
- sub_tree = subtree.call(sub, level + 1, toptree)
72
- tree.merge!(sub_tree)
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
- {entry => subnodes}
77
- end
80
+ {entry => subnodes}
81
+ end
78
82
 
79
- {}.tap do |tree|
80
- idx[:by_sup].keys.each do |sup_id|
81
- if sup = idx[:supers][sup_id]
82
- tree.merge!(subtree.call(sup, 0, tree))
83
- else
84
- idx[:by_sup][sup_id].each do |sub|
85
- tree.merge!(subtree.call(sub, 0, tree))
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
- private
93
-
94
- def get_super_indexes(values)
95
- raise "Expected non hash Enumerable. Given: #{values.class}" if values.is_a?(Hash)
96
- {}.tap do |indexes|
97
- indexes[:by_id] = values.map do |e|
98
- e.id && [e.id, e]
99
- end.compact.to_h
100
- indexes[:by_ext] = values.map do |e|
101
- e.external_id && [e.external_id, e]
102
- end.compact.to_h
103
-
104
- indexes[:by_sup] = {}.tap do |by_s|
105
- values.group_by do |e|
106
- e.supervisor_id
107
- end.tap do |by_sup|
108
- by_s[nil] = by_sup.delete(nil) if by_sup.key?(nil)
109
- by_s.merge!(by_sup)
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
- indexes[:supers] = {}.tap do |sups|
114
- indexes[:by_ext].select do |ext, e|
115
- ext && indexes[:by_sup].key?(ext)
116
- end.tap {|found| sups.merge!(found)}
117
- indexes[:by_id].select do |id, e|
118
- id && indexes[:by_sup].key?(id)
119
- end.tap {|found| sups.merge!(found)}
120
- end
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
- indexes[:is_super] = Proc.new do |entry|
123
- !!(indexes[:supers][entry.id] || indexes[:supers][entry.external_id])
124
- end
126
+ indexes[:is_super] = Proc.new do |entry|
127
+ !!(indexes[:supers][entry.id] || indexes[:supers][entry.external_id])
128
+ end
125
129
 
126
- indexes[:subordinates] = Proc.new do |entry|
127
- subs = nil
128
- if sup = indexes[:supers][entry.id] || indexes[:supers][entry.external_id]
129
- subs ||= indexes[:by_sup][sup.id] unless !sup.id
130
- subs ||= indexes[:by_sup][sup.external_id] unless !sup.external_id
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
@@ -44,7 +44,6 @@ module Eco
44
44
  end
45
45
 
46
46
  def policy_group(id_name)
47
- pp "the id: #{policy_group_id(id_name)}"
48
47
  @by_id.fetch(policy_group_id(id_name), nil)
49
48
  end
50
49
 
@@ -73,7 +72,6 @@ module Eco
73
72
  end
74
73
 
75
74
  def policy_group_id(id_name)
76
- pp "by name ('#{id_name}'): #{@by_name[id_name&.downcase]}"
77
75
  (@by_name[id_name&.downcase] || @by_id[id_name])&.id
78
76
  end
79
77
 
@@ -62,7 +62,7 @@ module Eco
62
62
  # @param key [String] tag to verify.
63
63
  # @return [Boolean]
64
64
  def tag?(key)
65
- @hash_tags.key?(key.upcase)
65
+ @hash_tags.key?(key&.upcase)
66
66
  end
67
67
 
68
68
  # Finds a subtree node.
@@ -24,21 +24,31 @@ module Eco
24
24
  CSV.open(file, "w") do |csv|
25
25
  deps = {"supervisor_id" => {people: people}}
26
26
  header = session.new_entry(people.first, dependencies: deps).to_hash.keys
27
+ header += ["Subordinates"]
28
+ header += ["Supervisor Name"]
27
29
  header += abilities
28
30
  header += ["Login Methods"] if login_providers.any_optional?
29
- header += ["Subordinates"]
30
31
  header += ["Landing Page"]
31
32
 
32
33
  csv << header
33
34
  people.each do |person|
34
35
  data = session.new_entry(person, dependencies: deps).to_hash.values
36
+
37
+ data.push(person.subordinates)
38
+ super_id = person.supervisor_id
39
+ if supervisor = people.person(id: super_id, external_id: super_id)
40
+ data.push(supervisor.name)
41
+ else
42
+ data.push("")
43
+ end
44
+
35
45
  person_abilities = (person.account && person.account.permissions_custom) || {}
36
46
  data += abilities.map {|key| person_abilities[key] || "no access"}
47
+
37
48
  if login_providers.any_optional?
38
49
  logins = (person.account && person.account.login_provider_ids) || []
39
50
  data.push(login_providers.to_name(logins).join("|"))
40
51
  end
41
- data.push(person.subordinates)
42
52
 
43
53
  if person.account && landing_id = person.account.landing_page_id
44
54
  data.push(landing_id)
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "1.3.10"
2
+ VERSION = "1.3.15"
3
3
  end
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.10
4
+ version: 1.3.15
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.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.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