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
@@ -30,7 +30,8 @@ module Eco
|
|
30
30
|
all_available: all_available
|
31
31
|
}
|
32
32
|
unknown = arguments.unknown(**args) do |key, correct|
|
33
|
-
suggestions[key] = correct unless correct.empty?
|
33
|
+
next suggestions[key] = correct unless correct.empty?
|
34
|
+
suggstions[key] = '-- not known similar options! --'
|
34
35
|
end
|
35
36
|
unknown = unknown.select {|arg| is_modifier?(arg)} if only_options
|
36
37
|
|
@@ -38,7 +39,7 @@ module Eco
|
|
38
39
|
|
39
40
|
suggestions_str = suggestions.slice(*unknown).map do |key, correct|
|
40
41
|
str = "Unknown option '#{key}'."
|
41
|
-
str_corr = correct.map {|
|
42
|
+
str_corr = correct.map {|ky| "'#{ky}'"}
|
42
43
|
str << " Did you mean: #{str_corr.join(', ')}" unless correct.empty?
|
43
44
|
str
|
44
45
|
end.join("\n * ")
|
@@ -2,12 +2,11 @@ module Eco
|
|
2
2
|
class CLI
|
3
3
|
class Scripting
|
4
4
|
class Argument
|
5
|
-
|
6
5
|
attr_reader :key
|
7
6
|
|
8
7
|
class << self
|
9
8
|
def is_modifier?(value)
|
10
|
-
|
9
|
+
value&.start_with?("-")
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
@@ -19,6 +18,7 @@ module Eco
|
|
19
18
|
def args_slice(*args)
|
20
19
|
#pp "known arg '#{key}' => included? #{args.include?(key)}"
|
21
20
|
return args unless args.include?(key)
|
21
|
+
|
22
22
|
i = args.index(key)
|
23
23
|
j = with_param?? i+1 : i
|
24
24
|
args - args.slice(i..j)
|
@@ -21,61 +21,65 @@ ASSETS.cli.config do |cnf|
|
|
21
21
|
|
22
22
|
cnf.input(default_option: "-entries-from") do |session, str_opt, options|
|
23
23
|
input = []
|
24
|
-
if SCR.get_arg(str_opt)
|
25
|
-
file = SCR.get_file(str_opt, required: true)
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
next matched if matched
|
31
|
-
next frm if used
|
32
|
-
end
|
25
|
+
next input unless SCR.get_arg(str_opt)
|
26
|
+
|
27
|
+
file = SCR.get_file(str_opt, required: true)
|
33
28
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
29
|
+
# Command line check
|
30
|
+
format = formats.reduce(nil) do |matched, (frm, selectors)|
|
31
|
+
used = selectors[:option].reduce(false) {|us, option| SCR.get_arg(option) || us}
|
32
|
+
next matched if matched
|
33
|
+
next frm if used
|
34
|
+
end
|
35
|
+
|
36
|
+
# File/Folder check
|
37
|
+
file = File.expand_path(file)
|
38
|
+
if File.directory?(file)
|
39
|
+
folder = file
|
40
|
+
file = Dir.glob("#{file}/*").reject {|f| File.directory?(f)}
|
41
|
+
ext = (format && formats[format][:extname]) || [File.extname(file.first)]
|
42
|
+
file = file.select {|f| ext.any? {|e| File.extname(f) == e}}.tap do |files|
|
43
|
+
if files.empty?
|
44
|
+
session.log(:error) {
|
45
|
+
"Could not find any file with extension: #{ext} in folder '#{folder}'"
|
46
|
+
}
|
47
|
+
exit(1)
|
45
48
|
end
|
46
|
-
else
|
47
|
-
ext = File.extname(file)
|
48
49
|
end
|
50
|
+
else
|
51
|
+
ext = File.extname(file)
|
52
|
+
end
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
format ||= formats.reduce(nil) do |matched, (frm, selectors)|
|
55
|
+
next matched if matched
|
56
|
+
next frm if selectors[:extname].any? {|e| ext == e}
|
57
|
+
end
|
58
|
+
format ||= :csv
|
55
59
|
|
56
|
-
|
57
|
-
|
60
|
+
options.deep_merge!(input: {file: {name: file}})
|
61
|
+
options.deep_merge!(input: {file: {format: format}})
|
58
62
|
|
59
|
-
|
63
|
+
encoding = options.dig(:input, :file, :encoding)
|
60
64
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
else # :csv
|
74
|
-
kargs = {check_headers: true}
|
75
|
-
kargs.merge!(encoding: encoding) if encoding
|
76
|
-
input = session.csv_entries(file, **kargs)
|
65
|
+
case format
|
66
|
+
when :xml
|
67
|
+
[file].flatten.each {|f| session.config.files.validate(:xml, f)}
|
68
|
+
kargs = {file: file, format: format}
|
69
|
+
kargs.merge!(encoding: encoding) if encoding
|
70
|
+
input = session.entries(**kargs)
|
71
|
+
when :xls
|
72
|
+
input = session.entries(file: file, format: format)
|
73
|
+
when :json
|
74
|
+
input = [file].flatten.reduce(Eco::API::Organization::People.new([])) do |people, filename|
|
75
|
+
people.merge(JSON.parse(File.read(filename)))
|
77
76
|
end
|
77
|
+
else # :csv
|
78
|
+
kargs = {check_headers: true}
|
79
|
+
kargs.merge!(encoding: encoding) if encoding
|
80
|
+
input = session.csv_entries(file, **kargs)
|
78
81
|
end
|
82
|
+
|
79
83
|
input
|
80
84
|
end
|
81
85
|
end
|
@@ -1,47 +1,62 @@
|
|
1
1
|
ASSETS.cli.config do |cnf|
|
2
2
|
cnf.input_filters do |filters|
|
3
|
-
|
4
|
-
filters.add("-input-filter-tags-all",
|
3
|
+
desc = "only those that have ALL the specified tags separated by '|'"
|
4
|
+
filters.add("-input-filter-tags-all", desc) do |input, session, options|
|
5
5
|
tags = SCR.get_arg("-input-filter-tags-all", with_param: true).upcase.split("|")
|
6
|
+
|
6
7
|
options.deep_merge!(input: {filter: {filter_tags: {all: tags}}})
|
8
|
+
|
7
9
|
input.filter_tags_all(tags).tap do |filtered|
|
8
|
-
msg
|
9
|
-
|
10
|
+
msg = "Filtered #{filtered.count} entries (out of #{input.count})"
|
11
|
+
msg << " with 'all' filter_tags #{tags}"
|
12
|
+
session.log(:info) { msg }
|
10
13
|
end
|
11
14
|
end
|
12
15
|
|
13
|
-
|
16
|
+
desc = "only those that have ANY the specified tags separated by '|'"
|
17
|
+
filters.add("-input-filter-tags-any", desc) do |input, session, options|
|
14
18
|
tags = SCR.get_arg("-input-filter-tags-any", with_param: true).upcase.split("|")
|
19
|
+
|
15
20
|
options.deep_merge!(input: {filter: {filter_tags: {any: tags}}})
|
21
|
+
|
16
22
|
input.filter_tags_any(tags).tap do |filtered|
|
17
|
-
msg
|
18
|
-
|
23
|
+
msg = "Filtered #{filtered.count} entries (out of #{input.count})"
|
24
|
+
msg << " with 'any' filter_tags #{tags}"
|
25
|
+
session.log(:info) { msg }
|
19
26
|
end
|
20
27
|
end
|
21
28
|
|
22
|
-
|
29
|
+
desc = "only those that have ANY tag in the specified subtrees separated by '|'"
|
30
|
+
filters.add("-input-filter-tags-tree", desc) do |input, session, options|
|
23
31
|
top_tags = SCR.get_arg("-input-filter-tags-tree", with_param: true).upcase.split("|")
|
24
|
-
tags = top_tags.each_with_object([]) do |top,
|
25
|
-
|
32
|
+
tags = top_tags.each_with_object([]) do |top, tgs|
|
33
|
+
tgs.concat(session.tagtree.node(top).tags)
|
26
34
|
end.uniq
|
35
|
+
|
27
36
|
options.deep_merge!(input: {filter: {filter_tags: {tree: top_tags, any: tags}}})
|
37
|
+
|
28
38
|
input.filter_tags_any(tags).tap do |filtered|
|
29
|
-
msg
|
30
|
-
|
39
|
+
msg = "Filtered #{filtered.count} entries (out of #{input.count})"
|
40
|
+
msg << " with 'any' filter_tags in subtrees #{top_tags}"
|
41
|
+
session.log(:info) { msg }
|
31
42
|
end
|
32
43
|
end
|
33
44
|
|
34
|
-
|
45
|
+
desc = "only those that do not have 'id' or 'external_id' specified"
|
46
|
+
filters.add("-input-no-id", desc) do |input, _sess, options|
|
35
47
|
options.deep_merge!(input: {filter: {external_id: nil}})
|
48
|
+
|
36
49
|
input.select do |entry|
|
37
|
-
|
38
|
-
end.
|
50
|
+
entry.id || entry.external_id
|
51
|
+
end.then do |filtered|
|
39
52
|
input.newFrom filtered
|
40
53
|
end
|
41
54
|
end
|
42
55
|
|
43
|
-
|
44
|
-
|
56
|
+
desc = "only those with certain supervisor id or external_id"
|
57
|
+
filters.add("-input-supervisor-id", desc) do |input, _sess, options|
|
58
|
+
id = SCR.get_arg("-input-supervisor-id", with_param: true)
|
59
|
+
|
45
60
|
options.deep_merge!(input: {filter: {supervisor_id: id}})
|
46
61
|
#unless sup = entries.find({"id" => id, "external_id" => id})
|
47
62
|
# raise "Could not find anyone in the input with that id '#{id}'"
|
@@ -7,18 +7,22 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
|
|
7
7
|
if (there = SCR.get_arg(opt))
|
8
8
|
refine = SCR.get_arg(opt, with_param: true)
|
9
9
|
end
|
10
|
+
|
10
11
|
refine || there
|
11
12
|
end
|
12
13
|
|
13
14
|
if (hpf = active.call("-filters"))
|
14
15
|
puts conf.people_filters.help(refine: hpf)
|
15
16
|
end
|
17
|
+
|
16
18
|
if (hif = active.call("-input-filters"))
|
17
19
|
puts conf.input_filters.help(refine: hif)
|
18
20
|
end
|
21
|
+
|
19
22
|
if (ho = active.call("-options"))
|
20
23
|
puts conf.options_set.help(refine: ho)
|
21
24
|
end
|
25
|
+
|
22
26
|
if (huc = active.call("-usecases"))
|
23
27
|
puts conf.usecases.help(refine: huc)
|
24
28
|
end
|
@@ -64,13 +68,13 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
|
|
64
68
|
|
65
69
|
unless sch_id
|
66
70
|
msg = "You need to specify a correct schema id or name. '#{sch_name}' does not exist"
|
67
|
-
session.
|
71
|
+
session.log(:error) { msg }
|
68
72
|
exit(1)
|
69
73
|
end
|
70
|
-
|
71
74
|
options.deep_merge!(people: {filter: {details: {schema_id: sch_id}}})
|
72
|
-
session.
|
73
|
-
|
75
|
+
session.log(:info) {
|
76
|
+
"Setting schema #{session.schemas.to_name(sch_id)}"
|
77
|
+
}
|
74
78
|
session.schema = sch_id
|
75
79
|
end
|
76
80
|
|
@@ -24,7 +24,7 @@ ASSETS.cli.config do |cnf|
|
|
24
24
|
msg = "(Optimization) "
|
25
25
|
msg << "Switching from partial to full people download. "
|
26
26
|
msg << "Input (#{input.count}) surpases MAX_GET_PARTIAL (#{MAX_GET_PARTIAL}) entries."
|
27
|
-
session.
|
27
|
+
session.log(:info) { msg }
|
28
28
|
|
29
29
|
options.deep_merge!(people: {
|
30
30
|
get: {
|
@@ -1,22 +1,21 @@
|
|
1
|
-
ASSETS.cli.config do |cnf|
|
2
|
-
cnf.people_filters do |filters|
|
3
|
-
|
4
|
-
filters.add("-only-users", "only those with account") do |people, session, options|
|
1
|
+
ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
|
2
|
+
cnf.people_filters do |filters| # rubocop:disable Metrics/BlockLength
|
3
|
+
filters.add("-only-users", "only those with account") do |people, _sess, options|
|
5
4
|
options.deep_merge!(people: {filter: {account: true}})
|
6
5
|
people.users
|
7
6
|
end
|
8
7
|
|
9
|
-
filters.add("-no-account", "only those with no account") do |people,
|
8
|
+
filters.add("-no-account", "only those with no account") do |people, _sess, options|
|
10
9
|
options.deep_merge!(people: {filter: {account: false}})
|
11
10
|
people.account_present(false)
|
12
11
|
end
|
13
12
|
|
14
|
-
filters.add("-with-details", "only those with details") do |people,
|
13
|
+
filters.add("-with-details", "only those with details") do |people, _sess, options|
|
15
14
|
options.deep_merge!(people: {filter: {details: true}})
|
16
15
|
people.details_present
|
17
16
|
end
|
18
17
|
|
19
|
-
filters.add("-no-id", "only those with no external_id") do |people,
|
18
|
+
filters.add("-no-id", "only those with no external_id") do |people, _sess, options|
|
20
19
|
options.deep_merge!(people: {filter: {external_id: nil}})
|
21
20
|
people.external_id_present(false)
|
22
21
|
end
|
@@ -27,25 +26,29 @@ ASSETS.cli.config do |cnf|
|
|
27
26
|
# end
|
28
27
|
|
29
28
|
filters.add("-supervisor-id", "only those with certain supervisor") do |people, session, options|
|
30
|
-
id
|
29
|
+
id = SCR.get_arg("-supervisor-id", with_param: true)
|
31
30
|
options.deep_merge!(people: {filter: {supervisor_id: id}})
|
32
|
-
|
31
|
+
|
32
|
+
unless (sup = session.micro.with_supervisor(id, people, strict: true))
|
33
33
|
status = session.batch.search([{"id" => id}])
|
34
34
|
sup = status.people.first
|
35
35
|
end
|
36
|
+
|
36
37
|
unless sup
|
37
|
-
session.
|
38
|
+
session.log(:error) {
|
39
|
+
"Supervisor with id '#{id}' does not exist"
|
40
|
+
}
|
38
41
|
exit(1)
|
39
42
|
end
|
40
43
|
|
41
44
|
people.supervisor_id(sup.id)
|
42
45
|
end
|
43
46
|
|
44
|
-
filters.add("-no-default-tag", "only those users with no default tag") do |people,
|
47
|
+
filters.add("-no-default-tag", "only those users with no default tag") do |people, _sess, options|
|
45
48
|
options.deep_merge!(people: {filter: {account: {default_tag: nil}}})
|
46
|
-
people.users.
|
47
|
-
|
48
|
-
end.
|
49
|
+
people.users.reject do |person|
|
50
|
+
person.account.default_tag
|
51
|
+
end.then do |filtered|
|
49
52
|
people.newFrom filtered
|
50
53
|
end
|
51
54
|
end
|
@@ -56,7 +59,7 @@ ASSETS.cli.config do |cnf|
|
|
56
59
|
options.deep_merge!(input: {filter: {filter_tags: {any: tags}}})
|
57
60
|
people.filter_tags_all(tags).tap do |filtered|
|
58
61
|
msg = "Filtered #{filtered.count} people (out of #{people.count}) with 'all' filter_tags #{tags}"
|
59
|
-
session.
|
62
|
+
session.log(:info) { msg }
|
60
63
|
end
|
61
64
|
end
|
62
65
|
|
@@ -66,20 +69,21 @@ ASSETS.cli.config do |cnf|
|
|
66
69
|
options.deep_merge!(input: {filter: {filter_tags_any: tags}})
|
67
70
|
people.filter_tags_any(tags).tap do |filtered|
|
68
71
|
msg = "Filtered #{filtered.count} people (out of #{people.count}) with 'any' filter_tags #{tags}"
|
69
|
-
session.
|
72
|
+
session.log(:info) { msg }
|
70
73
|
end
|
71
74
|
end
|
72
75
|
|
73
76
|
desc = "only those that have ANY tag in the specified subtrees separated by '|'"
|
74
77
|
filters.add("-filter-tags-tree", desc) do |people, session, options|
|
75
78
|
top_tags = SCR.get_arg("-filter-tags-tree", with_param: true).upcase.split("|").compact
|
76
|
-
tags = top_tags.each_with_object([])
|
77
|
-
|
79
|
+
tags = top_tags.each_with_object([]) do |top, tgs|
|
80
|
+
tgs.concat(session.tagtree.node(top).tags)
|
78
81
|
end.uniq
|
79
82
|
options.deep_merge!(input: {filter: {filter_tags: {tree: top_tags, any: tags}}})
|
80
83
|
people.filter_tags_any(tags).tap do |filtered|
|
81
|
-
msg
|
82
|
-
|
84
|
+
msg = "Filtered #{filtered.count} people (out of #{people.count})"
|
85
|
+
msg << " with 'any' filter_tags in subtrees #{top_tags}"
|
86
|
+
session.log(:info) { msg }
|
83
87
|
end
|
84
88
|
end
|
85
89
|
|
@@ -89,17 +93,21 @@ ASSETS.cli.config do |cnf|
|
|
89
93
|
|
90
94
|
unless sch_id
|
91
95
|
msg = "You need to specify a correct schema id or name. '#{sch_name}' does not exist"
|
92
|
-
session.
|
96
|
+
session.log(:error) { msg }
|
93
97
|
exit(1)
|
94
98
|
end
|
95
99
|
|
96
100
|
options.deep_merge!(people: {filter: {details: {schema_id: sch_id}}})
|
97
|
-
session.
|
101
|
+
session.log(:info) {
|
102
|
+
"Filtering people records with schema #{session.schemas.to_name(sch_id)}"
|
103
|
+
}
|
98
104
|
|
99
105
|
people.select do |person|
|
100
106
|
person.details && (person.details.schema_id == sch_id)
|
101
|
-
end.
|
102
|
-
session.
|
107
|
+
end.then do |filtered|
|
108
|
+
session.log(:info) {
|
109
|
+
"Filtered #{filtered.count} people out of #{people.count} total"
|
110
|
+
}
|
103
111
|
people.newFrom filtered
|
104
112
|
end
|
105
113
|
end
|
@@ -1,55 +1,5 @@
|
|
1
|
-
ASSETS.cli.config do |cnf|
|
2
|
-
cnf.usecases do |cases|
|
3
|
-
|
4
|
-
desc = "Draws the Supervisors hiearchy in a file"
|
5
|
-
cases.add("-supers-hierarchy", :export, desc, case_name: "supers-hierarchy") do |people, session, options|
|
6
|
-
options.deep_merge!(output: {file: "supers_hierarchy.txt"}) unless options.dig(:output, :file)
|
7
|
-
end.add_option("-to", "Specify the output file") do |options|
|
8
|
-
file = SCR.get_file("-to", required: true, should_exist: false)
|
9
|
-
options.deep_merge!(output: {file: file})
|
10
|
-
end
|
11
|
-
|
12
|
-
desc = "Draws the Cyclic Supervisors when identified"
|
13
|
-
cases.add("-identify-cyclic-supers", :export, desc, case_name: "identify-cyclic-supers") do |people, session, options|
|
14
|
-
options.deep_merge!(output: {file: "cyclic_supers.txt"}) unless options.dig(:output, :file)
|
15
|
-
end.add_option("-to", "Specify the output file") do |options|
|
16
|
-
file = SCR.get_file("-to", required: true, should_exist: false)
|
17
|
-
options.deep_merge!(output: {file: file})
|
18
|
-
end
|
19
|
-
|
20
|
-
desc = "Provides a set of tools to analyse a set of people (i.e. detect duplicates)"
|
21
|
-
cases.add("-analyse-people", :export, desc, case_name: "analyse-people") do |people, session, options|
|
22
|
-
options.deep_merge!(output: {file: "people_analysis.txt"}) unless options.dig(:output, :file)
|
23
|
-
#unless options.dig(:usecase, :analyse_people, :use_field)
|
24
|
-
# options.deep_merge!(usecase: {analyse_people: {use_field: :name}})
|
25
|
-
#end
|
26
|
-
end.add_option("-to", "Specify the output file.") do |options|
|
27
|
-
file = SCR.get_file("-to", required: true, should_exist: false)
|
28
|
-
options.deep_merge!(output: {file: file})
|
29
|
-
end.add_option("-identify-duplicates", "Generates a list of people with possible duplicates.") do |options|
|
30
|
-
options.deep_merge!(usecase: {analyse_people: {identify_duplicates: true}})
|
31
|
-
end.add_option("-use-field", "Works with -identify-duplicates. Sets field to be used in the comparison.") do |options|
|
32
|
-
expression = SCR.get_arg("-use-field", with_param: true)
|
33
|
-
options.deep_merge!(usecase: {analyse_people: {use_field: expression}})
|
34
|
-
end.add_option("-facet-field", "Works with -identify-duplicates. Adds an additional layer of comparison.") do |options|
|
35
|
-
expression = SCR.get_arg("-facet-field", with_param: true)
|
36
|
-
options.deep_merge!(usecase: {analyse_people: {facet_field: expression}})
|
37
|
-
end.add_option("-only-screening", "Works with -identify-duplicates. Skips the rearrangement stage.") do |options|
|
38
|
-
options.deep_merge!(usecase: {analyse_people: {only_screening: true}})
|
39
|
-
end.add_option("-ignore-matching-words", "Works with -identify-duplicates. Re-adjust scores ignoring matching words.") do |options|
|
40
|
-
options.deep_merge!(usecase: {analyse_people: {ignore_matching_words: true}})
|
41
|
-
end.add_option("-unique-words", "Works with -identify-duplicates. Re-adjust the comparing strings to do not have repeated words.") do |options|
|
42
|
-
options.deep_merge!(usecase: {analyse_people: {unique_words: true}})
|
43
|
-
end.add_option("-identify-unnamed", "Identifies all people with no names.") do |options|
|
44
|
-
options.deep_merge!(usecase: {analyse_people: {identify_unnamed: true}})
|
45
|
-
end.add_option("-backup-people-results", "Generates a json file with all the people involved in the final results of the analysis.") do |options|
|
46
|
-
file = SCR.get_file("-backup-people-results", required: true, should_exist: false)
|
47
|
-
options.deep_merge!(usecase: {analyse_people: {backup_people: File.expand_path(file)}})
|
48
|
-
end.add_option("-to-csv", "Genarates a CSV file with all people of the final results.") do |options|
|
49
|
-
file = SCR.get_file("-to-csv", required: true, should_exist: false) || "Results.csv"
|
50
|
-
options.deep_merge!(usecase: {analyse_people: {csv_file: File.expand_path(file)}})
|
51
|
-
end
|
52
|
-
|
1
|
+
ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
|
2
|
+
cnf.usecases do |cases| # rubocop:disable Metrics/BlockLength
|
53
3
|
desc = "It exports to a CSV the (filtered) people"
|
54
4
|
cases.add("-people-to-csv", :export, desc) do |people, session, options|
|
55
5
|
file = SCR.get_file("-people-to-csv", required: true, should_exist: false)
|
@@ -69,25 +19,6 @@ ASSETS.cli.config do |cnf|
|
|
69
19
|
options.deep_merge!(export: {options: {split_schemas: true}})
|
70
20
|
end
|
71
21
|
|
72
|
-
desc = "Adds a column 'ecoPortalTag' to the input CSV with the tags that the location codes map to"
|
73
|
-
cases.add("-codes-to-tags-from", :other, desc, case_name: "codes-to-tags-from")
|
74
|
-
.add_option("-codes-to-tags-from", "Specify the input 'csv' file") do |options|
|
75
|
-
file = SCR.get_file("-codes-to-tags-from", required: true, should_exist: true)
|
76
|
-
options.deep_merge!(other: {file: {name: file, format: :csv}})
|
77
|
-
end.add_option("-column", "Specify the input column header with the codes") do |options|
|
78
|
-
col_codes = SCR.get_arg("-column", with_param: true)
|
79
|
-
options.deep_merge!(other: {file: {codes_column: col_codes}})
|
80
|
-
end
|
81
|
-
|
82
|
-
desc = "Creates a CSV with the paths to each tag"
|
83
|
-
cases.add("-create-tag-paths", :other, desc, case_name: "create-tag-paths")
|
84
|
-
|
85
|
-
desc = "Creates a JSON file with the tagtree from a CSV file"
|
86
|
-
cases.add("-csv-to-tree", :other, desc, case_name: "csv-to-tree") do |session, options, usecase|
|
87
|
-
file = SCR.get_file("-csv-to-tree", required: true, should_exist: true)
|
88
|
-
options.deep_merge!(source: {file: file})
|
89
|
-
end
|
90
|
-
|
91
22
|
desc = "Forces a change of email in the same org. It won't succeed if email taken by an org member user"
|
92
23
|
cases.add("-change-email-from", :sync, desc, case_name: "change-email")
|
93
24
|
|
@@ -95,12 +26,12 @@ ASSETS.cli.config do |cnf|
|
|
95
26
|
cases.add("-switch-supervisor", :transform, desc, case_name: "switch-supervisor") do |people, session, options|
|
96
27
|
unless options[:super]&.key?(:old)
|
97
28
|
msg = "You must specify an -old-super to target whose supervisor is changing"
|
98
|
-
session.
|
29
|
+
session.log(:error) { msg }
|
99
30
|
exit(1)
|
100
31
|
end
|
101
32
|
unless options[:super]&.key?(:new)
|
102
33
|
msg = "You must specify the -new-super id. To reset to nil the supervisor, please, specify nil."
|
103
|
-
session.
|
34
|
+
session.log(:error) { msg }
|
104
35
|
exit(1)
|
105
36
|
end
|
106
37
|
end.add_option("-old-super", "The supervisor id to be replaced on the subordinates") do |options|
|
@@ -115,59 +46,13 @@ ASSETS.cli.config do |cnf|
|
|
115
46
|
end
|
116
47
|
end
|
117
48
|
|
118
|
-
desc
|
49
|
+
desc = "Input file dump into a CSV as is."
|
119
50
|
cases.add("-entries-to-csv", :import, desc, case_name: "entries-to-csv")
|
120
51
|
.add_option("-out") do |options|
|
121
52
|
file = SCR.get_file("-out")
|
122
53
|
options.deep_merge!(export: {file: file})
|
123
54
|
end
|
124
55
|
|
125
|
-
desc = "Usage '-org-data-convert backup.json -restore-db-from'."
|
126
|
-
desc += " Transforms an input .json file to the values of the destination environment "
|
127
|
-
desc += " (names missmatch won't solve: i.e. usergroups)"
|
128
|
-
cases.add("-org-data-convert", :import, desc, case_name: "org-data-convert") do |input, session, options|
|
129
|
-
unless input && input.is_a?(Eco::API::Organization::People)
|
130
|
-
file = SCR.get_file("-org-data-convert", required: true)
|
131
|
-
input = Eco::API::Organization::People.new(JSON.parse(File.read(file)))
|
132
|
-
session.logger.info("Source DB: loaded #{input.length} entries.")
|
133
|
-
end
|
134
|
-
|
135
|
-
unless options[:source_enviro]
|
136
|
-
session.logger.error("You need to specify a -source-enviro for the conversion to work out")
|
137
|
-
exit(1)
|
138
|
-
end
|
139
|
-
|
140
|
-
end.add_option("-source-enviro", "The defined -source-enviro API configuration that the backup file was generated from") do |options|
|
141
|
-
options.merge!(source_enviro: SCR.get_arg("-source-enviro", with_param: true))
|
142
|
-
end.add_option("-ignore-missing-policy-groups", "Prevents the script to crash when backup file has missing usergroups in the org") do |options|
|
143
|
-
options.deep_merge!(ignore: {missing: {policy_groups: true}})
|
144
|
-
end
|
145
|
-
|
146
|
-
desc = "Restores the people manager by using a backup.json file"
|
147
|
-
cases.add("-restore-db-from", :sync, desc, case_name: "restore-db") do |input, people, session, options|
|
148
|
-
unless input && input.is_a?(Eco::API::Organization::People)
|
149
|
-
file = SCR.get_file("-restore-db-from", required: true)
|
150
|
-
input = Eco::API::Organization::People.new(JSON.parse(File.read(file)))
|
151
|
-
session.logger.info("Source DB: loaded #{input.length} entries.")
|
152
|
-
end
|
153
|
-
end.add_option("-include-delete", "If it should DELETE people that do not exist in the backup file") do |options|
|
154
|
-
options.deep_merge!(include: {delete: true})
|
155
|
-
end.add_option("-include-create", "If it should CREATE people that do not exist in the people manager") do |options|
|
156
|
-
options.deep_merge!(include: {create: true})
|
157
|
-
end
|
158
|
-
|
159
|
-
desc = "Re-sends invites to all filtered users that have not accepted the invite as yet"
|
160
|
-
cases.add("-reinvite", :transform, desc, case_name: "reinvite")
|
161
|
-
.add_option("-force", "If also send an invite email to those that have accepted the invite") do |options|
|
162
|
-
options.deep_merge!(force: {invite: true})
|
163
|
-
end
|
164
|
-
|
165
|
-
desc = "Re-sends invites to target users that have not accepted the invite as yet"
|
166
|
-
cases.add("-reinvite-from", :sync, desc, case_name: "reinvite")
|
167
|
-
.add_option("-force", "If also send an invite email to those that have accepted the invite") do |options|
|
168
|
-
options.deep_merge!(force: {invite: true})
|
169
|
-
end
|
170
|
-
|
171
56
|
desc = "Clears the `permissions_custom`, provided that Policy Group abilities alone apply."
|
172
57
|
desc += " Please be mindfull if you use this option (there may be users that have been upgraded in ad-hoc manner)."
|
173
58
|
cases.add("-clear-abilities", :transform, desc, case_name: "clear-abilities")
|
@@ -219,7 +104,9 @@ ASSETS.cli.config do |cnf|
|
|
219
104
|
options.deep_merge!(export: {file: {name: file || "RegisterExport.csv", format: :csv}})
|
220
105
|
|
221
106
|
unless options.dig(:source, :register_id)
|
222
|
-
session.
|
107
|
+
session.log(:error) {
|
108
|
+
"You should specify the target register id"
|
109
|
+
}
|
223
110
|
exit(1)
|
224
111
|
end
|
225
112
|
end.add_option("-register-id", "Target register id") do |options|
|
@@ -38,6 +38,7 @@ ASSETS.cli do |cli| # rubocop:disable Metrics/BlockLength
|
|
38
38
|
|
39
39
|
wf_in.on(:filter) do |_wf_if, io|
|
40
40
|
next unless input && !input.empty?
|
41
|
+
|
41
42
|
io.new(input: cli.config.input_filters.process(io: io))
|
42
43
|
end
|
43
44
|
end
|
@@ -47,6 +48,7 @@ ASSETS.cli do |cli| # rubocop:disable Metrics/BlockLength
|
|
47
48
|
cases_with_people = cli.config.usecases.active(io: io).select do |usecase, _data|
|
48
49
|
io.class.people_required?(usecase.type)
|
49
50
|
end
|
51
|
+
|
50
52
|
next if cases_with_people.empty? && !options.dig(:people, :get)
|
51
53
|
|
52
54
|
io.new(people: cli.config.people(io: io))
|
@@ -78,7 +80,7 @@ ASSETS.cli do |cli| # rubocop:disable Metrics/BlockLength
|
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
81
|
-
wf.before(:launch_jobs) do |_wf_jobs,
|
83
|
+
wf.before(:launch_jobs) do |_wf_jobs, _io|
|
82
84
|
available_args = cli.config.available_option_args
|
83
85
|
SCR.stop_on_unknown!(all_available: available_args)
|
84
86
|
end
|
@@ -95,7 +97,7 @@ ASSETS.cli do |cli| # rubocop:disable Metrics/BlockLength
|
|
95
97
|
wf_post.skip!
|
96
98
|
log(:info) {
|
97
99
|
msg = "Although there are post_launch cases, they will NOT be RUN"
|
98
|
-
msg
|
100
|
+
msg << ", because we are in dry-run (simulate)." if options[:dry_run]
|
99
101
|
msg
|
100
102
|
}
|
101
103
|
next
|
@@ -109,9 +111,9 @@ ASSETS.cli do |cli| # rubocop:disable Metrics/BlockLength
|
|
109
111
|
log(:info) {
|
110
112
|
msg = "Although there are post_launch cases, data will not be refreshed before their run"
|
111
113
|
if io.options[:dry_run]
|
112
|
-
msg
|
114
|
+
msg << ", because we are in dry-run (simulate)."
|
113
115
|
elsif !partial_update
|
114
|
-
msg
|
116
|
+
msg << ", because it is not a partial update (-get-partial option not present)."
|
115
117
|
end
|
116
118
|
msg
|
117
119
|
}
|
data/lib/eco/csv/split.rb
CHANGED
@@ -21,11 +21,13 @@ module Eco
|
|
21
21
|
def copy_count
|
22
22
|
@copy_count ||= 0
|
23
23
|
end
|
24
|
+
attr_writer :copy_count
|
24
25
|
|
25
26
|
# @return [Integer] number of total input rows
|
26
27
|
def total_count
|
27
28
|
@total_count ||= 0
|
28
29
|
end
|
30
|
+
attr_writer :total_count
|
29
31
|
|
30
32
|
# @return [Array<String>] list of created files
|
31
33
|
def out_files
|