eco-helpers 2.0.16 → 2.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -6
  3. data/eco-helpers.gemspec +6 -4
  4. data/lib/eco-helpers.rb +1 -0
  5. data/lib/eco/api/common/base_loader.rb +14 -0
  6. data/lib/eco/api/common/people/default_parsers/date_parser.rb +11 -1
  7. data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +1 -1
  8. data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +11 -11
  9. data/lib/eco/api/common/people/person_entry.rb +4 -2
  10. data/lib/eco/api/common/session/mailer.rb +0 -1
  11. data/lib/eco/api/common/session/s3_uploader.rb +0 -1
  12. data/lib/eco/api/common/session/sftp.rb +0 -1
  13. data/lib/eco/api/microcases.rb +3 -1
  14. data/lib/eco/api/microcases/append_usergroups.rb +0 -1
  15. data/lib/eco/api/microcases/people_cache.rb +2 -2
  16. data/lib/eco/api/microcases/people_load.rb +2 -2
  17. data/lib/eco/api/microcases/people_refresh.rb +2 -2
  18. data/lib/eco/api/microcases/people_search.rb +6 -6
  19. data/lib/eco/api/microcases/preserve_default_tag.rb +23 -0
  20. data/lib/eco/api/microcases/preserve_filter_tags.rb +28 -0
  21. data/lib/eco/api/microcases/preserve_policy_groups.rb +30 -0
  22. data/lib/eco/api/microcases/set_account.rb +0 -1
  23. data/lib/eco/api/organization.rb +1 -0
  24. data/lib/eco/api/organization/people.rb +7 -0
  25. data/lib/eco/api/organization/people_analytics.rb +60 -0
  26. data/lib/eco/api/organization/presets_factory.rb +22 -83
  27. data/lib/eco/api/organization/presets_integrity.json +6 -0
  28. data/lib/eco/api/organization/presets_values.json +5 -4
  29. data/lib/eco/api/policies/default_policies/99_user_access_policy.rb +0 -30
  30. data/lib/eco/api/session.rb +1 -20
  31. data/lib/eco/api/session/batch.rb +23 -7
  32. data/lib/eco/api/session/config.rb +0 -10
  33. data/lib/eco/api/session/config/people.rb +1 -17
  34. data/lib/eco/api/usecases/default_cases.rb +1 -1
  35. data/lib/eco/api/usecases/default_cases/abstract_policygroup_abilities_case.rb +1 -1
  36. data/lib/eco/api/usecases/default_cases/analyse_people_case.rb +76 -0
  37. data/lib/eco/api/usecases/default_cases/codes_to_tags_case.rb +2 -3
  38. data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +11 -1
  39. data/lib/eco/api/usecases/default_cases/restore_db_case.rb +1 -2
  40. data/lib/eco/api/usecases/default_cases/supers_cyclic_identify_case.rb +1 -1
  41. data/lib/eco/api/usecases/default_cases/supers_hierarchy_case.rb +1 -1
  42. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +85 -27
  43. data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +62 -36
  44. data/lib/eco/cli/config/default/options.rb +19 -17
  45. data/lib/eco/cli/config/default/people_filters.rb +3 -3
  46. data/lib/eco/cli/config/default/usecases.rb +66 -32
  47. data/lib/eco/cli/config/default/workflow.rb +1 -1
  48. data/lib/eco/cli/config/help.rb +1 -0
  49. data/lib/eco/cli/config/options_set.rb +106 -13
  50. data/lib/eco/cli/config/use_cases.rb +33 -33
  51. data/lib/eco/cli/scripting/args_helpers.rb +30 -3
  52. data/lib/eco/data.rb +1 -0
  53. data/lib/eco/data/crypto/encryption.rb +3 -3
  54. data/lib/eco/data/files/helpers.rb +6 -4
  55. data/lib/eco/data/fuzzy_match.rb +119 -0
  56. data/lib/eco/data/fuzzy_match/array_helpers.rb +75 -0
  57. data/lib/eco/data/fuzzy_match/chars_position_score.rb +37 -0
  58. data/lib/eco/data/fuzzy_match/ngrams_score.rb +73 -0
  59. data/lib/eco/data/fuzzy_match/pairing.rb +102 -0
  60. data/lib/eco/data/fuzzy_match/result.rb +67 -0
  61. data/lib/eco/data/fuzzy_match/results.rb +53 -0
  62. data/lib/eco/data/fuzzy_match/score.rb +44 -0
  63. data/lib/eco/data/fuzzy_match/stop_words.rb +35 -0
  64. data/lib/eco/data/fuzzy_match/string_helpers.rb +69 -0
  65. data/lib/eco/version.rb +1 -1
  66. metadata +82 -10
  67. data/lib/eco/api/microcases/refresh_abilities.rb +0 -19
  68. data/lib/eco/api/organization/presets_reference.json +0 -59
  69. data/lib/eco/api/usecases/default_cases/refresh_abilities_case.rb +0 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 669f1a3e8d49a2499b02d925386477a8e52cc633c830072420484edcf8e4919d
