eco-helpers 2.6.3 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +95 -0
- data/CHANGELOG.md +135 -2
- data/Rakefile +13 -7
- data/eco-helpers.gemspec +3 -3
- data/lib/eco/api/common/loaders/base.rb +2 -2
- data/lib/eco/api/common/loaders/case_base.rb +1 -1
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +5 -5
- data/lib/eco/api/common/loaders/error_handler.rb +8 -5
- data/lib/eco/api/common/loaders/parser.rb +44 -22
- data/lib/eco/api/common/loaders/policy.rb +6 -4
- data/lib/eco/api/common/loaders/use_case.rb +13 -7
- data/lib/eco/api/common/people/base_parser.rb +0 -2
- data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +0 -1
- data/lib/eco/api/common/people/default_parsers/csv_parser.rb +1 -1
- data/lib/eco/api/common/people/default_parsers/date_parser.rb +64 -12
- data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +0 -1
- data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +13 -5
- data/lib/eco/api/common/people/default_parsers/multi_parser.rb +0 -1
- data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +18 -5
- data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +8 -8
- data/lib/eco/api/common/people/default_parsers/select_parser.rb +50 -26
- data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +6 -6
- data/lib/eco/api/common/people/default_parsers/xls_parser.rb +9 -12
- data/lib/eco/api/common/people/default_parsers.rb +1 -12
- data/lib/eco/api/common/people/entries.rb +13 -13
- data/lib/eco/api/common/people/entry_factory.rb +76 -45
- data/lib/eco/api/common/people/person_attribute_parser.rb +8 -12
- data/lib/eco/api/common/people/person_entry.rb +86 -75
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +60 -44
- data/lib/eco/api/common/people/person_factory.rb +30 -22
- data/lib/eco/api/common/people/person_modifier.rb +11 -13
- data/lib/eco/api/common/people/person_parser.rb +101 -39
- data/lib/eco/api/common/people/supervisor_helpers.rb +25 -26
- data/lib/eco/api/common/session/base_session.rb +9 -9
- data/lib/eco/api/common/session/environment.rb +7 -5
- data/lib/eco/api/common/session/sftp.rb +59 -32
- data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +10 -6
- data/lib/eco/api/common/version_patches/exception.rb +11 -13
- data/lib/eco/api/error.rb +32 -20
- data/lib/eco/api/microcases/set_supervisor.rb +0 -3
- data/lib/eco/api/organization/node_classifications.rb +82 -0
- data/lib/eco/api/organization/policy_groups.rb +4 -6
- data/lib/eco/api/organization/tag_tree.rb +169 -93
- data/lib/eco/api/organization.rb +1 -0
- data/lib/eco/api/session/batch/job.rb +1 -1
- data/lib/eco/api/session/config/tagtree.rb +41 -23
- data/lib/eco/api/session/config/workflow.rb +113 -88
- data/lib/eco/api/session/config.rb +6 -0
- data/lib/eco/api/session.rb +51 -29
- data/lib/eco/api/usecases/base_io.rb +28 -25
- data/lib/eco/api/usecases/default/locations/cli/tagtree_extract_cli.rb +7 -2
- data/lib/eco/api/usecases/default/locations/cli/tagtree_upload_cli.rb +21 -0
- data/lib/eco/api/usecases/default/locations/csv_to_tree_case.rb +3 -3
- data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +54 -23
- data/lib/eco/api/usecases/default/locations/tagtree_upload_case.rb +87 -0
- data/lib/eco/api/usecases/default/locations.rb +1 -0
- data/lib/eco/api/usecases/default/people/analyse_people_case.rb +60 -56
- data/lib/eco/api/usecases/default/people/change_email_case.rb +8 -9
- data/lib/eco/api/usecases/default/people/clean_unknown_tags_case.rb +13 -11
- data/lib/eco/api/usecases/default/people/clear_abilities_case.rb +2 -2
- data/lib/eco/api/usecases/default/people/org_data_convert_case.rb +25 -27
- data/lib/eco/api/usecases/default/people/refresh_case.rb +2 -2
- data/lib/eco/api/usecases/default/people/reinvite_trans_case.rb +1 -1
- data/lib/eco/api/usecases/default/people/reinvite_trans_cli.rb +0 -1
- data/lib/eco/api/usecases/default/people/restore_db_case.rb +39 -34
- data/lib/eco/api/usecases/default/people/set_default_tag_case.rb +19 -15
- data/lib/eco/api/usecases/default/people/supers_cyclic_identify_case.rb +16 -12
- data/lib/eco/api/usecases/default_cases/hris_case.rb +17 -15
- data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +30 -16
- data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +0 -2
- data/lib/eco/api/usecases/graphql/base.rb +5 -3
- data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +4 -1
- data/lib/eco/api/usecases/graphql/helpers/base/graphql_env.rb +14 -0
- data/lib/eco/api/usecases/graphql/helpers/base.rb +5 -4
- data/lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb +60 -0
- data/lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb +72 -0
- data/lib/eco/api/usecases/graphql/helpers/location/base.rb +25 -59
- data/lib/eco/api/usecases/graphql/helpers/location/command/diff/as_update.rb +59 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diff/compare.rb +49 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diff.rb +11 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/commandable.rb +46 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_archive.rb +23 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_unarchive.rb +65 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable.rb +49 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/sortable/relation_safe_sort.rb +119 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/sortable.rb +59 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages.rb +82 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs.rb +20 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/optimizations.rb +84 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +4 -4
- data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +24 -12
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +21 -24
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_map.rb +1 -1
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap/tags_set.rb +10 -11
- data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +8 -9
- data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +41 -12
- data/lib/eco/api/usecases/graphql/samples/location/command/results.rb +11 -80
- data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +89 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/service.rb +6 -0
- data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +89 -0
- data/lib/eco/api/usecases/graphql/samples/location/command.rb +3 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/base.rb +9 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/heading.rb +18 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/inputable.rb +53 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/classifications.rb +34 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/helpers.rb +28 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing.rb +46 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible.rb +38 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +105 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/discarded.rb +16 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/input.rb +15 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/node_attr_maps.rb +22 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/parser.rb +45 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter.rb +36 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/output.rb +56 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list.rb +41 -0
- data/lib/eco/api/usecases/graphql/samples/location/service.rb +8 -0
- data/lib/eco/api/usecases/graphql/samples/location.rb +1 -0
- data/lib/eco/api/usecases/graphql/utils/sftp.rb +96 -36
- data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +8 -6
- data/lib/eco/api/usecases/ooze_samples/helpers/creatable.rb +4 -3
- data/lib/eco/api/usecases/ooze_samples/helpers/exportable_ooze.rb +39 -25
- data/lib/eco/api/usecases/ooze_samples/helpers/exportable_register.rb +13 -15
- data/lib/eco/api/usecases/ooze_samples/helpers/filters.rb +50 -21
- data/lib/eco/api/usecases/ooze_samples/helpers/ooze_handlers.rb +21 -11
- data/lib/eco/api/usecases/ooze_samples/helpers/rescuable.rb +2 -0
- data/lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb +49 -43
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +17 -19
- data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +48 -43
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +34 -34
- data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +8 -10
- data/lib/eco/api/usecases.rb +0 -1
- data/lib/eco/cli/config/use_cases.rb +31 -29
- data/lib/eco/cli_default/input_filters.rb +0 -5
- data/lib/eco/cli_default/people_filters.rb +4 -4
- data/lib/eco/cli_default/workflow.rb +13 -14
- data/lib/eco/csv/table.rb +34 -25
- data/lib/eco/data/hashes/array_diff.rb +24 -35
- data/lib/eco/data/hashes/diff_result/meta.rb +131 -0
- data/lib/eco/data/hashes/diff_result.rb +65 -57
- data/lib/eco/data/hashes/sanke_camel_indifferent_access.rb +278 -0
- data/lib/eco/data/hashes.rb +1 -1
- data/lib/eco/data/locations/convert.rb +1 -1
- data/lib/eco/data/locations/node_base/csv_convert.rb +19 -9
- data/lib/eco/data/locations/node_base/parsing.rb +4 -2
- data/lib/eco/data/locations/node_base/treeify.rb +149 -132
- data/lib/eco/data/locations/node_base.rb +15 -4
- data/lib/eco/data/locations/node_diff/accessors.rb +13 -5
- data/lib/eco/data/locations/node_diff/nodes_diff/clustered_treeify.rb +101 -0
- data/lib/eco/data/locations/node_diff/nodes_diff/diffs_tree.rb +99 -0
- data/lib/eco/data/locations/node_diff/{selectors.rb → nodes_diff/selectors.rb} +1 -1
- data/lib/eco/data/locations/node_diff/nodes_diff.rb +50 -35
- data/lib/eco/data/locations/node_diff.rb +45 -17
- data/lib/eco/data/locations/node_level/parsing.rb +15 -21
- data/lib/eco/data/locations/node_level.rb +66 -22
- data/lib/eco/data/locations/node_plain/parsing.rb +1 -1
- data/lib/eco/data/locations/node_plain.rb +60 -7
- data/lib/eco/data/strings/camel_case.rb +35 -0
- data/lib/eco/data/strings/snake_case.rb +18 -0
- data/lib/eco/data/strings.rb +8 -0
- data/lib/eco/data.rb +1 -0
- data/lib/eco/language/methods/call_detector.rb +11 -0
- data/lib/eco/language/methods/dsl_able.rb +7 -1
- data/lib/eco/language/methods.rb +2 -1
- data/lib/eco/language/models/collection.rb +23 -25
- data/lib/eco/language/models/parser_serializer.rb +24 -5
- data/lib/eco/version.rb +1 -1
- data/lib/eco-helpers.rb +0 -1
- metadata +54 -9
- data/lib/eco/data/hashes/diff_meta.rb +0 -52
@@ -3,10 +3,13 @@ class Eco::API::UseCases::Default::People::OrgDataConvertCase < Eco::API::Common
|
|
3
3
|
type :import
|
4
4
|
|
5
5
|
def org_data_convert(people)
|
6
|
-
|
6
|
+
log(:info) {
|
7
|
+
"Going to convert data from '#{source_enviro}' to '#{ASSETS.active_config}'"
|
8
|
+
}
|
9
|
+
|
7
10
|
puts "\n"
|
8
11
|
people.each.with_index do |person, i|
|
9
|
-
if (i % 10
|
12
|
+
if (i % 10).zero?
|
10
13
|
percent = i * 100 / people.length
|
11
14
|
print "Processing: #{percent.round}% (#{i}/#{people.length} entries)\r"
|
12
15
|
$stdout.flush
|
@@ -19,44 +22,43 @@ class Eco::API::UseCases::Default::People::OrgDataConvertCase < Eco::API::Common
|
|
19
22
|
people
|
20
23
|
end
|
21
24
|
|
22
|
-
def main(people,
|
25
|
+
def main(people, _session, _options, _usecase)
|
23
26
|
org_data_convert(people)
|
24
27
|
end
|
25
28
|
|
26
29
|
private
|
27
30
|
|
28
31
|
def account_convert!(person)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
32
|
+
return unless (account = person.account)
|
33
|
+
account.policy_group_ids = policy_groups_convert(account.policy_group_ids)
|
34
|
+
account.doc.tap do |doc|
|
35
|
+
%w[login_provider_ids starred_ids landing_page_id].map do |attr|
|
36
|
+
doc.delete(attr)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
41
|
def details_convert!(person)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
42
|
+
return unless person.details
|
43
|
+
person.details.as_json.tap do |details_doc|
|
44
|
+
details_doc["schema_id"] = session.schema.id
|
45
|
+
person.add_details(session.schema)
|
46
|
+
person.details = details_doc
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
50
|
def policy_groups_convert(ids)
|
50
51
|
ids.map do |id|
|
51
|
-
|
52
|
+
name = source_policy_groups.to_name(id)
|
53
|
+
unless name || ignore_missing_policy_groups?
|
52
54
|
msg = "Ops, do not know #{id} usergroup for source environment"
|
53
|
-
msg
|
55
|
+
msg << "\nUse the option -ignore-missing-policy-groups if you do not care"
|
54
56
|
error(msg)
|
55
57
|
end
|
56
58
|
session.policy_groups.to_id(name).tap do |new_id|
|
57
59
|
unless new_id || ignore_missing_policy_groups?
|
58
60
|
msg = "Ops, do not know #{name} usergroup for destination environment"
|
59
|
-
msg
|
61
|
+
msg << "\nUse the option -ignore-missing-policy-groups if you do not care"
|
60
62
|
error(msg)
|
61
63
|
end
|
62
64
|
end
|
@@ -69,15 +71,15 @@ class Eco::API::UseCases::Default::People::OrgDataConvertCase < Eco::API::Common
|
|
69
71
|
|
70
72
|
def source_config
|
71
73
|
@source_config ||= ASSETS.config(key: source_enviro, update_active: false).tap do |config|
|
72
|
-
|
73
|
-
|
74
|
-
end
|
74
|
+
next if config
|
75
|
+
error("The source environment '#{source_enviro}' does not exit or is not configured")
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
78
79
|
def source_enviro
|
79
|
-
@source_enviro ||= options
|
80
|
-
|
80
|
+
@source_enviro ||= options[:source_enviro].tap do |enviro|
|
81
|
+
next if enviro
|
82
|
+
error("A source environment is required to migrate data from")
|
81
83
|
end
|
82
84
|
end
|
83
85
|
|
@@ -85,10 +87,6 @@ class Eco::API::UseCases::Default::People::OrgDataConvertCase < Eco::API::Common
|
|
85
87
|
options.dig(:ignore, :missing, :policy_groups)
|
86
88
|
end
|
87
89
|
|
88
|
-
def logger
|
89
|
-
@session.logger
|
90
|
-
end
|
91
|
-
|
92
90
|
def error(msg)
|
93
91
|
logger.error(msg)
|
94
92
|
exit(1)
|
@@ -2,8 +2,8 @@ class Eco::API::UseCases::Default::People::RefreshCase < Eco::API::Common::Loade
|
|
2
2
|
name "refresh"
|
3
3
|
type :transform
|
4
4
|
|
5
|
-
def main(people, session,
|
6
|
-
update
|
5
|
+
def main(people, session, _options, usecase)
|
6
|
+
update = session.new_job("main", "update", :update, usecase)
|
7
7
|
people.each {|person| update.add(person)}
|
8
8
|
end
|
9
9
|
end
|
@@ -9,7 +9,7 @@ class Eco::API::UseCases::Default::People::ReinviteTransCase < Eco::API::Common:
|
|
9
9
|
private
|
10
10
|
|
11
11
|
def reinvite(users)
|
12
|
-
invite
|
12
|
+
invite = session.new_job("main", "invite", :update, usecase, :account)
|
13
13
|
users.each do |person|
|
14
14
|
if force_invite?
|
15
15
|
person.account.force_send_invites = true
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# @example
|
2
|
+
# -restore-db-from backup.json -skip-api-policies -skip-batch-policy -include-excluded -simulate
|
1
3
|
class Eco::API::UseCases::Default::People::RestoreDBCase < Eco::API::Common::Loaders::UseCase
|
2
4
|
name "restore-db"
|
3
5
|
type :sync
|
4
6
|
|
5
|
-
def main(entries, people, session, options, usecase)
|
7
|
+
def main(entries, people, session, options, usecase) # rubocop:disable Metrics/AbcSize
|
6
8
|
require_people_as_entries!(entries)
|
7
9
|
|
8
10
|
restart = session.new_job("main", "restart", :create, usecase) if options.dig(:include, :create)
|
@@ -19,14 +21,14 @@ class Eco::API::UseCases::Default::People::RestoreDBCase < Eco::API::Common::Loa
|
|
19
21
|
|
20
22
|
micro.with_each(entries, people, options) do |entry, person|
|
21
23
|
if person.new? && !options.dig(:include, :create)
|
22
|
-
re_starters.push(entry)
|
24
|
+
re_starters.push(entry)
|
23
25
|
next
|
24
26
|
end
|
25
27
|
|
26
28
|
person.new? ? restart.add(person) : update.add(person)
|
27
29
|
|
28
|
-
core_copy(entry, person)
|
29
|
-
person.details = entry.details
|
30
|
+
core_copy(entry, person) unless options.dig(:exclude, :core)
|
31
|
+
person.details = entry.details unless options.dig(:exclude, :details)
|
30
32
|
|
31
33
|
unless options.dig(:exclude, :account) || !entry.account
|
32
34
|
person.account ||= {}
|
@@ -48,46 +50,49 @@ class Eco::API::UseCases::Default::People::RestoreDBCase < Eco::API::Common::Loa
|
|
48
50
|
person.freemium = entry.freemium
|
49
51
|
end
|
50
52
|
|
51
|
-
def account_copy(src, dst)
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
def account_copy(src, dst) # rubocop:disable Metrics/AbcSize
|
54
|
+
return unless src
|
55
|
+
dst.default_tag = src.default_tag unless options.dig(:exclude, :filter_tags)
|
56
|
+
dst.policy_group_ids = src.policy_group_ids unless options.dig(:exclude, :policy_groups)
|
57
|
+
dst.permissions_custom = src.permissions_custom unless options.dig(:exclude, :abilities)
|
55
58
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
unless options.dig(:exclude, :login_providers) || options.dig(:source_enviro)
|
61
|
-
dst.login_provider_ids = src.login_provider_ids
|
62
|
-
end
|
63
|
-
|
64
|
-
if src.preferences
|
65
|
-
dst.doc["preferences"] = JSON.parse((src.doc["preferences"] || {}).to_json)
|
66
|
-
end
|
59
|
+
unless options.dig(:exclude, :login_providers) || options[:source_enviro]
|
60
|
+
dst.login_provider_ids = src.login_provider_ids
|
61
|
+
end
|
67
62
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
63
|
+
if src.preferences # rubocop:disable Style/IfUnlessModifier
|
64
|
+
dst.doc["preferences"] = JSON.parse((src.doc["preferences"] || {}).to_json)
|
65
|
+
end
|
72
66
|
|
73
|
-
|
67
|
+
unless options[:source_enviro]
|
68
|
+
dst.starred_ids = src.starred_ids
|
69
|
+
dst.landing_page_id = src.landing_page_id
|
74
70
|
end
|
71
|
+
|
72
|
+
dst&.send_invites = options[:send_invites] if options.key?(:send_invites)
|
75
73
|
end
|
76
74
|
|
77
75
|
def require_people_as_entries!(entries)
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
76
|
+
return true if entries.is_a?(Eco::API::Organization::People)
|
77
|
+
log(:error) {
|
78
|
+
"Your input should be an 'Eco::API::Organization::People' object. Got: #{entries.class}"
|
79
|
+
}
|
80
|
+
exit(1)
|
82
81
|
end
|
83
82
|
|
84
83
|
def report_re_starters(re_starters)
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
re_starters.slice(0, 4).each_with_index do |entry, i|
|
89
|
-
logger.error("This person does not exist: #{entry.name} (#{entry.email})")
|
90
|
-
end
|
84
|
+
return if re_starters.empty?
|
85
|
+
examples = re_starters.slice(0, 4).map do |entry|
|
86
|
+
"This person does not exist: '#{entry.name}' (#{entry.email})"
|
91
87
|
end
|
88
|
+
|
89
|
+
log(:error) {
|
90
|
+
msg = []
|
91
|
+
msg << "There were #{re_starters.length} entries of the backup "
|
92
|
+
msg << "that do not exist in the (filtered?) people manager."
|
93
|
+
msg << "Some examples:"
|
94
|
+
msg << " • #{examples.join("\n • ")}"
|
95
|
+
msg.join("\n")
|
96
|
+
}
|
92
97
|
end
|
93
98
|
end
|
@@ -7,9 +7,9 @@ class Eco::API::UseCases::Default::People::SetDefaultTagCase < Eco::API::Common:
|
|
7
7
|
# => take the common node between them (i.e. you have Hamilton and Auckland -> take New Zealand)
|
8
8
|
# => if there's no common node between them, take the `first` (unless they are at top level of the tree)
|
9
9
|
def main(people, session, options, usecase)
|
10
|
-
tagtree_present!
|
11
|
-
users
|
12
|
-
update
|
10
|
+
tagtree_present!
|
11
|
+
users = users_present!
|
12
|
+
update = session.new_job("main", "update", :update, usecase, :account)
|
13
13
|
|
14
14
|
users.each do |person|
|
15
15
|
micro.refresh_default_tag(nil, person, options)
|
@@ -19,22 +19,26 @@ class Eco::API::UseCases::Default::People::SetDefaultTagCase < Eco::API::Common:
|
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
-
def tagtree_present!
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
22
|
+
def tagtree_present!
|
23
|
+
return unless tagtree?
|
24
|
+
|
25
|
+
msg = "There is no locs struct defined. Aborting..."
|
26
|
+
logger.fatal(msg)
|
27
|
+
raise msg
|
29
28
|
end
|
30
29
|
|
31
|
-
def users_present!
|
30
|
+
def users_present!
|
32
31
|
people.users.tap do |users|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
next if users.length.positive?
|
33
|
+
|
34
|
+
msg = "There are no people with account... aborting script"
|
35
|
+
log(:error) { msg }
|
36
|
+
raise msg
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
def tagtree?
|
41
|
+
return false unless (tree = session.tagtree)
|
42
|
+
!tree.empty?
|
43
|
+
end
|
40
44
|
end
|
@@ -6,8 +6,6 @@ class Eco::API::UseCases::Default::People::SupersCyclicIdentify < Eco::API::Comm
|
|
6
6
|
|
7
7
|
def main(people, session, options, usecase)
|
8
8
|
options[:end_get] = false
|
9
|
-
@people = people
|
10
|
-
|
11
9
|
save!(cyclic_sets)
|
12
10
|
end
|
13
11
|
|
@@ -27,19 +25,20 @@ class Eco::API::UseCases::Default::People::SupersCyclicIdentify < Eco::API::Comm
|
|
27
25
|
return
|
28
26
|
end
|
29
27
|
|
30
|
-
ext
|
28
|
+
ext = File.extname(file).downcase.delete(".")
|
31
29
|
|
32
30
|
File.open(file, "w") do |fd|
|
33
|
-
|
31
|
+
case ext
|
32
|
+
when "txt"
|
34
33
|
create_file(data, file: file, format: :txt)
|
35
|
-
|
36
|
-
|
34
|
+
when "html"
|
35
|
+
log(:warn) { "html is still not supported" }
|
37
36
|
exit(1)
|
38
|
-
create_file(data, file: file, format: :html)
|
39
|
-
|
40
|
-
|
37
|
+
# create_file(data, file: file, format: :html)
|
38
|
+
when "json"
|
39
|
+
log(:warn) { "json is still not supported" }
|
41
40
|
exit(1)
|
42
|
-
create_file(data, file: file, format: :json)
|
41
|
+
# create_file(data, file: file, format: :json)
|
43
42
|
end
|
44
43
|
end
|
45
44
|
end
|
@@ -62,10 +61,15 @@ class Eco::API::UseCases::Default::People::SupersCyclicIdentify < Eco::API::Comm
|
|
62
61
|
|
63
62
|
def set_to_str(set, lev: 0, format: :txt)
|
64
63
|
raise "Required Array. Given: #{set.class}" unless set.is_a?(Array)
|
64
|
+
|
65
65
|
"".tap do |str|
|
66
66
|
entry = set.shift
|
67
|
-
str << "#{" " * lev}
|
68
|
-
str <<
|
67
|
+
str << "#{" " * lev}"
|
68
|
+
str << lev > 0 ? "+-#{lev}- " : ""
|
69
|
+
str << entry.name
|
70
|
+
str << " (#{entry.external_id}|#{entry.email}|#{entry.id})\n"
|
71
|
+
next unless set && !set.empty?
|
72
|
+
str << set_to_str(set, lev: lev + 1, format: format)
|
69
73
|
end
|
70
74
|
end
|
71
75
|
end
|
@@ -8,7 +8,7 @@ class Eco::API::UseCases::DefaultCases::HrisCase < Eco::API::Common::Loaders::Us
|
|
8
8
|
def main(entries, people, session, options, usecase)
|
9
9
|
@people = people
|
10
10
|
require_only_one_schema!
|
11
|
-
micro
|
11
|
+
micro = session.micro
|
12
12
|
@leavers = session.new_job("pre", "leavers", :update, usecase, :account)
|
13
13
|
@creation = session.new_job("main", "create", :create, usecase)
|
14
14
|
@update = session.new_job("main", "update", :update, usecase)
|
@@ -38,19 +38,21 @@ class Eco::API::UseCases::DefaultCases::HrisCase < Eco::API::Common::Loaders::Us
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def require_only_one_schema!
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
41
|
+
return if options.dig(:people, :filter, :details, :schema_id)
|
42
|
+
|
43
|
+
active_schema = session.schema
|
44
|
+
other_schemas = session.schemas.map(&:id) - [active_schema.id]
|
45
|
+
other_people = people.group_by_schema.values_at(*other_schemas).map(&:to_a).flatten
|
46
|
+
return unless other_people.length > 3
|
47
|
+
|
48
|
+
msg = "There are #{other_people.length} people in schemas other than #{active_schema.name}."
|
49
|
+
msg << " Please, use the filter option '-schema-id SchemaName' for the 'hris' case"
|
50
|
+
msg << " to only include those of that schema in the current update."
|
51
|
+
msg << " The HRIS case identifies people that are not in the file as leavers"
|
52
|
+
msg << " (as it will remove the account of all the people of other schemas"
|
53
|
+
msg << " if they are not in the input file)."
|
54
|
+
msg << "\n For example: -schema-id '#{active_schema.name.downcase}'"
|
55
|
+
logger.error(msg)
|
56
|
+
raise msg
|
55
57
|
end
|
56
58
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:disable Naming/AccessorMethodName
|
1
2
|
class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loaders::UseCase
|
2
3
|
class WrongConst < ArgumentError; end
|
3
4
|
class MissRemoteFolder < ArgumentError; end
|
@@ -6,11 +7,12 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
|
|
6
7
|
name "sftp"
|
7
8
|
type :other
|
8
9
|
|
9
|
-
CONST_REFERRAL = /^(?:::)?(?:[A-Z][a-zA-Z0-9_]*(?:::[A-Z][a-zA-Z0-9_]*)*)
|
10
|
+
CONST_REFERRAL = /^(?:::)?(?:[A-Z][a-zA-Z0-9_]*(?:::[A-Z][a-zA-Z0-9_]*)*)$/.freeze
|
10
11
|
|
11
|
-
def main(session, options,
|
12
|
+
def main(session, options, _usecase)
|
12
13
|
options[:end_get] = false
|
13
14
|
raise "The SFTP is not configured" unless session.sftp?
|
15
|
+
|
14
16
|
case options.dig(:sftp, :command)
|
15
17
|
when :list
|
16
18
|
list_folder
|
@@ -29,11 +31,15 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
|
|
29
31
|
def file_pattern(require: true)
|
30
32
|
fpc = file_pattern_const
|
31
33
|
return fpc if fpc
|
32
|
-
|
34
|
+
return unless require
|
35
|
+
|
36
|
+
msg = "(#{self.class}) You should redefine the file_pattern function "
|
37
|
+
msg << "as a RegEx expression that matches the target remote file"
|
38
|
+
raise WrongConst, msg
|
33
39
|
end
|
34
40
|
|
35
41
|
def file_pattern_const
|
36
|
-
if fpc = options.dig(:sftp, :file_pattern_const)
|
42
|
+
if (fpc = options.dig(:sftp, :file_pattern_const))
|
37
43
|
raise WrongConst, "(#{self.class}) Invalid file pattern const referral: #{fpc}" unless fpc.match(CONST_REFERRAL)
|
38
44
|
begin
|
39
45
|
self.eval(fpc)
|
@@ -49,7 +55,11 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
|
|
49
55
|
def remote_subfolder(require: true)
|
50
56
|
rm_sf = options.dig(:sftp, :remote_subfolder)
|
51
57
|
return rm_sf if rm_sf
|
52
|
-
|
58
|
+
return unless require
|
59
|
+
|
60
|
+
msg = "(#{self.class}) You should redefine remote_subfolder "
|
61
|
+
msg << "as the folder where the target file sits. Ex: /IN/Personnel"
|
62
|
+
raise MissRemoteFolder, msg
|
53
63
|
end
|
54
64
|
|
55
65
|
# `remote_target_folder` overrides `sftp_config.remote_folder` as well as `remote_subfolder`
|
@@ -57,7 +67,7 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
|
|
57
67
|
def remote_folder
|
58
68
|
rm_tf = options.dig(:sftp, :remote_target_folder)
|
59
69
|
rm_fd = options.dig(:sftp, :remote_folder) || sftp_config.remote_folder
|
60
|
-
rm_tf ||
|
70
|
+
rm_tf || [rm_fd, remote_subfolder].compact.join('/')
|
61
71
|
end
|
62
72
|
|
63
73
|
def to_remote_path(file)
|
@@ -68,17 +78,19 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
|
|
68
78
|
options.dig(:sftp, :local_folder) || "."
|
69
79
|
end
|
70
80
|
|
71
|
-
def with_remote_files
|
72
|
-
|
73
|
-
|
74
|
-
yield(remote_file) if block_given?
|
75
|
-
end
|
76
|
-
rescue ArgumentError
|
77
|
-
raise
|
78
|
-
rescue ::Net::SFTP::StatusException => e
|
79
|
-
logger.error("(#{self.class}) There was an error trying to access the remote folder '#{remote_folder}'")
|
80
|
-
[]
|
81
|
+
def with_remote_files(folder: self.remote_folder, pattern: self.file_pattern)
|
82
|
+
sftp.files(folder, pattern: pattern).each do |remote_file|
|
83
|
+
yield(remote_file) if block_given?
|
81
84
|
end
|
85
|
+
rescue ArgumentError
|
86
|
+
raise
|
87
|
+
rescue ::Net::SFTP::StatusException => err
|
88
|
+
log(:error) {
|
89
|
+
msg = "(#{self.class}) There was an error trying to access "
|
90
|
+
msg << "the remote folder '#{remote_folder}': #{err}"
|
91
|
+
msg
|
92
|
+
}
|
93
|
+
[]
|
82
94
|
end
|
83
95
|
|
84
96
|
def list_folder
|
@@ -139,3 +151,5 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
|
|
139
151
|
session.sftp
|
140
152
|
end
|
141
153
|
end
|
154
|
+
|
155
|
+
# rubocop:enable Naming/AccessorMethodName
|
@@ -6,7 +6,6 @@ class Eco::API::UseCases::DefaultCases::ToCsvDetailedCase < Eco::API::UseCases::
|
|
6
6
|
|
7
7
|
def to_row(person)
|
8
8
|
data = super(person)
|
9
|
-
data << person.subordinates
|
10
9
|
data << person_supervisor(person)
|
11
10
|
data += user_abilities(person)
|
12
11
|
data += user_permissions_custom(person) if options.dig(:export, :options, :permissions_custom)
|
@@ -39,7 +38,6 @@ class Eco::API::UseCases::DefaultCases::ToCsvDetailedCase < Eco::API::UseCases::
|
|
39
38
|
|
40
39
|
def spot_header(person = people.first)
|
41
40
|
super(person) do |header|
|
42
|
-
header << "Subordinates"
|
43
41
|
header << "Supervisor Name"
|
44
42
|
header += abilities_header
|
45
43
|
header += abilities_header("custom") if options.dig(:export, :options, :permissions_custom)
|
@@ -1,13 +1,14 @@
|
|
1
1
|
class Eco::API::UseCases::GraphQL::Base < Eco::API::Common::Loaders::UseCase
|
2
2
|
class NotImplementedMethod < StandardError
|
3
3
|
end
|
4
|
-
|
4
|
+
|
5
5
|
name "graphql-base"
|
6
6
|
type :other
|
7
7
|
|
8
8
|
include Eco::API::UseCases::GraphQL::Helpers::Base
|
9
|
+
include Eco::Language::Methods::CallDetector
|
9
10
|
|
10
|
-
def main(
|
11
|
+
def main(_sess, options, _case)
|
11
12
|
options.deep_merge!(workflow: {no_email: true}) # prevent the default mailer to quick in
|
12
13
|
options[:end_get] = false
|
13
14
|
process
|
@@ -15,6 +16,7 @@ class Eco::API::UseCases::GraphQL::Base < Eco::API::Common::Loaders::UseCase
|
|
15
16
|
|
16
17
|
# Write here your script
|
17
18
|
def process
|
18
|
-
|
19
|
+
return unless called_via?(Eco::API::UseCases::GraphQL::Base, __method__)
|
20
|
+
raise NotImplementedMethod, "You need to inherit from this class ('#{self.class}')"
|
19
21
|
end
|
20
22
|
end
|
@@ -2,6 +2,9 @@ module Eco::API::UseCases::GraphQL::Helpers::Base
|
|
2
2
|
# Basic stuff you would need in any use case
|
3
3
|
module CaseEnv
|
4
4
|
include Eco::Language::AuxiliarLogger
|
5
|
+
|
6
|
+
private
|
7
|
+
|
5
8
|
attr_reader :session, :options
|
6
9
|
|
7
10
|
def config
|
@@ -9,7 +12,7 @@ module Eco::API::UseCases::GraphQL::Helpers::Base
|
|
9
12
|
end
|
10
13
|
|
11
14
|
def simulate?
|
12
|
-
options
|
15
|
+
options[:simulate]
|
13
16
|
end
|
14
17
|
end
|
15
18
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Eco::API::UseCases::GraphQL::Helpers::Base
|
2
|
+
# Basic stuff you would need in any use case
|
3
|
+
module GraphQLEnv
|
4
|
+
include CaseEnv
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def graphql
|
9
|
+
msg = "The credentials or basic graphql config are missing for the active environment"
|
10
|
+
raise msg unless session.api?(version: :graphql)
|
11
|
+
@graphql ||= session.api(version: :graphql)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module Eco::API::UseCases::GraphQL::Helpers
|
2
2
|
module Base
|
3
3
|
require_relative 'base/case_env'
|
4
|
-
|
4
|
+
require_relative 'base/graphql_env'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
include CaseEnv
|
7
|
+
include GraphQLEnv
|
8
|
+
|
9
|
+
private
|
9
10
|
|
10
11
|
# Keep a copy of the requests/responses for future reference
|
11
12
|
def backup(data, type:)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Eco::API::UseCases::GraphQL::Helpers::Location
|
2
|
+
module Base
|
3
|
+
module ClassificationsParser
|
4
|
+
include Eco::API::UseCases::GraphQL::Helpers::Base::CaseEnv
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
# @note
|
9
|
+
# 1. It returns `nil` unless there are classifications defined
|
10
|
+
# 2. If the value is wrong, it warns and returns `nil`
|
11
|
+
def to_classification(value)
|
12
|
+
return nil unless node_classifications?
|
13
|
+
raise ArgumentError, "Expecting a single element. Given: #{value.class}" if value.is_a?(Enumerator)
|
14
|
+
return nil unless value.is_a?(String)
|
15
|
+
|
16
|
+
node_classifications.to_id(value).tap do |type|
|
17
|
+
unknown_clasification!(value) unless type
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_classification_ids(values)
|
22
|
+
values = [values].flatten unless values.is_a?(Array)
|
23
|
+
values.compact.map {|val| to_classification(val)}.compact
|
24
|
+
end
|
25
|
+
|
26
|
+
# @note
|
27
|
+
# 1. It returns `nil` unless there are classifications defined
|
28
|
+
# 2. If the value is wrong, it warns and returns `nil`
|
29
|
+
def to_classification_name(value)
|
30
|
+
return nil unless node_classifications?
|
31
|
+
raise ArgumentError, "Expecting a single element. Given: #{value.class}" if value.is_a?(Enumerator)
|
32
|
+
return nil unless value.is_a?(String)
|
33
|
+
|
34
|
+
node_classifications.to_name(value) do |name|
|
35
|
+
unknown_clasification!(value) unless name
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def node_classifications?
|
40
|
+
node_classifications.any?
|
41
|
+
end
|
42
|
+
|
43
|
+
def node_classifications
|
44
|
+
@node_classifications ||= session.node_classifications
|
45
|
+
end
|
46
|
+
|
47
|
+
def unknown_clasification!(value)
|
48
|
+
return if unknown_classifications.include?(value)
|
49
|
+
unknown_classifications << value
|
50
|
+
log(:warn) {
|
51
|
+
"Unknown location node classification '#{value}'"
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def unknown_classifications
|
56
|
+
@unknown_classifications ||= []
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|