eco-helpers 1.4.1 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +145 -3
  3. data/LICENSE +21 -0
  4. data/eco-helpers.gemspec +11 -10
  5. data/lib/eco/api.rb +3 -0
  6. data/lib/eco/api/common.rb +5 -1
  7. data/lib/eco/api/common/base_loader.rb +54 -0
  8. data/lib/eco/api/common/class_auto_loader.rb +109 -0
  9. data/lib/eco/api/common/class_helpers.rb +33 -0
  10. data/lib/eco/api/common/class_hierarchy.rb +1 -1
  11. data/lib/eco/api/common/class_meta_basics.rb +16 -0
  12. data/lib/eco/api/common/loaders.rb +13 -0
  13. data/lib/eco/api/common/loaders/error_handler.rb +41 -0
  14. data/lib/eco/api/common/loaders/parser.rb +127 -0
  15. data/lib/eco/api/common/loaders/policy.rb +25 -0
  16. data/lib/eco/api/common/loaders/use_case.rb +40 -0
  17. data/lib/eco/api/common/people/default_parsers.rb +5 -10
  18. data/lib/eco/api/common/people/default_parsers/boolean_parser.rb +13 -23
  19. data/lib/eco/api/common/people/default_parsers/csv_parser.rb +20 -35
  20. data/lib/eco/api/common/people/default_parsers/date_parser.rb +15 -26
  21. data/lib/eco/api/common/people/default_parsers/freemium_parser.rb +20 -0
  22. data/lib/eco/api/common/people/default_parsers/login_providers_parser.rb +26 -0
  23. data/lib/eco/api/common/people/default_parsers/multi_parser.rb +15 -27
  24. data/lib/eco/api/common/people/default_parsers/numeric_parser.rb +14 -19
  25. data/lib/eco/api/common/people/default_parsers/policy_groups_parser.rb +31 -0
  26. data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +15 -24
  27. data/lib/eco/api/common/people/entries.rb +54 -24
  28. data/lib/eco/api/common/people/entry_factory.rb +18 -15
  29. data/lib/eco/api/common/people/person_attribute_parser.rb +29 -12
  30. data/lib/eco/api/common/people/person_entry.rb +308 -216
  31. data/lib/eco/api/common/people/person_entry_attribute_mapper.rb +5 -2
  32. data/lib/eco/api/common/people/person_parser.rb +52 -19
  33. data/lib/eco/api/common/session/base_session.rb +3 -6
  34. data/lib/eco/api/common/session/environment.rb +2 -23
  35. data/lib/eco/api/common/session/logger.rb +4 -0
  36. data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +2 -0
  37. data/lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb +9 -1
  38. data/lib/eco/api/common/version_patches/exception.rb +24 -2
  39. data/lib/eco/api/custom.rb +13 -0
  40. data/lib/eco/api/custom/error_handler.rb +20 -0
  41. data/lib/eco/api/custom/namespace.rb +7 -0
  42. data/lib/eco/api/custom/parser.rb +50 -0
  43. data/lib/eco/api/custom/policy.rb +28 -0
  44. data/lib/eco/api/custom/use_case.rb +16 -0
  45. data/lib/eco/api/error.rb +1 -0
  46. data/lib/eco/api/error/handlers.rb +10 -3
  47. data/lib/eco/api/microcases.rb +35 -0
  48. data/lib/eco/api/microcases/account_excluded.rb +24 -0
  49. data/lib/eco/api/microcases/append_usergroups.rb +19 -0
  50. data/lib/eco/api/microcases/core_excluded.rb +20 -0
  51. data/lib/eco/api/microcases/fix_default_group.rb +34 -0
  52. data/lib/eco/api/microcases/fix_filter_tags.rb +42 -0
  53. data/lib/eco/api/microcases/people_cache.rb +17 -0
  54. data/lib/eco/api/microcases/people_load.rb +59 -0
  55. data/lib/eco/api/microcases/people_refresh.rb +31 -0
  56. data/lib/eco/api/microcases/people_search.rb +65 -0
  57. data/lib/eco/api/microcases/refresh_abilities.rb +19 -0
  58. data/lib/eco/api/microcases/refresh_default_tag.rb +27 -0
  59. data/lib/eco/api/microcases/s3upload_targets.rb +39 -0
  60. data/lib/eco/api/microcases/set_account.rb +20 -0
  61. data/lib/eco/api/microcases/set_core.rb +18 -0
  62. data/lib/eco/api/microcases/set_core_with_supervisor.rb +23 -0
  63. data/lib/eco/api/microcases/set_supervisor.rb +30 -0
  64. data/lib/eco/api/microcases/strict_search.rb +19 -0
  65. data/lib/eco/api/microcases/with_each.rb +27 -0
  66. data/lib/eco/api/microcases/with_each_leaver.rb +24 -0
  67. data/lib/eco/api/microcases/with_each_present.rb +30 -0
  68. data/lib/eco/api/microcases/with_each_starter.rb +30 -0
  69. data/lib/eco/api/microcases/with_each_subordinate.rb +34 -0
  70. data/lib/eco/api/microcases/with_supervisor.rb +36 -0
  71. data/lib/eco/api/organization/people.rb +72 -35
  72. data/lib/eco/api/organization/presets_factory.rb +13 -4
  73. data/lib/eco/api/organization/presets_reference.json +9 -1
  74. data/lib/eco/api/organization/presets_values.json +4 -1
  75. data/lib/eco/api/policies.rb +11 -7
  76. data/lib/eco/api/session.rb +62 -29
  77. data/lib/eco/api/session/batch.rb +2 -45
  78. data/lib/eco/api/session/batch/base_policy.rb +7 -6
  79. data/lib/eco/api/session/batch/errors.rb +28 -4
  80. data/lib/eco/api/session/batch/feedback.rb +7 -1
  81. data/lib/eco/api/session/batch/job.rb +40 -23
  82. data/lib/eco/api/session/batch/jobs.rb +9 -4
  83. data/lib/eco/api/session/batch/jobs_groups.rb +1 -1
  84. data/lib/eco/api/session/batch/request_stats.rb +95 -58
  85. data/lib/eco/api/session/batch/status.rb +35 -31
  86. data/lib/eco/api/session/config.rb +106 -44
  87. data/lib/eco/api/session/config/api.rb +132 -7
  88. data/lib/eco/api/session/config/apis.rb +24 -25
  89. data/lib/eco/api/session/config/logger.rb +2 -2
  90. data/lib/eco/api/session/config/post_launch.rb +1 -1
  91. data/lib/eco/api/session/config/workflow.rb +8 -7
  92. data/lib/eco/api/usecases.rb +47 -33
  93. data/lib/eco/api/usecases/backup/append_usergroups_case.rb +36 -0
  94. data/lib/eco/api/usecases/backup/create_case.rb +104 -0
  95. data/lib/eco/api/usecases/backup/create_details_case.rb +31 -0
  96. data/lib/eco/api/usecases/backup/create_details_with_supervisor_case.rb +48 -0
  97. data/lib/eco/api/usecases/backup/hris_case.rb +124 -0
  98. data/lib/eco/api/usecases/backup/set_default_tag_case.rb +49 -0
  99. data/lib/eco/api/usecases/backup/set_supervisor_case.rb +41 -0
  100. data/lib/eco/api/usecases/backup/transfer_account_case.rb +90 -0
  101. data/lib/eco/api/usecases/backup/update_case.rb +112 -0
  102. data/lib/eco/api/usecases/backup/update_details_case.rb +64 -0
  103. data/lib/eco/api/usecases/backup/upsert_case.rb +114 -0
  104. data/lib/eco/api/usecases/base_case.rb +2 -0
  105. data/lib/eco/api/usecases/base_io.rb +3 -3
  106. data/lib/eco/api/usecases/default_cases.rb +23 -53
  107. data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +10 -31
  108. data/lib/eco/api/usecases/default_cases/change_email_case.rb +23 -47
  109. data/lib/eco/api/usecases/default_cases/codes_to_tags_case.rb +56 -43
  110. data/lib/eco/api/usecases/default_cases/create_case.rb +15 -101
  111. data/lib/eco/api/usecases/default_cases/create_details_case.rb +11 -26
  112. data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +12 -43
  113. data/lib/eco/api/usecases/default_cases/delete_sync_case.rb +11 -0
  114. data/lib/eco/api/usecases/default_cases/delete_trans_case.rb +14 -0
  115. data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +10 -21
  116. data/lib/eco/api/usecases/default_cases/hris_case.rb +23 -120
  117. data/lib/eco/api/usecases/default_cases/new_email_case.rb +10 -23
  118. data/lib/eco/api/usecases/default_cases/new_id_case.rb +11 -25
  119. data/lib/eco/api/usecases/default_cases/new_id_case0.rb +14 -0
  120. data/lib/eco/api/usecases/default_cases/org_data_convert_case.rb +83 -0
  121. data/lib/eco/api/usecases/default_cases/refresh_abilities_case.rb +30 -0
  122. data/lib/eco/api/usecases/default_cases/refresh_case.rb +7 -20
  123. data/lib/eco/api/usecases/default_cases/reinvite_sync_case.rb +11 -0
  124. data/lib/eco/api/usecases/default_cases/reinvite_trans_case.rb +17 -0
  125. data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +11 -0
  126. data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +17 -0
  127. data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +9 -19
  128. data/lib/eco/api/usecases/default_cases/restore_db_case.rb +92 -0
  129. data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +32 -40
  130. data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +15 -33
  131. data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +66 -57
  132. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +36 -44
  133. data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +40 -55
  134. data/lib/eco/api/usecases/default_cases/transfer_account_case.rb +264 -84
  135. data/lib/eco/api/usecases/default_cases/update_case.rb +15 -109
  136. data/lib/eco/api/usecases/default_cases/update_details_case.rb +14 -61
  137. data/lib/eco/api/usecases/default_cases/upsert_case.rb +16 -111
  138. data/lib/eco/api/usecases/use_case_io.rb +9 -9
  139. data/lib/eco/cli/config.rb +10 -2
  140. data/lib/eco/cli/config/default.rb +2 -1
  141. data/lib/eco/cli/config/default/input_filters.rb +58 -0
  142. data/lib/eco/cli/config/default/options.rb +60 -25
  143. data/lib/eco/cli/config/default/people.rb +4 -4
  144. data/lib/eco/cli/config/default/people_filters.rb +108 -0
  145. data/lib/eco/cli/config/default/usecases.rb +69 -32
  146. data/lib/eco/cli/config/default/workflow.rb +37 -27
  147. data/lib/eco/cli/config/filters.rb +50 -0
  148. data/lib/eco/cli/config/filters/input_filters.rb +29 -0
  149. data/lib/eco/cli/config/filters/people_filters.rb +29 -0
  150. data/lib/eco/cli/config/help.rb +49 -0
  151. data/lib/eco/cli/config/options_set.rb +17 -1
  152. data/lib/eco/cli/config/use_cases.rb +79 -53
  153. data/lib/eco/cli/scripting.rb +10 -2
  154. data/lib/eco/cli/scripting/args_helpers.rb +25 -15
  155. data/lib/eco/cli/scripting/argument.rb +1 -0
  156. data/lib/eco/cli/scripting/arguments.rb +1 -1
  157. data/lib/eco/csv.rb +8 -3
  158. data/lib/eco/csv/table.rb +1 -1
  159. data/lib/eco/data/crypto/encryption.rb +3 -0
  160. data/lib/eco/data/files/helpers.rb +6 -1
  161. data/lib/eco/language/match.rb +19 -9
  162. data/lib/eco/language/match_modifier.rb +13 -5
  163. data/lib/eco/language/models/collection.rb +77 -56
  164. data/lib/eco/language/models/parser_serializer.rb +39 -15
  165. data/lib/eco/version.rb +1 -1
  166. metadata +149 -63
  167. data/lib/eco/api/session/task.rb +0 -175
  168. data/lib/eco/api/usecases/default_case.rb +0 -19
  169. data/lib/eco/api/usecases/default_cases/delete_case.rb +0 -32
  170. data/lib/eco/api/usecases/default_cases/recover_db_case.rb +0 -98
  171. data/lib/eco/api/usecases/default_cases/refresh_presets_case.rb +0 -26
  172. data/lib/eco/api/usecases/default_cases/reinvite_case.rb +0 -41
  173. data/lib/eco/api/usecases/default_cases/remove_account_case.rb +0 -38
  174. data/lib/eco/cli/config/default/filters.rb +0 -70
  175. data/lib/eco/cli/config/people_filters.rb +0 -38
