eco-helpers 2.0.50 → 2.0.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c8f3ba10e4524d33de8f1339a48fa9c48c86a7e1b0650e29710d05083b6ed82
4
- data.tar.gz: f68a0adda4ccebff9552e652bc47bc25cbc72129fe025e5c31b9c542b83ed9f3
3
+ metadata.gz: 71ac6b334999283d1bab07efdb1ece3fdbbfaa56052f292010a3741faad92351
4
+ data.tar.gz: e432429671478dcca99ef444f1db0eeab66d9ad2dc7150cfc12577fb06f5b1e7
5
5
  SHA512:
6
- metadata.gz: 215c64f98db5f29daad59fad9b4f559e0c7e2a136671d87ab9e37a6e2403cafb123948fbb8cd852ddb3155f35e4b52545d9d948df638402f7c3a63797a397690
7
- data.tar.gz: 8a6119977b69ef6aa699ed718142d377866c1c5f379027b9b5713655525f578f837cf543df70be3dbeee1868cd6328f12ee782b1ba743f1aa87ce4cc592bc2cb
6
+ metadata.gz: ff99f0de94a2e87730f2d6b8496d4d556cbfe7ec3bb99289f3e27cf30512e0644b33f142f0664ee2c5f9f91e7fc13b83bc62178af26f3e0929668acd94f95088
7
+ data.tar.gz: 3b9b43011552a1cb9f37a46c18cabab8ad2892b3634908895ddd99b2269151c65bd3a4c5a6281ab080396ea3ec0890f29fd5f1e37c8427d80bbdb2c2e240b91f
data/CHANGELOG.md CHANGED
@@ -1,7 +1,32 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.0.50] - 2022-02-xx
4
+ ## [2.0.53] - 2022-03-xx
5
+
6
+ ### Added
7
+ - `Eco::API::MicroCases#set_supervisor` prevent to set someone as supervisor of themselves.
8
+ - `Eco::API::UseCases::DefaultCases::Samples::Sftp` integration to modify the `source_folder`
9
+
10
+ ### Changed
11
+ - upgrade `ecoportal-api` and `ecoportal-api-v2` dependencies
12
+
13
+ ### Fixed
14
+
15
+ ## [2.0.52] - 2022-03-04
16
+
17
+ ### Added
18
+ - `Eco::API::UseCases::DefaultCases::CleanUnknownTags` include `default_tag` refresh
19
+
20
+ ### Fixed
21
+ - `Eco::Data::Files::Directory#dir_files` to be returned in alphabetic order
22
+
23
+ ## [2.0.51] - 2022-02-27
24
+
25
+ ### Added
26
+ - `Eco::API::MicroCases#person_update!` launches an update against the Server for one person
27
+ - `Eco::API::MicroCases#take_email_from_account` with given an account associated to an `email` that we cannot take, it associates that account to a different email
28
+
29
+ ## [2.0.50] - 2022-02-23
5
30
 
6
31
  ### Added
7
32
  - Ability to configure delay between jobs and job groups
@@ -15,8 +40,6 @@ All notable changes to this project will be documented in this file.
15
40
  ### Changed
16
41
  - `workflow`, when no operation specified it logs as `info`, rather than `warn`
17
42
 
18
- ### Fixed
19
-
20
43
  ## [2.0.49] - 2022-02-14
21
44
 
22
45
  ### Added
data/eco-helpers.gemspec CHANGED
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "yard", ">= 0.9.26", "< 0.10"
31
31
  spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 3.6"
32
32
 
33
- spec.add_dependency 'ecoportal-api', '>= 0.8.4', '< 0.9'
34
- spec.add_dependency 'ecoportal-api-v2', '>= 0.8.25', '< 0.9'
33
+ spec.add_dependency 'ecoportal-api', '>= 0.8.5', '< 0.9'
34
+ spec.add_dependency 'ecoportal-api-v2', '>= 0.8.26', '< 0.9'
35
35
  spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
36
36
  spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
37
37
  spec.add_dependency 'dotenv', '>= 2.7.6', '< 2.8'
@@ -0,0 +1,39 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ # It updates an idividual person.
5
+ # @note if it succeeds the update, it calls `person.consolidate!`
6
+ # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
7
+ # @param context [String] main part of the message.
8
+ # @param reason [String] why are we updating now.
9
+ # @return [Boolean] `true` if it succeded to update, and `false` otherwise
10
+ def person_update!(person, context: "Session", reason: "")
11
+ logger.debug("#{context}, going to \"#{reason}\".\nPerson: #{person_ref(person)}")
12
+ if response = api.people.update(person)
13
+ if response.success?
14
+ person.consolidate!
15
+ true
16
+ else
17
+ msg = "#{context} Error #{response.status}: #{response.body}\n"
18
+ msg += " -- Failed to \"#{reason}\".\n"
19
+ msg += " • Person: #{person_ref(person)}"
20
+ logger.error(msg)
21
+ false
22
+ end
23
+ else
24
+ msg = "#{context} Error (connection error)\n"
25
+ msg += " -- Failed to \"#{reason}\".\n"
26
+ msg += " • Person: #{person_ref(person)}"
27
+ logger.error(msg)
28
+ false
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def person_ref(person)
35
+ Eco::API::Session::Batch::Feedback.person_ref(person)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -2,6 +2,8 @@ module Eco
2
2
  module API