4
- data.tar.gz: 86b36286a089bfa03d3cb17d4c17648a4dcc5f1ed07145ee81565cd19d102c90
3
+ metadata.gz: 4d982e3f0bdb6c5831544cc5a1e232f4d0902220adf9bf65dac88b64eee97d08
4
+ data.tar.gz: 0cc1d65f0336bef75df0f99cd972a99e5c986307fcb9e14bb3a7a3e5eef69173
5
5
  SHA512:
6
- metadata.gz: 0a346a01757374cc004c12b5aadadf6b3c1daebba937c8d1c0cf597608297ab825d604af3a7f70f92528e28e0f009fd482abd31eb660c4abcf9d9796f55f69db
7
- data.tar.gz: f912a967dfb21cb0e455b357c9f5ca28fae4de55cbacd060fd000add64992b86168a3ed38150d1ddaf9a264245da582a49c434d62d24bc28285d82b3f9a2e693
6
+ metadata.gz: 72b1e364f326a3d6e7fb0145ff8e4727bc41da1ae9f453be7d2aeec1c749e0b4463750cbe95370a5f241794d394ab79f3836339369ea6be131f2ebc18d7287ca
7
+ data.tar.gz: be3e03507f60c643a0b4d14eeca65f7a34534042a86a06239f9a015e9a2e8be6e2a757d1dfc94c7608663e53e503d6e0cc8bc9ffebe4ac54df8391be422df6a6
data/CHANGELOG.md CHANGED
@@ -1,7 +1,55 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.0.16] - 2021-04-xx
4
+ ## [2.0.17] - 2021-05-24
5
+
6
+ Specific changes due to eP **release `1.5.9.70`** (_Policy Group Abilities_)
7
+ - And some improvements as well as new tools
8
+
9
+ ### Added
10
+ - `Eco::API::Organization::PresetsFactory` added integrity validation for `person_abilities` ability
11
+ - `Eco::API::Organization::PresetsFactory`
12
+ - `#validate`: returns an `Array` with all the errors that a `permissions_custom` has
13
+ - `#valid?`: checks if a `permissions_custom` is valid
14
+ - `Eco::API::Organization::PeopleAnalytics`: a **helper** class to identify things in the People Manager and provide mitigation action methods to resolve them.
15
+ - Added dependencies to `fuzzy_match`, `amatch` and `jaro_winkler` **gems**
16
+ - `Eco::Data::FuzzyMatch` with string match helpers and a set of home-made generic libs.
17
+ - `Eco::API::Organization::PeopleAnalytics` to launch analysis on the People Manager
18
+ - `Eco::API::UseCases::DefaultCases::AnalysePeople` invokable via `-analyse-people`
19
+ - **new** -> a way to define a hierarchy of options (at least of 1 Level)
20
+ - `API::CLI::Config::OptionsSet`
21
+ - `API::CLI::Config::UseCases::CaseConfig`
22
+ - Integrated the new feature to the `--help` command and methods.
23
+ - **Usecase** `Eco::API::UseCases::DefaultCases::ResetLandingPageCase` added parameter to specify `-page-id`
24
+ - `Eco::API::Common::BaseLoader` new shortcut methods `#micro` (_MicroCases_), `#session` and `#config`
25
+ - At this stage of the execution workflow it uses `ASSETS.session`
26
+ - **Important note**: when the `#parser` or `#serializer` are called the `ASSETS.session` might already be linked to the specific invoked environment
27
+ - New method helpers in `Ecoporta::API::MicroCases`
28
+ - `preserve_filter_tags`, `preserve_default_tag` and `preserve_policy_groups`
29
+
30
+ ### Changed
31
+ - upgraded dependency on `ecoportal-api` and `ecoportal-api-v2`
32
+ - **removed** `Eco::API::MicroCases#refresh_abilities`
33
+ - `Eco::API::MicroCases#set_account` **removed** `refresh_abilities`
34
+ - `Eco::API::MicroCases#append_usergroups` **removed** `refresh_abilities`
35
+ - **removed** _usecase_ `Eco::API::UseCases::DefaultCases::RefreshAbilitiesCase` (`-refresh-abilities`)
36
+ - `Eco::API::Policies::DefaultPolicies::UserAccess`: **removed** `refresh_abilities`
37
+ - **removed** `Eco::API::Session#new_preset`
38
+ - `Eco::API::Organization::PresetsFactory`
39
+ - **removed** `rspecs`
40
+ - `.new`: **removed** parameters `presets_custom` & `presets_map`
41
+ - **removed** constants `DEFAULT_CUSTOM`, and `DEFAULT_MAP`
42
+ - **removed** private methods `#presets_custom` and `#presets_map`
43
+ - **changed** private method `#compile` receives directly an array of `permissions_custom`
44
+ - `Eco::API::Session::Config` **removed** methods `#presets_custom=` & `presets_map=`
45
+ - `Eco::API::Session::Config::People` **removed** methods `#presets_custom=`, `#presets_map=`,`#presets_custom` & `#presets_map`
46
+ - **removed** `eco/api/organization/presets_reference.json`
47
+ - **moved** case-specific options to only be active when the user case is previously invoked in the command line.
48
+
49
+ ### Fixed
50
+ - **handle** `Ecoportal::API:Errors::TimeOut` in `Eco::API::Session::Batch` by offering to retry.
51
+
52
+ ## [2.0.16] - 2021-05-04
5
53
 
