eco-helpers 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eco/api.rb +1 -0
- data/lib/eco/api/common.rb +1 -0
- data/lib/eco/api/common/class_helpers.rb +33 -0
- data/lib/eco/api/common/people.rb +1 -0
- data/lib/eco/api/common/people/person_attribute_parser.rb +52 -0
- data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +2 -2
- data/lib/eco/api/common/people/person_parser.rb +16 -10
- data/lib/eco/api/common/version_patches.rb +2 -3
- data/lib/eco/api/common/version_patches/ecoportal_api.rb +4 -0
- data/lib/eco/api/common/version_patches/{base_model.rb → ecoportal_api/base_model.rb} +0 -0
- data/lib/eco/api/common/version_patches/{external_person.rb → ecoportal_api/external_person.rb} +0 -0
- data/lib/eco/api/common/version_patches/{internal_person.rb → ecoportal_api/internal_person.rb} +0 -0
- data/lib/eco/api/common/version_patches/hash.rb +2 -0
- data/lib/eco/api/common/version_patches/hash/deep_merge.rb +34 -0
- data/lib/eco/api/error.rb +133 -0
- data/lib/eco/api/error/handler.rb +19 -0
- data/lib/eco/api/error/handlers.rb +22 -0
- data/lib/eco/api/organization/people.rb +11 -11
- data/lib/eco/api/organization/policy_groups.rb +8 -0
- data/lib/eco/api/policies.rb +26 -3
- data/lib/eco/api/policies/policy.rb +4 -5
- data/lib/eco/api/session.rb +27 -18
- data/lib/eco/api/session/batch.rb +12 -6
- data/lib/eco/api/session/batch/errors.rb +134 -0
- data/lib/eco/api/session/batch/job.rb +213 -0
- data/lib/eco/api/session/batch/jobs.rb +72 -0
- data/lib/eco/api/session/batch/jobs_groups.rb +85 -0
- data/lib/eco/api/session/batch/status.rb +133 -0
- data/lib/eco/api/session/config.rb +36 -14
- data/lib/eco/api/session/config/base_config.rb +2 -0
- data/lib/eco/api/session/config/people.rb +8 -0
- data/lib/eco/api/session/config/post_launch.rb +58 -0
- data/lib/eco/api/session/config/workflow.rb +189 -0
- data/lib/eco/api/session/task.rb +49 -6
- data/lib/eco/api/usecases.rb +137 -2
- data/lib/eco/api/usecases/base_case.rb +20 -8
- data/lib/eco/api/usecases/base_io.rb +97 -0
- data/lib/eco/api/usecases/default_case.rb +19 -0
- data/lib/eco/api/usecases/default_cases.rb +2 -2
- data/lib/eco/api/usecases/default_cases/change_email_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/create_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/create_details_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/delete_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/hris_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/new_email_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/new_id_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/recover_db_case.rb +11 -8
- data/lib/eco/api/usecases/default_cases/refresh_presets_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/reinvite_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/remove_account_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +4 -4
- data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +3 -3
- data/lib/eco/api/usecases/default_cases/update_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/update_details_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/upsert_case.rb +2 -2
- data/lib/eco/api/usecases/use_case.rb +23 -36
- data/lib/eco/api/usecases/use_case_chain.rb +14 -24
- data/lib/eco/api/usecases/use_case_io.rb +23 -75
- data/lib/eco/assets.rb +11 -11
- data/lib/eco/cli.rb +37 -0
- data/lib/eco/cli/config.rb +63 -1
- data/lib/eco/cli/config/default.rb +15 -0
- data/lib/eco/cli/config/default/filters.rb +69 -0
- data/lib/eco/cli/config/default/input.rb +21 -0
- data/lib/eco/cli/config/default/options.rb +47 -0
- data/lib/eco/cli/config/default/people.rb +39 -0
- data/lib/eco/cli/config/default/usecases.rb +63 -0
- data/lib/eco/cli/config/default/workflow.rb +86 -0
- data/lib/eco/cli/config/input.rb +40 -0
- data/lib/eco/cli/config/options_set.rb +35 -0
- data/lib/eco/cli/config/people_filters.rb +38 -0
- data/lib/eco/cli/config/use_cases.rb +87 -0
- data/lib/eco/cli/scripting/args_helpers.rb +10 -4
- data/lib/eco/cli/scripting/argument.rb +6 -0
- data/lib/eco/language/models/collection.rb +1 -0
- data/lib/eco/version.rb +1 -1
- metadata +32 -12
- data/lib/eco/api/policies/base_policy.rb +0 -14
- data/lib/eco/api/policies/used_policies.rb +0 -37
- data/lib/eco/api/session/batch_job.rb +0 -215
- data/lib/eco/api/session/batch_jobs.rb +0 -62
- data/lib/eco/api/session/batch_status.rb +0 -205
- data/lib/eco/api/session/job_groups.rb +0 -75
- data/lib/eco/api/usecases/use_group.rb +0 -124
- data/lib/eco/cli/config/options.rb +0 -11
@@ -0,0 +1,97 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class UseCases
|
4
|
+
class BaseIO < BaseCase
|
5
|
+
@types = [:import, :filter, :transform, :sync, :export]
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def input_required?(type)
|
9
|
+
!valid_type?(type) || [:import, :sync].include?(type)
|
10
|
+
end
|
11
|
+
|
12
|
+
def people_required?(type)
|
13
|
+
!valid_type?(type) || [:filter, :transform, :sync, :export].include?(type)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :input, :people, :session, :options
|
19
|
+
attr_reader :type
|
20
|
+
attr_accessor :output
|
21
|
+
|
22
|
+
# @param type [Symbol] a valid type (among `self.class.types`)
|
23
|
+
# @param input [Eco::API::Common::People::Entries, Eco::API::Organization::People] the input data of reference.
|
24
|
+
# @param people [Eco::API::Organization::People] people object.
|
25
|
+
# @param session [Eco::API:Session]
|
26
|
+
# @param options [Hash] hash with symbol keys (i.e. behaviour modifiers, cli trackers, filters, etc.)
|
27
|
+
def initialize(type: nil, input: nil, people: nil, session:, options: {})
|
28
|
+
@output = nil
|
29
|
+
self.type = type if type
|
30
|
+
|
31
|
+
if self.type
|
32
|
+
validate_args(input: input, people: people, session: session, options: options)
|
33
|
+
end
|
34
|
+
|
35
|
+
@input = input
|
36
|
+
@people = people
|
37
|
+
@session = session
|
38
|
+
@options = options
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param value [Symbol] a valid type (among `self.class.types`)
|
42
|
+
def type=(value)
|
43
|
+
self.class.validate_type(value)
|
44
|
+
@type = value
|
45
|
+
end
|
46
|
+
|
47
|
+
# Helper to obtain an `BaseIO` objcect from any child class.
|
48
|
+
# @return [Eco::API::UseCases::BaseIO]
|
49
|
+
def base
|
50
|
+
kargs = params(keyed: true).merge(type: self.type).slice(:type, :input, :people, :session, :options)
|
51
|
+
Eco::API::UseCases::BaseIO.new(**kargs)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @see Eco::API::UseCases::BaseIO#initialize
|
55
|
+
# @return [Eco::API::UseCases::BaseIO]
|
56
|
+
def new(type: self.type, input: self.input, people: self.people, session: self.session, options: self.options)
|
57
|
+
self.class.new(type: type, input: input, people: people, session: session, options: options)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Helper to build a `Hash` of symbol keys or `Array` with params to do callbacks.
|
61
|
+
def params(keyed: false)
|
62
|
+
kargs = {}
|
63
|
+
kargs.merge!(input: input) if input_required?
|
64
|
+
kargs.merge!(people: people) if people_required?
|
65
|
+
kargs.merge!(session: session, options: options)
|
66
|
+
keyed ? kargs : kargs.values
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def validate_args(input:, people:, session:, options:)
|
72
|
+
case
|
73
|
+
when !session.is_a?(Eco::API::Session)
|
74
|
+
raise "A UseCase needs a Session object. Given: #{session}"
|
75
|
+
when input_required? && !input
|
76
|
+
raise "UseCase of type '#{type}' requires a valid input. None given"
|
77
|
+
when people_required? && !people.is_a?(Eco::API::Organization::People)
|
78
|
+
raise "UseCase of type '#{type}' requires a People object. Given: #{people}"
|
79
|
+
when !options || (options && !options.is_a?(Hash))
|
80
|
+
raise "To inject dependencies via ':options' it should be a Hash object. Given: #{options}"
|
81
|
+
end
|
82
|
+
true
|
83
|
+
end
|
84
|
+
|
85
|
+
def input_required?
|
86
|
+
self.class.input_required?(type)
|
87
|
+
end
|
88
|
+
|
89
|
+
def people_required?
|
90
|
+
self.class.people_required?(type)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class UseCases
|
4
|
+
class DefaultCase
|
5
|
+
|
6
|
+
def initialize(cases, **options)
|
7
|
+
raise "Expected a Eco::API::UseCases object. Given #{cases.class}" if !cases.is_a?(Eco::API::UseCases)
|
8
|
+
@cases = cases
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def process
|
13
|
+
raise "You should reimplement this method"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
|
-
|
3
|
+
class UseCases
|
4
4
|
class DefaultCases
|
5
|
-
class CreateDetailsCase <
|
5
|
+
class CreateDetailsCase < DefaultCase
|
6
6
|
|
7
7
|
def process
|
8
8
|
@cases.define("create-details", type: :sync) do |entries, people, session, options, usecase|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
|
-
|
3
|
+
class UseCases
|
4
4
|
class DefaultCases
|
5
|
-
class CreateDetailsWithSupervisorCase <
|
5
|
+
class CreateDetailsWithSupervisorCase < DefaultCase
|
6
6
|
|
7
7
|
def process
|
8
8
|
# good candidate to do @cases.case("create-details").use.chain(@cases.case("set-supervisor").use)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
|
-
|
3
|
+
class UseCases
|
4
4
|
class DefaultCases
|
5
|
-
class RecoverDBCase <
|
5
|
+
class RecoverDBCase < DefaultCase
|
6
6
|
|
7
7
|
def process
|
8
8
|
@cases.define("recover-db", type: :sync) do |entries, people, session, options, usecase|
|
@@ -10,22 +10,25 @@ module Eco
|
|
10
10
|
raise "Your input should be an 'Eco::API::Organization::People' object. Got: #{entries.class}"
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
if options.dig(:include, :create)
|
14
|
+
creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details, :account])
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
pgs = session.policy_groups
|
17
|
+
update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account])
|
19
18
|
|
20
19
|
if options.dig(:include, :delete)
|
20
|
+
remove = session.job_group("main").new("remove", usecase: usecase, type: :delete, sets: [:core, :details, :account])
|
21
21
|
people.exclude(entries).map {|person| remove.add(person)}
|
22
22
|
end
|
23
23
|
|
24
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
25
|
+
pgs = session.policy_groups
|
26
|
+
|
24
27
|
entries.each.with_index do |entry, i|
|
25
28
|
create = ! (person = people.find(entry, strict: strict_search))
|
26
29
|
|
27
30
|
if create && !options.dig(:include, :create)
|
28
|
-
session.logger.error("Entry(#{i}) - this person does not exist: #{entry.email}")
|
31
|
+
session.logger.error("Entry(#{i}) - this person does not exist: #{entry.name} (#{entry.email})")
|
29
32
|
else
|
30
33
|
person = session.new_person if create
|
31
34
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
|
-
|
3
|
+
class UseCases
|
4
4
|
class DefaultCases
|
5
|
-
class ResetLandingPageCase <
|
5
|
+
class ResetLandingPageCase < DefaultCase
|
6
6
|
|
7
7
|
def process
|
8
8
|
@cases.define("reset-landing-page", type: :transform) do |people, session, options, usecase|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
|
-
|
3
|
+
class UseCases
|
4
4
|
class DefaultCases
|
5
|
-
class SetDefaultTagCase <
|
5
|
+
class SetDefaultTagCase < DefaultCase
|
6
6
|
# take the deepest tag (the one that is further down in the tree)
|
7
7
|
# different options (several nodes at the same depth):
|
8
8
|
# => take the common node between them (i.e. you have Hamilton and Auckland -> take New Zealand)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
|
-
|
3
|
+
class UseCases
|
4
4
|
class DefaultCases
|
5
|
-
class SetSupervisorCase <
|
5
|
+
class SetSupervisorCase < DefaultCase
|
6
6
|
|
7
7
|
def process
|
8
8
|
@cases.define("set-supervisor", type: :sync) do |entries, people, session, options, usecase|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
|
-
|
3
|
+
class UseCases
|
4
4
|
class DefaultCases
|
5
|
-
class SwitchSupervisorCase <
|
5
|
+
class SwitchSupervisorCase < DefaultCase
|
6
6
|
|
7
7
|
def process
|
8
8
|
@cases.define("switch-supervisor", type: :transform) do |people, session, options, usecase|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
|
-
|
3
|
+
class UseCases
|
4
4
|
class DefaultCases
|
5
|
-
class ToCsvCase <
|
5
|
+
class ToCsvCase < DefaultCase
|
6
6
|
|
7
7
|
def process
|
8
8
|
@cases.define("to-csv", type: :export) do |people, session, options, usecase|
|
@@ -11,7 +11,7 @@ module Eco
|
|
11
11
|
next false
|
12
12
|
end
|
13
13
|
|
14
|
-
unless file = options[:file]
|
14
|
+
unless file = options[:file] || options.dig(:export, :file, :name)
|
15
15
|
session.logger.error("Destination file not specified")
|
16
16
|
next false
|
17
17
|
end
|
@@ -22,7 +22,7 @@ module Eco
|
|
22
22
|
entry = session.new_entry(people.first, dependencies: deps)
|
23
23
|
header = entry.to_hash.keys
|
24
24
|
|
25
|
-
if options.dig(:nice_header)
|
25
|
+
if options.dig(:nice_header) || options.dig(:export, :options, :nice_header)
|
26
26
|
name_maps = session.schema.fields_by_alt_id.transform_values do |fld|
|
27
27
|
fld.name
|
28
28
|
end.merge({
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
|
-
|
3
|
+
class UseCases
|
4
4
|
class DefaultCases
|
5
|
-
class ToCsvDetailedCase <
|
5
|
+
class ToCsvDetailedCase < DefaultCase
|
6
6
|
|
7
7
|
def process
|
8
8
|
@cases.define("to-csv-detailed", type: :export) do |people, session, options, usecase|
|
@@ -11,7 +11,7 @@ module Eco
|
|
11
11
|
next false
|
12
12
|
end
|
13
13
|
|
14
|
-
unless file = options[:file]
|
14
|
+
unless file = options[:file] || options.dig(:export, :file, :name)
|
15
15
|
session.logger.error("Destination file not specified")
|
16
16
|
next false
|
17
17
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
|
-
|
3
|
+
class UseCases
|
4
4
|
class DefaultCases
|
5
|
-
class UpdateDetailsCase <
|
5
|
+
class UpdateDetailsCase < DefaultCase
|
6
6
|
|
7
7
|
def process
|
8
8
|
@cases.define("update-details", type: :sync) do |entries, people, session, options, usecase|
|