@@ -42,6 +42,11 @@ module Eco
42
42
  compile(*preset_names)
43
43
  end
44
44
 
45
+ # @return [Array<String>] all the abilities
46
+ def keys
47
+ @abilities.keys
48
+ end
49
+
45
50
  private
46
51
 
47
52
  def init_custom(file = DEFAULT_CUSTOM)
@@ -104,21 +109,25 @@ module Eco
104
109
 
105
110
  def compile(*preset_names)
106
111
  fatal("You need to specify an existing file for the custom presets.") if !@presets_custom
107
- @presets_custom.values_at(*preset_names).compact.reduce(empty_model) do |p1, p2|
112
+ @presets_custom.values_at(*preset_names).compact.reduce({}) do |p1, p2|
108
113
  merge(p1, p2)
109
114
  end
110
115
  end
111
116
 
112
117
  def merge(preset1, preset2)
113
- @abilities.map do |key, values|
118
+ keys = preset1.keys | preset2.keys
119
+
120
+ @abilities.each_with_object({}) do |(key, values), result|
121
+ next unless keys.include?(key)
114
122
  idx = [
115
123
  values.index(preset1[key]),
116
124
  values.index(preset2[key])
117
125
  ].compact.max
118
- [key, idx && values[idx]]
119
- end.to_h
126
+ result[key] = idx && values[idx]
127
+ end
120
128
  end
