eco-helpers 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +45 -2
  3. data/eco-helpers.gemspec +11 -10
  4. data/lib/eco/api.rb +1 -0
  5. data/lib/eco/api/common.rb +1 -1
  6. data/lib/eco/api/common/people/default_parsers.rb +4 -0
  7. data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +30 -0
  8. data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +42 -0
  9. data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +2 -1
  10. data/lib/eco/api/common/people/entry_factory.rb +8 -7
  11. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +2 -0
  12. data/lib/eco/api/common/people/person_parser.rb +1 -1
  13. data/lib/eco/api/common/session/base_session.rb +3 -6
  14. data/lib/eco/api/common/session/environment.rb +2 -23
  15. data/lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb +9 -1
  16. data/lib/eco/api/microcases.rb +31 -0
  17. data/lib/eco/api/microcases/core_excluded.rb +20 -0
  18. data/lib/eco/api/microcases/fix_filter_tags.rb +22 -0
  19. data/lib/eco/api/microcases/set_account.rb +32 -0
  20. data/lib/eco/api/microcases/set_core.rb +18 -0
  21. data/lib/eco/api/microcases/set_default_group.rb +33 -0
  22. data/lib/eco/api/microcases/set_default_tag.rb +23 -0
  23. data/lib/eco/api/microcases/set_supervisor.rb +26 -0
  24. data/lib/eco/api/microcases/strict_search.rb +14 -0
  25. data/lib/eco/api/organization/presets_values.json +1 -0
  26. data/lib/eco/api/session.rb +9 -6
  27. data/lib/eco/api/session/batch.rb +1 -44
  28. data/lib/eco/api/session/config.rb +2 -2
  29. data/lib/eco/api/session/config/api.rb +121 -7
  30. data/lib/eco/api/session/config/apis.rb +24 -25
  31. data/lib/eco/api/usecases/default_cases/recover_db_case.rb +1 -0
  32. data/lib/eco/api/usecases/microed_cases/hris_case.rb +53 -0
  33. data/lib/eco/api/usecases/microed_cases/update_case.rb +33 -0
  34. data/lib/eco/api/usecases/microed_cases/update_details_case.rb +30 -0
  35. data/lib/eco/api/usecases/microed_cases/upsert_case.rb +36 -0
  36. data/lib/eco/version.rb +1 -1
  37. metadata +94 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27ff9c6e496ac4cc7d08cb7f8fec22096ccd6aa915103de89048229e334cbc46
4
- data.tar.gz: 0baecbe3aeb2ea75ce995395f15d2daba1b59a8e5587d2ce1537d99c92db9c61
3
+ metadata.gz: a6fbde8a22ee5efad00700ad096396a008f9a8f9ecaf8e2096f22b7730fa28d2
4
+ data.tar.gz: dc498ae2c6f853f92f3e2703d116a442c2814b2c0a230270e319fabf8678342c
5
5
  SHA512:
6
- metadata.gz: 5c435f203bf8d3829829e8d00b74714a479544f48f0d0e081c83b1441a84a5bf6d9be678cab4aa60c09e9f5de3642388904ea52462477c83d259ba6960bab109
7
- data.tar.gz: 7750b44622529f48bc58d577e4783affa8b1b5c7db58e780ff974634ee88dadcc4b0a93fe86879eec8cc4854959ce95ffa5cf7c256d5f458a2814715c7b9b6bc
6
+ metadata.gz: 9cb6d878d32370e81c512b01de2da8c6c32abcd79d636f1d70189228445c0094acef7236ffc4447c0cdd79e05576c22ceeb4798160da8752d655ff71e35440fb
7
+ data.tar.gz: 14283f84d4fbdc87a160dcdb842a3b154987d606333018acc0a636bd2ee2db9a25167c0106b8c8ba5fc56b4107324c9afa07caaeebe9e219bdaac1aac9d21687
@@ -1,6 +1,49 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.5.1] - 2020-10-xx
5
+
6
+ ### Added
7
+ - `presets_values.json`: added the new ability `tasks` (eP release `1.5.3`)
8
+ - `Ecoportal::API::Internal::Person` patch helper methods:
9
+ * `new?`: to know if this person is new in the people manager as a result of the current launch
10
+ * `account_added?`: to know if this person did not have account but they will have it after the current launch
11
+ - `Eco::API::Session#new_job`: to shorten code
12
+ - `Eco::API::Common::DefaultPasers::PolicyGroupsParser`: made native, as it is a very common parser
13
+ - `Eco::API::Common::DefaultPasers::FreemiumParser` to parse/serialise boolean
14
+ - `Eco::API::Common::People::PersonParser`: added `freemium` as core attribute
15
+ - `Eco::API::UserCases::DefaultCases::RecoverDBCase`: recovers also `freemium`
16
+ - scoping **microcases** : to be able to centralize common code between use cases
17
+ - at its early stage (currently not available for usage)
18
+ - dependency on `ecoportal-api-oozes` gem
19
+ - added basic support for **api** `v2`
20
+ - you can use `session.api(:oozes)` to obtain an api `v2`
21
+ - you can manage your keys directly on the apis configuration
22
+ - added `external_key:`, `user_key:` and `apis.default_user_key`
23
+
24
+ ```ruby
25
+ ASSETS.config do |config|
26
+ config.apis.default_user_key = 'your-user-key-here'
27
+
28
+ config.add_api("org-environment", {
29
+ host: 'pre.dev.ecoportal.com',
30
+ key: 'an-internal-org-api-key',
31
+ version: :internal,
32
+ external_key: 'an-external-org-api-key',
33
+ user_key: 'org-user-key-for-activity-stream',
34
+ mode: :local
35
+ })
36
+ end
37
+ ```
38
+ ### Changed
39
+ - internally: load `Eco::API::Common::Session` before `Eco::API::Common::People`
40
+ - `Eco::API::Common::Person::EntryFactory`: made child of `Eco::API::Common::Session::BaseSession`
41
+ - refactored all the `api` connection creation for simplicity and to support multi api version
42
+ - delegated `Eco::API::Session::Batch#get` to `Ecoportal::API::V1::People#get_all`
43
+
44
+ ### Fixed
45
+ - correct `.gemspec` dependency version restrictions
46
+
4
47
  ## [1.5.0] - 2020-09-11
5
48
 
6
49
  ### Added
@@ -17,7 +60,7 @@ All notable changes to this project will be documented in this file.
17
60
  ### Added
18
61
  ### Changed
19
62
  ### Fixed
20
- - preserve backtrace on logging
63
+ - preserve backtrace on logging
21
64
 
22
65
  ## [1.4.0] - 2020-07-14
23
66
 
@@ -88,7 +131,7 @@ All notable changes to this project will be documented in this file.
88
131
  - `Eco::API::Organization::TagTree#tag?` to accept `nil` by returning `false`
89
132
  - `Eco::API::Common::People::DefaultParsers::DateParser` will parse to `Date` class
90
133
  * 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))
91
- ## [1.3.11] - 2020-05-19
134
+ ## [1.3.12] - 2020-05-19
92
135
 
93
136
  ### Added
94
137
  ### Changed
@@ -22,16 +22,17 @@ Gem::Specification.new do |s|
22
22
  #s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
23
  s.require_paths = ["lib"]
24
24
 
25
- s.add_development_dependency "bundler", "~> 2.1", ">= 2.1.3"
26
- s.add_development_dependency "rspec", "~> 3", ">= 3.9"
27
- s.add_development_dependency "rake", "~> 12.3.0"
28
- s.add_development_dependency "yard", "~> 0.9", ">= 0.9.18"
29
- s.add_development_dependency "redcarpet", "~> 3.5", ">= 3.5.0"
25
+ s.add_development_dependency "bundler", ">= 2.1.3", "< 2.2"
26
+ s.add_development_dependency "rspec", ">= 3.9", "< 4"
27
+ s.add_development_dependency "rake", ">= 12.3.0", "< 13"
28
+ s.add_development_dependency "yard", ">= 0.9.18", "< 0.10"
29
+ s.add_development_dependency "redcarpet", ">= 3.5.0", "< 3.6"
30
30
 
31
- s.add_dependency 'ecoportal-api', '~> 0.7', '>= 0.7.0'
32
- s.add_dependency 'aws-sdk-s3', '~> 1', '>= 1.64.0'
33
- s.add_dependency 'aws-sdk-ses', '~> 1', '>= 1.29.0'
34
- s.add_dependency 'dotenv', '~> 2.7', '>= 2.7.0'
35
- s.add_dependency 'net-sftp', '~> 2.1', '>= 2.1.2'
31
+ s.add_dependency 'ecoportal-api', '>= 0.7.1', '< 0.8'
32
+ s.add_dependency 'ecoportal-api-oozes', '>= 0.7.2', '< 0.8'
33
+ s.add_dependency 'aws-sdk-s3', '>= 1.64.0', '< 2'
34
+ s.add_dependency 'aws-sdk-ses', '>= 1.29.0', '< 2'
35
+ s.add_dependency 'dotenv', '>= 2.7.0', '< 2.8'
36
+ s.add_dependency 'net-sftp', '>= 2.1.2', '< 2.2'
36
37
 
