eco-helpers 1.4.0 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +150 -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/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 +24 -2
- 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_reference.json +9 -1
- data/lib/eco/api/organization/presets_values.json +4 -1
- 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 +91 -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.rb +8 -3
- data/lib/eco/csv/table.rb +1 -1
- data/lib/eco/data/crypto/encryption.rb +3 -0
- data/lib/eco/data/files/helpers.rb +6 -1
- 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 -63
- 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
@@ -23,7 +23,7 @@ module Eco
|
|
23
23
|
# - if `data` is a `Person` object, its behaviour is `serialise`.
|
24
24
|
# - if `data` is **not** a `Person` object, it does a `parse`.
|
25
25
|
# - currently **in rework**, so there may be subtle differences that make it temporarily unstable (yet it is reliable).
|
26
|
-
# @param data [Hash, Person] `Person` object to be serialized or hashed entry (note: `CSV::Row` is accepted).
|
26
|
+
# @param data [Hash, Ecoportal::API::V1::Person] `Person` object to be serialized or hashed entry to be parsed (note: `CSV::Row` is accepted).
|
27
27
|
# @param person_parser [Common::People::PersonParser] parser/serializer of person attributes (it contains a set of attribute parsers).
|
28
28
|
# @param attr_map [Eco::Data::Mapper] mapper to translate attribute names from _external_ to _internal_ names and _vice versa_.
|
29
29
|
# @param logger [Common::Session::Logger, ::Logger] object to manage logs.
|
@@ -42,6 +42,7 @@ module Eco
|
|
42
42
|
else # SERIALIZING
|
43
43
|
@person = data
|
44
44
|
@internal_attrs = @person_parser.all_attrs
|
45
|
+
@aliased_attrs = @attr_map.list(:internal)
|
45
46
|
end
|
46
47
|
|
47
48
|
@core_attrs = @person_parser.target_attrs_core(@internal_attrs)
|
@@ -53,7 +54,7 @@ module Eco
|
|
53
54
|
# To know if currently the object is in parse or serialize mode.
|
54
55
|
# @return [Boolean] returns `true` if we are **parsing**, `false` otherwise.
|
55
56
|
def parsing?
|
56
|
-
!@source.is_a?(Ecoportal::API::
|
57
|
+
!@source.is_a?(Ecoportal::API::V1::Person)
|
57
58
|
end
|
58
59
|
|
59
60
|
# To know if currently the object is in parse or serialize mode.
|
@@ -72,6 +73,8 @@ module Eco
|
|
72
73
|
# @param value [String, Array<String>] value(s) to be translated into internal names.
|
73
74
|
# @return [String, nil, Array<String] the internal name(s) of `value`.
|
74
75
|
def to_internal(value)
|
76
|
+
# TODO: check PersonEntry#to_internal and #to_external in init_attr_trackers
|
77
|
+
# => when attr_map is avoided, it doesn't work as it should
|
75
78
|
return value if !@attr_map
|
76
79
|
attr = value
|
77
80
|
case value
|
@@ -9,7 +9,11 @@ module Eco
|
|
9
9
|
# @attr_reader details_attrs [Array<String>] internal names of schema details attributes.
|
10
10
|
# @attr_reader all_attrs [Array<String>] all the internal name attributes, including _core_, _account_ and _details_.
|
11
11
|
class PersonParser
|
12
|
-
|
12
|
+
extend Eco::API::Common::ClassAutoLoader
|
13
|
+
autoloads_children_of "Eco::API::Common::Loaders::Parser"
|
14
|
+
autoload_namespace_ignore "Eco::API"
|
15
|
+
|
16
|
+
CORE_ATTRS = ["id", "external_id", "email", "name", "supervisor_id", "filter_tags", "freemium"]
|
13
17
|
ACCOUNT_ATTRS = ["policy_group_ids", "default_tag", "send_invites", "landing_page_id", "login_provider_ids"]
|
14
18
|
TYPE = [:select, :text, :date, :number, :phone_number, :boolean, :multiple]
|
15
19
|
FORMAT = [:csv, :xml, :json]
|
@@ -43,12 +47,19 @@ module Eco
|
|
43
47
|
end
|
44
48
|
|
45
49
|
@all_attrs = CORE_ATTRS + ACCOUNT_ATTRS + @details_attrs
|
50
|
+
self.class.autoload_children(self)
|
46
51
|
end
|
47
52
|
|
48
53
|
def patched!
|
49
54
|
@patch_version += 1
|
50
55
|
end
|
51
56
|
|
57
|
+
def new(schema: nil)
|
58
|
+
self.class.new(schema: schema || self.schema).merge(self)
|
59
|
+
end
|
60
|
+
|
61
|
+
# @!group Scopping attributes (identifying, presence & active)
|
62
|
+
|
52
63
|
# Scopes `source_attrs` using the _**core** attributes_.
|
53
64
|
# @note use this helper to know which among your attributes are **core** ones.
|
54
65
|
# @param source_attrs [Array<String>]
|
@@ -78,9 +89,9 @@ module Eco
|
|
78
89
|
|
79
90
|
# Lists all defined attributes, types and formats.
|
80
91
|
# @return [Array<String>] the list of defined parsers/serializers.
|
81
|
-
|
82
|
-
|
83
|
-
|
92
|
+
def defined_list
|
93
|
+
@parsers.keys
|
94
|
+
end
|
84
95
|
|
85
96
|
# Returns a list of all the internal attributes of the model that have a parser defined.
|
86
97
|
# @note
|
@@ -94,10 +105,19 @@ module Eco
|
|
94
105
|
end
|
95
106
|
|
96
107
|
# Returns a list of all the internal attributes of the model that have a parser defined & that should be active.
|
97
|
-
# @param [Hash, Array<String>]
|
98
|
-
# @
|
99
|
-
|
100
|
-
|
108
|
+
# @param source_data [Hash, Array<String>] the data that we scope for parsing
|
109
|
+
# @param phase [Symbol] the phase when the attr parser is expected to be called.
|
110
|
+
# Can be [:internal, :final, :person]
|
111
|
+
# @param process [Symbol] either `:parse` or `:serialize`, depending if we want to parse or serialize the `attr`.
|
112
|
+
# @return [Array<String>] list of all attribute defined parsers that should be active for the given `source_data`.
|
113
|
+
def active_attrs(source_data, phase = :any, process: :parse)
|
114
|
+
defined_attrs.select do |attr|
|
115
|
+
if process == :serialize
|
116
|
+
@parsers[attr].serializer_active?(phase)
|
117
|
+
else
|
118
|
+
@parsers[attr].parser_active?(source_data, phase)
|
119
|
+
end
|
120
|
+
end
|
101
121
|
end
|
102
122
|
|
103
123
|
# Returns a list of all the internal attributes of the model that do **not** have a parser defined.
|
@@ -112,6 +132,9 @@ module Eco
|
|
112
132
|
def defined?(attr)
|
113
133
|
@parsers.key?(attr)
|
114
134
|
end
|
135
|
+
# @!endgroup
|
136
|
+
|
137
|
+
# @!group Defining attributes
|
115
138
|
|
116
139
|
# Helper to **merge** a set of parsers of another `PersonParser` into the current object.
|
117
140
|
# @note if there are parsers with same name, it **overrides** the ones of the current object with them.
|
@@ -120,12 +143,11 @@ module Eco
|
|
120
143
|
def merge(parser)
|
121
144
|
return self if !parser
|
122
145
|
raise "Expected a PersonParser object. Given #{parser}" if !parser.is_a?(PersonParser)
|
123
|
-
|
146
|
+
to_h.merge!(parser.to_h)
|
124
147
|
patched!
|
125
148
|
self
|
126
149
|
end
|
127
150
|
|
128
|
-
|
129
151
|
# Helper to define and associate a parser/serializer to a type or attribute.
|
130
152
|
# @raise [Exception] if trying to define a parser/serializer for:
|
131
153
|
# - an unkown attribute (`String`)
|
@@ -136,7 +158,7 @@ module Eco
|
|
136
158
|
# @yieldparam parser [Eco::Language::Models::ParserSerializer] parser to define.
|
137
159
|
# @return [Eco::API::Common::People::PersonParser] the current object (to ease chainig).
|
138
160
|
def define_attribute(attr, dependencies: {}, &definition)
|
139
|
-
|
161
|
+
unless valid?(attr)
|
140
162
|
msg = "The attribute '#{attr_to_str(attr)}' is not part of core, account or target schema, or does not match any type: #{@details_attrs}"
|
141
163
|
raise msg
|
142
164
|
end
|
@@ -147,6 +169,9 @@ module Eco
|
|
147
169
|
patched!
|
148
170
|
self
|
149
171
|
end
|
172
|
+
# @!endgroup
|
173
|
+
|
174
|
+
# @!group Launching parser/serializer
|
150
175
|
|
151
176
|
# Call to parser `source` value of attribute or type `attr` into an internal valid value.
|
152
177
|
# @note dependencies introduced on `parse` call will be merged with those defined during the
|
@@ -154,11 +179,13 @@ module Eco
|
|
154
179
|
# @raise [Exception] if there is **no** parser for attribute or type `attr`.
|
155
180
|
# @param attr [String] target attribute or type to **parse**.
|
156
181
|
# @param source [Any] source value to be parsed.
|
182
|
+
# @param phase [Symbol] the phase when the attr parser is expected to be called.
|
183
|
+
# Must be [:internal, :final]
|
157
184
|
# @param deps [Hash] key-value pairs of call dependencies.
|
158
185
|
# @return [Any] a valid internal value.
|
159
|
-
def parse(attr, source, deps: {})
|
186
|
+
def parse(attr, source, phase = :internal, deps: {})
|
160
187
|
raise "There is no parser for attribute '#{attr}'" if !self.defined?(attr)
|
161
|
-
@parsers[attr].parse(source, dependencies: deps)
|
188
|
+
@parsers[attr].parse(source, phase, dependencies: deps)
|
162
189
|
end
|
163
190
|
|
164
191
|
# Call to serialise `object` value of attribute or type `attr` into an external valid value.
|
@@ -167,26 +194,32 @@ module Eco
|
|
167
194
|
# @raise [Exception] if there is **no** serialiser for attribute or type `attr`.
|
168
195
|
# @param attr [String] target attribute or type to **serialize**.
|
169
196
|
# @param object [Any] object value to be serialized.
|
197
|
+
# @param phase [Symbol] the phase when the attr serializer is expected to be called.
|
198
|
+
# Must be [:internal, :final, :person]
|
170
199
|
# @param deps [Hash] key-value pairs of call dependencies.
|
171
200
|
# @return a valid external value.
|
172
|
-
def serialize(attr, object, deps: {})
|
201
|
+
def serialize(attr, object, phase = :person, deps: {})
|
173
202
|
raise "There is no parser for attribute '#{attr}'" if !self.defined?(attr)
|
174
|
-
@parsers[attr].serialize(object, dependencies: deps)
|
203
|
+
@parsers[attr].serialize(object, phase, dependencies: deps)
|
175
204
|
end
|
205
|
+
# @!endgroup
|
176
206
|
|
177
207
|
protected
|
178
208
|
|
179
209
|
# @return [Hash] attr-parser pairs with all the defined type and attribute parsers/serializers.
|
180
|
-
def
|
210
|
+
def to_h
|
211
|
+
self.class.autoload_children(self)
|
181
212
|
@parsers
|
182
213
|
end
|
183
214
|
|
184
215
|
private
|
185
216
|
|
217
|
+
# Some attribute parsers are **inactive**, and therefore out of scope
|
218
|
+
# @param source_attrs [Array<String>] the attrs we want to filter from to only those in scope.
|
219
|
+
# @param section_attrs [Array<String>] the attrs of reference to scope `source_attrs`.
|
220
|
+
# @return [Array<String>] the `source_attrs` in `section_attrs` + the `section_attrs` with active parser
|
186
221
|
def scoped_attrs(source_attrs, section_attrs)
|
187
|
-
|
188
|
-
parsed_attrs = active_attrs(source_attrs) & section_attrs
|
189
|
-
(source_attrs + parsed_attrs) & (direct_attrs + parsed_attrs)
|
222
|
+
(source_attrs | active_attrs(source_attrs)) & section_attrs
|
190
223
|
end
|
191
224
|
|
192
225
|
def attr_to_str(attr)
|
@@ -3,9 +3,6 @@ module Eco
|
|
3
3
|
module Common
|
4
4
|
module Session
|
5
5
|
class BaseSession
|
6
|
-
|
7
|
-
include Common::People
|
8
|
-
|
9
6
|
attr_accessor :session
|
10
7
|
attr_accessor :environment, :config
|
11
8
|
alias_method :enviro, :environment
|
@@ -32,8 +29,8 @@ module Eco
|
|
32
29
|
enviro.config
|
33
30
|
end
|
34
31
|
|
35
|
-
def api
|
36
|
-
enviro.api
|
32
|
+
def api(version: nil)
|
33
|
+
enviro.api(version: version)
|
37
34
|
end
|
38
35
|
|
39
36
|
def file_manager
|
@@ -47,7 +44,7 @@ module Eco
|
|
47
44
|
def mailer?
|
48
45
|
enviro.mailer?
|
49
46
|
end
|
50
|
-
|
47
|
+
|
51
48
|
def sftp
|
52
49
|
enviro.sftp
|
53
50
|
end
|
@@ -3,11 +3,7 @@ module Eco
|
|
3
3
|
module Common
|
4
4
|
module Session
|
5
5
|
class Environment
|
6
|
-
|
7
|
-
include Common::People
|
8
|
-
|
9
6
|
attr_reader :config, :session
|
10
|
-
attr_reader :api #, :host, :version
|
11
7
|
attr_reader :file_manager, :logger
|
12
8
|
attr_reader :mailer, :sftp, :s3uploader
|
13
9
|
|
@@ -57,25 +53,8 @@ module Eco
|
|
57
53
|
config.s3storage.configured?
|
58
54
|
end
|
59
55
|
|
60
|
-
def api
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
def new_api
|
65
|
-
return nil unless config.apis.active_api
|
66
|
-
|
67
|
-
log_connection = config.logger.log_connection?
|
68
|
-
logg = log_connection ? logger : ::Logger.new(IO::NULL)
|
69
|
-
|
70
|
-
api = config.api(logg)
|
71
|
-
|
72
|
-
unless log_connection
|
73
|
-
logger.info("Created connection pointing to '#{config.apis.active_api.host}' in '#{config.apis.active_api.mode}' mode")
|
74
|
-
api.logger.level = ::Logger::UNKNOWN
|
75
|
-
end
|
76
|
-
|
77
|
-
@api = api
|
78
|
-
api
|
56
|
+
def api(version: nil)
|
57
|
+
config.api(logger, version: version)
|
79
58
|
end
|
80
59
|
|
81
60
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module Ecoportal
|
2
2
|
module API
|
3
3
|
class V1
|
4
|
+
# @attr entry [Eco::API::Common::People::PersonEntry, Hash] the input entry plain hash data used to update/create this person.
|
4
5
|
class Person
|
6
|
+
attr_accessor :entry
|
5
7
|
|
6
8
|
def reset_details!
|
7
9
|
doc["details"] = JSON.parse(original_doc["details"])
|
@@ -2,7 +2,7 @@ module Ecoportal
|
|
2
2
|
module API
|
3
3
|
class Internal
|
4
4
|
class Person
|
5
|
-
|
5
|
+
|
6
6
|
def reset_account!
|
7
7
|
doc["account"] = JSON.parse(original_doc["account"])
|
8
8
|
end
|
@@ -11,6 +11,14 @@ module Ecoportal
|
|
11
11
|
original_doc["account"] = JSON.parse(doc["account"])
|
12
12
|
end
|
13
13
|
|
14
|
+
def new?
|
15
|
+
!initial_doc["details"] && !initial_doc["account"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def account_added?
|
19
|
+
account && !initial_doc["account"]
|
20
|
+
end
|
21
|
+
|
14
22
|
end
|
15
23
|
end
|
16
24
|
end
|
@@ -1,8 +1,30 @@
|
|
1
1
|
class ::Exception
|
2
2
|
def patch_full_message
|
3
3
|
msg = []
|
4
|
-
msg << "#{backtrace.
|
5
|
-
backtrace.
|
4
|
+
msg << "\n#{backtrace.first} \n#{message} (#{self.class.to_s})"
|
5
|
+
backtrace[1..-1].each_with_index {|bt, i| msg << "#{" "*8}#{i+1}: from #{bt}"}
|
6
6
|
msg.join("\n")
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
10
|
+
# To extend an exception message preserving same exception object
|
11
|
+
# @see https://stackoverflow.com/a/30133010/4352306
|
12
|
+
Exception.class_eval do
|
13
|
+
def prepend_message(message)
|
14
|
+
mod = Module.new do
|
15
|
+
define_method :to_s do
|
16
|
+
String(message) + super()
|
17
|
+
end
|
18
|
+
end
|
19
|
+
self.extend mod
|
20
|
+
end
|
21
|
+
|
22
|
+
def append_message(message)
|
23
|
+
mod = Module.new do
|
24
|
+
define_method :to_s do
|
25
|
+
super() + String(message)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
self.extend mod
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
# Set of helper classes to boost configuration easiness
|
4
|
+
module Custom
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
require_relative 'custom/namespace'
|
10
|
+
require_relative 'custom/use_case'
|
11
|
+
require_relative 'custom/policy'
|
12
|
+
require_relative 'custom/error_handler'
|
13
|
+
require_relative 'custom/parser'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Helper class to create a custom `ErrorHandler`
|
2
|
+
# @example Example of usage:
|
3
|
+
# class Custom::ErrorHandler::EmailTaken < Eco::API::Custom::ErrorHandler
|
4
|
+
# error Eco::API::Error::EmailTaken
|
5
|
+
#
|
6
|
+
# def main(people, session, options, handler, job)
|
7
|
+
# people.each do |person|
|
8
|
+
# prev_email = person.initial_doc["email"]
|
9
|
+
# if person.email != prev_email
|
10
|
+
# person.email = prev_email
|
11
|
+
# else
|
12
|
+
# person.account = nil
|
13
|
+
# end
|
14
|
+
# job.add(person)
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
class Eco::API::Custom::ErrorHandler < Eco::API::Common::Loaders::ErrorHandler
|
20
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Helper class to create a custom `Parser`
|
2
|
+
# @example Example of usage:
|
3
|
+
# class Custom::Parser::LoginProviders < Eco::API::Custom::Parser
|
4
|
+
# attribute "login_provider_ids"
|
5
|
+
#
|
6
|
+
# active_when_any "some-field1", "some-field2" # optional
|
7
|
+
# parsing_phase :final # optional, default is (default :internal)
|
8
|
+
# serializing_phase :final # optional, it will be (default :person)
|
9
|
+
#
|
10
|
+
# def parser(hash, deps)
|
11
|
+
# get_values(hash).map do |name|
|
12
|
+
# login_providers.to_id(name&.downcase.strip)
|
13
|
+
# end.compact
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# def serializer(hash, deps)
|
17
|
+
# if ids = hash["login_provider_ids"]
|
18
|
+
# login_providers.to_name(ids)
|
19
|
+
# else
|
20
|
+
# []
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# private
|
25
|
+
#
|
26
|
+
# def get_values(hash)
|
27
|
+
# value, field1, field2 = hash.values_at("login_provider_ids", "some-field1", "some-field2")
|
28
|
+
# return value if value # at the :final parsing phase, login_provider_ids is already an Array
|
29
|
+
# some_logics(field1, field2)
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# def some_logics(a, b)
|
33
|
+
# case a
|
34
|
+
# when "staff"
|
35
|
+
# ["Company SSO"]
|
36
|
+
# when "contractor"
|
37
|
+
# ["Password"]
|
38
|
+
# elsif b
|
39
|
+
# return ["Password"] if b.end_with?("Owner")
|
40
|
+
# ["Password", "Company SSO 2"]
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# def login_providers
|
45
|
+
# @login_providers ||= ASSETS.config.login_providers
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# end
|
49
|
+
class Eco::API::Custom::Parser < Eco::API::Common::Loaders::Parser
|
50
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Helper class to create a custom `Policy`
|
2
|
+
# @example Example of usage:
|
3
|
+
# class Custom::Policy::StartersNLeavers < Eco::API::Custom::Policy
|
4
|
+
# name "starters'n'leavers"
|
5
|
+
#
|
6
|
+
# INACTIVE = "Non active"
|
7
|
+
#
|
8
|
+
# def main(people, session, options, policy, job)
|
9
|
+
# people.each do |person|
|
10
|
+
# next unless details = person.details
|
11
|
+
# # starters
|
12
|
+
# if person.new?
|
13
|
+
# details["status"] = "Active"
|
14
|
+
# details["hris-managed"] = true unless options.dig(:include, :excluded)
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # leavers: native job queue to remove account
|
18
|
+
# if job.name == "leavers"
|
19
|
+
# details["status"] = INACTIVE
|
20
|
+
# person.external_id = person.name
|
21
|
+
# details["staff-id"] = person.name
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# end
|
27
|
+
class Eco::API::Custom::Policy < Eco::API::Common::Loaders::Policy
|
28
|
+
end
|