121
129
 
130
+ # unsused: only play with the given abilities
122
131
  def empty_model
123
132
  JSON.parse(@abilities.to_json).transform_values {|v| nil }
124
133
  end
@@ -6,6 +6,8 @@
6
6
  "organization": null,
7
7
  "people": null,
8
8
  "person_core": null,
9
+ "person_core_create": null,
10
+ "person_core_edit": null,
9
11
  "person_account": null,
10
12
  "person_details": null,
11
13
  "pages": "view",
@@ -18,6 +20,8 @@
18
20
  "reports": "view",
19
21
  "organization": null,
20
22
  "person_core": "attach",
23
+ "person_core_create": null,
24
+ "person_core_edit": null,
21
25
  "person_account": null,
22
26
  "person_details": "view",
23
27
  "pages": "create",
@@ -30,6 +34,8 @@
30
34
  "reports": "edit",
31
35
  "organization": "view",
32
36
  "person_core": "view_people_manager",
37
+ "person_core_create": null,
38
+ "person_core_edit": null,
33
39
  "person_account": "view",
34
40
  "person_details": "view",
35
41
  "pages": "create",
@@ -41,7 +47,9 @@
41
47
  "data": "administrate",
42
48
  "reports": "administrate",
43
49
  "organization": "administrate",