37
38
  end
@@ -1,4 +1,5 @@
1
1
  require 'ecoportal/api'
2
+ require 'ecoportal/api-oozes'
2
3
 
3
4
  module Eco
4
5
  module API
@@ -8,5 +8,5 @@ end
8
8
  require_relative 'common/version_patches'
9
9
  require_relative 'common/class_helpers'
10
10
  require_relative 'common/class_hierarchy'
11
- require_relative 'common/people'
12
11
  require_relative 'common/session'
12
+ require_relative 'common/people'
@@ -31,6 +31,8 @@ module Eco
31
31
 
32
32
  # ALWAYS PRESENT FIELDS
33
33
  SendInvitesParser.new(self).process
34
+ FreemiumParser.new(self).process
35
+ PolicyGroupsParser.new(self).process
34
36
 
35
37
  # FORMAT PARSER
36
38
  CSVParser.new(self).process
@@ -48,4 +50,6 @@ require_relative 'default_parsers/numeric_parser'
48
50
  require_relative 'default_parsers/date_parser'
49
51
  require_relative 'default_parsers/multi_parser'
50
52
  require_relative 'default_parsers/send_invites_parser'
53
+ require_relative 'default_parsers/freemium_parser'
54
+ require_relative 'default_parsers/policy_groups_parser'
51
55
  require_relative 'default_parsers/csv_parser'
@@ -0,0 +1,30 @@
1
+ module Eco
2
+ module API
3
+ module Common
4
+ module People
5
+ class DefaultParsers
6
+ class FreemiumParser < People::BaseParser
7
+
8
+ def process
9
+ @parsers.define_attribute("freemium") do |parser|
10
+ parser.def_parser do |hash|
11
+ value = hash["freemium"]
12
+ value = value.first if value.is_a?(Array)
13
+ truthy(value)
14
+ end.def_serializer do |person|
15
+ person.freemium&.to_s
16
+ end
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def truthy (value)
23
+ %w[true y yes x].include?(value.to_s&.downcase)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ module Eco
2
+ module API
3
+ module Common
4
+ module People
5
+ class DefaultParsers
6
+ class PolicyGroupsParser < People::BaseParser
7
+
8
+ def process
9
+ @parsers.define_attribute("policy_group_ids") do |parser|
10
+ parser.def_parser do |columns_hash|
11
+ policy_group_ids = []
12
+ if policy_ids = columns_hash["policy_group_ids"]
13
+ policy_group_ids = policy_ids.split("|").map do |name|
14
+ policy_groups.to_id(name&.downcase.strip)
15
+ end.compact
16
+ end
17
+ policy_group_ids.empty?? default_id : policy_group_ids.join("|")
18
+ end.def_serializer do |person|
19
+ ids = person&.account&.policy_group_ids || []
20
+ ids.map do |id|
21
+ policy_groups.to_name(id)
22
+ end.compact.join("|")
23
+ end
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def policy_groups
30
+ @policy_groups ||= ASSETS.config.policy_groups
31
+ end
32
+
33
+ def default_id
34
+ @default_id ||= policy_groups.to_id(ASSETS.config.people.default_usergroup)
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -9,7 +9,8 @@ module Eco
9
9
  @parsers.define_attribute("send_invites") do |parser|
10
10
  parser.def_parser do |hash|
11
11
  value = hash["send_invites"]
12
- value.is_a?(Array) ? value.map { |v| truthy(v) } : truthy(value)
12
+ value = value.first if value.is_a?(Array)
13
+ truthy(value)
13
14
  end.def_serializer do |person|
14
15
  person.account && person.account.send_invites&.to_s
15
16
  end
@@ -4,21 +4,21 @@ module Eco
4
4
  module People
5
5
  # Helper factory class to generate entries (input entries).
6
6
  # @attr_reader schema [Ecoportal::API::V1::PersonSchema] person schema to be used in this entry factory