6
54
  ### Added
7
55
  - Use case `Eco::API::UseCases::DefaultCases::SupersCyclicIdentify`, invokable via `-identify-cyclic-supers`
@@ -11,14 +59,10 @@ All notable changes to this project will be documented in this file.
11
59
  2. `-enviro [live|pre.dev]`
12
60
  3. `-org NAME_OF_ORG`
13
61
 
14
- ### Changed
15
- ### Fixed
16
-
17
-
18
62
  ## [2.0.15] - 2021-04-29
19
63
 
20
64
  ### Added
21
- - Use case `Eco::API::UseCases::DefaultCases::SupersHierarchy`, invokable via `-supers-hiearchy`
65
+ - Use case `Eco::API::UseCases::DefaultCases::SupersHierarchy`, invokable via `-supers-hierarchy`
22
66
  ### Fixed
23
67
  - `eco/cli/config/default/workflow.rb` prevent `rescue` looping
24
68
 
data/eco-helpers.gemspec CHANGED
@@ -24,17 +24,19 @@ Gem::Specification.new do |spec|
24
24
  #spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
26
 
27
- spec.add_development_dependency "bundler", ">= 2.2.11", "< 2.3"
27
+ spec.add_development_dependency "bundler", ">= 2.2.17", "< 2.3"
28
28
  spec.add_development_dependency "rspec", ">= 3.10.0", "< 3.11"
29
29
  spec.add_development_dependency "rake", ">= 13.0.3", "< 13.1"
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.2', '< 0.9'
34
- spec.add_dependency 'ecoportal-api-v2', '>= 0.8.6', '< 0.9'
33
+ spec.add_dependency 'ecoportal-api', '>= 0.8.3', '< 0.9'
34
+ spec.add_dependency 'ecoportal-api-v2', '>= 0.8.7', '< 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'
38
38
  spec.add_dependency 'net-sftp', '>= 3.0.0', '< 3.1'