44
- "person_core": "edit",
50
+ "person_core": "view_people_manager",
51
+ "person_core_create": "create",
52
+ "person_core_edit": "edit",
45
53
  "person_account": "edit",
46
54
  "person_details": "edit_private",
47
55
  "pages": "administrate",
@@ -2,8 +2,11 @@
2
2
  "files": [null, "download", "upload", "browse", "administrate"],
3
3
  "data": [null, "view", "update", "administrate", "implement"],
4
4
  "reports": [null, "view", "edit", "administrate"],
5
+ "tasks": [null, "reassign_self", "reassign", "administrate"],
5
6
  "organization": [null, "view", "administrate", "implement"],
6
- "person_core": [null, "attach", "view_people_manager", "create", "edit", "dashboard"],
7
+ "person_core": [null, "attach", "view_people_manager", "dashboard"],
8
+ "person_core_create": [null, "create"],
9
+ "person_core_edit": [null, "edit"],
7
10
  "person_account": [null, "view", "create", "edit"],
8
11
  "person_details": [null, "view", "edit_public", "view_private", "edit_private"],
9
12
  "pages": [null, "view", "update", "create", "administrate"],
@@ -1,12 +1,12 @@
1
1
  module Eco
2
2
  module API
3
+ # @todo the autoloading happens on `add`, and there could be multiple pending children to load.
4
+ # This could translate into the policies not being loaded in order
3
5
  class Policies < Eco::API::UseCases
4
- attr_reader :policies
6
+ autoloads_children_of "Eco::API::Common::Loaders::Policy"
7
+ autoload_namespace_ignore "Eco::API"
5
8
 