7
- # @attr_reader person_parser [Eco::API::Common::People::PersonParser] set of attribute, type and format parsers/serializers.
8
- class EntryFactory
7
+ class EntryFactory < Eco::API::Common::Session::BaseSession
9
8
 
10
9
  attr_reader :schema, :person_parser
11
10
 
11
+ # @param e [Eco::API::Common::Session::Environment] requires a session environment, as any child of `Eco::API::Common::Session::BaseSession`
12
12
  # @param schema [Ecoportal::API::V1::PersonSchema] schema of person details that the parser will be based upon.
13
13
  # @param person_parser [nil, Eco::API::Common::People::PersonParser] set of attribute, type and format parsers/serializers.
14
14
  # @param attr_map [nil, Eco::Data::Mapper] attribute names mapper to translate external names into internal ones and _vice versa_.
15
15
  # @param logger [Common::Session::Logger, ::Logger] object to manage logs.
16
- def initialize(schema:, person_parser: nil, attr_map: nil, logger: ::Logger.new(IO::NULL))
16
+ def initialize(e, schema:, person_parser: nil, attr_map: nil)
17
17
  fatal "Constructor needs a PersonSchema. Given: #{schema}" if !schema.is_a?(Ecoportal::API::V1::PersonSchema)
18
18
  fatal "Expecting PersonParser. Given: #{person_parser}" if person_parser && !person_parser.is_a?(Eco::API::Common::People::PersonParser)
19
19
  fatal "Expecting Mapper object. Given: #{fields_mapper}" if attr_map && !attr_map.is_a?(Eco::Data::Mapper)
20
+ super(e)
20
21
 
21
- @logger = logger
22
22
  @schema = Ecoportal::API::V1::PersonSchema.new(JSON.parse(schema.doc.to_json))
23
23
 
24
24
  @source_person_parser = person_parser
@@ -34,6 +34,7 @@ module Eco
34
34
 
35
35
  # provides with a Eco::API::Common::People::PersonParser object (collection of attribute parsers)
36
36
  # @note if the custom person parser has changed, it updates the copy of this EntryFactory instance
37
+ # @return [Eco::API::Common::People::PersonParser] set of attribute, type and format parsers/serializers.
37
38
  def person_parser
38
39
  if @person_parser_patch_version < @source_person_parser.patch_version
39
40
  @person_parser.merge(@source_person_parser)
@@ -52,7 +53,7 @@ module Eco
52
53
  person_parser: person_parser,
53
54
  attr_map: @attr_map,
54
55
  dependencies: dependencies,
55
- logger: @logger
56
+ logger: logger
56
57
  )
57
58
  end
58
59
 
@@ -81,7 +82,7 @@ module Eco
81
82
  file_content = File.read(file, encoding: encoding)
82
83
  arr_hash = person_parser.parse(format, file_content)
83
84
  else
84
- @logger.warn("File does not exist: #{file}")
85
+ logger.warn("File does not exist: #{file}")
85
86
  end
86
87
 
87
88
  entries(data: arr_hash)
@@ -131,7 +132,7 @@ module Eco
131
132
  private
132
133
 
133
134
  def fatal(msg)
134
- @logger.fatal(msg)
135
+ logger.fatal(msg)
135
136
  raise msg
136
137
  end
137
138
 
@@ -72,6 +72,8 @@ module Eco
72
72
  # @param value [String, Array<String>] value(s) to be translated into internal names.
73
73
  # @return [String, nil, Array<String] the internal name(s) of `value`.
74
74
  def to_internal(value)
75
+ # TODO: check PersonEntry#to_internal and #to_external in init_attr_trackers
76
+ # => when attr_map is avoided, it doesn't work as it should
75
77
  return value if !@attr_map
76
78
  attr = value
77
79
  case value
@@ -9,7 +9,7 @@ module Eco
9
9
  # @attr_reader details_attrs [Array<String>] internal names of schema details attributes.
10
10
  # @attr_reader all_attrs [Array<String>] all the internal name attributes, including _core_, _account_ and _details_.
11
11
  class PersonParser
12
- CORE_ATTRS = ["id", "external_id", "email", "name", "supervisor_id", "filter_tags"]
12
+ CORE_ATTRS = ["id", "external_id", "email", "name", "supervisor_id", "filter_tags", "freemium"]
13
13
  ACCOUNT_ATTRS = ["policy_group_ids", "default_tag", "send_invites", "landing_page_id", "login_provider_ids"]