39
- #spec.add_dependency 'fuzzy_match' '>= 2.1.0', '< 2.2'
39
+ spec.add_dependency 'fuzzy_match', '>= 2.1.0', '< 2.2'
40
+ spec.add_dependency 'amatch', '>= 0.4.0', '< 0.5'
41
+ spec.add_dependency 'jaro_winkler', '>= 1.5.4', '< 1.6'
40
42
  end
data/lib/eco-helpers.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'csv'
2
2
  require 'json'
3
3
  require 'pp'
4
+ require 'dotenv/load'
4
5
 
5
6
 
6
7
  module Eco
@@ -48,6 +48,20 @@ module Eco
48
48
  self.class.name
49
49
  end
50
50
 
51
+ private
52
+
53
+ def session
54
+ @session ||= ASSETS.session
55
+ end
56
+
57
+ def micro
58
+ session.micro
59
+ end
60
+
61
+ def config
62
+ @config ||= ASSETS.config
63
+ end
64
+
51
65
  end
52
66
  end
53
67
  end
@@ -6,7 +6,7 @@ class Eco::API::Common::People::DefaultParsers::DateParser < Eco::API::Common::L
6
6
  end
7
7
 
8
8
  def serializer(value, deps)
9
- value.is_a?(Array) ? value.map { |d| d && d.strftime('%Y-%m-%d') } : value && value.strftime('%Y-%m-%d')
9
+ value.is_a?(Array) ? value.map { |d| serialize_date(d) } : serialize_date(value)
10
10
  end
11
11
 
12
12
  private
@@ -19,4 +19,14 @@ class Eco::API::Common::People::DefaultParsers::DateParser < Eco::API::Common::L
19
19
  end
20
20
  end
21
21
 
22
+ def serialize_date(value)
23
+ return value if value.is_a?(String)
24
+ begin
25
+ value && value.strftime('%Y-%m-%d')
26
+ rescue
27
+ nil
28
+ end
29
+ end
30
+
31
+
22
32
  end
@@ -20,7 +20,7 @@ class Eco::API::Common::People::DefaultParsers::LoginProvidersParser < Eco::API:
20
20
  private
21
21
 
22
22
  def login_providers
23
- @login_providers ||= ASSETS.config.login_providers
23
+ @login_providers ||= config.login_providers
24
24
  end
25
25
 
26
26
  end
@@ -1,31 +1,31 @@
1
1
  class Eco::API::Common::People::DefaultParsers::PolicyGroupsParser < Eco::API::Common::Loaders::Parser
2
2
  attribute "policy_group_ids"
3
+ parsing_phase :final
3
4
 
4
5
  def parser(hash, deps)
5
- policy_group_ids = []
6
- if policy_ids = hash["policy_group_ids"]
7
- policy_group_ids = policy_ids.split("|").map do |name|
8
- policy_groups.to_id(name&.downcase.strip)
9
- end.compact
6
+ policy_group_ids = hash["policy_group_ids"] || []
7
+ policy_group_ids.map do |name|
8
+ policy_groups.to_id(name&.downcase.strip)
9
+ end.compact.tap do |pg_names|
10
+ pg_names.push(default_id) if pg_names.empty?
10
11
  end
11
- policy_group_ids.empty?? default_id : policy_group_ids.join("|")
12
12
  end
13
13
 
14
14
  def serializer(person, deps)
15
15
  ids = person&.account&.policy_group_ids || []
16
16
  ids.map do |id|
17
17
  policy_groups.to_name(id)
18
- end.compact.join("|")
18
+ end.compact
19
19
  end
20
20
 
21
21
  private
22
22
 
23
- def policy_groups
24
- @policy_groups ||= ASSETS.config.policy_groups
23
+ def default_id
24
+ @default_id ||= policy_groups.to_id(config.people.default_usergroup)
25
25
  end
26
26
 
27
- def default_id
28
- @default_id ||= policy_groups.to_id(ASSETS.config.people.default_usergroup)
27
+ def policy_groups
28
+ @policy_groups ||= config.policy_groups
29
29
  end
30
30
 
31
31
  end
@@ -210,7 +210,6 @@ module Eco
210
210
  # @param exclude [String, Array<String>] account properties that should not be set/changed to the person.
211
211
  def set_account(person, exclude: nil)
212
212
  person.account = {} if !person.account