6
- def add(policy)
7
- raise "Expected Eco::API::Policies::Policy object. Given: #{policy}" unless policy.is_a?(Eco::API::Policies::Policy)
8
- super(policy)
9
- end
9
+ attr_reader :policies
10
10
 
11
11
  def define(name, type: :transform, &block)
12
12
  Eco::API::Policies::Policy.new(name, type: type, root: self, &block).tap do |policy|
@@ -14,12 +14,16 @@ module Eco
14
14
  end
15
15
  end
16
16
 
17
- def launch(people:, session:, job:, options: {})
17
+ def add(policy)
18
+ raise "Expected Eco::API::Policies::Policy object. Given: #{policy}" unless policy.is_a?(Eco::API::Policies::Policy)
19
+ super(policy)
20
+ end
18
21
 
22
+ def launch(people:, session:, job:, options: {})
19
23
  args = {
20
24
  people: people,
21
25
  session: session,
22
- job: job,
26
+ job: job,
23
27
  options: options
24
28
  }
25
29
 
@@ -17,17 +17,13 @@ module Eco
17
17
  logger.debug("LINE COMMAND: #{$0} #{ARGV.join(" ")}")
18
18
  end
19
19
 
20
- # Helper to perform multiple operations in one go.
21
- # @return [Eco::API::Session::Task] provides shortcuts to manage certain kind of operations.
22
- def do
23
- @task ||= Task.new(enviro)
24
- end
25
-
26
20
  # @return [Eco::API::Session::Batch] provides helper to launch batch operations.
27
21
  def batch
28
22
  @batch ||= Batch.new(enviro)
29
23
  end
30
24
 
25
+ # @!group Pure organization helpers
26
+
31
27
  # @see Eco::API::Session::Config#policy_groups
32
28
  def policy_groups
33
29
  config.policy_groups
@@ -47,6 +43,9 @@ module Eco
47
43
  def schemas
48
44
  config.schemas
49
45
  end
46
+ # @!endgroup
47
+
48
+ # @!group People and Input entries helpers
50
49
 
51
50
  # @return [String, Ecoportal::API::V1::PersonSchema] current active session's schema
52
51
  def schema
@@ -56,7 +55,7 @@ module Eco
56
55
 
57
56
  # Sets the current target `PersonSchema` of this session.
58
57
  # @note observe that it is essential for the parsers/serialisers to identify target/present attributes.
59
- # @param schema [String, Ecoportal::API::V1::PersonSchema] where `String` can be the _name_ or the _id_ of the schema.
58
+ # @param value [String, Ecoportal::API::V1::PersonSchema] where `String` can be the _name_ or the _id_ of the schema.
60
59
  def schema=(value)
61
60
  @schema = to_schema(value)
62
61
  self
@@ -64,7 +63,7 @@ module Eco
64
63
 
65
64
  # Builds the presets using the usergroup ids of the input.
66
65
  # @note for each flag/ability it will take the highest among those mapped for the present usergroups.
67
- # @param [Ecoportal::API::Internal::Person, Array<String>] the array should be of usegroup names or ids.
66
+ # @param input [Ecoportal::API::Internal::Person, Array<String>] the array should be of usegroup names or ids.
68
67
  # @return [Hash] with custom presets.
69
68
  def new_preset(input)
70
69
  case input
@@ -77,6 +76,15 @@ module Eco
77
76
  end
78
77
  end
79
78
 
79
+ # Helper to state the abilities that a person should have with given their usergroups
80
+ def presets_factory
81
+ @presets_factory ||= Eco::API::Organization::PresetsFactory.new({
82
+ presets_custom: file_manager.dir.file(config.people.presets_custom, should_exist: true),
83
+ presets_map: file_manager.dir.file(config.people.presets_map, should_exist: true),
84
+ enviro: enviro
85
+ })
86
+ end
87
+
80
88
  # Helper to obtain a EntryFactory
81
89
  # @param schema [String, Ecoportal::API::V1::PersonSchema] `schema` to which associate the EntryFactory,
82
90
  # where `String` can be the _name_ or the _id_ of the schema.
@@ -86,26 +94,24 @@ module Eco
86
94
  schema = to_schema(schema) || self.schema
87
95
  return @entry_factories[schema&.id] if @entry_factories.key?(schema&.id)
88
96
 
89
- # TODO: check PersonEntry#to_internal and #to_external in init_attr_trackers
90
- # => when attr_map is avoided, it doesn't work as it should
91
97
  mappings = []
