eco-helpers 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eco/api/common/people/default_parsers/multi_parser.rb +2 -2
- data/lib/eco/api/common/people/person_entry.rb +3 -4
- data/lib/eco/api/common/people/person_parser.rb +5 -2
- data/lib/eco/api/organization.rb +2 -1
- data/lib/eco/api/organization/login_providers.rb +83 -0
- data/lib/eco/api/session.rb +5 -0
- data/lib/eco/api/session/batch.rb +1 -1
- data/lib/eco/api/session/config.rb +6 -0
- data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +7 -0
- data/lib/eco/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1fc8637aef6c15d4e73834479411965ecc2de80df899df4f937d4eb7b002718
|
4
|
+
data.tar.gz: 104e50e1d40d9009af0674d432e03e63ba3b327be70fac18909d011b2cf55ce6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d66f400ec477cd5c2ea341231adea190475d34580fb97492467ad18952ed1565c643fb6dc3776dcc0993c05087b92f5621bd012dc2da2d529f56b60fed9fef3e
|
7
|
+
data.tar.gz: 70d2695c6eb5421cfe17bac16543df3706a2740481013fcd5a7ad76139cfe6650449e2ee8321cbf85e907b087436e6970597ff321f296e064ba952c164b2aac6
|
@@ -8,7 +8,7 @@ module Eco
|
|
8
8
|
def process
|
9
9
|
@parsers.define_attribute(:multiple) do |parser|
|
10
10
|
parser.def_parser do |value|
|
11
|
-
|
11
|
+
next value if value.is_a?(Array)
|
12
12
|
value = value.split("|") if value&.include?("|")
|
13
13
|
into_a(value)
|
14
14
|
end.def_serializer do |value|
|
@@ -18,7 +18,7 @@ module Eco
|
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
21
|
-
|
21
|
+
|
22
22
|
def into_a(value)
|
23
23
|
value = [] if value == nil
|
24
24
|
value = [].push(value) unless value.is_a?(Array)
|
@@ -340,10 +340,9 @@ module Eco
|
|
340
340
|
# @param aliased_entry [Hash] the entry with the _internal attribute_ names but the _external values_.
|
341
341
|
# @return [Hash] the `internal entry` with the **internal** attributes names and values.
|
342
342
|
def _parsed_entry(aliased_entry)
|
343
|
-
parsed = @person_parser.active_attrs(aliased_entry).
|
344
|
-
|
345
|
-
|
346
|
-
end.to_h
|
343
|
+
parsed = @person_parser.active_attrs(aliased_entry).each_with_object({}) do |attr, hash|
|
344
|
+
hash[attr] = @person_parser.parse(attr, aliased_entry.merge(hash))
|
345
|
+
end
|
347
346
|
aliased_entry.merge(parsed)
|
348
347
|
end
|
349
348
|
|
@@ -57,7 +57,7 @@ module Eco
|
|
57
57
|
# @param source_attrs [Array<String>]
|
58
58
|
# @return [Array<String>] the scoped **details** attributes, if `source_attrs` is not `nil`. All the _details attributes_, otherwise.
|
59
59
|
def target_attrs_details(source_attrs = nil)
|
60
|
-
return @details_attrs if !
|
60
|
+
return @details_attrs if !source_attrs
|
61
61
|
scoped_attrs(source_attrs, @details_attrs)
|
62
62
|
end
|
63
63
|
|
@@ -77,10 +77,13 @@ module Eco
|
|
77
77
|
#end
|
78
78
|
|
79
79
|
# Returns a list of all the internal attributes of the model that have a parser defined.
|
80
|
-
# @note
|
80
|
+
# @note
|
81
|
+
# - it excludes any parser that is not in the model, such as type parsers (i.e. `:boolean`, `:multiple`)
|
82
|
+
# - the list is sorted according `CORE_ATTRS` + `ACCOUNT_ATTRS` + schema attrs
|
81
83
|
# @return [Array<String>] list of all attribute defined parsers.
|
82
84
|
def defined_attrs
|
83
85
|
defined = @parsers.keys
|
86
|
+
defined = (all_attrs || defined) && defined
|
84
87
|
defined - (defined - all_attrs)
|
85
88
|
end
|
86
89
|
|
data/lib/eco/api/organization.rb
CHANGED
@@ -9,5 +9,6 @@ require_relative 'organization/tag_tree'
|
|
9
9
|
require_relative 'organization/presets_factory'
|
10
10
|
require_relative 'organization/preferences'
|
11
11
|
require_relative 'organization/people'
|
12
|
-
require_relative 'organization/policy_groups'
|
13
12
|
require_relative 'organization/person_schemas'
|
13
|
+
require_relative 'organization/policy_groups'
|
14
|
+
require_relative 'organization/login_providers'
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module Organization
|
4
|
+
class LoginProviders < Eco::Language::Models::Collection
|
5
|
+
# build the shortcuts of Collection
|
6
|
+
attr_collection :id, :name
|
7
|
+
|
8
|
+
def initialize(login_providers = [], klass: Ecoportal::API::Internal::LoginProvider, factory: nil)
|
9
|
+
@klass = Ecoportal::API::Internal::LoginProvider
|
10
|
+
@caches_init = false
|
11
|
+
super(login_providers, klass: @klass)
|
12
|
+
init_caches
|
13
|
+
end
|
14
|
+
|
15
|
+
def password_id
|
16
|
+
to_id("password")
|
17
|
+
end
|
18
|
+
|
19
|
+
def active
|
20
|
+
select {|lp| lp != "disabled"}
|
21
|
+
end
|
22
|
+
|
23
|
+
def any_optional?
|
24
|
+
active.any? do |lp|
|
25
|
+
lp.enabled_for = "some"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def ids
|
30
|
+
@by_id.keys
|
31
|
+
end
|
32
|
+
|
33
|
+
def names
|
34
|
+
@by_name.keys
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_id(name)
|
38
|
+
case name
|
39
|
+
when Enumerable
|
40
|
+
name.map do |n|
|
41
|
+
login_provider(n)&.id
|
42
|
+
end.compact
|
43
|
+
else
|
44
|
+
login_provider(name)&.id
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_name(id)
|
49
|
+
case name
|
50
|
+
when Enumerable
|
51
|
+
id.map do |i|
|
52
|
+
login_provider(i)&.name
|
53
|
+
end.compact
|
54
|
+
else
|
55
|
+
login_provider(id)&.name
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def login_provider(id_name)
|
60
|
+
@by_id.fetch(login_provider_id(id_name), nil)
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def login_provider_name(id_name)
|
66
|
+
(@by_id[id_name] || @by_name[id_name&.downcase])&.name&.downcase
|
67
|
+
end
|
68
|
+
|
69
|
+
def login_provider_id(id_name)
|
70
|
+
(@by_name[id_name&.downcase] || @by_id[id_name])&.id
|
71
|
+
end
|
72
|
+
|
73
|
+
def init_caches
|
74
|
+
return if @caches_init
|
75
|
+
@by_id = self.map { |pg| [pg.id, pg] }.to_h
|
76
|
+
@by_name = self.map { |pg| [pg.name&.downcase, pg] }.to_h
|
77
|
+
@caches_init = true
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/eco/api/session.rb
CHANGED
@@ -184,6 +184,12 @@ module Eco
|
|
184
184
|
@schemas = Eco::API::Organization::PersonSchemas.new(schs)
|
185
185
|
end
|
186
186
|
|
187
|
+
def login_providers
|
188
|
+
return @login_providers if instance_variable_defined?(:@login_providers)
|
189
|
+
provs = api&.login_providers.to_a
|
190
|
+
@login_providers = Eco::API::Organization::LoginProviders.new(provs)
|
191
|
+
end
|
192
|
+
|
187
193
|
def session
|
188
194
|
@session ||= Eco::API::Session.new(self)
|
189
195
|
end
|
@@ -16,6 +16,8 @@ module Eco
|
|
16
16
|
next false
|
17
17
|
end
|
18
18
|
|
19
|
+
login_providers = session.login_providers
|
20
|
+
|
19
21
|
abilities = session.new_preset([]).keys
|
20
22
|
|
21
23
|
session.logger.info("going to create file: #{file}")
|
@@ -23,12 +25,17 @@ module Eco
|
|
23
25
|
deps = {"supervisor_id" => {people: people}}
|
24
26
|
header = session.new_entry(people.first, dependencies: deps).to_hash.keys
|
25
27
|
header += abilities
|
28
|
+
header += ["Login Methods"] if login_providers.any_optional?
|
26
29
|
|
27
30
|
csv << header
|
28
31
|
people.each do |person|
|
29
32
|
data = session.new_entry(person, dependencies: deps).to_hash.values
|
30
33
|
person_abilities = (person.account && person.account.permissions_custom) || {}
|
31
34
|
data += abilities.map {|key| person_abilities[key] || "no access"}
|
35
|
+
if login_providers.any_optional?
|
36
|
+
logins = (person.account && person.account.login_provider_ids) || []
|
37
|
+
data.push(login_providers.to_name(logins).join("|"))
|
38
|
+
end
|
32
39
|
csv << data
|
33
40
|
end
|
34
41
|
end
|
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.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
@@ -272,6 +272,7 @@ files:
|
|
272
272
|
- lib/eco/api/error/handler.rb
|
273
273
|
- lib/eco/api/error/handlers.rb
|
274
274
|
- lib/eco/api/organization.rb
|
275
|
+
- lib/eco/api/organization/login_providers.rb
|
275
276
|
- lib/eco/api/organization/people.rb
|
276
277
|
- lib/eco/api/organization/person_schemas.rb
|
277
278
|
- lib/eco/api/organization/policy_groups.rb
|