213
- person.account.permissions_preset = nil unless person.account.permissions_preset = "custom"
214
213
  scoped_attrs = @emap.account_attrs - into_a(exclude)
215
214
  @final_entry.slice(*scoped_attrs).each do |attr, value|
216
215
  set_part(person.account, attr, value)
@@ -290,7 +289,10 @@ module Eco
290
289
  # @param internal_entry [Hash] entry with **internal** names and values, but **external** types.
291
290
  # @return [Hash] entry with **internal** names and **external** values and types.
292
291
  def _mapped_serializing(internal_entry)
293
- internal_entry.merge(_serialize_values(internal_entry, :internal))
292
+ mapped_hash = internal_entry.merge(_serialize_values(internal_entry, :internal))
293
+ model_attrs = @person_parser.all_model_attrs - ["send_invites"]
294
+ aux_hash = mapped_hash.slice(*model_attrs)
295
+ merge_missing_attrs(aux_hash, mapped_hash)
294
296
  end
295
297
 
296
298
  # Parsing helper that just **parses the values** that have a parser/serializer defined.
@@ -1,5 +1,4 @@
1
1
  require 'aws-sdk-ses'
2
- require 'dotenv/load'
3
2
 
4
3
  module Eco
5
4
  module API
@@ -1,5 +1,4 @@
1
1
  require 'aws-sdk-s3'
2
- require 'dotenv/load'
3
2
 
4
3
  module Eco
5
4
  module API
@@ -1,5 +1,4 @@
1
1
  require "net/sftp"
2
- require 'dotenv/load'
3
2
 
4
3
  module Eco
5
4
  module API
@@ -19,7 +19,9 @@ 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/refresh_abilities'
22
+ require_relative 'microcases/preserve_filter_tags'
23
+ require_relative 'microcases/preserve_default_tag'
24
+ require_relative 'microcases/preserve_policy_groups'
23
25
  require_relative 'microcases/set_account'
24
26
  require_relative 'microcases/set_core_with_supervisor'
25
27
  require_relative 'microcases/set_core'
@@ -9,7 +9,6 @@ module Eco
9
9
  unless options.dig(:exclude, :account)
10
10
  if person.account
11
11
  person.account.policy_group_ids |= entry.policy_group_ids
12
- micro.refresh_abilities(person, options)
13
12
  end
14
13
  end
15
14
  end
@@ -9,9 +9,9 @@ module Eco
9
9
 
10
10
  start = Time.now
11
11
  people = session.batch.get_people
12
- secs = Time.now - start
12
+ secs = (Time.now - start).round(3)
13
13
  cnt = people.count
14
- per_sec = (cnt.to_f / secs).floor
14
+ per_sec = (cnt.to_f / secs).round(2)
15
15
  logger.info("Loaded #{cnt} people in #{secs} seconds (#{per_sec} people/sec)")
16
16
 
17
17
  file = file_manager.save_json(people, filename, :timestamp)
@@ -34,9 +34,9 @@ module Eco
34
34
 
35
35
  start = Time.now
36
36
  session.batch.get_people.tap do |people|
37
- secs = Time.now - start
37
+ secs = (Time.now - start).round(3)
38
38
  cnt = people.count
39
- per_sec = (cnt.to_f / secs).floor
39
+ per_sec = (cnt.to_f / secs).round(2)
40
40
  logger.info("Loaded #{cnt} people in #{secs} seconds (#{per_sec} people/sec)")
41
41
 
42
42
  if modifier.include?(:save) && people && people.length > 0
@@ -21,9 +21,9 @@ module Eco
21
21
 
22
22
  start = Time.now
23
23
  entries = session.batch.get_people(people, silent: true)
24
- secs = Time.now - start
24
+ secs = (Time.now - start).round(3)
25
25
  cnt = entries.count
26
- per_sec = (cnt.to_f / secs).floor
26
+ per_sec = (cnt.to_f / secs).round(2)
27
27
  logger.info("Re-loaded #{cnt} people (out of #{people.length}) in #{secs} seconds (#{per_sec} people/sec)")
28
28
 
29
29
  missing = people.length - entries.length
@@ -14,10 +14,10 @@ module Eco
14
14
 
15
15
  start = Time.now
