eco-helpers 1.5.1 → 1.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +114 -2
- data/LICENSE +21 -0
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api.rb +2 -0
- data/lib/eco/api/common.rb +4 -0
- data/lib/eco/api/common/base_loader.rb +54 -0
- data/lib/eco/api/common/class_auto_loader.rb +109 -0
- data/lib/eco/api/common/class_helpers.rb +33 -0
- data/lib/eco/api/common/class_hierarchy.rb +1 -1
- data/lib/eco/api/common/class_meta_basics.rb +16 -0
- data/lib/eco/api/common/loaders.rb +13 -0
- data/lib/eco/api/common/loaders/error_handler.rb +41 -0
- data/lib/eco/api/common/loaders/parser.rb +127 -0
- data/lib/eco/api/common/loaders/policy.rb +25 -0
- data/lib/eco/api/common/loaders/use_case.rb +40 -0
- data/lib/eco/api/common/people/default_parsers.rb +3 -12
- data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +13 -23
- data/lib/eco/api/common/people/default_parsers/csv_parser.rb +20 -35
- data/lib/eco/api/common/people/default_parsers/date_parser.rb +15 -26
- data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +15 -25
- data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +26 -0
- data/lib/eco/api/common/people/default_parsers/multi_parser.rb +15 -27
- data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +14 -19
- data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +24 -35
- data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +15 -25
- data/lib/eco/api/common/people/entries.rb +54 -24
- data/lib/eco/api/common/people/entry_factory.rb +10 -8
- data/lib/eco/api/common/people/person_attribute_parser.rb +29 -12
- data/lib/eco/api/common/people/person_entry.rb +308 -216
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +3 -2
- data/lib/eco/api/common/people/person_parser.rb +51 -18
- data/lib/eco/api/common/session/logger.rb +4 -0
- data/lib/eco/api/common/version_patches.rb +1 -0
- data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +2 -0
- data/lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb +1 -1
- data/lib/eco/api/common/version_patches/exception.rb +22 -0
- data/lib/eco/api/common/version_patches/object.rb +10 -0
- data/lib/eco/api/custom.rb +13 -0
- data/lib/eco/api/custom/error_handler.rb +20 -0
- data/lib/eco/api/custom/namespace.rb +7 -0
- data/lib/eco/api/custom/parser.rb +50 -0
- data/lib/eco/api/custom/policy.rb +28 -0
- data/lib/eco/api/custom/use_case.rb +16 -0
- data/lib/eco/api/error.rb +1 -0
- data/lib/eco/api/error/handlers.rb +10 -3
- data/lib/eco/api/microcases.rb +17 -13
- data/lib/eco/api/microcases/account_excluded.rb +24 -0
- data/lib/eco/api/microcases/append_usergroups.rb +19 -0
- data/lib/eco/api/microcases/core_excluded.rb +4 -4
- data/lib/eco/api/microcases/{set_default_group.rb → fix_default_group.rb} +10 -9
- data/lib/eco/api/microcases/fix_filter_tags.rb +26 -6
- data/lib/eco/api/microcases/people_cache.rb +17 -0
- data/lib/eco/api/microcases/people_load.rb +59 -0
- data/lib/eco/api/microcases/people_refresh.rb +31 -0
- data/lib/eco/api/microcases/people_search.rb +65 -0
- data/lib/eco/api/microcases/refresh_abilities.rb +19 -0
- data/lib/eco/api/microcases/refresh_default_tag.rb +27 -0
- data/lib/eco/api/microcases/s3upload_targets.rb +39 -0
- data/lib/eco/api/microcases/set_account.rb +7 -19
- data/lib/eco/api/microcases/set_core.rb +5 -5
- data/lib/eco/api/microcases/set_core_with_supervisor.rb +23 -0
- data/lib/eco/api/microcases/set_supervisor.rb +17 -13
- data/lib/eco/api/microcases/strict_search.rb +12 -7
- data/lib/eco/api/microcases/with_each.rb +27 -0
- data/lib/eco/api/microcases/with_each_leaver.rb +24 -0
- data/lib/eco/api/microcases/with_each_present.rb +30 -0
- data/lib/eco/api/microcases/with_each_starter.rb +30 -0
- data/lib/eco/api/microcases/with_each_subordinate.rb +34 -0
- data/lib/eco/api/microcases/with_supervisor.rb +36 -0
- data/lib/eco/api/organization/people.rb +72 -35
- data/lib/eco/api/organization/presets_factory.rb +13 -4
- data/lib/eco/api/policies.rb +11 -7
- data/lib/eco/api/session.rb +54 -24
- data/lib/eco/api/session/batch.rb +1 -1
- data/lib/eco/api/session/batch/base_policy.rb +7 -6
- data/lib/eco/api/session/batch/errors.rb +28 -4
- data/lib/eco/api/session/batch/feedback.rb +7 -1
- data/lib/eco/api/session/batch/job.rb +40 -23
- data/lib/eco/api/session/batch/jobs.rb +9 -4
- data/lib/eco/api/session/batch/jobs_groups.rb +1 -1
- data/lib/eco/api/session/batch/request_stats.rb +95 -58
- data/lib/eco/api/session/batch/status.rb +35 -31
- data/lib/eco/api/session/config.rb +104 -42
- data/lib/eco/api/session/config/api.rb +17 -6
- data/lib/eco/api/session/config/logger.rb +2 -2
- data/lib/eco/api/session/config/post_launch.rb +1 -1
- data/lib/eco/api/session/config/workflow.rb +8 -7
- data/lib/eco/api/usecases.rb +47 -33
- data/lib/eco/api/usecases/backup/append_usergroups_case.rb +36 -0
- data/lib/eco/api/usecases/backup/create_case.rb +104 -0
- data/lib/eco/api/usecases/backup/create_details_case.rb +31 -0
- data/lib/eco/api/usecases/backup/create_details_with_supervisor_case.rb +48 -0
- data/lib/eco/api/usecases/backup/hris_case.rb +124 -0
- data/lib/eco/api/usecases/backup/set_default_tag_case.rb +49 -0
- data/lib/eco/api/usecases/backup/set_supervisor_case.rb +41 -0
- data/lib/eco/api/usecases/backup/transfer_account_case.rb +90 -0
- data/lib/eco/api/usecases/backup/update_case.rb +112 -0
- data/lib/eco/api/usecases/backup/update_details_case.rb +64 -0
- data/lib/eco/api/usecases/backup/upsert_case.rb +114 -0
- data/lib/eco/api/usecases/base_case.rb +2 -0
- data/lib/eco/api/usecases/base_io.rb +3 -3
- data/lib/eco/api/usecases/default_cases.rb +23 -53
- data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +10 -31
- data/lib/eco/api/usecases/default_cases/change_email_case.rb +23 -47
- data/lib/eco/api/usecases/default_cases/codes_to_tags_case.rb +56 -43
- data/lib/eco/api/usecases/default_cases/create_case.rb +15 -101
- data/lib/eco/api/usecases/default_cases/create_details_case.rb +11 -26
- data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +12 -43
- data/lib/eco/api/usecases/default_cases/delete_sync_case.rb +11 -0
- data/lib/eco/api/usecases/default_cases/delete_trans_case.rb +14 -0
- data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +10 -21
- data/lib/eco/api/usecases/default_cases/hris_case.rb +23 -120
- data/lib/eco/api/usecases/default_cases/new_email_case.rb +10 -23
- data/lib/eco/api/usecases/default_cases/new_id_case.rb +11 -25
- data/lib/eco/api/usecases/default_cases/new_id_case0.rb +14 -0
- data/lib/eco/api/usecases/default_cases/org_data_convert_case.rb +101 -0
- data/lib/eco/api/usecases/default_cases/refresh_abilities_case.rb +30 -0
- data/lib/eco/api/usecases/default_cases/refresh_case.rb +7 -20
- data/lib/eco/api/usecases/default_cases/reinvite_sync_case.rb +11 -0
- data/lib/eco/api/usecases/default_cases/reinvite_trans_case.rb +17 -0
- data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +11 -0
- data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +17 -0
- data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +9 -19
- data/lib/eco/api/usecases/default_cases/restore_db_case.rb +104 -0
- data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +32 -40
- data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +15 -33
- data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +66 -57
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +36 -44
- data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +40 -55
- data/lib/eco/api/usecases/default_cases/transfer_account_case.rb +264 -84
- data/lib/eco/api/usecases/default_cases/update_case.rb +15 -109
- data/lib/eco/api/usecases/default_cases/update_details_case.rb +14 -61
- data/lib/eco/api/usecases/default_cases/upsert_case.rb +16 -111
- data/lib/eco/api/usecases/use_case.rb +1 -1
- data/lib/eco/api/usecases/use_case_io.rb +9 -10
- data/lib/eco/cli/config.rb +10 -2
- data/lib/eco/cli/config/default.rb +2 -1
- data/lib/eco/cli/config/default/input_filters.rb +58 -0
- data/lib/eco/cli/config/default/options.rb +60 -25
- data/lib/eco/cli/config/default/people.rb +4 -4
- data/lib/eco/cli/config/default/people_filters.rb +108 -0
- data/lib/eco/cli/config/default/usecases.rb +89 -31
- data/lib/eco/cli/config/default/workflow.rb +37 -27
- data/lib/eco/cli/config/filters.rb +50 -0
- data/lib/eco/cli/config/filters/input_filters.rb +29 -0
- data/lib/eco/cli/config/filters/people_filters.rb +29 -0
- data/lib/eco/cli/config/help.rb +49 -0
- data/lib/eco/cli/config/options_set.rb +17 -1
- data/lib/eco/cli/config/use_cases.rb +79 -53
- data/lib/eco/cli/scripting.rb +10 -2
- data/lib/eco/cli/scripting/args_helpers.rb +25 -15
- data/lib/eco/cli/scripting/argument.rb +1 -0
- data/lib/eco/cli/scripting/arguments.rb +1 -1
- data/lib/eco/csv/table.rb +1 -1
- data/lib/eco/data/crypto/encryption.rb +3 -0
- data/lib/eco/language/match.rb +19 -9
- data/lib/eco/language/match_modifier.rb +13 -5
- data/lib/eco/language/models/collection.rb +77 -56
- data/lib/eco/language/models/parser_serializer.rb +39 -15
- data/lib/eco/version.rb +1 -1
- metadata +64 -18
- data/lib/eco/api/microcases/set_default_tag.rb +0 -23
- data/lib/eco/api/session/task.rb +0 -175
- data/lib/eco/api/usecases/default_case.rb +0 -19
- data/lib/eco/api/usecases/default_cases/delete_case.rb +0 -32
- data/lib/eco/api/usecases/default_cases/recover_db_case.rb +0 -99
- data/lib/eco/api/usecases/default_cases/refresh_presets_case.rb +0 -26
- data/lib/eco/api/usecases/default_cases/reinvite_case.rb +0 -41
- data/lib/eco/api/usecases/default_cases/remove_account_case.rb +0 -38
- data/lib/eco/api/usecases/microed_cases/hris_case.rb +0 -53
- data/lib/eco/api/usecases/microed_cases/update_case.rb +0 -33
- data/lib/eco/api/usecases/microed_cases/update_details_case.rb +0 -30
- data/lib/eco/api/usecases/microed_cases/upsert_case.rb +0 -36
- data/lib/eco/cli/config/default/filters.rb +0 -70
- data/lib/eco/cli/config/people_filters.rb +0 -38
data/lib/eco/api/microcases.rb
CHANGED
@@ -1,17 +1,6 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
3
|
class MicroCases < Eco::API::Common::Session::BaseSession
|
4
|
-
class << self
|
5
|
-
def define(name, &block)
|
6
|
-
name = name.to_sym
|
7
|
-
@helpers[name] = block
|
8
|
-
define_method(name.to_sym, &block)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def define(*args)
|
13
|
-
self.class.define(*args)
|
14
|
-
end
|
15
4
|
|
16
5
|
def micro
|
17
6
|
self
|
@@ -21,11 +10,26 @@ module Eco
|
|
21
10
|
end
|
22
11
|
end
|
23
12
|
|
13
|
+
require_relative 'microcases/account_excluded'
|
14
|
+
require_relative 'microcases/append_usergroups'
|
24
15
|
require_relative 'microcases/core_excluded'
|
16
|
+
require_relative 'microcases/fix_default_group'
|
25
17
|
require_relative 'microcases/fix_filter_tags'
|
18
|
+
require_relative 'microcases/people_cache'
|
19
|
+
require_relative 'microcases/people_load'
|
20
|
+
require_relative 'microcases/people_refresh'
|
21
|
+
require_relative 'microcases/people_search'
|
22
|
+
require_relative 'microcases/refresh_abilities'
|
26
23
|
require_relative 'microcases/set_account'
|
24
|
+
require_relative 'microcases/set_core_with_supervisor'
|
27
25
|
require_relative 'microcases/set_core'
|
28
|
-
require_relative 'microcases/
|
29
|
-
require_relative 'microcases/set_default_tag'
|
26
|
+
require_relative 'microcases/refresh_default_tag'
|
30
27
|
require_relative 'microcases/set_supervisor'
|
31
28
|
require_relative 'microcases/strict_search'
|
29
|
+
require_relative 'microcases/s3upload_targets'
|
30
|
+
require_relative 'microcases/with_each'
|
31
|
+
require_relative 'microcases/with_each_leaver'
|
32
|
+
require_relative 'microcases/with_each_present'
|
33
|
+
require_relative 'microcases/with_each_starter'
|
34
|
+
require_relative 'microcases/with_each_subordinate'
|
35
|
+
require_relative 'microcases/with_supervisor'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
5
|
+
# @param options [Hash] the options.
|
6
|
+
# @return [Array<String>] the account parameters that should not be included.
|
7
|
+
def account_excluded(person, options)
|
8
|
+
[].tap do |account_excluded|
|
9
|
+
unless person.new?
|
10
|
+
if options.dig(:exclude, :policy_groups)
|
11
|
+
account_excluded.push("policy_group_ids")
|
12
|
+
end
|
13
|
+
if options.dig(:exclude, :default_tag)
|
14
|
+
account_excluded.push("default_tag")
|
15
|
+
end
|
16
|
+
if options.dig(:exclude, :login_providers)
|
17
|
+
account_excluded.push("login_provider_ids")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# It preserves the usergroups of `person` and appends those defined in `policy_group_ids` of the `entry`
|
5
|
+
# @param entry [PersonEntry] the input entry with the data we should set on person.
|
6
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
7
|
+
# @param options [Hash] the options.
|
8
|
+
def append_usergroups(entry, person, options)
|
9
|
+
unless options.dig(:exclude, :account)
|
10
|
+
if person.account
|
11
|
+
person.account.policy_group_ids |= entry.policy_group_ids
|
12
|
+
micro.refresh_abilities(person, options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
3
|
class MicroCases
|
4
|
-
#
|
5
|
-
|
6
|
-
# @param
|
7
|
-
# @
|
4
|
+
# @note by default `supervisor_id` is always excluded.
|
5
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
6
|
+
# @param options [Hash] the options.
|
7
|
+
# @return [Array<String>] the core parameters that should not be included.
|
8
8
|
def core_excluded(person, options)
|
9
9
|
["supervisor_id"].tap do |core_excluded|
|
10
10
|
unless person.new?
|
@@ -1,20 +1,19 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
3
|
class MicroCases
|
4
|
-
#
|
5
|
-
|
4
|
+
# If defined, it sets the default usergroup, only when the `policy_group_ids` was not part of the input data.
|
6
5
|
# @param entry [PersonEntry] the input entry with the data we should set on person.
|
7
|
-
# @param person [Person] the person we want to update, carrying the changes to be done.
|
8
|
-
# @param options [Hash] the options
|
9
|
-
def
|
6
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
7
|
+
# @param options [Hash] the options.
|
8
|
+
def fix_default_group(entry, person, options)
|
10
9
|
unless options.dig(:exclude, :account)
|
11
10
|
unless options.dig(:exclude, :policy_groups) && !person.new?
|
12
|
-
end_pg_ids = person.account.policy_group_ids
|
11
|
+
end_pg_ids = person.account.policy_group_ids
|
13
12
|
|
14
|
-
if person.account_added? &&
|
13
|
+
if person.account_added? && __def_usergroup_id && !entry.policy_group_ids?
|
15
14
|
# on account creation, if missing policy_group_ids column in the input
|
16
15
|
# use default_usergroup, if it's defined
|
17
|
-
end_pg_ids = [
|
16
|
+
end_pg_ids = [__def_usergroup_id]
|
18
17
|
end
|
19
18
|
|
20
19
|
person.account.policy_group_ids = end_pg_ids
|
@@ -22,7 +21,9 @@ module Eco
|
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
25
|
-
|
24
|
+
private
|
25
|
+
|
26
|
+
def __def_usergroup_id
|
26
27
|
@def_usergroup_id ||= if session.config.people.default_usergroup?
|
27
28
|
session.policy_groups.to_id(session.config.people.default_usergroup)
|
28
29
|
end
|
@@ -1,22 +1,42 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
3
|
class MicroCases
|
4
|
-
#
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
4
|
+
# Helper that makes sure the **custom `tags`** are preserved.
|
5
|
+
# @note
|
6
|
+
# - this feature is essential to preserve custom `tags` in users that have register tags.
|
7
|
+
# - for this to work out, it requires a `tagtree` to be defined.
|
8
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes already done.
|
9
|
+
# @param options [Hash] the options.
|
10
|
+
# @option options [Hash<Symbol, Object>] :filter_tags options around `filter_tags`.
|
11
|
+
# * `:preserve_custom` (Boolean) [true] indicates if original tags that are not in the tree should be added/preserved.
|
12
|
+
# * `:add_custom` (Boolean) [true] indicates if target tags that are not in the tree should be really added.
|
8
13
|
def fix_filter_tags(person, options)
|
9
14
|
if session.tagtree
|
10
15
|
unless !person.new? && (options.dig(:exclude, :core) || options.dig(:exclude, :filter_tags))
|
11
16
|
person.filter_tags = session.tagtree.user_tags(
|
12
17
|
initial: person.original_doc["filter_tags"] || [],
|
13
18
|
final: person.filter_tags,
|
14
|
-
preserve_custom:
|
15
|
-
add_custom:
|
19
|
+
preserve_custom: _fix_filter_tags_preserve_custom?(options),
|
20
|
+
add_custom: _fix_filter_tags_add_custom?(options)
|
16
21
|
)
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# default `true`
|
29
|
+
def _fix_filter_tags_preserve_custom?(options)
|
30
|
+
key_defined = options.key?(:filter_tags) && options[:filter_tags].key?(:preserve_custom)
|
31
|
+
!key_defined || options.dig(:filter_tags, :preserve_custom)
|
32
|
+
end
|
33
|
+
|
34
|
+
# default `true`
|
35
|
+
def _fix_filter_tags_add_custom?(options)
|
36
|
+
key_defined = options.key?(:filter_tags) && options[:filter_tags].key?(:add_custom)
|
37
|
+
!key_defined || options.dig(:filter_tags, :add_custom)
|
38
|
+
end
|
39
|
+
|
20
40
|
end
|
21
41
|
end
|
22
42
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# Helper to locally cache the people manager.
|
5
|
+
# @param filename [String] the name of the file where the data should be cached.
|
6
|
+
# @return [Eco::API::Organization::People] the `People` object with the data.
|
7
|
+
def people_cache(filename = enviro.config.people.cache)
|
8
|
+
logger.info("Going to get all the people via API")
|
9
|
+
people = session.batch.get_people
|
10
|
+
file = file_manager.save_json(people, filename, :timestamp)
|
11
|
+
logger.info("#{people.length} people loaded and saved locally to #{file}.")
|
12
|
+
Eco::API::Organization::People.new(people)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# Helper to load `People` that works in different phases:
|
5
|
+
# 1. first tries to get the newest cached file that follows `filename` pattern
|
6
|
+
# - if not the newest, it tries to find the specific filename
|
7
|
+
# 2. if it succeeds to identif a cached file, it loads it
|
8
|
+
# - if it fails, it tries to get people from the server
|
9
|
+
# @note
|
10
|
+
# - `filename` will be relative to the working directory (the one of the session `enviro` set by the user).
|
11
|
+
# @param filename [String] the name of the file where the cached data is to be found.
|
12
|
+
# @param modifier [Array<Symbol>] modifiers to specify how this function should proceed:
|
13
|
+
# - `:newest` if it should try to find the newest file (pattern alike).
|
14
|
+
# - `:api` if it should try to get people from the server in case there's no cache.
|
15
|
+
# - `:file` if it is supposed to load people from a file.
|
16
|
+
# - `:save` if it is supposed to cache/save the data locally once obtained people from the server (`:api`)
|
17
|
+
# @return [Eco::API::Organization::People] the `People` object with the data.
|
18
|
+
def people_load(filename = enviro.config.people.cache, modifier: [:newest, :api])
|
19
|
+
modifier = [modifier].flatten
|
20
|
+
load_file = [:file, :newest].any? {|flag| modifier.include?(flag)}
|
21
|
+
people = case
|
22
|
+
when filename && load_file
|
23
|
+
if file = people_load_filename(filename, newest: modifier.include?(:newest))
|
24
|
+
file_manager.load_json(file).tap do |people|
|
25
|
+
logger.info("#{people&.length} people loaded from file #{file}") if people.is_a?(Array)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
logger.error("could not find the file #{file_manager.dir.file(filename)}")
|
29
|
+
exit unless modifier.include?(:api)
|
30
|
+
people_load(modifier: modifier - [:newest, :file])
|
31
|
+
end
|
32
|
+
when modifier.include?(:api)
|
33
|
+
logger.info("Going to get all the people via API")
|
34
|
+
session.batch.get_people.tap do |people|
|
35
|
+
if modifier.include?(:save) && people && people.length > 0
|
36
|
+
file = file_manager.save_json(people, filename, :timestamp)
|
37
|
+
logger.info("#{people.length } people saved to file #{file}.")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
Eco::API::Organization::People.new(people)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def people_load_filename(filename, newest: false)
|
47
|
+
if newest
|
48
|
+
# search input file based on pattern (in case the name has a timestamp)
|
49
|
+
file_manager.dir.newest_file(file: filename).tap do |file|
|
50
|
+
logger.info("previous file found: #{file}") if file
|
51
|
+
end
|
52
|
+
else
|
53
|
+
file_manager.dir.file(filename, should_exist: true)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# Helper to obtain all the elements of `people` anew from the _People Manager_.
|
5
|
+
# @note this helper is normally used to run consecutive usecases, where data needs refresh.
|
6
|
+
# @param people [Eco::API::Organization::People] the people that needs refresh.
|
7
|
+
# @param include_created [Boolean] include people created during this session? (will check `:create` batch jobs).
|
8
|
+
# @return [Eco::API::Organization::People] the `People` object with the data.
|
9
|
+
def people_refresh(people:, include_created: true)
|
10
|
+
ini = people.length
|
11
|
+
if include_created
|
12
|
+
session.job_groups.find_jobs(type: :create).map do |job|
|
13
|
+
people = people.merge(job.people)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
created = people.length - ini
|
18
|
+
msg = "Going to refresh #{people.length} people with server data"
|
19
|
+
msg += " (including #{created} that were created)" if created > 0
|
20
|
+
logger.info(msg)
|
21
|
+
entries = session.batch.get_people(people, silent: true)
|
22
|
+
|
23
|
+
missing = people.length - entries.length
|
24
|
+
logger.error("Missed to obtain #{missing} people during the refresh") if missing > 0
|
25
|
+
|
26
|
+
Eco::API::Organization::People.new(entries)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# Helper to search/obtain people from `data` against the server (_People Manager_).
|
5
|
+
# @note
|
6
|
+
# - this helper is normally used to **get partial** part of the people manager.
|
7
|
+
# - therefore, normally used with _**delta** input files_ (files with only the differences).
|
8
|
+
# @param data [Eco::API::Organization::People, Enumerable<Person>, Enumerable<Hash>] `People` to search against the server.
|
9
|
+
# @param options [Hash] the options.
|
10
|
+
# @param silent [Boolean] `false` if low level search messages should be shown.
|
11
|
+
# @return [Eco::API::Organization::People] the `People` object with the found persons.
|
12
|
+
def people_search(data, options: {}, silent: true)
|
13
|
+
session.logger.info("Going to api get #{data.length} entries...")
|
14
|
+
status = session.batch.search(data, silent: silent)
|
15
|
+
people = Eco::API::Organization::People.new(status.people)
|
16
|
+
session.logger.info("... could get #{people.length} people (out of #{data.length} entries)")
|
17
|
+
|
18
|
+
# get the supervisors of found people (current supervisors)
|
19
|
+
supers = people_search_prepare_supers_request(people)
|
20
|
+
if supers.length > 0
|
21
|
+
session.logger.info(" Going to api get #{supers.length} current supervisors...")
|
22
|
+
status = session.batch.search(supers, silent: silent)
|
23
|
+
people = people.merge(status.people, strict: micro.strict_search?(options))
|
24
|
+
end
|
25
|
+
|
26
|
+
# get the supervisors referred in the input data (future supervisors)
|
27
|
+
supers = people_search_prepare_supers_request(data, people)
|
28
|
+
if supers.length > 0
|
29
|
+
session.logger.info(" Going to api get #{supers.length} supervisors as per entries...")
|
30
|
+
status = session.batch.search(supers, silent: silent)
|
31
|
+
people = people.merge(status.people, strict: micro.strict_search?(options))
|
32
|
+
end
|
33
|
+
|
34
|
+
session.logger.info("Finally got #{people.length} people (out of #{data.length} entries)")
|
35
|
+
people
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# Prepares a unique request with only the supervisor ids missing in `people`
|
41
|
+
def people_search_prepare_supers_request(data, people = data)
|
42
|
+
data.each_with_object([]) do |entry, request|
|
43
|
+
spr = {"id" => (sup_id = people_search_super_id(entry))}
|
44
|
+
unless !sup_id || request.include?(spr)
|
45
|
+
micro.with_supervisor(sup_id, people) do |supervisor|
|
46
|
+
request.push(spr) unless supervisor
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Gets the `supervisor_id` from `value`
|
53
|
+
def people_search_super_id(value)
|
54
|
+
sup_id = if value.respond_to?(:supervisor_id)
|
55
|
+
value.supervisor_id
|
56
|
+
elsif value.is_a?(Hash) && value.key("supervisor_id")
|
57
|
+
value["supervisor_id"]
|
58
|
+
end
|
59
|
+
sup_id = nil if sup_id.to_s.strip.empty?
|
60
|
+
sup_id
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# It sets the correct set of abilities based on the usergroups of `person`.
|
5
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
6
|
+
# @param options [Hash] the options.
|
7
|
+
def refresh_abilities(person, options)
|
8
|
+
unless options.dig(:exclude, :account)
|
9
|
+
if person.account
|
10
|
+
unless options.dig(:exclude, :abilities) && !person.new?
|
11
|
+
person.account.permissions_custom = session.new_preset(person)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# When the input data, or `entry`, does not provide the `default_tag`,
|
5
|
+
# it sets the `default_tag` of the user following some criteria
|
6
|
+
# @note it assumes `default_tag` has been already set to `person.account`
|
7
|
+
# @param entry [PersonEntry] the input entry with the data we should set on person.
|
8
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
9
|
+
# @param options [Hash] the options
|
10
|
+
def refresh_default_tag(entry, person, options)
|
11
|
+
if person.account
|
12
|
+
unless options.dig(:exclude, :account)
|
13
|
+
unless options.dig(:exclude, :filter_tags) || options.dig(:exclude, :default_tag) || entry&.default_tag?
|
14
|
+
if session.tagtree
|
15
|
+
person.account.default_tag = session.tagtree.default_tag(*person.filter_tags)
|
16
|
+
else
|
17
|
+
tags = person.filter_tags || []
|
18
|
+
person.account.default_tag = tags.first unless tags.length > 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# Helper to upload target files to `S3`.
|
5
|
+
# @return [Array<String>] the paths in `S3` of the uploaded files.
|
6
|
+
def s3upload_targets
|
7
|
+
[].tap do |paths|
|
8
|
+
session.config.s3storage.target_files.each_with_object(paths) do |file, arr|
|
9
|
+
arr.push(session.s3upload(file: file))
|
10
|
+
end
|
11
|
+
session.config.s3storage.target_directories.each_with_object(paths) do |folder, arr|
|
12
|
+
arr.concat(session.s3upload(directory: folder))
|
13
|
+
end
|
14
|
+
session.config.s3storage.target_file_patterns.each_with_object(paths) do |pattern, arr|
|
15
|
+
filenames = []
|
16
|
+
case pattern
|
17
|
+
when Regexp
|
18
|
+
Dir.entries(".").sort.each do |file|
|
19
|
+
next unless File.file?(file) # Skip directories
|
20
|
+
filenames.push(file) if file =~ pattern
|
21
|
+
end
|
22
|
+
when String
|
23
|
+
Dir.glob(pattern).sort.each do |file|
|
24
|
+
next unless File.file?(file) # Skip directories
|
25
|
+
filenames.push(file)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
# missconfiguration
|
29
|
+
end
|
30
|
+
filenames.each do |file|
|
31
|
+
arr.push(session.s3upload(file: file))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|