3
3
  class MicroCases
4
4
  # Unique access point to set the `supervisor_id` value on a person.
5
+ # @note
6
+ # - It prevents the basic cyclic supervisor case (supervisor to be supervisor of hemselves)
5
7
  # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
6
8
  # @param sup_id [nil, String] the **supervisor id** we should set on the `person`.
7
9
  # @param people [Eco::API::Organization::People] _People_ involved in the current update.
@@ -10,6 +12,7 @@ module Eco
10
12
  # @yieldparam supervisor_id [String] the **unknown** `supervisor_id`.
11
13
  def set_supervisor(person, sup_id, people, options)
12
14
  unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
15
+ return false if sup_id && ((person.id == sup_id) || (person.external_id == sup_id))
13
16
  cur_id = person.supervisor_id
14
17
  cur_super = cur_id && with_supervisor(cur_id, people)
15
18
  micro.with_supervisor(sup_id, people) do |new_super|
@@ -0,0 +1,89 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ # Frees up `target_email` from an account not present in this org.
5
+ # Allows to force `target_email` on the current user's account.
6
+ # - If the person does not have account, this case will not do anything.
7
+ # - If `original_doc["account"]` is `nil` (no account on server side), this case will not do anything.
8
+ # - If the `target_email` and the `current_email` are the same or empty, this case will not do anything.
9
+ # @note
10
+ # - **It does not do the final update to the server to the `target_email`**. You will need to do this part yourself.
11
+ # - You would call this function only when you got an error of `email already taken`.
12
+ # - If the `target_email` is associated to a user in the same org, this will fail.
13
+ # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
14
+ # @param dest_email [String, Proc] the email that we will move the other account to, when we free up `target_email`.
15
+ # @param target_email [String] the email that we want to free up from another account and bring to ours.
16
+ # If it's empty, the `person.email` will be used instead.
17
+ # @param options [Hash] the options.
18
+ # @param current_email [String] the email that the person's account is currently linked.
19
+ # As the current email should be associated with this person's account on server side, we use `original_doc["email"]`.
20
+ # @param context [String] main core part of logs. Provides context to the logs.
21
+ def take_email_from_account(person, dest_email:, target_email: nil, options: {}, context: "Session")
22
+ return false if options.dig(:exclude, :account)
23
+ return false unless account = person.account
24
+ return false unless had_account = person.original_doc["account"]
25
+
26
+ target_email ||= person.email
27
+ account_email = person.original_doc["email"]
28
+
29
+ return false unless target_email != account_email
30
+ return false if account_email.to_s.strip.empty?
31
+ return false if target_email.to_s.strip.empty?
32
+
33
+ if dest_email.is_a?(String)
34
+ return false unless target_email != dest_email
35
+ return false unless dest_email != account_email
36
+ return false if dest_email.to_s.strip.empty?
37
+ end
38
+
39
+ account_json = JSON.parse(account.to_json)
40
+ person.email = account_email
41
+
42
+ if success = _take_email_remove_account!(person, context: context)
43
+ if success = _take_email_acquire_account!(person, target_email, account: {}, context: context)
44
+ if success = _take_email_email_free_up!(person, dest_email: dest_email, context: context)
45
+ if success = _take_email_remove_account!(person, context: context)
46
+ if success = _take_email_acquire_account!(person, account_email, account: account_json, context: context)
47
+ person.email = target_email
48
+ end
49
+ end
50
+ else # free up target email
51
+ # restore
52
+ if _take_email_remove_account!(person, context: context)
53
+ _take_email_acquire_account!(person, account_email, account: account_json, context: context)
54
+ end
55
+ success = false
56
+ end
57
+ else # aquire other account
58
+ # restore
59
+ _take_email_acquire_account!(person, account_email, account: account_json, context: context)
60
+ success = false
61
+ end
62
+ end
63
+ success
64
+ end
65
+
66
+ private
67
+
68
+ def _take_email_acquire_account!(person, target_email, account: {}, context: "Session")
69
+ person.account = account
70
+ person.account.send_invites = false
71
+ person.email = target_email
72
+ micro.person_update!(person, reason: "bring account with email '#{target_email}'", context: context)
73
+ end
74
+
75
+ def _take_email_email_free_up!(person, dest_email:, target_email: nil, context: "Session")
76
+ target_email ||= person.email
77
+ person.email = dest_email.is_a?(Proc)? dest_email.call(target_email) : dest_email
78
+ reason = "free up email '#{target_email}', by moving account to '#{person.email}'"
79
+ micro.person_update!(person, reason: reason, context: context)
80
+ end
81
+
82
+ def _take_email_remove_account!(person, context: "Session")
83
+ person.account = nil
84
+ micro.person_update!(person, reason: "remove account", context: context)
85
+ end
86
+
87
+ end
88
+ end
89
+ end
@@ -19,6 +19,7 @@ require_relative 'microcases/people_cache'
19
19
  require_relative 'microcases/people_load'