14
14
  TYPE = [:select, :text, :date, :number, :phone_number, :boolean, :multiple]
15
15
  FORMAT = [:csv, :xml, :json]
@@ -3,9 +3,6 @@ module Eco
3
3
  module Common
4
4
  module Session
5
5
  class BaseSession
6
-
7
- include Common::People
8
-
9
6
  attr_accessor :session
10
7
  attr_accessor :environment, :config
11
8
  alias_method :enviro, :environment
@@ -32,8 +29,8 @@ module Eco
32
29
  enviro.config
33
30
  end
34
31
 
35
- def api
36
- enviro.api
32
+ def api(version: nil)
33
+ enviro.api(version: version)
37
34
  end
38
35
 
39
36
  def file_manager
@@ -47,7 +44,7 @@ module Eco
47
44
  def mailer?
48
45
  enviro.mailer?
49
46
  end
50
-
47
+
51
48
  def sftp
52
49
  enviro.sftp
53
50
  end
@@ -3,11 +3,7 @@ module Eco
3
3
  module Common
4
4
  module Session
5
5
  class Environment
6
-
7
- include Common::People
8
-
9
6
  attr_reader :config, :session
10
- attr_reader :api #, :host, :version
11
7
  attr_reader :file_manager, :logger
12
8
  attr_reader :mailer, :sftp, :s3uploader
13
9
 
@@ -57,25 +53,8 @@ module Eco
57
53
  config.s3storage.configured?
58
54
  end
59
55
 
60
- def api
61
- @api || new_api
62
- end
63
-
64
- def new_api
65
- return nil unless config.apis.active_api
66
-
67
- log_connection = config.logger.log_connection?
68
- logg = log_connection ? logger : ::Logger.new(IO::NULL)
69
-
70
- api = config.api(logg)
71
-
72
- unless log_connection
73
- logger.info("Created connection pointing to '#{config.apis.active_api.host}' in '#{config.apis.active_api.mode}' mode")
74
- api.logger.level = ::Logger::UNKNOWN
75
- end
76
-
77
- @api = api
78
- api
56
+ def api(version: nil)
57
+ config.api(logger, version: version)
79
58
  end
80
59
 
81
60
  end
@@ -2,7 +2,7 @@ module Ecoportal
2
2
  module API
3
3
  class Internal
4
4
  class Person
5
-
5
+
6
6
  def reset_account!
7
7
  doc["account"] = JSON.parse(original_doc["account"])
8
8
  end
@@ -11,6 +11,14 @@ module Ecoportal
11
11
  original_doc["account"] = JSON.parse(doc["account"])
12
12
  end
13
13
 
14
+ def new?
15
+ !initial_doc["details"] && !initial_doc["account"]
16
+ end
17
+
18
+ def account_added?
19
+ person.account && !initial_doc["account"]
20
+ end
21
+
14
22
  end
15
23
  end
16
24
  end
@@ -0,0 +1,31 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases < Eco::API::Common::Session::BaseSession
4
+ class << self
5
+ def define(name, &block)
6
+ name = name.to_sym
7
+ @helpers[name] = block
8
+ define_method(name.to_sym, &block)
9
+ end
10
+ end
11
+
12
+ def define(*args)
13
+ self.class.define(*args)
14
+ end
15
+
16
+ def micro
17
+ self
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+
24
+ require_relative 'microcases/core_excluded'
25
+ require_relative 'microcases/fix_filter_tags'
26
+ require_relative 'microcases/set_account'
27
+ require_relative 'microcases/set_core'
28
+ require_relative 'microcases/set_default_group'
29
+ require_relative 'microcases/set_default_tag'
30
+ require_relative 'microcases/set_supervisor'
31
+ require_relative 'microcases/strict_search'
@@ -0,0 +1,20 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ #self.define(:core_excluded) do |options|
5
+
6
+ # @param person [Person] the person we want to update, carrying the changes to be done.
7
+ # @param options [Hash] the options
8
+ def core_excluded(person, options)
9
+ ["supervisor_id"].tap do |core_excluded|
10
+ unless person.new?
11
+ exclusions = ["name", "external_id", "email", "filter_tags"].select do |attr|
12
+ options.dig(:exclude, attr.to_sym)
13
+ end
14
+ core_excluded.concat(exclusions)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end