16
16
  people = session.batch.search(data, silent: silent).yield_self do |status|
17
- secs = Time.now - start
17
+ secs = (Time.now - start).round(3)
18
18
  Eco::API::Organization::People.new(status.people).tap do |people|
19
19
  cnt = people.count
20
- per_sec = (cnt.to_f / secs).floor
20
+ per_sec = (cnt.to_f / secs).round(2)
21
21
  msg = "... could get #{cnt} people (out of #{data.length} entries) in #{secs} seconds (#{per_sec} people/sec)"
22
22
  session.logger.info(msg)
23
23
  end
@@ -29,10 +29,10 @@ module Eco
29
29
  session.logger.info(" Going to api get #{supers.length} current supervisors...")
30
30
  start = Time.now
31
31
  people = session.batch.search(supers, silent: silent).yield_self do |status|
32
- secs = Time.now - start
32
+ secs = (Time.now - start).round(3)
33
33
  found = status.people
34
34
  cnt = found.count
35
- per_sec = (cnt.to_f / secs).floor
35
+ per_sec = (cnt.to_f / secs).round(2)
36
36
  msg = "... could find #{cnt} current supers (out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)"
37
37
  session.logger.info(msg)
38
38
  people.merge(found, strict: micro.strict_search?(options))
@@ -46,10 +46,10 @@ module Eco
46
46
  start = Time.now
47
47
 
48
48
  people = session.batch.search(supers, silent: silent).yield_self do |status|
49
- secs = Time.now - start
49
+ secs = (Time.now - start).round(3)
50
50
  found = status.people
51
51
  cnt = found.count
52
- per_sec = (cnt.to_f / secs).floor
52
+ per_sec = (cnt.to_f / secs).round(2)
53
53
  msg = "... could find #{cnt} input supers (out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)"
54
54
  session.logger.info(msg)
55
55
  people.merge(found, strict: micro.strict_search?(options))
@@ -0,0 +1,23 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ # Helper to preserve the original `default_tag`.
5
+ # @note
6
+ # 1. It only works if the original value of `default_tag` was **not** empty
7
+ # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
8
+ # @param options [Hash] the options.
9
+ # @return [String] the final value of `default_tag`.
10
+ def preserve_default_tag(person, options)
11
+ if account = person.account
12
+ if account.as_update.key?("default_tag")
13
+ if original = person.original_doc.dig("account", "default_tag")
14
+ person.account.default_tag = original
15
+ end
16
+ end
17
+ end
18
+ person.account&.default_tag
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ # Helper to preserve the original filter tags.
5
+ # @note
6
+ # 1. It only works if the original value of `filter_tags` was **not** empty
7
+ # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
8
+ # @param options [Hash] the options.
9
+ # @param keep_new [Boolean] tells if it should keep the new tags or get rid of them.
10
+ # @return [Array<String>] the final value of `filter_tags`.
11
+ def preserve_filter_tags(person, options, keep_new: false)
12
+ if person.as_update.key?("filter_tags")
13
+ if original = person.original_doc["filter_tags"]
14
+ unless original.empty?
15
+ if keep_new
16
+ person.filter_tags += original
17
+ else
18
+ person.filter_tags = original
19
+ end
20
+ end
21
+ end
22
+ end
23
+ person.filter_tags
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ module Eco
2
+ module API
3
+ class MicroCases
4
+ # Helper to preserve the original `policy_group_ids`.
5
+ # @note
6
+ # 1. It only works if the original value of `policy_group_ids` was **not** empty
7
+ # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
8
+ # @param options [Hash] the options.
9
+ # @param keep_new [Boolean] tells if it should keep the new policy groups or get rid of them.
10
+ # @return [String] the final value of `policy_group_ids`.
11
+ def preserve_policy_groups(person, options, keep_new: false)
12
+ if account = person.account
13
+ if account.as_update.key?("policy_group_ids")
14
+ if original = person.original_doc.dig("account", "policy_group_ids")
15
+ unless original.empty?
16
+ if keep_new
17
+ person.account.policy_group_ids += original
18
+ else
19
+ person.account.policy_group_ids = original
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ person.account&.policy_group_ids
26
+ end
27
+
28
+ end
29
+ end
30
+ end