eco-helpers 2.0.50 → 2.0.51

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: 9c8f3ba10e4524d33de8f1339a48fa9c48c86a7e1b0650e29710d05083b6ed82
4
- data.tar.gz: f68a0adda4ccebff9552e652bc47bc25cbc72129fe025e5c31b9c542b83ed9f3
3
+ metadata.gz: fb5e3755230835f1a3ad402b7dd2fc9b25902ea2ca3a621c8eae0229de716791
4
+ data.tar.gz: c0af346142ec3ff97c32503597ae36d9844273e1c20fb6908a3cfcf5595dff54
5
5
  SHA512:
6
- metadata.gz: 215c64f98db5f29daad59fad9b4f559e0c7e2a136671d87ab9e37a6e2403cafb123948fbb8cd852ddb3155f35e4b52545d9d948df638402f7c3a63797a397690
7
- data.tar.gz: 8a6119977b69ef6aa699ed718142d377866c1c5f379027b9b5713655525f578f837cf543df70be3dbeee1868cd6328f12ee782b1ba743f1aa87ce4cc592bc2cb
6
+ metadata.gz: 4a2f508415dac83ffe596e330d56a55eb427788d57d239b62b1523bb6abb8f465d6400c1f0c61135d7eb6e036a595d7aacb158cc464e9840a5af8ac56d3582af
7
+ data.tar.gz: b791358e41d4aa2db17b5fcd68e0e2aa97af7b4c31d21d9308132e470f07a67c638b53085846006363e2d9d962dba9b5250a9afe358844b113ac4a7c73a4df53
data/CHANGELOG.md CHANGED
@@ -1,7 +1,16 @@
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.51] - 2022-02-27
5
+
6
+ ### Added
7
+ - `Eco::API::MicroCases#person_update!` launches an update against the Server for one person
8
+ - `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
9
+
10
+ ### Changed
11
+ ### Fixed
12
+
13
+ ## [2.0.50] - 2022-02-23
5
14
 
6
15
  ### Added
7
16
  - Ability to configure delay between jobs and job groups
@@ -15,8 +24,6 @@ All notable changes to this project will be documented in this file.
15
24
  ### Changed
16
25
  - `workflow`, when no operation specified it logs as `info`, rather than `warn`
17
26
 
18
- ### Fixed
19
-
20
27
  ## [2.0.49] - 2022-02-14
21
28
 
22
29
  ### Added
@@ -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
@@ -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'
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.0.50"
2
+ VERSION = "2.0.51"
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.51
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -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