92
98
  if map_file = config.people.fields_mapper
93
99
  mappings = map_file ? file_manager.load_json(map_file) : []
94
100
  end
95
101
 
96
- @entry_factories[schema&.id] = Eco::API::Common::People::EntryFactory.new({
102
+ @entry_factories[schema&.id] = Eco::API::Common::People::EntryFactory.new(
103
+ enviro,
97
104
  schema: schema,
98
105
  person_parser: config.people.parser,
99
- attr_map: Eco::Data::Mapper.new(mappings),
100
- logger: logger
101
- })
106
+ attr_map: Eco::Data::Mapper.new(mappings)
107
+ )
102
108
  end
103
109
 
104
110
  # Helper to obtain a PersonFactory
105
111
  # @param schema [String, Ecoportal::API::V1::PersonSchema] `schema` to which associate the PersonFactory,
106
112
  # where `String` can be the _name_ or the _id_ of the schema.
107
113
  # @return [Eco::API::Common::People::PersonFactory] associated to `schema`.
108
- # If `schema` is `nil` or not provided it uses the currently associated to the `session`
114
+ # If `schema` is `nil` or not provided it uses the currently associated to the `session`
109
115
  def person_factory(schema: nil)
110
116
  schema = to_schema(schema) || self.schema
111
117
  @person_factories[schema&.id] ||= Eco::API::Common::People::PersonFactory.new(schema: schema)
@@ -115,18 +121,22 @@ module Eco
115
121
  # @note the use of these method requires to know which is the expected format of `source`
116
122
  # @param attr [String] type (`Symbol`) or attribute (`String`) to target a specific parser.
117
123
  # @param source [Any] source value to be parsed.
118
- def parse_attribute(attr, source)
124
+ # @param phase [Symbol] the phase when this parser should be active.
125
+ def parse_attribute(attr, source, phase = :internal)
119
126
  unless parsers = entry_factory.person_parser
120
127
  raise "There are no parsers defined"
121
128
  end
122
129
  parsers.parse(attr, source)
123
130
  end
124
131
 
132
+ # @see Eco::API::Common::People::EntryFactory#export
133
+ # @param (see Eco::API::Common::People::EntryFactory#export)
125
134
  def export(*args)
126
135
  entry_factory.export(*args)
127
136
  end
128
137
 
129
138
  # @see Eco::API::Common::People::EntryFactory#new
139
+ # @param (see Eco::API::Common::People::EntryFactory#new)
130
140
  # @return [Ecoportal::API::Internal::Person]
131
141
  def new_person(**keyed_args)
132
142
  person_factory.new(**keyed_args)
@@ -140,6 +150,7 @@ module Eco
140
150
  end
141
151
 
142
152
  # @see Eco::API::Common::People::EntryFactory#entries
153
+ # @param (see Eco::API::Common::People::EntryFactory#entries)
143
154
  # @return [Eco::API::Common::People::Entries] collection of entries.
144
155
  def entries(*args)
145
156
  entry_factory.entries(*args).tap do |collection|
@@ -161,33 +172,52 @@ module Eco
161
172
  def discarded_entries
162
173
  return @discarded_entries if instance_variable_defined?(:@discarded_entries)
163
174
  file = config.people.discarded_file
164
- file = file_manager.dir.file(file)
175
+ fatal("You have not specified the 'discarded_people_file'") unless file = file_manager.dir.file(file)
165
176
  @discarded_entries = csv_entries(file)
166
177
  end
178
+ # @!endgroup
179
+
180
+ # @!group Session workflow and batch job launces
167
181
 
182
+ # Opens up the `workflow` configuration
168
183
  def workflow(io:)
169
184
  config.workflow.tap do |wf|
170
185
  yield(wf, io) if block_given?
171
186
  end
172
187
  end
173
188
 
189
+ # Does merge `Eco::API::UseCases::DefaultCases` with the custom cases.
190
+ # @return [Eco::API::UseCases]
174
191
  def usecases
