eco-helpers 2.7.24 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.ruby-version +1 -0
- data/CHANGELOG.md +16 -1
- data/eco-helpers.gemspec +12 -11
- data/lib/eco/api/common/session/base_session.rb +1 -0
- data/lib/eco/api/common/session/helpers/prompt_user.rb +3 -1
- data/lib/eco/api/common/session/helpers.rb +0 -9
- data/lib/eco/api/common/session/logger.rb +2 -0
- data/lib/eco/api/microcases/account_excluded.rb +2 -0
- data/lib/eco/api/microcases/append_usergroups.rb +4 -6
- data/lib/eco/api/microcases/core_excluded.rb +2 -1
- data/lib/eco/api/microcases/fix_default_group.rb +13 -14
- data/lib/eco/api/microcases/people_cache.rb +10 -3
- data/lib/eco/api/microcases/people_load.rb +21 -7
- data/lib/eco/api/microcases/people_refresh.rb +11 -3
- data/lib/eco/api/microcases/people_search.rb +24 -10
- data/lib/eco/api/microcases/person_update.rb +8 -4
- data/lib/eco/api/microcases/preserve_default_tag.rb +9 -9
- data/lib/eco/api/microcases/preserve_policy_groups.rb +14 -14
- data/lib/eco/api/microcases/refresh_default_tag.rb +11 -12
- data/lib/eco/api/microcases/s3upload_targets.rb +3 -2
- data/lib/eco/api/microcases/set_account.rb +6 -7
- data/lib/eco/api/microcases/strict_search.rb +0 -1
- data/lib/eco/api/microcases/take_email_from_account.rb +46 -27
- data/lib/eco/api/microcases/with_each.rb +15 -5
- data/lib/eco/api/microcases/with_each_leaver.rb +1 -1
- data/lib/eco/api/microcases/with_each_present.rb +6 -2
- data/lib/eco/api/microcases/with_each_starter.rb +7 -3
- data/lib/eco/api/microcases/with_each_subordinate.rb +0 -1
- data/lib/eco/api/microcases/with_supervisor.rb +0 -1
- data/lib/eco/api/microcases.rb +0 -2
- data/lib/eco/api/organization/login_providers.rb +23 -5
- data/lib/eco/api/session.rb +1 -1
- data/lib/eco/cli_default/input.rb +17 -14
- data/lib/eco/cli_default/options.rb +41 -23
- data/lib/eco/cli_default/people.rb +50 -12
- data/lib/eco/cli_default/people_filters.rb +1 -1
- data/lib/eco/cli_default/workflow.rb +4 -0
- data/lib/eco/data/files/helpers.rb +1 -0
- data/lib/eco/version.rb +1 -1
- data/lib/eco-helpers.rb +4 -0
- metadata +18 -60
- /data/{.markdownlint.jsonc → .markdownlint.json} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f87b772a3ca7272d32299e202d5f0a500f4e814b5281e00d2e49484a52fa42df
|
4
|
+
data.tar.gz: dde02113e49cc438157123b892b5ab2e747707f824ec0b228240a1f8aacebe29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cc9947ab00adc1881db3a69cbe0873b5a2ec1275c92d3127f5826b5acb96db5b9b72cdc4297a0658172cdd321cdd46c4f02fddb7b93f05296ad2d2be2509298
|
7
|
+
data.tar.gz: '0330899821bab587d827d9079638e9cef5528f8c01e68aab5379e7d358b9de7dffb18ed6b49f12268737b953c4bb95419cbf0c4816b96dcf819d03857880d451'
|
data/.rubocop.yml
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
data/CHANGELOG.md
CHANGED
@@ -2,14 +2,29 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
-
## [
|
5
|
+
## [3.0.0] - 2024-08-01
|
6
6
|
|
7
7
|
### Added
|
8
8
|
|
9
9
|
### Changed
|
10
10
|
|
11
|
+
- require `ruby 3`
|
12
|
+
|
11
13
|
### Fixed
|
12
14
|
|
15
|
+
- have `Eco::VERSION` defined
|
16
|
+
|
17
|
+
## [2.7.25] - 2024-08-01
|
18
|
+
|
19
|
+
### Added
|
20
|
+
|
21
|
+
- `Eco::API::Organization::LoginProviders#to_id`
|
22
|
+
- added support for `:magic_link` and `:magiclink`
|
23
|
+
|
24
|
+
### Changed
|
25
|
+
|
26
|
+
- `-get-partial` switches to full people download when it the input file surpases `MAX_GET_PARTIAL`
|
27
|
+
|
13
28
|
## [2.7.24] - 2024-07-30
|
14
29
|
|
15
30
|
### Fixed
|
data/eco-helpers.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
lib = File.expand_path(
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
|
4
4
|
require "./lib/eco/version"
|
@@ -9,12 +9,14 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.platform = Gem::Platform::RUBY
|
10
10
|
spec.authors = ["Oscar Segura"]
|
11
11
|
spec.email = ["oscar@ecoportal.co.nz"]
|
12
|
-
|
13
|
-
spec.summary =
|
12
|
+
|
13
|
+
spec.summary = "eco-helpers to manage people api cases"
|
14
14
|
spec.homepage = "https://www.ecoportal.com"
|
15
15
|
spec.licenses = %w[MIT]
|
16
16
|
|
17
|
-
spec.
|
17
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
18
|
+
|
19
|
+
spec.required_ruby_version = '>= 3.2.2'
|
18
20
|
|
19
21
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
22
|
f.match(%r{^(test|spec|features)/})
|
@@ -24,7 +26,6 @@ Gem::Specification.new do |spec|
|
|
24
26
|
#spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
27
|
spec.require_paths = ["lib"]
|
26
28
|
|
27
|
-
spec.add_development_dependency "bundler", ">= 2.4.12", "< 3"
|
28
29
|
spec.add_development_dependency "rake", ">= 13.0.3", "< 14"
|
29
30
|
spec.add_development_dependency "redcarpet", ">= 3.6.0", "< 4"
|
30
31
|
spec.add_development_dependency "rspec", ">= 3.12.0", "< 4"
|
@@ -32,15 +33,15 @@ Gem::Specification.new do |spec|
|
|
32
33
|
spec.add_development_dependency "rubocop-rake", "~> 0"
|
33
34
|
spec.add_development_dependency "yard", ">= 0.9.34", "< 1"
|
34
35
|
|
35
|
-
spec.add_dependency 'amatch', '>= 0.4.1',
|
36
|
+
spec.add_dependency 'amatch', '>= 0.4.1', '< 0.5'
|
36
37
|
spec.add_dependency 'aws-sdk-s3', '>= 1.142.0', '< 2'
|
37
38
|
spec.add_dependency 'aws-sdk-ses', '>= 1.58.0', '< 2'
|
38
39
|
spec.add_dependency 'bcrypt_pbkdf', '~> 1.0'
|
39
|
-
spec.add_dependency 'docx', '>= 0.8.0',
|
40
|
-
spec.add_dependency 'dotenv', '
|
41
|
-
spec.add_dependency 'ecoportal-api', '
|
42
|
-
spec.add_dependency 'ecoportal-api-graphql', '
|
43
|
-
spec.add_dependency 'ecoportal-api-v2', '
|
40
|
+
spec.add_dependency 'docx', '>= 0.8.0', '< 0.9'
|
41
|
+
spec.add_dependency 'dotenv', '~> 3'
|
42
|
+
spec.add_dependency 'ecoportal-api', '~> 0.10'
|
43
|
+
spec.add_dependency 'ecoportal-api-graphql', '~> 0.4'
|
44
|
+
spec.add_dependency 'ecoportal-api-v2', '~> 2.0'
|
44
45
|
spec.add_dependency 'ed25519', '~> 1.2'
|
45
46
|
spec.add_dependency 'fast_excel', '>= 0.5.0', '< 0.6'
|
46
47
|
spec.add_dependency 'fuzzy_match', '>= 2.1.0', '< 2.2'
|
@@ -7,12 +7,13 @@ module Eco
|
|
7
7
|
# Prompts user for input with option for default on timeout.
|
8
8
|
def prompt_user(question, default:, explanation: "", timeout: nil)
|
9
9
|
require 'timeout'
|
10
|
-
response =
|
10
|
+
response =
|
11
11
|
if config.run_mode_remote?
|
12
12
|
default
|
13
13
|
else
|
14
14
|
puts explanation
|
15
15
|
print "#{question} "
|
16
|
+
|
16
17
|
if timeout
|
17
18
|
begin
|
18
19
|
Timeout::timeout(timeout) { STDIN.gets.chop }
|
@@ -24,6 +25,7 @@ module Eco
|
|
24
25
|
end
|
25
26
|
end
|
26
27
|
return response unless block_given?
|
28
|
+
|
27
29
|
yield(response)
|
28
30
|
end
|
29
31
|
end
|
@@ -5,24 +5,15 @@ module Eco
|
|
5
5
|
module Common
|
6
6
|
module Session
|
7
7
|
module Helpers
|
8
|
-
|
9
8
|
class << self
|
10
9
|
def included(base)
|
11
10
|
base.send(:include, InstanceMethods)
|
12
|
-
base.extend(ClassMethods)
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
16
|
-
|
17
|
-
module ClassMethods
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
14
|
module InstanceMethods
|
22
15
|
include Helpers::PromptUser
|
23
|
-
|
24
16
|
end
|
25
|
-
|
26
17
|
end
|
27
18
|
end
|
28
19
|
end
|
@@ -21,6 +21,7 @@ module Eco
|
|
21
21
|
logger.formatter = format_proc(console: false) do |severity, datetime, msg, formatted_msg|
|
22
22
|
cache.add(severity, datetime, msg, formatted_msg)
|
23
23
|
end
|
24
|
+
|
24
25
|
logger.level = file_level
|
25
26
|
end
|
26
27
|
end
|
@@ -54,6 +55,7 @@ module Eco
|
|
54
55
|
log_file = @enviro.file_manager.dir.file(log_file) if @enviro
|
55
56
|
FileManager.create_directory(log_file, includes_file: true)
|
56
57
|
end
|
58
|
+
|
57
59
|
log_file
|
58
60
|
end
|
59
61
|
end
|
@@ -10,9 +10,11 @@ module Eco
|
|
10
10
|
if options.dig(:exclude, :policy_groups)
|
11
11
|
account_excluded.push("policy_group_ids")
|
12
12
|
end
|
13
|
+
|
13
14
|
if options.dig(:exclude, :default_tag)
|
14
15
|
account_excluded.push("default_tag")
|
15
16
|
end
|
17
|
+
|
16
18
|
if options.dig(:exclude, :login_providers)
|
17
19
|
account_excluded.push("login_provider_ids")
|
18
20
|
end
|
@@ -6,13 +6,11 @@ module Eco
|
|
6
6
|
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
7
7
|
# @param options [Hash] the options.
|
8
8
|
def append_usergroups(entry, person, options)
|
9
|
-
|
10
|
-
|
11
|
-
person.account.policy_group_ids |= entry.policy_group_ids
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
9
|
+
return if options.dig(:exclude, :account)
|
10
|
+
return unless person.account
|
15
11
|
|
12
|
+
person.account.policy_group_ids |= entry.policy_group_ids
|
13
|
+
end
|
16
14
|
end
|
17
15
|
end
|
18
16
|
end
|
@@ -7,7 +7,8 @@ module Eco
|
|
7
7
|
# @return [Array<String>] the core parameters that should not be included.
|
8
8
|
def core_excluded(person, options)
|
9
9
|
["supervisor_id"].tap do |core_excluded|
|
10
|
-
can_exclude = person.new?? ["filter_tags"] : [
|
10
|
+
can_exclude = person.new?? ["filter_tags"] : %w[name external_id email filter_tags]
|
11
|
+
|
11
12
|
exclusions = can_exclude.select do |attr|
|
12
13
|
options.dig(:exclude, attr.to_sym)
|
13
14
|
end
|
@@ -6,29 +6,28 @@ module Eco
|
|
6
6
|
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
7
7
|
# @param options [Hash] the options.
|
8
8
|
def fix_default_group(entry, person, options)
|
9
|
-
|
10
|
-
|
11
|
-
end_pg_ids = person.account.policy_group_ids
|
9
|
+
return if options.dig(:exclude, :account)
|
10
|
+
return if options.dig(:exclude, :policy_groups) && !person.new?
|
12
11
|
|
13
|
-
|
14
|
-
# on account creation, if missing policy_group_ids column in the input
|
15
|
-
# use default_usergroup, if it's defined
|
16
|
-
end_pg_ids = [__def_usergroup_id]
|
17
|
-
end
|
12
|
+
end_pg_ids = person.account.policy_group_ids
|
18
13
|
|
19
|
-
|
20
|
-
|
14
|
+
if person.account_added? && __def_usergroup_id && !entry.policy_group_ids?
|
15
|
+
# on account creation, if missing policy_group_ids column in the input
|
16
|
+
# use default_usergroup, if it's defined
|
17
|
+
end_pg_ids = [__def_usergroup_id]
|
21
18
|
end
|
19
|
+
|
20
|
+
person.account.policy_group_ids = end_pg_ids
|
22
21
|
end
|
23
22
|
|
24
23
|
private
|
25
24
|
|
26
25
|
def __def_usergroup_id
|
27
|
-
@
|
28
|
-
session.
|
29
|
-
|
26
|
+
@__def_usergroup_id ||=
|
27
|
+
if session.config.people.default_usergroup?
|
28
|
+
session.policy_groups.to_id(session.config.people.default_usergroup)
|
29
|
+
end
|
30
30
|
end
|
31
|
-
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|
@@ -5,17 +5,24 @@ module Eco
|
|
5
5
|
# @param filename [String] the name of the file where the data should be cached.
|
6
6
|
# @return [Eco::API::Organization::People] the `People` object with the data.
|
7
7
|
def people_cache(filename = enviro.config.people.cache)
|
8
|
-
|
8
|
+
log(:info) { "Going to get all the people via API" }
|
9
9
|
|
10
10
|
start = Time.now
|
11
11
|
people = session.batch.get_people
|
12
12
|
secs = (Time.now - start).round(3)
|
13
13
|
cnt = people.count
|
14
14
|
per_sec = (cnt.to_f / secs).round(2)
|
15
|
-
|
15
|
+
|
16
|
+
log(:info) {
|
17
|
+
"Loaded #{cnt} people in #{secs} seconds (#{per_sec} people/sec)"
|
18
|
+
}
|
16
19
|
|
17
20
|
file = file_manager.save_json(people, filename, :timestamp)
|
18
|
-
|
21
|
+
|
22
|
+
log(:info) {
|
23
|
+
"#{people.length} people loaded and saved locally to #{file}."
|
24
|
+
}
|
25
|
+
|
19
26
|
Eco::API::Organization::People.new(people)
|
20
27
|
end
|
21
28
|
end
|
@@ -4,7 +4,7 @@ module Eco
|
|
4
4
|
# Helper to load `People` that works in different phases:
|
5
5
|
# 1. first tries to get the newest cached file that follows `filename` pattern
|
6
6
|
# - if not the newest, it tries to find the specific filename
|
7
|
-
# 2. if it succeeds to
|
7
|
+
# 2. if it succeeds to identify a cached file, it loads it
|
8
8
|
# - if it fails, it tries to get people from the server
|
9
9
|
# @note
|
10
10
|
# - `filename` will be relative to the working directory (the one of the session `enviro` set by the user).
|
@@ -25,27 +25,37 @@ module Eco
|
|
25
25
|
|
26
26
|
if file
|
27
27
|
file_manager.load_json(file).tap do |people|
|
28
|
-
|
28
|
+
next unless people.is_a?(Array)
|
29
|
+
|
30
|
+
log(:info) {
|
31
|
+
"#{people&.length} people loaded from file #{file}"
|
32
|
+
}
|
29
33
|
end
|
30
34
|
else
|
31
|
-
|
35
|
+
log(:error) {
|
36
|
+
"could not find the file #{file_manager.dir.file(filename)}"
|
37
|
+
}
|
38
|
+
|
32
39
|
exit unless modifier.include?(:api)
|
33
40
|
|
34
41
|
people_load(modifier: modifier - %i[newest file])
|
35
42
|
end
|
36
43
|
when modifier.include?(:api)
|
37
|
-
|
44
|
+
log(:info) { "Going to get all the people via API (load)" }
|
38
45
|
|
39
46
|
start = Time.now
|
40
47
|
session.batch.get_people.tap do |people|
|
41
48
|
secs = (Time.now - start).round(3)
|
42
49
|
cnt = people.count
|
43
50
|
per_sec = (cnt.to_f / secs).round(2)
|
44
|
-
|
51
|
+
|
52
|
+
log(:info) {
|
53
|
+
"Loaded #{cnt} people in #{secs} seconds (#{per_sec} people/sec)"
|
54
|
+
}
|
45
55
|
|
46
56
|
if modifier.include?(:save) && people && people.length.positive?
|
47
57
|
file = file_manager.save_json(people, filename, :timestamp)
|
48
|
-
|
58
|
+
log(:info) { "#{people.length} people saved to file #{file}." }
|
49
59
|
end
|
50
60
|
end
|
51
61
|
end.then do |people|
|
@@ -59,7 +69,11 @@ module Eco
|
|
59
69
|
if newest
|
60
70
|
# search input file based on pattern (in case the name has a timestamp)
|
61
71
|
file_manager.dir.newest_file(file: filename).tap do |file|
|
62
|
-
|
72
|
+
next unless file
|
73
|
+
|
74
|
+
log(:info) {
|
75
|
+
"previous file found: #{file}"
|
76
|
+
}
|
63
77
|
end
|
64
78
|
else
|
65
79
|
file_manager.dir.file(filename, should_exist: true)
|
@@ -26,17 +26,25 @@ module Eco
|
|
26
26
|
created = people.length - ini
|
27
27
|
msg = "Going to refresh #{people.length} people with server data"
|
28
28
|
msg += " (including #{created} that were created)" if created.positive?
|
29
|
-
|
29
|
+
log(:info) { msg }
|
30
30
|
|
31
31
|
start = Time.now
|
32
32
|
entries = session.batch.get_people(people, silent: true)
|
33
33
|
secs = (Time.now - start).round(3)
|
34
34
|
cnt = entries.count
|
35
35
|
per_sec = (cnt.to_f / secs).round(2)
|
36
|
-
|
36
|
+
|
37
|
+
log(:info) {
|
38
|
+
"Re-loaded #{cnt} people (out of #{people.length}) in #{secs} seconds (#{per_sec} people/sec)"
|
39
|
+
}
|
37
40
|
|
38
41
|
missing = people.length - entries.length
|
39
|
-
|
42
|
+
|
43
|
+
if missing.positive?
|
44
|
+
log(:error) {
|
45
|
+
"Missed to obtain #{missing} people during the refresh"
|
46
|
+
}
|
47
|
+
end
|
40
48
|
|
41
49
|
Eco::API::Organization::People.new(entries)
|
42
50
|
end
|
@@ -10,36 +10,43 @@ module Eco
|
|
10
10
|
# @param options [Hash] the options.
|
11
11
|
# @param silent [Boolean] `false` if low level search messages should be shown.
|
12
12
|
# @return [Eco::API::Organization::People] the `People` object with the found persons.
|
13
|
-
def people_search(data, options: {}, silent: true) # rubocop:disable Metrics/AbcSize
|
14
|
-
|
13
|
+
def people_search(data, options: {}, silent: true) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
14
|
+
log(:info) { "Going to api get #{data.length} entries..." }
|
15
15
|
|
16
|
-
silent
|
16
|
+
silent &&= data.count <= 500
|
17
17
|
|
18
18
|
start = Time.now
|
19
19
|
people = session.batch.search(data, silent: silent).then do |status|
|
20
20
|
secs = (Time.now - start).round(3)
|
21
|
+
|
21
22
|
Eco::API::Organization::People.new(status.people).tap do |people| # rubocop:disable Lint/ShadowingOuterLocalVariable
|
22
23
|
cnt = people.count
|
23
24
|
per_sec = (cnt.to_f / secs).round(2)
|
25
|
+
|
24
26
|
msg = "... could get #{cnt} people "
|
25
27
|
msg << "(out of #{data.length} entries) in #{secs} seconds (#{per_sec} people/sec)"
|
26
|
-
|
28
|
+
|
29
|
+
log(:info) { msg }
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
30
33
|
# get the supervisors of found people (current supervisors)
|
31
34
|
supers = people_search_prepare_supers_request(people)
|
32
35
|
if supers.length.positive?
|
33
|
-
|
36
|
+
log(:info) {
|
37
|
+
" Going to api get #{supers.length} current supervisors..."
|
38
|
+
}
|
39
|
+
|
34
40
|
start = Time.now
|
35
41
|
people = session.batch.search(supers, silent: silent).then do |status|
|
36
42
|
secs = (Time.now - start).round(3)
|
37
43
|
found = status.people
|
38
44
|
cnt = found.count
|
39
45
|
per_sec = (cnt.to_f / secs).round(2)
|
46
|
+
|
40
47
|
msg = "... could find #{cnt} current supers "
|
41
48
|
msg << "(out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)"
|
42
|
-
|
49
|
+
log(:info) { msg }
|
43
50
|
|
44
51
|
people.merge(found, strict: micro.strict_search?(options))
|
45
52
|
end
|
@@ -48,22 +55,29 @@ module Eco
|
|
48
55
|
# get the supervisors referred in the input data (future supervisors)
|
49
56
|
supers = people_search_prepare_supers_request(data, people)
|
50
57
|
if supers.length.positive?
|
51
|
-
|
52
|
-
|
58
|
+
log(:info) {
|
59
|
+
" Going to api get #{supers.length} supervisors as per input entries..."
|
60
|
+
}
|
53
61
|
|
62
|
+
start = Time.now
|
54
63
|
people = session.batch.search(supers, silent: silent).then do |status|
|
55
64
|
secs = (Time.now - start).round(3)
|
56
65
|
found = status.people
|
57
66
|
cnt = found.count
|
58
67
|
per_sec = (cnt.to_f / secs).round(2)
|
68
|
+
|
59
69
|
msg = "... could find #{cnt} input supers "
|
60
70
|
msg << "(out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)"
|
61
|
-
|
71
|
+
log(:info) { msg }
|
72
|
+
|
62
73
|
people.merge(found, strict: micro.strict_search?(options))
|
63
74
|
end
|
64
75
|
end
|
65
76
|
|
66
|
-
|
77
|
+
log(:info) {
|
78
|
+
"Finally got #{people.length} people (out of #{data.length} entries)"
|
79
|
+
}
|
80
|
+
|
67
81
|
people
|
68
82
|
end
|
69
83
|
|
@@ -8,8 +8,11 @@ module Eco
|
|
8
8
|
# @param reason [String] why are we updating now.
|
9
9
|
# @return [Boolean] `true` if it succeded to update, and `false` otherwise
|
10
10
|
def person_update!(person, context: "Session", reason: "")
|
11
|
-
|
12
|
-
|
11
|
+
log(:debug) {
|
12
|
+
"#{context}, going to \"#{reason}\".\nPerson: #{person_ref(person)}"
|
13
|
+
}
|
14
|
+
|
15
|
+
if (response = api.people.update(person))
|
13
16
|
if response.success?
|
14
17
|
person.consolidate!
|
15
18
|
true
|
@@ -17,14 +20,15 @@ module Eco
|
|
17
20
|
msg = "#{context} Error #{response.status}: #{response.body}\n"
|
18
21
|
msg += " -- Failed to \"#{reason}\".\n"
|
19
22
|
msg += " • Person: #{person_ref(person)}"
|
20
|
-
|
23
|
+
log(:error) { msg }
|
21
24
|
false
|
22
25
|
end
|
23
26
|
else
|
24
27
|
msg = "#{context} Error (connection error)\n"
|
25
28
|
msg += " -- Failed to \"#{reason}\".\n"
|
26
29
|
msg += " • Person: #{person_ref(person)}"
|
27
|
-
|
30
|
+
|
31
|
+
log(:error) { msg }
|
28
32
|
false
|
29
33
|
end
|
30
34
|
end
|
@@ -7,17 +7,17 @@ module Eco
|
|
7
7
|
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
8
8
|
# @param options [Hash] the options.
|
9
9
|
# @return [String] the final value of `default_tag`.
|
10
|
-
def preserve_default_tag(person,
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
def preserve_default_tag(person, _options)
|
11
|
+
return unless (account = person.account)
|
12
|
+
|
13
|
+
account.default_tag.tap do
|
14
|
+
next unless account.as_update.key?("default_tag")
|
15
|
+
next unless (original = person.original_doc.dig("account", "default_tag"))
|
16
|
+
|
17
|
+
person.account.default_tag = original
|
18
|
+
return original
|
17
19
|
end
|
18
|
-
person.account&.default_tag
|
19
20
|
end
|
20
|
-
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -8,23 +8,23 @@ module Eco
|
|
8
8
|
# @param options [Hash] the options.
|
9
9
|
# @param keep_new [Boolean] tells if it should keep the new policy groups or get rid of them.
|
10
10
|
# @return [String] the final value of `policy_group_ids`.
|
11
|
-
def preserve_policy_groups(person,
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
def preserve_policy_groups(person, _options, keep_new: false)
|
12
|
+
return unless (account = person.account)
|
13
|
+
|
14
|
+
account.policy_group_ids.tap do
|
15
|
+
next unless account.as_update.key?("policy_group_ids")
|
16
|
+
next unless (original = person.original_doc.dig("account", "policy_group_ids"))
|
17
|
+
next if original.empty?
|
18
|
+
|
19
|
+
if keep_new
|
20
|
+
person.account.policy_group_ids += original
|
21
|
+
else
|
22
|
+
person.account.policy_group_ids = original
|
23
23
|
end
|
24
|
+
|
25
|
+
return account.policy_group_ids
|
24
26
|
end
|
25
|
-
person.account&.policy_group_ids
|
26
27
|
end
|
27
|
-
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -8,20 +8,19 @@ module Eco
|
|
8
8
|
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
9
9
|
# @param options [Hash] the options
|
10
10
|
def refresh_default_tag(entry, person, options)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
return unless person.account
|
12
|
+
return if options.dig(:exclude, :account)
|
13
|
+
return if options.dig(:exclude, :filter_tags)
|
14
|
+
return if options.dig(:exclude, :default_tag)
|
15
|
+
return if entry&.default_tag?
|
16
|
+
|
17
|
+
if session.tagtree
|
18
|
+
person.account.default_tag = session.tagtree.default_tag(*person.filter_tags)
|
19
|
+
else
|
20
|
+
tags = person.filter_tags || []
|
21
|
+
person.account.default_tag = tags.first unless tags.length > 1
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
@@ -3,14 +3,16 @@ module Eco
|
|
3
3
|
class MicroCases
|
4
4
|
# Helper to upload target files to `S3`.
|
5
5
|
# @return [Array<String>] the paths in `S3` of the uploaded files.
|
6
|
-
def s3upload_targets
|
6
|
+
def s3upload_targets # rubocop:disable Metrics/AbcSize
|
7
7
|
[].tap do |paths|
|
8
8
|
session.config.s3storage.target_files.each_with_object(paths) do |file, arr|
|
9
9
|
arr.push(session.s3upload(file: file))
|
10
10
|
end
|
11
|
+
|
11
12
|
session.config.s3storage.target_directories.each_with_object(paths) do |folder, arr|
|
12
13
|
arr.concat(session.s3upload(directory: folder))
|
13
14
|
end
|
15
|
+
|
14
16
|
session.config.s3storage.target_file_patterns.each_with_object(paths) do |pattern, arr|
|
15
17
|
filenames = []
|
16
18
|
case pattern
|
@@ -33,7 +35,6 @@ module Eco
|
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
36
|
-
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|