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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b8f8b8d8377570d48f13252508d8193694c79455b76d18ea467841c5e543f9f
4
- data.tar.gz: 8208f96191dc3e658f034fe59f1d07bc25bcfe2b74a6385dcafcc0715ff8d8a3
3
+ metadata.gz: d1fc8637aef6c15d4e73834479411965ecc2de80df899df4f937d4eb7b002718
4
+ data.tar.gz: 104e50e1d40d9009af0674d432e03e63ba3b327be70fac18909d011b2cf55ce6
5
5
  SHA512:
6
- metadata.gz: a65fd6bce522a94d37c97fce7b3834b88ed0f75738a0f368ccea9f3357c27391763c3793555a0829e18ce4a29ef40d2df03854d744365c505cf1921874f2bd5c
7
- data.tar.gz: 57b6be6d03a982a1ad23432017898573b59cccf4dda63369e83e6fb0c022ecdff4220e356724d00b8adc4a6230b815d46f7af1693e53c3a1ce863654be1c55a9
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
- return value if value.is_a?(Array)
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).map do |attr|
344
- value = @person_parser.parse(attr, aliased_entry)
345
- [attr, value]
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 ! source_attrs
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 it excludes any parser that is not in the model, such as type parsers (i.e. `:boolean`, `:multiple`)
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
 
@@ -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
@@ -62,6 +62,11 @@ module Eco
62
62
  config.policy_groups
63
63
  end
64
64
 
65
+ # @see Eco::API::Session::Config#login_providers
66
+ def login_providers
67
+ config.login_providers
68
+ end
69
+
65
70
  # @see Eco::API::Session::Config#tagtree
66
71
  def tagtree
67
72
  config.tagtree(enviro: enviro)
@@ -77,7 +77,7 @@ module Eco
77
77
  when 1
78
78
  status.set_person_match(entry, people_matching.first)
79
79
  when 2..Float::INFINITY
80
- status.set_people_match(entry, people.matching)
80
+ status.set_people_match(entry, people_matching)
81
81
  end
82
82
  end
83
83
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
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.0.3
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