175
- @usecases ||= Eco::API::UseCases::DefaultCases.new.merge(config.usecases)
192
+ @usecases ||= config.usecases.dup.tap do |cases|
193
+ all_cases = Eco::API::UseCases::DefaultCases.new.merge(config.usecases)
194
+ cases.merge(all_cases)
195
+ end
196
+ end
197
+
198
+ # Set of helpers to simplify your code
199
+ # @see Eco::API::MicroCases
200
+ # @return [Eco::API::MicroCases]
201
+ def micro
202
+ @micro ||= Eco::API::MicroCases.new(enviro)
176
203
  end
177
204
 
178
205
  def post_launch
179
206
  @post_launch ||= config.post_launch.select(usecases)
180
207
  end
181
208
 
209
+ # @see Eco::API::UseCases::Case#launch
182
210
  def process_case(name, io: nil, type: nil, **params)
183
211
  args = { session: self }.merge(params)
184
212
  usecases.case(name, type: type).launch(io: io, **args)
185
213
  end
186
214
 
215
+ # @return [Eco::API::Session::Batch::JobsGroups]
187
216
  def job_groups
188
217
  @job_groups ||= Batch::JobsGroups.new(enviro)
189
218
  end
190
219
 
220
+ # @return [Eco::API::Session::Batch::Jobs]
191
221
  def job_group(name, order: :last)
192
222
  case
193
223
  when job_groups.exists?(name)
@@ -197,16 +227,28 @@ module Eco
197
227
  end
198
228
  end
199
229
 
230
+ # Shortcut to create a job of certain type within a group
231
+ # @return [Eco::API::Session::Batch::Job]
232
+ def new_job(group, name, type, usecase, sets = [:core, :details, :account])
233
+ job_group(group).new(name, usecase: usecase, type: type, sets: sets)
234
+ end
235
+
236
+ # @see Eco::API::Session::Batch::JobsGroups#launch
200
237
  def jobs_launch(simulate: false)
201
238
  job_groups.launch(simulate: simulate)
202
239
  end
203
240
 
241
+ # @see Eco::API::Session::Batch::JobsGroups#summary
204
242
  def summary
205
243
  job_groups.summary
206
244
  end
245
+ # @!endgroup
246
+
247
+ # @!group Additional resources
207
248
 
208
249
  # Sends an email
209
250
  # @see Eco::API::Common::Session::Mailer#mail
251
+ # @param (see Eco::API::Common::Session::Mailer#mail)
210
252
  def mail(**kargs)
211
253
  if mailer?
212
254
  mailer.mail(**kargs)
@@ -229,7 +271,7 @@ module Eco
229
271
  def s3upload(content: nil, file: nil, directory: nil, recurse: false, link: false)
230
272
  if s3uploader?
231
273
  if content == :target
232
- path = self.do.s3upload_targets
274
+ path = micro.s3upload_targets
233
275
  elsif content && file
234
276
  path = s3uploader.upload(file, content)
235
277
  elsif file
@@ -246,18 +288,10 @@ module Eco
246
288
  nil
247
289
  end
248
290
  end
291
+ # @!endgroup
249
292
 
250
293
  private
251
294
 
252
- # Helper to state the abilities that a person should have with given their usergroups
253
- def presets_factory
254
- @presets_factory ||= Eco::API::Organization::PresetsFactory.new({
255
- presets_custom: file_manager.dir.file(config.people.presets_custom, should_exist: true),
256
- presets_map: file_manager.dir.file(config.people.presets_map, should_exist: true),
257
- enviro: enviro
258
- })
259
- end
260
-
261
295
  # Comparer to state if 2 schemas are different
262
296
  def same_schema? (schema1, schema2)
263
297
  eq = schema1&.id == schema2&.id
@@ -288,4 +322,3 @@ end
288
322
 
289
323
  require_relative 'session/config'
290
324
  require_relative 'session/batch'
291
- require_relative 'session/task'
@@ -24,7 +24,7 @@ module Eco
24
24
  # @option params [String] :q some text to search. Omit this parameter to target all the people.
25
25
  # @return [Array<People>] all the people based on `params`
26
26
  def get_people(people = nil, params: {}, silent: false)
27
- return launch(people, method: :get, params: params, silent: silent) if people.is_a?(Enumerable)
27
+ return launch(people, method: :get, params: params, silent: silent).people if people.is_a?(Enumerable)
28
28
  return get(params: params, silent: silent)
29
29
  end
30
30
 
@@ -92,50 +92,7 @@ module Eco
92
92
  params = {per_page: DEFAULT_BATCH_BLOCK}.merge(params)
