eco-helpers 3.0.4 → 3.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +44 -4
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api/common/class_helpers.rb +24 -23
- data/lib/eco/api/common/class_meta_basics.rb +0 -2
- data/lib/eco/api/common/loaders/use_case.rb +1 -0
- data/lib/eco/api/common/people/entry_factory.rb +6 -4
- data/lib/eco/api/common/people/person_entry.rb +4 -6
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +25 -12
- data/lib/eco/api/common/people/person_parser.rb +8 -0
- data/lib/eco/api/common/session/base_session.rb +1 -1
- data/lib/eco/api/common/session/environment.rb +7 -0
- data/lib/eco/api/common/session/file_manager.rb +15 -8
- data/lib/eco/api/common/session/logger/cache.rb +14 -10
- data/lib/eco/api/common/session/logger/log.rb +8 -7
- data/lib/eco/api/common/session/mailer.rb +22 -13
- data/lib/eco/api/common/session/s3_uploader.rb +29 -20
- data/lib/eco/api/microcases/people_search.rb +1 -1
- data/lib/eco/api/organization/login_providers.rb +11 -4
- data/lib/eco/api/organization/node_classifications.rb +3 -0
- data/lib/eco/api/organization/presets_factory.rb +37 -31
- data/lib/eco/api/organization/tag_tree.rb +14 -5
- data/lib/eco/api/policies/default_policies/99_user_access_policy.rb +28 -18
- data/lib/eco/api/session/batch/errors.rb +38 -20
- data/lib/eco/api/session/batch/job.rb +252 -135
- data/lib/eco/api/session/batch/status.rb +55 -36
- data/lib/eco/api/session/batch.rb +2 -2
- data/lib/eco/api/session/config/base_config.rb +12 -11
- data/lib/eco/api/session/config/tagtree.rb +10 -14
- data/lib/eco/api/session/config/workflow.rb +15 -3
- data/lib/eco/api/session/config.rb +19 -26
- data/lib/eco/api/session.rb +13 -4
- data/lib/eco/api/usecases/cli.rb +4 -0
- data/lib/eco/api/usecases/default/locations/cli/codes_to_tags_cli.rb +18 -0
- data/lib/eco/api/usecases/default/locations/cli/csv_to_tree_cli.rb +12 -0
- data/lib/eco/api/usecases/default/locations/cli/tagtree_paths_cli.rb +12 -0
- data/lib/eco/api/usecases/default/locations/codes_to_tags_case.rb +32 -13
- data/lib/eco/api/usecases/default/locations/csv_to_tree_case.rb +15 -5
- data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +6 -0
- data/lib/eco/api/usecases/default/locations/tagtree_paths_case.rb +51 -0
- data/lib/eco/api/usecases/default/locations.rb +1 -1
- data/lib/eco/api/usecases/default/people/amend/cli/reinvite_sync_cli.rb +8 -0
- data/lib/eco/api/usecases/default/people/amend/cli/reinvite_trans_cli.rb +11 -0
- data/lib/eco/api/usecases/default/people/amend/cli/restore_db_cli.rb +26 -0
- data/lib/eco/api/usecases/default/people/amend/reinvite_sync_case.rb +2 -0
- data/lib/eco/api/usecases/default/people/amend/reinvite_trans_case.rb +2 -0
- data/lib/eco/api/usecases/default/people/amend/restore_db_case.rb +3 -0
- data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +15 -5
- data/lib/eco/api/usecases/default/people/treat/cli/analyse_people_cli.rb +66 -0
- data/lib/eco/api/usecases/default/people/treat/cli/org_data_convert_cli.rb +35 -0
- data/lib/eco/api/usecases/default/people/treat/cli/supers_cyclic_identify_cli.rb +15 -0
- data/lib/eco/api/usecases/default/people/treat/cli/supers_hierachy_cli.rb +15 -0
- data/lib/eco/api/usecases/default/people/treat/org_data_convert_case.rb +11 -5
- data/lib/eco/api/usecases/default/people/treat/supers_cyclic_identify_case.rb +28 -7
- data/lib/eco/api/usecases/default/people/treat/supers_hierarchy_case.rb +32 -9
- data/lib/eco/api/usecases/default/people/utils/set_default_tag_case.rb +2 -1
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +2 -2
- data/lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb +5 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +2 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable.rb +2 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +2 -1
- data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +3 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +1 -0
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +3 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +2 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +1 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/classifications.rb +2 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +6 -2
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/parser.rb +6 -2
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb +2 -0
- data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +1 -0
- data/lib/eco/api/usecases/ooze_samples/helpers_migration/copying.rb +66 -29
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +25 -3
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +10 -0
- data/lib/eco/api/usecases/use_case.rb +3 -1
- data/lib/eco/cli/config/use_cases.rb +4 -0
- data/lib/eco/cli/scripting/args_helpers.rb +3 -2
- data/lib/eco/cli/scripting/argument.rb +2 -2
- data/lib/eco/cli_default/input.rb +49 -45
- data/lib/eco/cli_default/input_filters.rb +32 -17
- data/lib/eco/cli_default/options.rb +8 -4
- data/lib/eco/cli_default/people.rb +1 -1
- data/lib/eco/cli_default/people_filters.rb +32 -24
- data/lib/eco/cli_default/usecases.rb +8 -121
- data/lib/eco/cli_default/workflow.rb +6 -4
- data/lib/eco/csv/split.rb +2 -0
- data/lib/eco/csv/table.rb +13 -0
- data/lib/eco/data/files/encoding.rb +15 -8
- data/lib/eco/data/files/helpers.rb +6 -2
- data/lib/eco/data/hashes/diff_result.rb +5 -0
- data/lib/eco/data/locations/node_diff/nodes_diff.rb +13 -0
- data/lib/eco/data/locations/node_diff.rb +4 -0
- data/lib/eco/data/locations/node_level.rb +6 -0
- data/lib/eco/language/auxiliar_logger.rb +2 -0
- data/lib/eco/version.rb +1 -1
- data/lib/eco-helpers.rb +1 -1
- metadata +15 -6
- data/lib/eco/api/usecases/default/locations/create_tag_paths_case.rb +0 -25
- data/lib/eco/api/usecases/default/people/amend/reinvite_trans_cli.rb +0 -4
@@ -4,7 +4,6 @@ module Eco
|
|
4
4
|
module Session
|
5
5
|
class Logger
|
6
6
|
class Log
|
7
|
-
|
8
7
|
attr_accessor :level, :datetime, :message, :formatted
|
9
8
|
|
10
9
|
def initialize(level, datetime, message, formatted)
|
@@ -15,20 +14,22 @@ module Eco
|
|
15
14
|
end
|
16
15
|
|
17
16
|
def to_s
|
18
|
-
|
17
|
+
formatted
|
19
18
|
end
|
20
19
|
|
21
20
|
def <=>(other)
|
22
|
-
|
21
|
+
datetime <=> other.datetime
|
23
22
|
end
|
24
23
|
|
25
24
|
def before?(value)
|
26
|
-
return true
|
25
|
+
return true unless value
|
26
|
+
|
27
27
|
datetime <= to_datetime(value)
|
28
28
|
end
|
29
29
|
|
30
30
|
def after?(value)
|
31
|
-
return true
|
31
|
+
return true unless value
|
32
|
+
|
32
33
|
datetime >= to_datetime(value)
|
33
34
|
end
|
34
35
|
|
@@ -36,10 +37,10 @@ module Eco
|
|
36
37
|
|
37
38
|
def to_datetime(value)
|
38
39
|
return value if value.is_a?(Time)
|
39
|
-
return
|
40
|
+
return unless value
|
41
|
+
|
40
42
|
Time.parse(value)
|
41
43
|
end
|
42
|
-
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
@@ -1,12 +1,16 @@
|
|
1
|
+
# rubocop:disable Naming/MethodParameterName
|
1
2
|
module Eco
|
2
3
|
module API
|
3
4
|
module Common
|
4
5
|
module Session
|
5
6
|
class Mailer
|
7
|
+
include Eco::Language::AuxiliarLogger
|
6
8
|
|
7
9
|
# @param enviro [Eco::API::Common::Session::Environment]
|
8
|
-
def initialize
|
9
|
-
|
10
|
+
def initialize(enviro:)
|
11
|
+
msg = "Required Environment object (enviro:). Given: #{enviro.class}"
|
12
|
+
raise msg if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment)
|
13
|
+
|
10
14
|
@enviro = enviro
|
11
15
|
end
|
12
16
|
|
@@ -14,28 +18,28 @@ module Eco
|
|
14
18
|
# @param to [String] destination email address
|
15
19
|
# @param subject [String] subject of the email
|
16
20
|
# @param body [String] `html` or plain text message
|
17
|
-
def mail(to: nil,
|
21
|
+
def mail(subject:, body:, to: nil, cc: nil, bcc: nil)
|
18
22
|
ses.send_email(
|
19
23
|
destination: fetch_destination(to: to, cc: cc, bcc: bcc),
|
20
|
-
source:
|
21
|
-
message:
|
24
|
+
source: fetch_from,
|
25
|
+
message: {
|
22
26
|
subject: {
|
23
27
|
charset: "UTF-8",
|
24
|
-
data:
|
28
|
+
data: subject,
|
25
29
|
},
|
26
|
-
body:
|
27
|
-
# NOTE
|
30
|
+
body: {
|
31
|
+
# NOTE: (html) will let you send html instead
|
28
32
|
# you can use both at once if you like
|
29
33
|
text: {
|
30
34
|
charset: "UTF-8",
|
31
|
-
data:
|
35
|
+
data: body
|
32
36
|
}
|
33
37
|
}
|
34
38
|
}
|
35
39
|
).tap do |response|
|
36
40
|
msg = "Sent email (MessageId: #{response.message_id}) to #{fetch_destination(to: to, cc: cc, bcc: bcc)}"
|
37
41
|
puts msg
|
38
|
-
|
42
|
+
log(:debug) { msg }
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
@@ -49,14 +53,17 @@ module Eco
|
|
49
53
|
secret_access_key: fetch_secret_access_key,
|
50
54
|
region: fetch_region
|
51
55
|
)
|
52
|
-
rescue
|
53
|
-
|
56
|
+
rescue StandardError => err
|
57
|
+
log(:error) {
|
58
|
+
"Trying to send an email with wrong email configuration: #{err}"
|
59
|
+
}
|
54
60
|
end
|
61
|
+
|
55
62
|
@ses
|
56
63
|
end
|
57
64
|
|
58
65
|
def logger
|
59
|
-
@enviro&.logger ||
|
66
|
+
@enviro&.logger || super
|
60
67
|
end
|
61
68
|
|
62
69
|
def config
|
@@ -104,3 +111,5 @@ module Eco
|
|
104
111
|
end
|
105
112
|
end
|
106
113
|
end
|
114
|
+
|
115
|
+
# rubocop:enable Naming/MethodParameterName
|
@@ -3,11 +3,15 @@ module Eco
|
|
3
3
|
module Common
|
4
4
|
module Session
|
5
5
|
class S3Uploader
|
6
|
+
include Eco::Language::AuxiliarLogger
|
7
|
+
|
6
8
|
attr_reader :prefix
|
7
9
|
|
8
10
|
# @param enviro [Eco::API::Common::Session::Environment]
|
9
|
-
def initialize
|
10
|
-
|
11
|
+
def initialize(enviro:)
|
12
|
+
msg = "Required Environment object (enviro:). Given: #{enviro.class}"
|
13
|
+
raise msg if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment)
|
14
|
+
|
11
15
|
@enviro = enviro
|
12
16
|
@prefix = fetch_prefix
|
13
17
|
@timestamp = Time.now.iso8601
|
@@ -18,22 +22,23 @@ module Eco
|
|
18
22
|
# @param content [String] that to be uploaded
|
19
23
|
# @return [String] S3 path to the uploaded `filename` object
|
20
24
|
def upload(filename, content)
|
21
|
-
if obj = new_s3_object(filename)
|
25
|
+
if (obj = new_s3_object(filename))
|
22
26
|
log_upload(obj) do
|
23
27
|
obj.put(body: content)
|
24
28
|
end
|
25
29
|
end
|
26
|
-
|
30
|
+
|
31
|
+
full_path(obj)
|
27
32
|
end
|
28
33
|
|
29
34
|
# Uploads a single file
|
30
35
|
# @param path [String] the target file to be uploaded
|
31
36
|
# @return [String] S3 path to the uploaded `path` file
|
32
37
|
def upload_file(path)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
38
|
+
return unless File.exist?(path)
|
39
|
+
|
40
|
+
File.open(path, "rb") do |f|
|
41
|
+
upload(File.basename(path), f)
|
37
42
|
end
|
38
43
|
end
|
39
44
|
|
@@ -45,9 +50,10 @@ module Eco
|
|
45
50
|
path = File.expand_path(path)
|
46
51
|
prefix = File.expand_path(File.join(path, ".."))
|
47
52
|
wildcard = recurse ? "**/*" : "*"
|
53
|
+
|
48
54
|
Dir.glob(File.join(path, wildcard)).sort.map do |file|
|
49
55
|
next unless File.file?(file) # Skip directories
|
50
|
-
key = file.sub(prefix,"").gsub(/\\/,"/").sub(/^\/+/,"")
|
56
|
+
key = file.sub(prefix, "").gsub(/\\/, "/").sub(/^\/+/, "")
|
51
57
|
|
52
58
|
File.open(file, "rb") do |f|
|
53
59
|
upload(key, f)
|
@@ -58,18 +64,18 @@ module Eco
|
|
58
64
|
# @param path [String] a full path to a S3 object
|
59
65
|
# @return [String] `link` to the S3 object on console
|
60
66
|
def link(path)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
+
return path.map { |pth| link(pth) } if path.is_a?(Enumerable)
|
68
|
+
return unless path.is_a?(String)
|
69
|
+
|
70
|
+
s3_path_str = "https://s3.console.aws.amazon.com/s3/object"
|
71
|
+
s3_params = "region=#{fetch_region}&tab=overview"
|
72
|
+
"#{s3_path_str}/#{path.sub('s3://', '')}?#{s3_params}"
|
67
73
|
end
|
68
74
|
|
69
75
|
private
|
70
76
|
|
71
77
|
def full_path(obj)
|
72
|
-
|
78
|
+
"s3://#{bucket.name}/#{obj.key}" if obj
|
73
79
|
end
|
74
80
|
|
75
81
|
def bucket
|
@@ -80,8 +86,10 @@ module Eco
|
|
80
86
|
secret_access_key: fetch_secret_access_key,
|
81
87
|
region: fetch_region
|
82
88
|
).bucket(fetch_bucket)
|
83
|
-
rescue
|
84
|
-
|
89
|
+
rescue StandardError => err
|
90
|
+
log(:error) {
|
91
|
+
"Trying to upload to S3 with wrong configuration: #{err}"
|
92
|
+
}
|
85
93
|
end
|
86
94
|
@bucket
|
87
95
|
end
|
@@ -97,11 +105,12 @@ module Eco
|
|
97
105
|
|
98
106
|
def log_upload(obj)
|
99
107
|
yield
|
100
|
-
|
108
|
+
|
109
|
+
log(:debug) { "Uploaded #{full_path(obj)}" }
|
101
110
|
end
|
102
111
|
|
103
112
|
def logger
|
104
|
-
@enviro&.logger ||
|
113
|
+
@enviro&.logger || super
|
105
114
|
end
|
106
115
|
|
107
116
|
def config
|
@@ -10,7 +10,7 @@ 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:
|
13
|
+
def people_search(data, options: {}, silent: false) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
14
14
|
log(:info) { "Going to api get #{data.length} entries..." }
|
15
15
|
|
16
16
|
silent &&= data.count <= 500
|
@@ -8,7 +8,9 @@ module Eco
|
|
8
8
|
def initialize(login_providers = [], klass: Ecoportal::API::Internal::LoginProvider, factory: nil)
|
9
9
|
@klass = Ecoportal::API::Internal::LoginProvider
|
10
10
|
@caches_init = false
|
11
|
+
|
11
12
|
super(login_providers, klass: @klass)
|
13
|
+
|
12
14
|
init_caches
|
13
15
|
end
|
14
16
|
|
@@ -88,7 +90,15 @@ module Eco
|
|
88
90
|
@by_name = enabled_lps.each_with_object({}) do |lp, hash|
|
89
91
|
hash[lp.name.downcase] = lp
|
90
92
|
|
91
|
-
|
93
|
+
if lp.type == 'saml'
|
94
|
+
hash['sso'] = lp unless hash.key?('sso')
|
95
|
+
end
|
96
|
+
|
97
|
+
next unless lp.type == 'onetimepassword'
|
98
|
+
|
99
|
+
hash['magic link'] = lp
|
100
|
+
hash['magic_link'] = lp
|
101
|
+
hash['magiclink'] = lp
|
92
102
|
end
|
93
103
|
|
94
104
|
@by_type = enabled_lps.each_with_object({}) do |lp, hash|
|
@@ -99,15 +109,12 @@ module Eco
|
|
99
109
|
if lp.type == 'saml'
|
100
110
|
# only map the first :sso
|
101
111
|
hash[:sso] = lp unless hash.key?(:sso)
|
102
|
-
hash['sso'] = lp unless hash.key?('sso')
|
103
112
|
end
|
104
113
|
|
105
114
|
next unless lp.type == 'onetimepassword'
|
106
115
|
|
107
116
|
hash[:magic_link] = lp
|
108
117
|
hash[:magiclink] = lp
|
109
|
-
hash['magic_link'] = lp
|
110
|
-
hash['magiclink'] = lp
|
111
118
|
end
|
112
119
|
|
113
120
|
@caches_init = true
|
@@ -8,7 +8,9 @@ module Eco
|
|
8
8
|
def initialize(types = [], klass: Ecoportal::API::GraphQL::Base::LocationClassificationType) # rubocop:disable Lint/UnusedMethodArgument
|
9
9
|
@klass = Ecoportal::API::GraphQL::Base::LocationClassificationType
|
10
10
|
@caches_init = false
|
11
|
+
|
11
12
|
super(types, klass: @klass)
|
13
|
+
|
12
14
|
init_caches
|
13
15
|
end
|
14
16
|
|
@@ -66,6 +68,7 @@ module Eco
|
|
66
68
|
|
67
69
|
def treat_classication(value)
|
68
70
|
return value unless value.is_a?(String)
|
71
|
+
|
69
72
|
value.strip.gsub(/\W+/, '').downcase
|
70
73
|
end
|
71
74
|
|
@@ -1,13 +1,11 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
3
|
module Organization
|
4
|
-
|
5
4
|
class PresetsFactory
|
6
5
|
ABILITIES = File.join(__dir__, 'presets_values.json')
|
7
6
|
INTEGRITY = File.join(__dir__, 'presets_integrity.json')
|
8
7
|
|
9
8
|
class << self
|
10
|
-
|
11
9
|
def all_abilities(hash = {})
|
12
10
|
Hash[abilities.each_with_object(nil).to_a].merge(hash)
|
13
11
|
end
|
@@ -23,11 +21,12 @@ module Eco
|
|
23
21
|
def abilities
|
24
22
|
@abilities ||= abilities_model.keys
|
25
23
|
end
|
26
|
-
|
27
24
|
end
|
28
25
|
|
29
26
|
def initialize(enviro: nil, policy_groups: nil)
|
30
|
-
|
27
|
+
msg = "Expecting Environment object. Given: #{enviro.class}"
|
28
|
+
fatal(msg) if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment)
|
29
|
+
|
31
30
|
@enviro = enviro
|
32
31
|
@policy_groups = policy_groups
|
33
32
|
end
|
@@ -38,15 +37,16 @@ module Eco
|
|
38
37
|
end
|
39
38
|
|
40
39
|
def valid?(preset)
|
41
|
-
validate(
|
40
|
+
validate(preset).empty?
|
42
41
|
end
|
43
42
|
|
44
43
|
def validate(preset)
|
45
44
|
[].tap do |errors|
|
46
|
-
if err = preset_errors(preset)
|
45
|
+
if (err = preset_errors(preset))
|
47
46
|
errors << "{ '#{key}' preset -> #{err}}"
|
48
47
|
end
|
49
|
-
|
48
|
+
|
49
|
+
if (err = preset_integrity(preset))
|
50
50
|
errors << "{ '#{key}' preset -> #{err}}"
|
51
51
|
end
|
52
52
|
end
|
@@ -55,54 +55,60 @@ module Eco
|
|
55
55
|
private
|
56
56
|
|
57
57
|
def compile(*presets)
|
58
|
-
presets.compact.reduce({}) do |
|
59
|
-
merge(
|
58
|
+
presets.compact.reduce({}) do |p_1, p_2|
|
59
|
+
merge(p_1, p_2)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
def merge(
|
64
|
-
keys =
|
63
|
+
def merge(preset_1, preset_2)
|
64
|
+
keys = preset_1.keys | preset_2.keys
|
65
65
|
|
66
66
|
abilities_model.each_with_object({}) do |(key, values), result|
|
67
67
|
next unless keys.include?(key)
|
68
|
+
|
68
69
|
idx = [
|
69
|
-
values.index(
|
70
|
-
values.index(
|
70
|
+
values.index(preset_1[key]),
|
71
|
+
values.index(preset_2[key])
|
71
72
|
].compact.max
|
73
|
+
|
72
74
|
result[key] = idx && values[idx]
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
76
78
|
def preset_errors(preset)
|
77
|
-
return "No preset given"
|
79
|
+
return "No preset given" unless preset
|
80
|
+
|
78
81
|
errors = preset.map do |k, v|
|
79
82
|
value_exists?(k, v) ? nil : "#{k}:#{v}"
|
80
83
|
end.compact
|
81
|
-
|
82
|
-
|
84
|
+
|
85
|
+
" Unknown: {#{errors.join(", ")}}" if errors.length.positive?
|
83
86
|
end
|
84
87
|
|
85
|
-
def preset_integrity(preset)
|
88
|
+
def preset_integrity(preset) # rubocop:disable Metrics/AbcSize
|
86
89
|
preset.each_with_object([]) do |(ability, value), errors|
|
87
|
-
next unless checks = integrity_model[ability]
|
90
|
+
next unless (checks = integrity_model[ability])
|
88
91
|
|
89
92
|
suberrors = []
|
90
93
|
|
91
94
|
checks.each do |check|
|
92
95
|
next unless check["value"] == value
|
96
|
+
|
93
97
|
check["conditions"].each do |cond, targets|
|
94
98
|
case cond
|
95
99
|
when "at_least"
|
96
100
|
targets.each do |other, minimum|
|
97
|
-
|
98
|
-
|
99
|
-
|
101
|
+
min_idx = ability_value_idx(other, minimum)
|
102
|
+
oth_idx = ability_value_idx(other, preset[other])
|
103
|
+
next if min_idx <= oth_idx
|
104
|
+
|
105
|
+
suberrors << "'#{other}' should be at least '#{minimum}'"
|
100
106
|
end
|
101
107
|
when "one_of"
|
102
108
|
unless targets.any? {|other, expected| preset[other] == expected}
|
103
109
|
suberrors << targets.each_with_object([]) do |(other, expected), out|
|
104
110
|
out << "'#{other}': '#{expected}'"
|
105
|
-
end.join(", ").
|
111
|
+
end.join(", ").then do |msg|
|
106
112
|
"there should be at least one of: {#{msg}}"
|
107
113
|
end
|
108
114
|
end
|
@@ -112,11 +118,11 @@ module Eco
|
|
112
118
|
end
|
113
119
|
end
|
114
120
|
|
115
|
-
|
121
|
+
unless suberrors.empty?
|
116
122
|
errors << "Incorrect value '#{value}' for '#{ability}' - reasons: {#{suberrors.join(", ")}}"
|
117
123
|
end
|
118
|
-
end.
|
119
|
-
" Integrity errors: { #{errors.join(", ")} }"
|
124
|
+
end.then do |errors|
|
125
|
+
" Integrity errors: { #{errors.join(", ")} }" unless errors.empty?
|
120
126
|
end
|
121
127
|
end
|
122
128
|
|
@@ -129,8 +135,8 @@ module Eco
|
|
129
135
|
end
|
130
136
|
|
131
137
|
def abilities_model_inverted
|
132
|
-
@abilities_model_inverted ||= abilities_model.
|
133
|
-
|
138
|
+
@abilities_model_inverted ||= abilities_model.transform_values do |values|
|
139
|
+
values.each_with_object({}) {|v, h| h[v] = true }
|
134
140
|
end
|
135
141
|
end
|
136
142
|
|
@@ -153,18 +159,18 @@ module Eco
|
|
153
159
|
end
|
154
160
|
|
155
161
|
def fatal(msg)
|
156
|
-
raise msg
|
162
|
+
raise msg unless @enviro
|
163
|
+
|
157
164
|
@enviro.logger.fatal(msg)
|
158
165
|
raise msg
|
159
166
|
end
|
160
167
|
|
161
168
|
def warn(msg)
|
162
|
-
raise msg
|
169
|
+
raise msg unless @enviro
|
170
|
+
|
163
171
|
@enviro.logger.warn(msg)
|
164
172
|
end
|
165
|
-
|
166
173
|
end
|
167
|
-
|
168
174
|
end
|
169
175
|
end
|
170
176
|
end
|
@@ -65,7 +65,7 @@ module Eco
|
|
65
65
|
init_node
|
66
66
|
end
|
67
67
|
|
68
|
-
|
68
|
+
@path.push(self.id) unless top?
|
69
69
|
|
70
70
|
@nodes = @raw_nodes.map.with_index do |cnode, idx|
|
71
71
|
self.class.new(cnode, depth: depth + 1, path: @path.dup, parent: self, _weight: idx)
|
@@ -100,6 +100,7 @@ module Eco
|
|
100
100
|
def merge(other)
|
101
101
|
msg = "Expecting Eco::API::Organization::TagTree. Given: #{other.class}"
|
102
102
|
raise ArgumentError, msg unless other.is_a?(Eco::API::Organization::TagTree)
|
103
|
+
|
103
104
|
mid = [id, other.id].join('|')
|
104
105
|
mname = [name, other.name].join('|')
|
105
106
|
self.class.new(as_json | other.as_json, id: mid, name: mname)
|
@@ -121,6 +122,7 @@ module Eco
|
|
121
122
|
# @return [Enumerable<Eco::API::Organization::TagTree>]
|
122
123
|
def each(&block)
|
123
124
|
return to_enum(:each) unless block
|
125
|
+
|
124
126
|
all_nodes.each(&block)
|
125
127
|
end
|
126
128
|
|
@@ -130,9 +132,11 @@ module Eco
|
|
130
132
|
raise ArgumentError, "Missing block" unless block_given?
|
131
133
|
[].tap do |out_nodes|
|
132
134
|
selected = false
|
135
|
+
|
133
136
|
selected = (yield(self) == when_is) unless top?
|
134
137
|
out_nodes.push(self) if selected
|
135
138
|
next unless selected || top?
|
139
|
+
|
136
140
|
nodes.each do |nd|
|
137
141
|
out_nodes.concat(nd.select(when_is: when_is, &block))
|
138
142
|
end
|
@@ -154,6 +158,7 @@ module Eco
|
|
154
158
|
out_nodes.push(self)
|
155
159
|
yield(self) if block_given?
|
156
160
|
end
|
161
|
+
|
157
162
|
nodes.each do |nd|
|
158
163
|
out_nodes.concat(nd.all_nodes(&block))
|
159
164
|
end
|
@@ -165,10 +170,10 @@ module Eco
|
|
165
170
|
# @return [Array<TagTree>] ancestors sorted from top to bottom.
|
166
171
|
def ancestors
|
167
172
|
[].tap do |ans|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
173
|
+
next if parent.top?
|
174
|
+
|
175
|
+
ans << parent
|
176
|
+
ans.concat(parent.ancestors)
|
172
177
|
end
|
173
178
|
end
|
174
179
|
|
@@ -321,6 +326,7 @@ module Eco
|
|
321
326
|
# @return [TagTree, nil] if the tag `key` is a node, returns that node.
|
322
327
|
def node(key)
|
323
328
|
return nil unless tag?(key)
|
329
|
+
|
324
330
|
@hash_tags[key.upcase]
|
325
331
|
end
|
326
332
|
|
@@ -329,6 +335,7 @@ module Eco
|
|
329
335
|
# @return [Array<String>]
|
330
336
|
def filter_tags(list)
|
331
337
|
return [] unless list.is_a?(Array)
|
338
|
+
|
332
339
|
list.select {|str| tag?(str)}
|
333
340
|
end
|
334
341
|
|
@@ -339,6 +346,7 @@ module Eco
|
|
339
346
|
# @return [Array<String>]
|
340
347
|
def path(key = nil)
|
341
348
|
return @path.dup unless key
|
349
|
+
|
342
350
|
@hash_paths[key.upcase].dup
|
343
351
|
end
|
344
352
|
|
@@ -444,6 +452,7 @@ module Eco
|
|
444
452
|
@hash_tags = nodes.reduce(@hash_tags) do |h, n|
|
445
453
|
h.merge(n.hash)
|
446
454
|
end
|
455
|
+
|
447
456
|
@hash_paths = {}
|
448
457
|
@hash_paths[@id] = @path unless top?
|
449
458
|
@hash_paths = nodes.reduce(@hash_paths) do |h, n|
|
@@ -5,11 +5,11 @@
|
|
5
5
|
class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loaders::Policy
|
6
6
|
name "default-user-access"
|
7
7
|
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :job
|
9
9
|
attr_accessor :account_removed_count
|
10
10
|
|
11
|
-
def main(
|
12
|
-
@
|
11
|
+
def main(_peo, _sess, _opts, _plc, job)
|
12
|
+
@job = job
|
13
13
|
|
14
14
|
self.account_removed_count = 0
|
15
15
|
|
@@ -17,9 +17,8 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
|
|
17
17
|
remove_account_when_no_email!(person) if person.email.to_s.empty?
|
18
18
|
next unless account = person.account
|
19
19
|
next if options.dig(:exclude, :account)
|
20
|
-
|
21
|
-
|
22
|
-
end
|
20
|
+
|
21
|
+
add_def_policy_group_if_applicable!(account)
|
23
22
|
add_login_method_if_applicable!(account)
|
24
23
|
end
|
25
24
|
|
@@ -29,30 +28,41 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
|
|
29
28
|
private
|
30
29
|
|
31
30
|
def warn_account_removal!
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
return unless account_removed_count.positive?
|
32
|
+
|
33
|
+
msg = "(DefaultPolicy on job '#{job.name}') Removed account to #{account_removed_count} people"
|
34
|
+
log(:info) { msg }
|
36
35
|
end
|
37
36
|
|
38
37
|
def remove_account_when_no_email!(person)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
return unless person.account
|
39
|
+
|
40
|
+
self.account_removed_count += 1 if had_account?(person)
|
41
|
+
person.account = nil
|
43
42
|
end
|
44
43
|
|
45
44
|
def had_account?(person)
|
46
45
|
return false if person.new?
|
47
46
|
return false if person.account_added?
|
48
|
-
|
47
|
+
|
48
|
+
!!person.original_doc["account"]
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_def_policy_group_if_applicable!(account)
|
52
|
+
return unless account
|
53
|
+
return unless account.policy_group_ids.empty?
|
54
|
+
return unless def_pg
|
55
|
+
|
56
|
+
account.policy_group_ids = [def_pg]
|
49
57
|
end
|
50
58
|
|
51
59
|
def add_login_method_if_applicable!(account)
|
60
|
+
return unless account
|
52
61
|
return unless account.as_update.key?("login_provider_ids")
|
53
|
-
|
54
|
-
|
55
|
-
|
62
|
+
return unless account.login_provider_ids.empty?
|
63
|
+
return unless def_login
|
64
|
+
|
65
|
+
account.login_provider_ids = [def_login]
|
56
66
|
end
|
57
67
|
|
58
68
|
def def_pg
|