20
20
  require_relative 'microcases/people_refresh'
21
21
  require_relative 'microcases/people_search'
22
+ require_relative 'microcases/person_update'
22
23
  require_relative 'microcases/preserve_filter_tags'
23
24
  require_relative 'microcases/preserve_default_tag'
24
25
  require_relative 'microcases/preserve_policy_groups'
@@ -26,9 +27,10 @@ require_relative 'microcases/set_account'
26
27
  require_relative 'microcases/set_core_with_supervisor'
27
28
  require_relative 'microcases/set_core'
28
29
  require_relative 'microcases/refresh_default_tag'
30
+ require_relative 'microcases/s3upload_targets'
29
31
  require_relative 'microcases/set_supervisor'
30
32
  require_relative 'microcases/strict_search'
31
- require_relative 'microcases/s3upload_targets'
33
+ require_relative 'microcases/take_email_from_account'
32
34
  require_relative 'microcases/with_each'
33
35
  require_relative 'microcases/with_each_leaver'
34
36
  require_relative 'microcases/with_each_present'
@@ -23,6 +23,12 @@ class Eco::API::UseCases::DefaultCases::CleanUnknownTags < Eco::API::Common::Loa
23
23
  unknown_tags = person.filter_tags.select {|tag| !tag?(tag)}
24
24
  person.filter_tags -= unknown_tags
25
25
  unknown_tag!(*unknown_tags)
26
+ if (account = person.account) && tag = account.default_tag
27
+ unless tag?(tag)
28
+ micro.refresh_default_tag(person.entry, person, options)
29
+ unknown_tag!(tag)
30
+ end
31
+ end
26
32
  update.add(person)
27
33
  end
28
34
  end
@@ -2,10 +2,10 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
2
2
  name "sftp-sample"
3
3
  type :other
4
4
 
5
- attr_reader :session
5
+ attr_reader :session, :options
6
6
 
7
7
  def main(session, options, usecase)
8
- @session = session
8
+ @session = session; @options = options
9
9
  options[:end_get] = false
10
10
  raise "The SFTP is not configured" unless session.sftp?
11
11
  case options.dig(:sftp, :command)
@@ -92,7 +92,7 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
92
92
  end
93
93
 
94
94
  def local_folder
95
- "."
95
+ options.dig(:sftp, :local_folder) || "."
96
96
  end
97
97
 
98
98
  def remote_folder
@@ -53,7 +53,7 @@ module Eco
53
53
 
54
54
  def dir_files(file: nil, pattern: dir_pattern)
55
55
  find = !!file ? file_pattern(file) : file_pattern(pattern)
56
- Dir.glob(find)
56
+ Dir.glob(find).sort
57
57
  end
58
58
 
59
59
  def newest_file(files_list = nil, file: nil)
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.0.50"
2
+ VERSION = "2.0.53"
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: 2.0.50
4
+ version: 2.0.53
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -116,7 +116,7 @@ dependencies:
116
116
  requirements:
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- version: 0.8.4
119
+ version: 0.8.5
120
120
  - - "<"
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0.9'
@@ -126,7 +126,7 @@ dependencies:
126
126
  requirements:
127
127
  - - ">="
128
128
  - !ruby/object:Gem::Version
129
- version: 0.8.4
129
+ version: 0.8.5
130
130
  - - "<"
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0.9'
@@ -136,7 +136,7 @@ dependencies:
136
136
  requirements:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
- version: 0.8.25
139
+ version: 0.8.26
140
140
  - - "<"
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0.9'
@@ -146,7 +146,7 @@ dependencies:
146
146
  requirements:
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
- version: 0.8.25
149
+ version: 0.8.26
150
150
  - - "<"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.9'
@@ -462,6 +462,7 @@ files:
462
462
  - lib/eco/api/microcases/people_load.rb
463
463
  - lib/eco/api/microcases/people_refresh.rb
464
464
  - lib/eco/api/microcases/people_search.rb
465
+ - lib/eco/api/microcases/person_update.rb
465
466
  - lib/eco/api/microcases/preserve_default_tag.rb
466
467
  - lib/eco/api/microcases/preserve_filter_tags.rb
467
468
  - lib/eco/api/microcases/preserve_policy_groups.rb
@@ -472,6 +473,7 @@ files:
472
473
  - lib/eco/api/microcases/set_core_with_supervisor.rb
473
474
  - lib/eco/api/microcases/set_supervisor.rb
474
475
  - lib/eco/api/microcases/strict_search.rb
476
+ - lib/eco/api/microcases/take_email_from_account.rb
475
477
  - lib/eco/api/microcases/with_each.rb
476
478
  - lib/eco/api/microcases/with_each_leaver.rb
477
479
  - lib/eco/api/microcases/with_each_present.rb