93
93
  client = people_api.client
94
94
 
95
- looping = !params.key?(:page)
96
- page = params[:page] || 1
97
-
98
- people = []; total_pages = nil
99
- cursor_id = nil
100
- loop do
101
- params.merge!(cursor_id: cursor_id) unless !cursor_id
102
- people_res, response = client_get(client, params: params.merge(page: page), silent: silent)
103
- people += people_res
104
-
105
- total_iterations ||= response.body["total_pages"]
106
- no_pages = !response.body["total_pages"]
107
- total_results ||= response.body["total_results"]
108
-
109
- if !total_iterations
110
- total_iterations ||= (total_results.to_f / params[:per_page]).ceil
111
- end
112
-
113
- msg = "iteration number: #{page}/#{total_iterations}, got num people #{people_res.length}, with total #{people.length} people got"
114
- msg = "search(q=#{params[:q]}) " + msg if params.key?(:q)
115
- logger.info(msg) unless silent
116
-
117
- iterate = (no_pages && cursor_id = response.body["cursor_id"]) || (looping && page < total_iterations)
118
- break unless iterate
119
- page += 1
120
- end
121
-
122
- return people
123
- end
124
-
125
- def client_get(client, params:, silent: false)
126
- response = client.get("/people", params: params)
127
- unless response.success?
128
- msg = "Request failed - params: #{params}"
129
- msg += "\n Error message: - Status #{response.status}: #{response.body}"
130
- fatal msg
131
- end
132
- people = []
133
- response.body["results"].each do |person_hash|
134
- person = Ecoportal::API::Internal::Person.new(person_hash)
135
- yield person if block_given?
136
- people.push(person)
137
- end
138
- [people, response]
95
+ return people_api.get_all(params: params, silent: silent)
139
96
  end
140
97
 
141
98
  def batch_from(data, method:, params: {}, silent: false)
@@ -2,7 +2,7 @@ module Eco
2
2
  module API
3
3
  class Session
4
4
  class Batch
5
- # Helper class to build a hiearchical model of policies
5
+ # Helper class to build a hierarchical model of policies
6
6
  # @example Usage:
7
7
  # class PolicyModel < Eco::API::Session::Batch::BasePolicy
8
8
  # MODEL = {attr1: ["prop1a", "prop1b", {"prop1c": ["prop1c1"]}]}
@@ -37,7 +37,7 @@ module Eco
37
37
  end
38
38
 
39
39
  # Attributes of this level of the model that should be included
40
- # @param attr [Symbol, String] each of the subpolicies of the model that should be available
40
+ # @param attrs [Array<Symbol>, Array<String>] each of the subpolicies of the model that should be available
41
41
  def policy_attrs(*attrs)
42
42
  attrs = attrs.map(&:to_sym)
43
43
 
@@ -82,14 +82,14 @@ module Eco
82
82
 
83
83
  # @note if there's no `min` defined, it always returns `true`
84
84
  # @param value [Integer] value to check if it's in the minimum required
85
- # @retrun [Boolen] `true` if `value` is grater or equal to `min`
85
+ # @return [Boolen] `true` if `value` is grater or equal to `min`
86
86
  def min?(value)
87
87
  !min || !value|| (min <= value)
88
88
  end
89
89
 
90
90
  # @note if there's no `max` defined, it always returns `true`
91
91
  # @param value [Integer] value to check if it's in the maximum allowed
92
- # @retrun [Boolen] `true` if `value` is lesser or equal to `min`
92
+ # @return [Boolen] `true` if `value` is lesser or equal to `min`
93
93
  def max?(value)
94
94
  !max || !value || (max >= value)
95
95
  end
@@ -109,7 +109,7 @@ module Eco
109
109
  !empty?
110
110
  end
111
111
 
112
- def each(params: {}, &block)
112
+ def each(&block)
113
113
  return to_enum(:each) unless block
114
114
  items.each(&block)
115
115
  end
@@ -212,7 +212,8 @@ module Eco
212
212
  end
213
213
 
214
214
  def model_attr(hash)
215
- hash[self.attr] || hash[self.attr.to_s] if model_attr?(hash)
215
+ return hash[self.attr] if hash.key?(self.attr)
216
+ hash[self.attr.to_s] if model_attr?(hash)
216
217
  end
217
218
 
218
219
  private