eco-helpers 3.0.21 → 3.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.idea/.gitignore +10 -0
- data/CHANGELOG.md +34 -2
- data/eco-helpers.gemspec +3 -3
- data/lib/eco/api/common/class_hierarchy.rb +6 -9
- data/lib/eco/api/common/loaders/case_base.rb +12 -4
- data/lib/eco/api/common/loaders/config/workflow/cases_extension.rb +53 -0
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +2 -14
- data/lib/eco/api/common/loaders/config/workflow.rb +4 -0
- data/lib/eco/api/common/loaders/error_handler.rb +3 -2
- data/lib/eco/api/common/loaders/policy.rb +3 -2
- data/lib/eco/api/common/loaders/use_case/cli_identify.rb +28 -0
- data/lib/eco/api/common/loaders/use_case/target_model.rb +25 -0
- data/lib/eco/api/common/loaders/use_case/type.rb +37 -0
- data/lib/eco/api/common/loaders/use_case.rb +16 -43
- data/lib/eco/api/error/handler.rb +6 -4
- data/lib/eco/api/error/handlers.rb +12 -5
- data/lib/eco/api/microcases/people/apply_changes/set_account/account_excluded.rb +34 -0
- data/lib/eco/api/microcases/people/apply_changes/set_account.rb +28 -0
- data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +28 -0
- data/lib/eco/api/microcases/people/apply_changes/set_core.rb +27 -0
- data/lib/eco/api/microcases/people/apply_changes/set_core_with_supervisor.rb +38 -0
- data/lib/eco/api/microcases/people/apply_changes/set_supervisor.rb +69 -0
- data/lib/eco/api/microcases/people/apply_changes.rb +19 -0
- data/lib/eco/api/microcases/people/fetch/with_each.rb +109 -0
- data/lib/eco/api/microcases/people/fetch/with_each_leaver.rb +33 -0
- data/lib/eco/api/microcases/people/fetch/with_each_present.rb +42 -0
- data/lib/eco/api/microcases/people/fetch/with_each_starter.rb +43 -0
- data/lib/eco/api/microcases/people/fetch/with_each_subordinate.rb +41 -0
- data/lib/eco/api/microcases/people/fetch/with_supervisor.rb +46 -0
- data/lib/eco/api/microcases/people/fetch.rb +23 -0
- data/lib/eco/api/microcases/people/integrity/fix_default_group.rb +39 -0
- data/lib/eco/api/microcases/people/integrity/fix_filter_tags.rb +55 -0
- data/lib/eco/api/microcases/people/integrity/refresh_default_tag.rb +32 -0
- data/lib/eco/api/microcases/people/integrity.rb +17 -0
- data/lib/eco/api/microcases/people/macro/take_email.rb +141 -0
- data/lib/eco/api/microcases/people/macro.rb +13 -0
- data/lib/eco/api/microcases/people/manage/cache.rb +36 -0
- data/lib/eco/api/microcases/people/manage/load.rb +90 -0
- data/lib/eco/api/microcases/people/manage/refresh.rb +59 -0
- data/lib/eco/api/microcases/people/manage/search.rb +118 -0
- data/lib/eco/api/microcases/people/manage.rb +19 -0
- data/lib/eco/api/microcases/people/preserve/default_tag.rb +29 -0
- data/lib/eco/api/microcases/people/preserve/filter_tags.rb +34 -0
- data/lib/eco/api/microcases/people/preserve/policy_groups.rb +36 -0
- data/lib/eco/api/microcases/people/preserve.rb +17 -0
- data/lib/eco/api/microcases/people.rb +21 -0
- data/lib/eco/api/microcases/person_update.rb +1 -1
- data/lib/eco/api/microcases/s3upload_targets.rb +1 -1
- data/lib/eco/api/microcases/with_each_contractor_present.rb +40 -0
- data/lib/eco/api/microcases.rb +3 -23
- data/lib/eco/api/organization/people/multiple_search_results.rb +48 -0
- data/lib/eco/api/organization/{people_similarity.rb → people/similarity.rb} +89 -72
- data/lib/eco/api/organization/people.rb +40 -66
- data/lib/eco/api/organization.rb +0 -1
- data/lib/eco/api/policies/policy.rb +7 -5
- data/lib/eco/api/policies.rb +9 -4
- data/lib/eco/api/session/batch/feedback/generate.rb +60 -0
- data/lib/eco/api/session/batch/feedback/getters.rb +28 -0
- data/lib/eco/api/session/batch/feedback/identifiers.rb +20 -0
- data/lib/eco/api/session/batch/feedback/job_dependencies.rb +45 -0
- data/lib/eco/api/session/batch/feedback/request_stat.rb +27 -0
- data/lib/eco/api/session/batch/feedback/request_stats.rb +270 -0
- data/lib/eco/api/session/batch/feedback.rb +45 -119
- data/lib/eco/api/session/batch/job/sets.rb +23 -0
- data/lib/eco/api/session/batch/job/type.rb +22 -0
- data/lib/eco/api/session/batch/job.rb +8 -18
- data/lib/eco/api/session/batch/jobs.rb +6 -2
- data/lib/eco/api/session/batch/launcher/mode_size.rb +1 -1
- data/lib/eco/api/session/batch/launcher/retry.rb +4 -4
- data/lib/eco/api/session/batch/launcher.rb +2 -2
- data/lib/eco/api/session/batch/policies.rb +4 -4
- data/lib/eco/api/session/batch/searcher.rb +2 -1
- data/lib/eco/api/session/batch.rb +0 -1
- data/lib/eco/api/session/config/workflow.rb +19 -9
- data/lib/eco/api/usecases/base_case/model.rb +54 -0
- data/lib/eco/api/usecases/base_case/type.rb +52 -0
- data/lib/eco/api/usecases/base_case.rb +5 -29
- data/lib/eco/api/usecases/base_io/chaining.rb +48 -0
- data/lib/eco/api/usecases/base_io/validations.rb +114 -0
- data/lib/eco/api/usecases/base_io.rb +65 -115
- data/lib/eco/api/usecases/cli/dsl.rb +3 -1
- data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +7 -4
- data/lib/eco/api/usecases/default/people/treat/supers_cyclic_identify_case.rb +1 -3
- data/lib/eco/api/usecases/default/people/treat/supers_hierarchy_case.rb +1 -5
- data/lib/eco/api/usecases/default_cases/entries_to_csv_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/hris_case.rb +0 -2
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +3 -6
- data/lib/eco/api/usecases/graphql/base.rb +3 -2
- data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +1 -1
- data/lib/eco/api/usecases/graphql/helpers/base/error_handling.rb +3 -3
- data/lib/eco/api/usecases/graphql/helpers/contractors/base/load.rb +17 -0
- data/lib/eco/api/usecases/graphql/helpers/contractors/base.rb +8 -0
- data/lib/eco/api/usecases/graphql/helpers/contractors.rb +6 -0
- data/lib/eco/api/usecases/graphql/helpers/location/base.rb +5 -4
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +2 -2
- data/lib/eco/api/usecases/graphql/helpers.rb +1 -0
- data/lib/eco/api/usecases/graphql/samples/contractors/dsl.rb +5 -0
- data/lib/eco/api/usecases/graphql/samples/contractors.rb +17 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/base.rb +1 -1
- data/lib/eco/api/usecases/graphql/samples/location.rb +1 -1
- data/lib/eco/api/usecases/graphql/samples.rb +1 -0
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +0 -1
- data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +8 -8
- data/lib/eco/api/usecases/use_case/chainer.rb +12 -0
- data/lib/eco/api/usecases/use_case.rb +32 -23
- data/lib/eco/api/usecases/use_case_chain/chaining.rb +88 -0
- data/lib/eco/api/usecases/use_case_chain.rb +17 -62
- data/lib/eco/api/usecases/use_case_io/chain.rb +24 -0
- data/lib/eco/api/usecases/use_case_io.rb +17 -22
- data/lib/eco/api/usecases.rb +12 -4
- data/lib/eco/assets.rb +1 -1
- data/lib/eco/cli/config/filters/people_filters.rb +6 -5
- data/lib/eco/cli/config/input.rb +6 -2
- data/lib/eco/cli/config/use_cases.rb +4 -2
- data/lib/eco/cli_default/people_filters.rb +1 -0
- data/lib/eco/cli_default/workflow.rb +149 -138
- data/lib/eco/data/mapper.rb +51 -19
- data/lib/eco/language/methods/dsl_able.rb +3 -0
- data/lib/eco/version.rb +1 -1
- metadata +66 -33
- data/lib/eco/api/microcases/account_excluded.rb +0 -26
- data/lib/eco/api/microcases/core_excluded.rb +0 -20
- data/lib/eco/api/microcases/fix_default_group.rb +0 -33
- data/lib/eco/api/microcases/fix_filter_tags.rb +0 -49
- data/lib/eco/api/microcases/people_cache.rb +0 -30
- data/lib/eco/api/microcases/people_load.rb +0 -84
- data/lib/eco/api/microcases/people_refresh.rb +0 -53
- data/lib/eco/api/microcases/people_search.rb +0 -112
- data/lib/eco/api/microcases/preserve_default_tag.rb +0 -23
- data/lib/eco/api/microcases/preserve_filter_tags.rb +0 -28
- data/lib/eco/api/microcases/preserve_policy_groups.rb +0 -30
- data/lib/eco/api/microcases/refresh_default_tag.rb +0 -26
- data/lib/eco/api/microcases/set_account.rb +0 -18
- data/lib/eco/api/microcases/set_core.rb +0 -17
- data/lib/eco/api/microcases/set_core_with_supervisor.rb +0 -32
- data/lib/eco/api/microcases/set_supervisor.rb +0 -63
- data/lib/eco/api/microcases/take_email_from_account.rb +0 -129
- data/lib/eco/api/microcases/with_each.rb +0 -103
- data/lib/eco/api/microcases/with_each_leaver.rb +0 -27
- data/lib/eco/api/microcases/with_each_present.rb +0 -36
- data/lib/eco/api/microcases/with_each_starter.rb +0 -37
- data/lib/eco/api/microcases/with_each_subordinate.rb +0 -33
- data/lib/eco/api/microcases/with_supervisor.rb +0 -35
- data/lib/eco/api/session/batch/request_stats.rb +0 -266
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c24fea5e80af03052ddec1ce701651a61e7575d812161ff4f62f8f70c29da1d1
|
4
|
+
data.tar.gz: 2c72186bf780afd1b706eb0fbf44669cd68ac1239e0ba95f923462190a08d85d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bf253ab9cc07090b25ffcec1ff853422e292ce4fe1dcddab026bead5ef48d5a4710d55f79b4a16477c6671d764296938374c6f18521e27ac808529eb1435fa7
|
7
|
+
data.tar.gz: 28da9eaed628e6e37c22b5dc3c703867c9941eac6ea2d364142823ffa3e00e86ed54d45648b75231b4e93f86aff666f5a69892cc9255260af4c2c6953b6483bd
|
data/.idea/.gitignore
ADDED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,40 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## [3.0.22] - 2024-12-xx
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- `Eco::Data::Mapper`
|
10
|
+
- Ability to pair in lower case
|
11
|
+
- `#internal?` and `#external?` would evaluate `true` for a lower case check.
|
12
|
+
- `:model` named argument to use cases
|
13
|
+
- To diversify use cases
|
14
|
+
- `Contractors` namespace (skeleton) onto `Eco::API::UseCases::GraphQL` within:
|
15
|
+
- `Helpers`
|
16
|
+
- `Samples`
|
17
|
+
- Decoupled `Eco::API::Session::Batch::Feedback` into mulitple **modules**
|
18
|
+
- Moved `Eco::API::Session::Batch::RequestStats` to be
|
19
|
+
- `Eco::API::Session::Batch::Feedback::RequestStats`
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
|
23
|
+
- Moved `Cli` class methods out of `Eco::API::Common::Loaders::UseCase` (to `CliIdentify`)
|
24
|
+
- Moved `Eco::API::Organization::PeopleSimilarity` to `Eco::API::Organization::People::Similarity`
|
25
|
+
- **IMPORTANT** refactor to base UseCase and IO related classes on `data` (rather than `people`).
|
26
|
+
- This change aims for re-usability of existing use case logic.
|
27
|
+
- The changes have had impact on the workflow definitions.
|
28
|
+
- There is a **todo** list in the default_cli workflow implementation.
|
29
|
+
- **Refactor** of `MicroCases` to be based on data model.
|
30
|
+
- Upgrade dependencies:
|
31
|
+
- `ecoportal-api` gem upgrade.
|
32
|
+
- `ecoportal-api-v2` gem upgrade.
|
33
|
+
- `ecoportal-api-graphql` gem upgrade.
|
34
|
+
|
35
|
+
### Fixed
|
36
|
+
|
37
|
+
- Workflow should raise exception when referring to an unknown stage
|
38
|
+
|
5
39
|
## [3.0.21] - 2024-12-16
|
6
40
|
|
7
41
|
### Added
|
@@ -180,8 +214,6 @@ All notable changes to this project will be documented in this file.
|
|
180
214
|
|
181
215
|
## [3.0.6] - 2024-08-26
|
182
216
|
|
183
|
-
### Added
|
184
|
-
|
185
217
|
### Changed
|
186
218
|
|
187
219
|
- `Eco::API::Microcases#people_search`
|
data/eco-helpers.gemspec
CHANGED
@@ -40,9 +40,9 @@ Gem::Specification.new do |spec|
|
|
40
40
|
spec.add_dependency 'bcrypt_pbkdf', '~> 1.0'
|
41
41
|
spec.add_dependency 'docx', '>= 0.8.0', '< 0.9'
|
42
42
|
spec.add_dependency 'dotenv', '~> 3'
|
43
|
-
spec.add_dependency 'ecoportal-api', '~> 0.10', '>= 0.10.
|
44
|
-
spec.add_dependency 'ecoportal-api-graphql', '~> 0.4', '>= 0.4.
|
45
|
-
spec.add_dependency 'ecoportal-api-v2', '~> 2.0', '>= 2.0.
|
43
|
+
spec.add_dependency 'ecoportal-api', '~> 0.10', '>= 0.10.8'
|
44
|
+
spec.add_dependency 'ecoportal-api-graphql', '~> 0.4', '>= 0.4.4'
|
45
|
+
spec.add_dependency 'ecoportal-api-v2', '~> 2.0', '>= 2.0.15'
|
46
46
|
spec.add_dependency 'ed25519', '~> 1.2'
|
47
47
|
spec.add_dependency 'fast_excel', '>= 0.5.0', '< 0.6'
|
48
48
|
spec.add_dependency 'fuzzy_match', '>= 2.1.0', '< 2.2'
|
@@ -15,7 +15,7 @@ module Eco
|
|
15
15
|
|
16
16
|
# @return [Array<String>] the `keys` of the current class' `model`
|
17
17
|
def model_attrs
|
18
|
-
|
18
|
+
model&.keys || []
|
19
19
|
end
|
20
20
|
|
21
21
|
# Thanks to this step the format on the declaration of the model is flexible
|
@@ -24,24 +24,21 @@ module Eco
|
|
24
24
|
def parse_model(model)
|
25
25
|
case model
|
26
26
|
when String
|
27
|
-
|
27
|
+
parse_model(model.to_sym)
|
28
28
|
when Symbol
|
29
|
-
|
29
|
+
{model => nil}
|
30
30
|
when Hash
|
31
|
-
|
32
|
-
hash[k.to_sym] = v
|
33
|
-
end
|
31
|
+
model.transform_keys(&:to_sym)
|
34
32
|
when Enumerable
|
35
|
-
|
33
|
+
model.each_with_object({}) do |sub, hash|
|
36
34
|
hash.merge!(parse_model(sub))
|
37
35
|
end
|
38
36
|
when NilClass
|
39
|
-
|
37
|
+
nil
|
40
38
|
else
|
41
39
|
raise "Incorrect model declaration, allowed String, Symbol, Hash and Enumerable. Given: #{model.class}"
|
42
40
|
end
|
43
41
|
end
|
44
|
-
|
45
42
|
end
|
46
43
|
end
|
47
44
|
end
|
@@ -6,17 +6,25 @@ module Eco
|
|
6
6
|
class << self
|
7
7
|
attr_writer :name, :type
|
8
8
|
|
9
|
+
alias_method :original_name, :name
|
10
|
+
|
9
11
|
# The name that this case, policy or error handler will have.
|
10
12
|
def name(value = nil)
|
11
|
-
name_only_once!
|
12
|
-
set_created_at!
|
13
|
-
return @name
|
13
|
+
name_only_once! if value
|
14
|
+
set_created_at! unless @name
|
15
|
+
return original_name unless @name || value
|
16
|
+
return @name unless value
|
17
|
+
|
14
18
|
@name = value
|
15
19
|
end
|
16
20
|
|
17
21
|
# Prevent the same class to be re-opened/re-named
|
18
22
|
def name_only_once!
|
19
|
-
|
23
|
+
return unless @name
|
24
|
+
|
25
|
+
msg = "You have already declared #{self} "
|
26
|
+
msg << "or you are trying to give it a name twice"
|
27
|
+
raise msg if @name
|
20
28
|
end
|
21
29
|
end
|
22
30
|
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class Eco::API::Common::Loaders::Workflow
|
2
|
+
module CasesExtension
|
3
|
+
private
|
4
|
+
|
5
|
+
def cli_usecases
|
6
|
+
cli.config.usecases
|
7
|
+
end
|
8
|
+
|
9
|
+
def cli_active_cases(io)
|
10
|
+
cli_usecases.active(io: io)
|
11
|
+
end
|
12
|
+
|
13
|
+
def cli_update_cases(io)
|
14
|
+
cli_active_cases(io).select do |usecase, _data|
|
15
|
+
%i[transform sync].any? { |type| usecase.type == type }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def cli_other_cases(io)
|
20
|
+
cli_active_cases(io).select do |usecase, _data|
|
21
|
+
%i[other].any? { |type| usecase.type == type }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def cli_input_cases(io)
|
26
|
+
cli_active_cases(io).select do |usecase, _data|
|
27
|
+
io.class.input_required?(usecase.type)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def cli_data_cases(io)
|
32
|
+
cli_active_cases(io).select do |usecase, _data|
|
33
|
+
io.class.data_required?(usecase.type)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def some_update_case?(io)
|
38
|
+
cli_update_cases(io).any?
|
39
|
+
end
|
40
|
+
|
41
|
+
def some_other_case?(io)
|
42
|
+
cli_other_cases(io).any?
|
43
|
+
end
|
44
|
+
|
45
|
+
def some_input_case?(io)
|
46
|
+
cli_input_cases(io).any?
|
47
|
+
end
|
48
|
+
|
49
|
+
def some_data_case?(io)
|
50
|
+
cli_data_cases(io).any?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -19,7 +19,7 @@ class Eco::API::Common::Loaders::Workflow::Mailer < Eco::API::Common::Loaders::W
|
|
19
19
|
next unless session.config.run_mode_remote?
|
20
20
|
|
21
21
|
# temporary contingency: maybe_error_or_tree_updates?
|
22
|
-
next unless
|
22
|
+
next unless some_update_case?(io) || maybe_error_pages_or_tree_updates?(io)
|
23
23
|
|
24
24
|
subject = base_subject
|
25
25
|
|
@@ -57,25 +57,13 @@ class Eco::API::Common::Loaders::Workflow::Mailer < Eco::API::Common::Loaders::W
|
|
57
57
|
"#{active_enviro}#{space_desc}"
|
58
58
|
end
|
59
59
|
|
60
|
-
def some_update?(io)
|
61
|
-
cli.config.usecases.active(io: io).any? do |usecase, _data|
|
62
|
-
%i[transform sync].any? { |type| usecase.type == type }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def other_case?(io)
|
67
|
-
cli.config.usecases.active(io: io).any? do |usecase, _data|
|
68
|
-
%i[other].any? { |type| usecase.type == type }
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
60
|
def error?
|
73
61
|
!!error
|
74
62
|
end
|
75
63
|
|
76
64
|
# @note at some stage, tree cases should have their own case type
|
77
65
|
def maybe_error_pages_or_tree_updates?(io)
|
78
|
-
|
66
|
+
some_other_case?(io) && error?
|
79
67
|
end
|
80
68
|
|
81
69
|
def errors_n_warnings(io)
|
@@ -1,10 +1,14 @@
|
|
1
1
|
class Eco::API::Common::Loaders::Workflow < Eco::API::Common::Loaders::Config
|
2
|
+
require_relative 'workflow/cases_extension'
|
3
|
+
|
2
4
|
class << self
|
3
5
|
def workflow
|
4
6
|
config.workflow
|
5
7
|
end
|
6
8
|
end
|
7
9
|
|
10
|
+
extend CasesExtension
|
11
|
+
|
8
12
|
delegate_missing_to :workflow
|
9
13
|
end
|
10
14
|
|
@@ -25,12 +25,13 @@ module Eco
|
|
25
25
|
handlers.on(error, &method(:main))
|
26
26
|
end
|
27
27
|
|
28
|
-
# @param
|
28
|
+
# @param data [Variant]
|
29
|
+
# - people [Eco::API::Organization::People] the people in the queue of the current `job`
|
29
30
|
# @param session [Eco::API::Session] the current session where the usecase kicks in.
|
30
31
|
# @param options [Hash] the options that modify the case behaviour or bring some dependencies.
|
31
32
|
# @param handler [Eco::API::Error::Hanlder] the `error handler` instance object.
|
32
33
|
# @param job [Eco::API::Session::Batch::Job] the `Batch::Job` made on purpose for this handler.
|
33
|
-
def main(
|
34
|
+
def main(data, session, options, handler, job) # rubocop:disable Lint/UnusedMethodArgument
|
34
35
|
raise "You should implement this method"
|
35
36
|
end
|
36
37
|
|
@@ -10,12 +10,13 @@ module Eco
|
|
10
10
|
policies.define(name, &method(:main))
|
11
11
|
end
|
12
12
|
|
13
|
-
# @param
|
13
|
+
# @param data [Variant]
|
14
|
+
# - people [Eco::API::Organization::People] the people in the queue of the current `job`
|
14
15
|
# @param session [Eco::API::Session] the current session where the usecase kicks in.
|
15
16
|
# @param options [Hash] the options that modify the case behaviour or bring some dependencies.
|
16
17
|
# @param policy [Eco::API::Policies::Policy] the `policy` instance object.
|
17
18
|
# @param job [Eco::API::Session::Batch::Job] the `Batch::Job` that these `people` belong to the queue thereof.
|
18
|
-
def main(
|
19
|
+
def main(data, session, options, policy, job = nil) # rubocop:disable Lint/UnusedMethodArgument
|
19
20
|
raise "You should implement this method"
|
20
21
|
end
|
21
22
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Eco::API::Common::Loaders::UseCase
|
2
|
+
module CliIdentify
|
3
|
+
def cli!
|
4
|
+
cli&.apply!
|
5
|
+
end
|
6
|
+
|
7
|
+
def cli(cli_class = nil)
|
8
|
+
if cli_class.is_a?(Class)
|
9
|
+
msg = 'cli_class should inherit from Eco::API::UseCases::Cli'
|
10
|
+
raise ArgumentError, msg unless cli_class < Eco::API::UseCases::Cli
|
11
|
+
|
12
|
+
@cli = cli_class
|
13
|
+
elsif cli_class.nil?
|
14
|
+
return @cli if instance_variable_defined?(:@cli) && !@cli.nil?
|
15
|
+
|
16
|
+
# try to see if it's namespaced after the use case it provisions cli integration
|
17
|
+
begin
|
18
|
+
try_class = [to_s, 'Cli'].join('::')
|
19
|
+
@cli = Kernel.const_get(try_class)
|
20
|
+
rescue NameError
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
else
|
24
|
+
raise ArgumentError, "Expecting a class. Given: #{cli_class.class} object"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Eco::API::Common::Loaders::UseCase
|
2
|
+
module TargetModel
|
3
|
+
class << self
|
4
|
+
def included(base)
|
5
|
+
super
|
6
|
+
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
#@note it inherently defaults to `:people` (out of backwards compatibility)
|
13
|
+
# @return [String] the `target_model`
|
14
|
+
def target_model(value = nil)
|
15
|
+
return @target_model = value if value
|
16
|
+
|
17
|
+
@target_model if @target_model
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def target_model
|
22
|
+
self.class.target_model
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Eco::API::Common::Loaders::UseCase
|
2
|
+
module Type
|
3
|
+
class << self
|
4
|
+
def included(base)
|
5
|
+
super
|
6
|
+
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
# @return [Symbol] the `type` of usecase (i.e. `:sync`, `:transform`, `:import`, `:other`)
|
13
|
+
def type(value = nil)
|
14
|
+
return @type = value if value
|
15
|
+
return @type if @type
|
16
|
+
|
17
|
+
types_sym_str = available_types.map do |tp|
|
18
|
+
":#{tp}"
|
19
|
+
end.join(', ')
|
20
|
+
|
21
|
+
msg = "You should specify a type of case "
|
22
|
+
msg << "[#{types_sym_str}] for #{self}"
|
23
|
+
raise msg
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def available_types
|
29
|
+
Eco::API::UseCases::BaseCase.types
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def type
|
34
|
+
self.class.type
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -3,66 +3,39 @@ module Eco
|
|
3
3
|
module Common
|
4
4
|
module Loaders
|
5
5
|
class UseCase < Eco::API::Common::Loaders::CaseBase
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
unless value
|
10
|
-
msg = "You should specify a type of case "
|
11
|
-
msg << "[:sync, :transform, :import, :other] for #{self}"
|
12
|
-
return @type || (raise msg)
|
13
|
-
end
|
14
|
-
@type = value
|
15
|
-
end
|
6
|
+
require_relative 'use_case/type'
|
7
|
+
require_relative 'use_case/target_model'
|
8
|
+
require_relative 'use_case/cli_identify'
|
16
9
|
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
include Type
|
11
|
+
include TargetModel
|
12
|
+
extend CliIdentify
|
20
13
|
|
21
|
-
|
22
|
-
if cli_class.is_a?(Class)
|
23
|
-
msg = "cli_class should inherit from Eco::API::UseCases::Cli"
|
24
|
-
raise ArgumentError, msg unless cli_class < Eco::API::UseCases::Cli
|
25
|
-
|
26
|
-
@cli = cli_class
|
27
|
-
elsif cli_class.nil?
|
28
|
-
return @cli if instance_variable_defined?(:@cli) && !@cli.nil?
|
29
|
-
|
30
|
-
# try to see if it's namespaced after the use case it provisions cli integration
|
31
|
-
begin
|
32
|
-
try_class = [to_s, 'Cli'].join('::')
|
33
|
-
@cli = Kernel.const_get(try_class)
|
34
|
-
rescue NameError
|
35
|
-
nil
|
36
|
-
end
|
37
|
-
else
|
38
|
-
raise ArgumentError, "Expecting a class. Given: #{cli_class.class} object"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
inheritable_class_vars :type, :cli
|
14
|
+
inheritable_class_vars :cli, :type, :target_model
|
44
15
|
|
45
16
|
def initialize(usecases) # rubocop:disable Lint/MissingSuper
|
46
17
|
msg = "Expected Eco::API::UseCases. Given #{usecases.class}"
|
47
18
|
raise msg unless usecases.is_a?(Eco::API::UseCases)
|
48
19
|
|
49
|
-
usecases.define(
|
20
|
+
usecases.define(
|
21
|
+
name,
|
22
|
+
type: type,
|
23
|
+
model: target_model,
|
24
|
+
&method(:main)
|
25
|
+
)
|
50
26
|
end
|
51
27
|
|
52
28
|
# The parameters of this method will depend on the `type` of usecase.
|
53
29
|
# @param entries [Eco::API::Common::People::Entries] the input entries with the data.
|
54
|
-
# @param
|
30
|
+
# @param data [Variant]
|
31
|
+
# - people [Eco::API::Organization::People] the people in the queue of the current `job`
|
55
32
|
# @param session [Eco::API::Session] the current session where the usecase kicks in.
|
56
33
|
# @param options [Hash] the options that modify the case behaviour or bring some dependencies.
|
57
34
|
# @param usecase [Eco::API::Policies::Policy] the `usecase` instance object.
|
58
|
-
def main(
|
35
|
+
def main(*_args)
|
59
36
|
raise "You should implement this method"
|
60
37
|
end
|
61
38
|
|
62
|
-
def type
|
63
|
-
self.class.type
|
64
|
-
end
|
65
|
-
|
66
39
|
def cli_apply!
|
67
40
|
self.class.cli!
|
68
41
|
end
|
@@ -2,17 +2,19 @@ module Eco
|
|
2
2
|
module API
|
3
3
|
class Error
|
4
4
|
class Handler < Eco::API::UseCases::UseCase
|
5
|
-
|
5
|
+
TYPES = [:error_handler].freeze
|
6
6
|
|
7
7
|
def initialize(name, type: :error_handler, root:, &block)
|
8
|
-
super
|
8
|
+
super
|
9
9
|
end
|
10
10
|
|
11
11
|
def root=(value)
|
12
|
-
|
12
|
+
msg = "Root should be a Eco::API::Error::Handlers object. "
|
13
|
+
msg << "Given: #{value.class}"
|
14
|
+
raise ArgumentError, msg unless value.is_a?(Eco::API::Error::Handlers)
|
15
|
+
|
13
16
|
@root = value
|
14
17
|
end
|
15
|
-
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
@@ -5,7 +5,7 @@ module Eco
|
|
5
5
|
autoloads_children_of "Eco::API::Common::Loaders::ErrorHandler"
|
6
6
|
autoload_namespace_ignore "Eco::API"
|
7
7
|
|
8
|
-
def define(*
|
8
|
+
def define(*_args)
|
9
9
|
raise "Missusage. You should use 'on' method instead"
|
10
10
|
end
|
11
11
|
|
@@ -13,16 +13,23 @@ module Eco
|
|
13
13
|
def on(klass_err, type: :error_handler, retry: true, &block)
|
14
14
|
Eco::API::Error.validate_err_class(klass_err)
|
15
15
|
raise "Expected block but not given" unless block
|
16
|
-
|
16
|
+
|
17
|
+
Eco::API::Error::Handler.new(
|
18
|
+
klass_err,
|
19
|
+
type: type,
|
20
|
+
root: self,
|
21
|
+
&block
|
22
|
+
).tap do |handler|
|
17
23
|
add(handler)
|
18
24
|
end
|
19
25
|
end
|
20
26
|
|
21
27
|
def add(handler)
|
22
|
-
|
23
|
-
|
24
|
-
end
|
28
|
+
msg = "Expected Eco::API::Error::Handler object. Given: #{handler.class}"
|
29
|
+
raise ArgumentError, msg unless handler.is_a?(Eco::API::Error::Handler)
|
25
30
|
|
31
|
+
super
|
32
|
+
end
|
26
33
|
end
|
27
34
|
end
|
28
35
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
module People
|
5
|
+
module ApplyChanges
|
6
|
+
module SetAccount
|
7
|
+
module AccountExcluded
|
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
|
+
# @return [Array<String>] the account parameters that should not be included.
|
11
|
+
def account_excluded(person, options)
|
12
|
+
[].tap do |account_excluded|
|
13
|
+
next if person.new?
|
14
|
+
|
15
|
+
if options.dig(:exclude, :policy_groups)
|
16
|
+
account_excluded.push('policy_group_ids')
|
17
|
+
end
|
18
|
+
|
19
|
+
if options.dig(:exclude, :default_tag)
|
20
|
+
account_excluded.push('default_tag')
|
21
|
+
end
|
22
|
+
|
23
|
+
if options.dig(:exclude, :login_providers)
|
24
|
+
account_excluded.push('login_provider_ids')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'set_account/account_excluded'
|
2
|
+
|
3
|
+
module Eco
|
4
|
+
module API
|
5
|
+
class MicroCases
|
6
|
+
module People
|
7
|
+
module ApplyChanges
|
8
|
+
module SetAccount
|
9
|
+
include AccountExcluded
|
10
|
+
|
11
|
+
# @param entry [PersonEntry] the input entry with the data we should set on person.
|
12
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
13
|
+
# @param options [Hash] the options.
|
14
|
+
def set_account(entry, person, options)
|
15
|
+
return if options.dig(:exclude, :account)
|
16
|
+
|
17
|
+
entry.set_account(person, exclude: micro.account_excluded(person, options))
|
18
|
+
|
19
|
+
person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
|
20
|
+
micro.refresh_default_tag(entry, person, options)
|
21
|
+
micro.fix_default_group(entry, person, options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
module People
|
5
|
+
module ApplyChanges
|
6
|
+
module SetCore
|
7
|
+
module CoreExcluded
|
8
|
+
# @note by default `supervisor_id` is always excluded.
|
9
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
10
|
+
# @param options [Hash] the options.
|
11
|
+
# @return [Array<String>] the core parameters that should not be included.
|
12
|
+
def core_excluded(person, options)
|
13
|
+
['supervisor_id'].tap do |core_excluded|
|
14
|
+
can_exclude = person.new?? ['filter_tags'] : %w[name external_id email filter_tags]
|
15
|
+
|
16
|
+
exclusions = can_exclude.select do |attr|
|
17
|
+
options.dig(:exclude, attr.to_sym)
|
18
|
+
end
|
19
|
+
core_excluded.concat(exclusions)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'set_core/core_excluded'
|
2
|
+
|
3
|
+
module Eco
|
4
|
+
module API
|
5
|
+
class MicroCases
|
6
|
+
module People
|
7
|
+
module ApplyChanges
|
8
|
+
module SetCore
|
9
|
+
include CoreExcluded
|
10
|
+
|
11
|
+
# Sets all the core details, but the supervisor.
|
12
|
+
# @note `supervisor_id` requires a special treatment, and therefore is always excluded.
|
13
|
+
# @param entry [PersonEntry] the input entry with the data we should set on person.
|
14
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
15
|
+
# @param options [Hash] the options
|
16
|
+
def set_core(entry, person, options)
|
17
|
+
return if options.dig(:exclude, :core) && !person.new?
|
18
|
+
|
19
|
+
entry.set_core(person, exclude: micro.core_excluded(person, options))
|
20
|
+
micro.fix_filter_tags(person, options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|