eco-helpers 1.5.0 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +147 -2
- data/LICENSE +21 -0
- data/eco-helpers.gemspec +11 -10
- data/lib/eco/api.rb +3 -0
- data/lib/eco/api/common.rb +5 -1
- 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 +5 -10
- 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 +20 -0
- 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 +31 -0
- data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +15 -24
- data/lib/eco/api/common/people/entries.rb +54 -24
- data/lib/eco/api/common/people/entry_factory.rb +18 -15
- 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 +5 -2
- data/lib/eco/api/common/people/person_parser.rb +52 -19
- data/lib/eco/api/common/session/base_session.rb +3 -6
- data/lib/eco/api/common/session/environment.rb +2 -23
- 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 +9 -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 +35 -0
- 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 +20 -0
- data/lib/eco/api/microcases/fix_default_group.rb +34 -0
- data/lib/eco/api/microcases/fix_filter_tags.rb +42 -0
- 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 +20 -0
- data/lib/eco/api/microcases/set_core.rb +18 -0
- data/lib/eco/api/microcases/set_core_with_supervisor.rb +23 -0
- data/lib/eco/api/microcases/set_supervisor.rb +30 -0
- data/lib/eco/api/microcases/strict_search.rb +19 -0
- 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/organization/presets_values.json +1 -0
- data/lib/eco/api/policies.rb +11 -7
- data/lib/eco/api/session.rb +62 -29
- data/lib/eco/api/session/batch.rb +2 -45
- 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 +106 -44
- data/lib/eco/api/session/config/api.rb +132 -7
- data/lib/eco/api/session/config/apis.rb +24 -25
- 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 +83 -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 +92 -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_io.rb +9 -9
- 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 +69 -32
- 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 +149 -62
- 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 -98
- 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/cli/config/default/filters.rb +0 -70
- data/lib/eco/cli/config/people_filters.rb +0 -38
@@ -26,17 +26,24 @@ module Eco
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def add(name, key:, host:, version: :internal, mode: :local)
|
29
|
+
def add(name, key:, host:, version: :internal, mode: :local, user_key: nil, external_key: nil)
|
30
30
|
apis[name] = Session::Config::Api.new(
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
name,
|
32
|
+
key: key,
|
33
|
+
host: host,
|
34
|
+
version: version,
|
35
|
+
mode: mode,
|
36
|
+
root: self,
|
37
|
+
user_key: user_key,
|
38
|
+
external_key: external_key
|
36
39
|
)
|
37
40
|
self
|
38
41
|
end
|
39
42
|
|
43
|
+
def active_api
|
44
|
+
self["active-api"]
|
45
|
+
end
|
46
|
+
|
40
47
|
def active_name=(name)
|
41
48
|
raise "'#{name}' Api environment not defined" if !apis[name]
|
42
49
|
self["active-name"] = name
|
@@ -53,34 +60,26 @@ module Eco
|
|
53
60
|
active_name
|
54
61
|
end
|
55
62
|
|
56
|
-
def active_api
|
57
|
-
self["active-api"]
|
58
|
-
end
|
59
|
-
|
60
63
|
def service_up?
|
61
|
-
|
62
|
-
@api_test ||= api_klass.new("foobar", host: active_api.host, logger: ::Logger.new(IO::NULL))
|
64
|
+
@api_test ||= Session::Config::Api.api_class(active_api.version).new("foobar", host: active_api.host, logger: ::Logger.new(IO::NULL))
|
63
65
|
status = @api_test.client.get("/policy_groups").status
|
64
66
|
# 401 Unauthorized "Permission denied. API key may be invalid."
|
65
67
|
status == 401
|
66
68
|
end
|
67
69
|
|
68
|
-
def api(logger = ::Logger.new(IO::NULL),
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
version
|
73
|
-
|
74
|
-
|
75
|
-
api_klass = (version == :external)? Ecoportal::API::External : Ecoportal::API::Internal
|
70
|
+
def api(logger = ::Logger.new(IO::NULL), version: nil)
|
71
|
+
unless active_api
|
72
|
+
raise "There's no 'active_api'. Use apis.active_name='api_enviro_name' to set the active api"
|
73
|
+
end
|
74
|
+
active_api.api(version: version, logger: logger)
|
75
|
+
end
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
@api
|
77
|
+
def default_user_key=(key)
|
78
|
+
self["user_key"] = key
|
80
79
|
end
|
81
80
|
|
82
|
-
def
|
83
|
-
|
81
|
+
def default_user_key
|
82
|
+
self["user_key"]
|
84
83
|
end
|
85
84
|
|
86
85
|
end
|
@@ -7,9 +7,10 @@ module Eco
|
|
7
7
|
|
8
8
|
WORKFLOW_MODEL = [
|
9
9
|
:options,
|
10
|
-
{load: [:
|
10
|
+
{load: [{input: [:get, :filter]}, {people: [:get, :filter]}, :filter]},
|
11
11
|
:usecases, :launch_jobs,
|
12
12
|
{post_launch: [:usecases, :launch_jobs]},
|
13
|
+
:report,
|
13
14
|
:end, :close
|
14
15
|
]
|
15
16
|
|
@@ -49,7 +50,7 @@ module Eco
|
|
49
50
|
|
50
51
|
@pending = true
|
51
52
|
# moments
|
52
|
-
@on
|
53
|
+
@on = nil
|
53
54
|
@before = []
|
54
55
|
@after = []
|
55
56
|
end
|
@@ -104,7 +105,7 @@ module Eco
|
|
104
105
|
# @yield [stage_workflow, io] the behaviour of the target stage `key` when the _workflow_ reaches it
|
105
106
|
# @yieldparam stage_workflow [Eco::API::Session::Config::Workflow] the _target stage_ referred by `key`
|
106
107
|
# @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
|
107
|
-
# @yieldreturn
|
108
|
+
# @yieldreturn [Eco::API::UseCases::BaseIO] the `io` input/output object carried througout all the _workflow_
|
108
109
|
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
|
109
110
|
def on(key = nil, &block)
|
110
111
|
raise "A block should be given." unless block
|
@@ -120,7 +121,7 @@ module Eco
|
|
120
121
|
# @yield [exception, io] the `callback` to do something with an `Exception` raised within this _workflow_ stage
|
121
122
|
# @yieldparam exception [Exception] the exception object that was raised
|
122
123
|
# @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
|
123
|
-
# @yieldreturn
|
124
|
+
# @yieldreturn [Eco::API::UseCases::BaseIO] the `io` input/output object carried througout all the _workflow_
|
124
125
|
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
|
125
126
|
def rescue(&block)
|
126
127
|
return @rescue unless block
|
@@ -138,7 +139,7 @@ module Eco
|
|
138
139
|
# @yield [stage_workflow, io] one of the things to do **before** the `on` _callback_ of the (sub)stage `key` is actually `run`
|
139
140
|
# @yieldparam stage_workflow [Eco::API::Session::Config::Workflow] the _target stage_ referred by `key`
|
140
141
|
# @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
|
141
|
-
# @yieldreturn
|
142
|
+
# @yieldreturn [Eco::API::UseCases::BaseIO] `io` the input/output object carried througout all the _workflow_
|
142
143
|
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
|
143
144
|
def before(key = nil, &block)
|
144
145
|
raise "A block should be given." unless block
|
@@ -160,7 +161,7 @@ module Eco
|
|
160
161
|
# @yield [stage_workflow, io] one of the things to do **after** the `on` _callback_ of the (sub)stage `key` is actually `run`
|
161
162
|
# @yieldparam stage_workflow [Eco::API::Session::Config::Workflow] the _target stage_ referred by `key`
|
162
163
|
# @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
|
163
|
-
# @yieldreturn
|
164
|
+
# @yieldreturn [Eco::API::UseCases::BaseIO] `io` the input/output object carried througout all the _workflow_
|
164
165
|
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
|
165
166
|
def after(key = nil, &block)
|
166
167
|
raise "A block should be given." unless block
|
@@ -191,7 +192,7 @@ module Eco
|
|
191
192
|
# @yield [stage_workflow, io] if a `block` is provided, see `note`
|
192
193
|
# @yieldparam stage_workflow [Eco::API::Session::Config::Workflow] the _target stage_ referred by `key`
|
193
194
|
# @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
|
194
|
-
# @yieldreturn
|
195
|
+
# @yieldreturn [Eco::API::UseCases::BaseIO] the `io` input/output object carried througout all the _workflow_
|
195
196
|
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
|
196
197
|
def run(key = nil, io:, &block)
|
197
198
|
begin
|
data/lib/eco/api/usecases.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
3
|
class UseCases
|
4
|
+
|
4
5
|
class UnkownCase < Exception
|
5
6
|
def initialize(msg = nil, case_name: nil, type: nil)
|
6
7
|
msg ||= "Unkown case"
|
@@ -19,8 +20,12 @@ module Eco
|
|
19
20
|
|
20
21
|
end
|
21
22
|
|
23
|
+
extend Eco::API::Common::ClassAutoLoader
|
22
24
|
include Enumerable
|
23
25
|
|
26
|
+
autoloads_children_of "Eco::API::Common::Loaders::UseCase"
|
27
|
+
autoload_namespace_ignore "Eco::API"
|
28
|
+
|
24
29
|
def initialize()
|
25
30
|
@usecases = {}
|
26
31
|
@cache_init = false
|
@@ -35,38 +40,61 @@ module Eco
|
|
35
40
|
count == 0
|
36
41
|
end
|
37
42
|
|
38
|
-
def each(
|
43
|
+
def each(&block)
|
39
44
|
return to_enum(:each) unless block
|
40
45
|
items.each(&block)
|
41
46
|
end
|
42
47
|
|
43
48
|
def items
|
44
|
-
|
49
|
+
to_h.values
|
50
|
+
end
|
51
|
+
|
52
|
+
def defined?(name, type: nil)
|
53
|
+
return to_h.key?(key(name, type)) if type
|
54
|
+
name?(name)
|
55
|
+
end
|
56
|
+
|
57
|
+
def name?(name)
|
58
|
+
!!by_name[name]
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [Eco::API::UseCases::UseCase] the `name` usecase of type `type` with the defined `block`.
|
62
|
+
def define(name, type:, &block)
|
63
|
+
Eco::API::UseCases::UseCase.new(name, type: type, root: self, &block).tap do |usecase|
|
64
|
+
add(usecase)
|
65
|
+
end
|
45
66
|
end
|
46
67
|
|
68
|
+
# Adds `usecase` to the _Collection_. Before it tries to auto-load pending classes of `auto_loaded_class`.
|
69
|
+
# @param usecase [Eco::API::UseCases::UseCase] the usecase to be added.
|
47
70
|
def add(usecase)
|
48
71
|
raise "Expected Eco::API::UseCases::UseCase object. Given: #{usecase}" if !usecase || !usecase.is_a?(Eco::API::UseCases::UseCase)
|
49
72
|
name = usecase.name
|
50
73
|
type = usecase.type
|
51
74
|
puts "Warning: overriding '#{type.to_s}' case #{name}" if self.defined?(name, type: type)
|
75
|
+
to_h[key(name, type)] = usecase
|
52
76
|
@cache_init = false
|
53
|
-
@usecases[key(name, type)] = usecase
|
54
77
|
usecase
|
55
78
|
end
|
56
79
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
80
|
+
# @return [Eco::API::UseCases] a copy of instance object of `self`.
|
81
|
+
def dup
|
82
|
+
self.class.new.merge(self)
|
61
83
|
end
|
62
84
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
85
|
+
# Merges cases overriding self for exisint parsers
|
86
|
+
# @param cases [Eco::API::UseCases] the source set of cases to be merged.
|
87
|
+
# @return [Eco::API::UseCases] `self`.
|
88
|
+
def merge(cases)
|
89
|
+
return self if !cases
|
90
|
+
raise "Expected a Eco::API::UseCases object. Given #{cases.class}" if !cases.is_a?(Eco::API::UseCases)
|
67
91
|
|
68
|
-
|
69
|
-
|
92
|
+
to_h.merge!(cases.to_h).transform_values do |usecase|
|
93
|
+
usecase.root = self
|
94
|
+
end
|
95
|
+
|
96
|
+
@cache_init = false
|
97
|
+
self
|
70
98
|
end
|
71
99
|
|
72
100
|
def names
|
@@ -79,7 +107,7 @@ module Eco
|
|
79
107
|
end
|
80
108
|
|
81
109
|
def case(name, type: nil)
|
82
|
-
if type && target_case =
|
110
|
+
if type && target_case = to_h[key(name, type)]
|
83
111
|
return target_case
|
84
112
|
elsif type
|
85
113
|
raise UseCases::UnkownCase.new(case_name: name, type: type)
|
@@ -89,25 +117,10 @@ module Eco
|
|
89
117
|
cases.first
|
90
118
|
end
|
91
119
|
|
92
|
-
# merges cases overriding self for exisint parsers
|
93
|
-
def merge(cases)
|
94
|
-
return self if !cases
|
95
|
-
raise "Expected a Eco::API::UseCases object. Given #{cases.class}" if !cases.is_a?(Eco::API::UseCases)
|
96
|
-
cases_hash = cases.to_h
|
97
|
-
|
98
|
-
@usecases.merge!(cases_hash)
|
99
|
-
|
100
|
-
cases_hash.transform_values do |usecase|
|
101
|
-
usecase.root = self
|
102
|
-
end
|
103
|
-
|
104
|
-
@cache_init = false
|
105
|
-
self
|
106
|
-
end
|
107
|
-
|
108
120
|
protected
|
109
121
|
|
110
122
|
def to_h
|
123
|
+
init_caches
|
111
124
|
@usecases
|
112
125
|
end
|
113
126
|
|
@@ -119,9 +132,11 @@ module Eco
|
|
119
132
|
end
|
120
133
|
|
121
134
|
def init_caches
|
122
|
-
|
123
|
-
|
135
|
+
# first, make sure it loads pending `:custom_children` children to be loaded
|
136
|
+
re_init = self.class.autoload_children(self)
|
137
|
+
return true if @cache_init && !re_init
|
124
138
|
@by_name = @usecases.values.group_by { |usecase| usecase.name }
|
139
|
+
@cache_init = true
|
125
140
|
end
|
126
141
|
|
127
142
|
def key(name, type)
|
@@ -140,7 +155,6 @@ module Eco
|
|
140
155
|
end
|
141
156
|
|
142
157
|
require_relative 'usecases/base_case'
|
143
|
-
require_relative 'usecases/default_case'
|
144
158
|
require_relative 'usecases/use_case'
|
145
159
|
require_relative 'usecases/use_case_chain'
|
146
160
|
require_relative 'usecases/base_io'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class UseCases
|
4
|
+
class DefaultCases
|
5
|
+
class AppendUsergroupsCase < DefaultCase
|
6
|
+
|
7
|
+
def process
|
8
|
+
@cases.define("append-usergroups", type: :sync) do |entries, people, session, options, usecase|
|
9
|
+
update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account])
|
10
|
+
|
11
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
12
|
+
pgs = session.policy_groups
|
13
|
+
|
14
|
+
entries.each.with_index do |entry, i|
|
15
|
+
if person = people.find(entry, strict: strict_search)
|
16
|
+
if person.account
|
17
|
+
ini_pg_ids = person.account&.policy_group_ids || []
|
18
|
+
add = entry.internal_entry["policy_group_ids"].to_s.split("|").compact
|
19
|
+
person.account.policy_group_ids = (ini_pg_ids | add).uniq
|
20
|
+
|
21
|
+
person.account.permissions_custom = session.new_preset(person) unless options.dig(:exclude, :abilities)
|
22
|
+
update.add(person)
|
23
|
+
end
|
24
|
+
else
|
25
|
+
session.logger.error("This person does not exist: #{entry.to_s(:identify)}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class UseCases
|
4
|
+
class DefaultCases
|
5
|
+
class CreateCase < DefaultCase
|
6
|
+
|
7
|
+
def process
|
8
|
+
@cases.define("create", type: :sync) do |entries, people, session, options, usecase|
|
9
|
+
creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details, :account])
|
10
|
+
supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
|
11
|
+
|
12
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
13
|
+
pgs = session.policy_groups
|
14
|
+
|
15
|
+
if session.config.people.default_usergroup?
|
16
|
+
def_id = pgs.to_id(session.config.people.default_usergroup)
|
17
|
+
end
|
18
|
+
|
19
|
+
entries.each.with_index do |entry, i|
|
20
|
+
if person = people.find(entry, strict: strict_search)
|
21
|
+
session.logger.error("This person (id: '#{person.id}') already exists: #{entry.to_s(:identify)}")
|
22
|
+
else
|
23
|
+
person = session.new_person
|
24
|
+
core_excluded = ["supervisor_id"]
|
25
|
+
|
26
|
+
ini_tags = person.filter_tags || []
|
27
|
+
entry.set_core(person, exclude: core_excluded)
|
28
|
+
|
29
|
+
if session.tagtree
|
30
|
+
person.filter_tags = session.tagtree.user_tags(
|
31
|
+
initial: ini_tags,
|
32
|
+
final: person.filter_tags,
|
33
|
+
preserve_custom: true,
|
34
|
+
add_custom: true
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
entry.set_details(person) unless options.dig(:exclude, :details)
|
39
|
+
|
40
|
+
unless options.dig(:exclude, :account)
|
41
|
+
add_account = !person.account
|
42
|
+
ini_pg_ids = person.account&.policy_group_ids || []
|
43
|
+
|
44
|
+
account_excluded = []
|
45
|
+
account_excluded.push("policy_group_ids") if options.dig(:exclude, :policy_groups) && !create
|
46
|
+
|
47
|
+
entry.set_account(person, exclude: account_excluded)
|
48
|
+
|
49
|
+
person.account&.send_invites = options[:send_invites] if options.key?(:send_invites)
|
50
|
+
|
51
|
+
unless options.dig(:exclude, :policy_groups) && !create
|
52
|
+
end_pg_ids = person.account.policy_group_ids || []
|
53
|
+
|
54
|
+
if add_account && def_id && !entry.policy_group_ids?
|
55
|
+
# on account creation, if missing policy_group_ids column in the input
|
56
|
+
# use default_usergroup, if it's defined
|
57
|
+
end_pg_ids = [def_id]
|
58
|
+
end
|
59
|
+
|
60
|
+
# avoid false updates by preserving the original order
|
61
|
+
person.account.policy_group_ids = pgs.user_pg_ids(
|
62
|
+
initial: ini_pg_ids,
|
63
|
+
final: end_pg_ids
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
person.account.permissions_custom = session.new_preset(person)
|
68
|
+
|
69
|
+
if session.tagtree
|
70
|
+
person.account.default_tag = session.tagtree.default_tag(*person.filter_tags)
|
71
|
+
else
|
72
|
+
tags = person.filter_tags || []
|
73
|
+
person.account.default_tag = tags.first unless tags.length > 1
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
creation.add(person)
|
78
|
+
|
79
|
+
# set supervisor
|
80
|
+
unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
|
81
|
+
if !(sup_id = entry.supervisor_id)
|
82
|
+
person.supervisor_id = nil
|
83
|
+
else
|
84
|
+
if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)
|
85
|
+
person.supervisor_id = supervisor.id
|
86
|
+
else
|
87
|
+
# delay setting supervisor if does not exit
|
88
|
+
supers.add(person) do |person|
|
89
|
+
person.supervisor_id = sup_id
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|