eco-helpers 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +82 -2
  3. data/LICENSE +21 -0
  4. data/eco-helpers.gemspec +1 -1
  5. data/lib/eco/api.rb +2 -0
  6. data/lib/eco/api/common.rb +4 -0
  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 +3 -12
  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 +15 -25
  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 +24 -35
  26. data/lib/eco/api/common/people/default_parsers/send_invites_parser.rb +15 -25
  27. data/lib/eco/api/common/people/entries.rb +54 -24
  28. data/lib/eco/api/common/people/entry_factory.rb +10 -8
  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 +3 -2
  32. data/lib/eco/api/common/people/person_parser.rb +51 -18
  33. data/lib/eco/api/common/session/logger.rb +4 -0
  34. data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +2 -0
  35. data/lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb +1 -1
  36. data/lib/eco/api/common/version_patches/exception.rb +22 -0
  37. data/lib/eco/api/custom.rb +13 -0
  38. data/lib/eco/api/custom/error_handler.rb +20 -0
  39. data/lib/eco/api/custom/namespace.rb +7 -0
  40. data/lib/eco/api/custom/parser.rb +50 -0
  41. data/lib/eco/api/custom/policy.rb +28 -0
  42. data/lib/eco/api/custom/use_case.rb +16 -0
  43. data/lib/eco/api/error.rb +1 -0
  44. data/lib/eco/api/error/handlers.rb +10 -3
  45. data/lib/eco/api/microcases.rb +17 -13
  46. data/lib/eco/api/microcases/account_excluded.rb +24 -0
  47. data/lib/eco/api/microcases/append_usergroups.rb +19 -0
  48. data/lib/eco/api/microcases/core_excluded.rb +4 -4
  49. data/lib/eco/api/microcases/{set_default_group.rb → fix_default_group.rb} +10 -9
  50. data/lib/eco/api/microcases/fix_filter_tags.rb +26 -6
  51. data/lib/eco/api/microcases/people_cache.rb +17 -0
  52. data/lib/eco/api/microcases/people_load.rb +59 -0
  53. data/lib/eco/api/microcases/people_refresh.rb +31 -0
  54. data/lib/eco/api/microcases/people_search.rb +65 -0
  55. data/lib/eco/api/microcases/refresh_abilities.rb +19 -0
  56. data/lib/eco/api/microcases/refresh_default_tag.rb +27 -0
  57. data/lib/eco/api/microcases/s3upload_targets.rb +39 -0
  58. data/lib/eco/api/microcases/set_account.rb +7 -19
  59. data/lib/eco/api/microcases/set_core.rb +5 -5
  60. data/lib/eco/api/microcases/set_core_with_supervisor.rb +23 -0
  61. data/lib/eco/api/microcases/set_supervisor.rb +17 -13
  62. data/lib/eco/api/microcases/strict_search.rb +12 -7
  63. data/lib/eco/api/microcases/with_each.rb +27 -0
  64. data/lib/eco/api/microcases/with_each_leaver.rb +24 -0
  65. data/lib/eco/api/microcases/with_each_present.rb +30 -0
  66. data/lib/eco/api/microcases/with_each_starter.rb +30 -0
  67. data/lib/eco/api/microcases/with_each_subordinate.rb +34 -0
  68. data/lib/eco/api/microcases/with_supervisor.rb +36 -0
  69. data/lib/eco/api/organization/people.rb +72 -35
  70. data/lib/eco/api/organization/presets_factory.rb +13 -4
  71. data/lib/eco/api/policies.rb +11 -7
  72. data/lib/eco/api/session.rb +54 -24
  73. data/lib/eco/api/session/batch.rb +1 -1
  74. data/lib/eco/api/session/batch/base_policy.rb +7 -6
  75. data/lib/eco/api/session/batch/errors.rb +28 -4
  76. data/lib/eco/api/session/batch/feedback.rb +7 -1
  77. data/lib/eco/api/session/batch/job.rb +40 -23
  78. data/lib/eco/api/session/batch/jobs.rb +9 -4
  79. data/lib/eco/api/session/batch/jobs_groups.rb +1 -1
  80. data/lib/eco/api/session/batch/request_stats.rb +91 -58
  81. data/lib/eco/api/session/batch/status.rb +35 -31
  82. data/lib/eco/api/session/config.rb +104 -42
  83. data/lib/eco/api/session/config/api.rb +17 -6
  84. data/lib/eco/api/session/config/logger.rb +2 -2
  85. data/lib/eco/api/session/config/post_launch.rb +1 -1
  86. data/lib/eco/api/session/config/workflow.rb +8 -7
  87. data/lib/eco/api/usecases.rb +47 -33
  88. data/lib/eco/api/usecases/backup/append_usergroups_case.rb +36 -0
  89. data/lib/eco/api/usecases/backup/create_case.rb +104 -0
  90. data/lib/eco/api/usecases/backup/create_details_case.rb +31 -0
  91. data/lib/eco/api/usecases/backup/create_details_with_supervisor_case.rb +48 -0
  92. data/lib/eco/api/usecases/backup/hris_case.rb +124 -0
  93. data/lib/eco/api/usecases/backup/set_default_tag_case.rb +49 -0
  94. data/lib/eco/api/usecases/backup/set_supervisor_case.rb +41 -0
  95. data/lib/eco/api/usecases/backup/transfer_account_case.rb +90 -0
  96. data/lib/eco/api/usecases/backup/update_case.rb +112 -0
  97. data/lib/eco/api/usecases/backup/update_details_case.rb +64 -0
  98. data/lib/eco/api/usecases/backup/upsert_case.rb +114 -0
  99. data/lib/eco/api/usecases/base_case.rb +2 -0
  100. data/lib/eco/api/usecases/base_io.rb +3 -3
  101. data/lib/eco/api/usecases/default_cases.rb +23 -53
  102. data/lib/eco/api/usecases/default_cases/append_usergroups_case.rb +10 -31
  103. data/lib/eco/api/usecases/default_cases/change_email_case.rb +23 -47
  104. data/lib/eco/api/usecases/default_cases/codes_to_tags_case.rb +56 -43
  105. data/lib/eco/api/usecases/default_cases/create_case.rb +15 -101
  106. data/lib/eco/api/usecases/default_cases/create_details_case.rb +11 -26
  107. data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +12 -43
  108. data/lib/eco/api/usecases/default_cases/delete_sync_case.rb +11 -0
  109. data/lib/eco/api/usecases/default_cases/delete_trans_case.rb +14 -0
  110. data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +10 -21
  111. data/lib/eco/api/usecases/default_cases/hris_case.rb +23 -120
  112. data/lib/eco/api/usecases/default_cases/new_email_case.rb +10 -23
  113. data/lib/eco/api/usecases/default_cases/new_id_case.rb +11 -25
  114. data/lib/eco/api/usecases/default_cases/new_id_case0.rb +14 -0
  115. data/lib/eco/api/usecases/default_cases/org_data_convert_case.rb +83 -0
  116. data/lib/eco/api/usecases/default_cases/refresh_abilities_case.rb +30 -0
  117. data/lib/eco/api/usecases/default_cases/refresh_case.rb +7 -20
  118. data/lib/eco/api/usecases/default_cases/reinvite_sync_case.rb +11 -0
  119. data/lib/eco/api/usecases/default_cases/reinvite_trans_case.rb +17 -0
  120. data/lib/eco/api/usecases/default_cases/remove_account_sync_case.rb +11 -0
  121. data/lib/eco/api/usecases/default_cases/remove_account_trans_case.rb +17 -0
  122. data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +9 -19
  123. data/lib/eco/api/usecases/default_cases/restore_db_case.rb +92 -0
  124. data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +32 -40
  125. data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +15 -33
  126. data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +66 -57
  127. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +36 -44
  128. data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +40 -55
  129. data/lib/eco/api/usecases/default_cases/transfer_account_case.rb +264 -84
  130. data/lib/eco/api/usecases/default_cases/update_case.rb +15 -109
  131. data/lib/eco/api/usecases/default_cases/update_details_case.rb +14 -61
  132. data/lib/eco/api/usecases/default_cases/upsert_case.rb +16 -111
  133. data/lib/eco/api/usecases/use_case_io.rb +9 -9
  134. data/lib/eco/cli/config.rb +10 -2
  135. data/lib/eco/cli/config/default.rb +2 -1
  136. data/lib/eco/cli/config/default/input_filters.rb +58 -0
  137. data/lib/eco/cli/config/default/options.rb +60 -25
  138. data/lib/eco/cli/config/default/people.rb +4 -4
  139. data/lib/eco/cli/config/default/people_filters.rb +108 -0
  140. data/lib/eco/cli/config/default/usecases.rb +69 -32
  141. data/lib/eco/cli/config/default/workflow.rb +37 -27
  142. data/lib/eco/cli/config/filters.rb +50 -0
  143. data/lib/eco/cli/config/filters/input_filters.rb +29 -0
  144. data/lib/eco/cli/config/filters/people_filters.rb +29 -0
  145. data/lib/eco/cli/config/help.rb +49 -0
  146. data/lib/eco/cli/config/options_set.rb +17 -1
  147. data/lib/eco/cli/config/use_cases.rb +79 -53
  148. data/lib/eco/cli/scripting.rb +10 -2
  149. data/lib/eco/cli/scripting/args_helpers.rb +25 -15
  150. data/lib/eco/cli/scripting/argument.rb +1 -0
  151. data/lib/eco/cli/scripting/arguments.rb +1 -1
  152. data/lib/eco/csv/table.rb +1 -1
  153. data/lib/eco/data/crypto/encryption.rb +3 -0
  154. data/lib/eco/language/match.rb +19 -9
  155. data/lib/eco/language/match_modifier.rb +13 -5
  156. data/lib/eco/language/models/collection.rb +77 -56
  157. data/lib/eco/language/models/parser_serializer.rb +39 -15
  158. data/lib/eco/version.rb +1 -1
  159. metadata +63 -18
  160. data/lib/eco/api/microcases/set_default_tag.rb +0 -23
  161. data/lib/eco/api/session/task.rb +0 -175
  162. data/lib/eco/api/usecases/default_case.rb +0 -19
  163. data/lib/eco/api/usecases/default_cases/delete_case.rb +0 -32
  164. data/lib/eco/api/usecases/default_cases/recover_db_case.rb +0 -99
  165. data/lib/eco/api/usecases/default_cases/refresh_presets_case.rb +0 -26
  166. data/lib/eco/api/usecases/default_cases/reinvite_case.rb +0 -41
  167. data/lib/eco/api/usecases/default_cases/remove_account_case.rb +0 -38
  168. data/lib/eco/api/usecases/microed_cases/hris_case.rb +0 -53
  169. data/lib/eco/api/usecases/microed_cases/update_case.rb +0 -33
  170. data/lib/eco/api/usecases/microed_cases/update_details_case.rb +0 -30
  171. data/lib/eco/api/usecases/microed_cases/upsert_case.rb +0 -36
  172. data/lib/eco/cli/config/default/filters.rb +0 -70
  173. data/lib/eco/cli/config/people_filters.rb +0 -38
@@ -1,28 +1,14 @@
1
- module Eco
2
- module API
3
- class UseCases
4
- class DefaultCases
5
- class NewIdCase < DefaultCase
6
-
7
- def process
8
- @cases.define("new-id", type: :sync) do |entries, people, session, options, usecase|
9
- job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :core)
10
-
11
- strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
12
-
13
- entries.each.with_index do |entry, i|
14
- if person = people.find(entry, strict: strict_search)
15
- person.external_id = entry.external_id
16
- job.add(person)
17
- else
18
- session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
19
- end
20
- end
21
- end
22
- end
23
-
24
- end
25
- end
1
+ class Eco::API::UseCases::DefaultCases::NewIdCase < Eco::API::Common::Loaders::UseCase
2
+ name "new-id"
3
+ type :sync
4
+
5
+ def main(entries, people, session, options, usecase)
6
+ micro = session.micro
7
+ update = session.new_job("main", "update", :update, usecase, :core)
8
+ micro.with_each_present(entries, people, options, log_starter: true) do |entry, person|
9
+ update.add(person)
10
+ person.external_id = entry.external_id
26
11
  end
27
12
  end
13
+
28
14
  end
@@ -0,0 +1,14 @@
1
+ class Eco::API::UseCases::DefaultCases::NewIdCase < Eco::API::Common::Loaders::UseCase
2
+ name "new-id"
3
+ type :sync
4
+
5
+ def main(entries, people, session, options, usecase)
6
+ micro = session.micro
7
+ update = session.new_job("main", "update", :update, usecase, :core)
8
+ micro.with_each_present(entries, people, options, log_starter: true) do |entry, person|
9
+ update.add(person)
10
+ person.external_id = entry.external_id
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,83 @@
1
+ class Eco::API::UseCases::DefaultCases::OrgDataConvertCase < Eco::API::Common::Loaders::UseCase
2
+ name "org-data-convert"
3
+ type :import
4
+
5
+ def org_data_convert(people)
6
+ pp "Going to convert data from '#{source_enviro}' to '#{ASSETS.active_config}'"
7
+ puts "\n"
8
+ people.each.with_index do |person, i|
9
+ if (i % 10 == 0)
10
+ percent = i * 100 / people.length
11
+ print "Processing: #{percent.round}% (#{i}/#{people.length} entries)\r"
12
+ $stdout.flush
13
+ end
14
+
15
+ person.id = nil
16
+ details_convert!(person)
17
+ account_convert!(person)
18
+ end
19
+ people
20
+ end
21
+
22
+ def main(people, session, options, usecase)
23
+ @options = options
24
+ @session = session
25
+ org_data_convert(people)
26
+ end
27
+
28
+ private
29
+
30
+ def account_convert!(person)
31
+ if account = person.account
32
+ account.policy_group_ids = policy_groups_convert(account.policy_group_ids)
33
+ account.doc.tap do |doc|
34
+ ["login_provider_ids", "starred_ids", "landing_page_id"].map do |attr|
35
+ doc.delete(attr)
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ def details_convert!(person)
42
+ if person.details
43
+ person.details.as_json.tap do |details_doc|
44
+ details_doc["schema_id"] = @session.schema.id
45
+ person.add_details(@session.schema)
46
+ person.details = details_doc
47
+ end
48
+ end
49
+ end
50
+
51
+ def policy_groups_convert(ids)
52
+ ids.map do |id|
53
+ unless name = source_config.policy_groups.to_name(id)
54
+ error("Ops, do not know #{id} usergroup for source environment")
55
+ end
56
+ session.policy_groups.to_id(name).tap do |new_id|
57
+ unless new_id
58
+ error("Ops, do not know #{name} usergroup for destination environment")
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def source_config
65
+ @source_config ||= ASSETS.config(key: source_enviro, update_active: false)
66
+ end
67
+
68
+ def source_enviro
69
+ @source_enviro ||= options.dig(:source_enviro).tap do |enviro|
70
+ error("A source organization is required to migrate data") unless enviro
71
+ end
72
+ end
73
+
74
+ def logger
75
+ @session.logger
76
+ end
77
+
78
+ def error(msg)
79
+ logger.error(msg)
80
+ exit(1)
81
+ end
82
+
83
+ end
@@ -0,0 +1,30 @@
1
+ class Eco::API::UseCases::DefaultCases::RefreshAbilitiesCase < Eco::API::Common::Loaders::UseCase
2
+ name "refresh-abilities"
3
+ type :transform
4
+
5
+ # Usecase to refresh the user's account abilities as defined in the org config for their usergroups.
6
+ # @param people [Eco::API::Organization::People] target existing _People_ of the current update.
7
+ # @param session [Eco::API::Session] the current session where the usecase kicks in.
8
+ # @param options [Hash] the options that modify the case behaviour or bring some dependencies.
9
+ # @return [Void]
10
+ def main(people, session, options, usecase)
11
+ users = require_users!(people, session.logger)
12
+ update = session.new_job("main", "update", :update, usecase, :account)
13
+ users.each do |person|
14
+ person.account.permissions_custom = session.new_preset(person)
15
+ update.add(person)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def require_users!(people, logger)
22
+ people.users.tap do |users|
23
+ unless users.length > 0
24
+ logger.warn("There are no people with account amoung your #{people.length} people")
25
+ exit(1)
26
+ end
27
+ end
28
+ end
29
+
30
+ end
@@ -1,23 +1,10 @@
1
- module Eco
2
- module API
3
- class UseCases
4
- class DefaultCases
5
- class Refresh < DefaultCase
1
+ class Eco::API::UseCases::DefaultCases::RefreshCase < Eco::API::Common::Loaders::UseCase
2
+ name "refresh"
3
+ type :transform
6
4
 
7
- def process
8
- @cases.define("refresh", type: :transform) do |people, session, options, usecase|
9
- job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :account)
10
-
11
- people.each_with_index do |person, i|
12
- job.add(person)
13
- end
14
-
15
- end
16
- end
17
-
18
- end
19
-
20
- end
21
- end
5
+ def main(people, session, options, usecase)
6
+ update = session.new_job("main", "update", :update, usecase)
7
+ people.each {|person| job.add(person)}
22
8
  end
9
+
23
10
  end
@@ -0,0 +1,11 @@
1
+ class Eco::API::UseCases::DefaultCases::ReinviteSyncCase < Eco::API::UseCases::DefaultCases::ReinviteTransCase
2
+ name "reinvite"
3
+ type :sync
4
+
5
+ def main(entries, people, session, options, usecase)
6
+ micro = session.micro
7
+ found = micro.with_each_present(entries, people, options, log_starter: true)
8
+ reinvite(found.users, session, options, usecase)
9
+ end
10
+
11
+ end
@@ -0,0 +1,17 @@
1
+ class Eco::API::UseCases::DefaultCases::ReinviteTransCase < Eco::API::Common::Loaders::UseCase
2
+ name "reinvite"
3
+ type :transform
4
+
5
+ def reinvite(users, session, options, usecase)
6
+ invite = session.new_job("main", "invite", :update, usecase, :account)
7
+ users.each do |person|
8
+ person.account.send_invites = true
9
+ invite.add(person)
10
+ end
11
+ end
12
+
13
+ def main(people, session, options, usecase)
14
+ reinvite(people.users, session, options, usecase)
15
+ end
16
+
17
+ end
@@ -0,0 +1,11 @@
1
+ class Eco::API::UseCases::DefaultCases::RemoveAccountSyncCase < Eco::API::UseCases::DefaultCases::RemoveAccountTransCase
2
+ name "remove-account"
3
+ type :sync
4
+
5
+ def main(entries, people, session, options, usecase)
6
+ micro = session.micro
7
+ found = micro.with_each_present(entries, people, options, log_starter: true)
8
+ remove_account(found.users, session, options, usecase)
9
+ end
10
+
11
+ end
@@ -0,0 +1,17 @@
1
+ class Eco::API::UseCases::DefaultCases::RemoveAccountTransCase < Eco::API::Common::Loaders::UseCase
2
+ name "remove-account"
3
+ type :transform
4
+
5
+ def remove_account(users, session, options, usecase)
6
+ update = session.new_job("main", "update", :update, usecase, :account)
7
+ users.each do |user|
8
+ user.account = nil
9
+ update.add(user)
10
+ end
11
+ end
12
+
13
+ def main(people, session, options, usecase)
14
+ remove_account(people.users, session, options, usecase)
15
+ end
16
+
17
+ end
@@ -1,24 +1,14 @@
1
- module Eco
2
- module API
3
- class UseCases
4
- class DefaultCases
5
- class ResetLandingPageCase < DefaultCase
1
+ class Eco::API::UseCases::DefaultCases::ResetLandingPageCase < Eco::API::Common::Loaders::UseCase
2
+ name "reset-landing-page"
3
+ type :transform
6
4
 
7
- def process
8
- @cases.define("reset-landing-page", type: :transform) do |people, session, options, usecase|
9
- job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :account)
5
+ def main(people, session, options, usecase)
6
+ update = session.new_job("main", "update", :update, usecase, :core)
10
7
 
11
- people.users.each do |user|
12
- user.account.landing_page_id = nil
13
- job.add(user)
14
- end
15
-
16
- job
17
- end
18
- end
19
-
20
- end
21
- end
8
+ people.users.each do |user|
9
+ user.account.landing_page_id = nil
10
+ update.add(user)
22
11
  end
23
12
  end
13
+
24
14
  end
@@ -0,0 +1,92 @@
1
+ class Eco::API::UseCases::DefaultCases::RestoreDBCase < Eco::API::Common::Loaders::UseCase
2
+ name "restore-db"
3
+ type :sync
4
+
5
+ def main(entries, people, session, options, usecase)
6
+ micro = session.micro
7
+ require_people_as_entries!(entries)
8
+
9
+ restart = session.new_job("main", "restart", :create, usecase) if options.dig(:include, :create)
10
+ update = session.new_job("main", "update", :update, usecase)
11
+ delete = session.new_job("main", "delete", :update, usecase)
12
+
13
+ if options.dig(:include, :delete)
14
+ micro.with_each_leaver(entries, people, options) do |person|
15
+ delete.add(person)
16
+ end
17
+ end
18
+
19
+ re_starters = []
20
+
21
+ micro.with_each(entries, people, options) do |entry, person|
22
+ if person.new? && !options.dig(:include, :create)
23
+ re_starters.push(entry);
24
+ next
25
+ end
26
+
27
+ person.new? ? restart.add(person) : update.add(person)
28
+
29
+ core_copy(entry, person, options) unless options.dig(:exclude, :core)
30
+ person.details = entry.details unless options.dig(:exclude, :details)
31
+
32
+ unless options.dig(:exclude, :account) || !entry.account
33
+ person.account ||= {}
34
+ account_copy(entry.account, person.account, options)
35
+ end
36
+ end
37
+
38
+ report_re_starters(re_starters, session.logger)
39
+ end
40
+
41
+ private
42
+
43
+ def core_copy(entry, person, options)
44
+ person.external_id = entry.external_id unless options.dig(:exclude, :external_id)
45
+ person.name = entry.name unless options.dig(:exclude, :name)
46
+ person.email = entry.email unless options.dig(:exclude, :email)
47
+ person.supervisor_id = entry.supervisor_id unless options.dig(:exclude, :supervisor)
48
+ person.filter_tags = entry.filter_tags unless options.dig(:exclude, :filter_tags)
49
+ person.freemium = entry.freemium
50
+ end
51
+
52
+ def account_copy(src, dst, options)
53
+ if src = entry.account
54
+ dst.default_tag = src.default_tag unless options.dig(:exclude, :filter_tags)
55
+ dst.policy_group_ids = src.policy_group_ids unless options.dig(:exclude, :policy_groups)
56
+
57
+ unless options.dig(:exclude, :abilities)
58
+ dst.permissions_preset = src.permissions_preset
59
+ dst.permissions_custom = src.permissions_custom
60
+ end
61
+
62
+ dst.login_provider_ids = src.login_provider_ids
63
+ dst.accept_eula = src.accept_eula
64
+
65
+ if src.preferences
66
+ dst.doc["preferences"] = JSON.parse((src.doc["preferences"] || {}).to_json)
67
+ end
68
+
69
+ dst.starred_ids = src.starred_ids
70
+ dst.landing_page_id = src.landing_page_id
71
+ dst&.send_invites = options[:send_invites] if options.key?(:send_invites)
72
+ end
73
+ end
74
+
75
+ def require_people_as_entries!(entries, logger)
76
+ unless entries.is_a?(Eco::API::Organization::People)
77
+ logger.error("Your input should be an 'Eco::API::Organization::People' object. Got: #{entries.class}")
78
+ exit(1)
79
+ end
80
+ end
81
+
82
+ def report_re_starters(re_starters, logger)
83
+ unless re_starters.empty?
84
+ logger.error("There were #{re_starters.length} entries of the backup that do not exist in the (filtered?) people manager")
85
+ logger.error("Some examples:")
86
+ re_starters.slice(0, 4).each_with_index do |entry, i|
87
+ logger.error("This person does not exist: #{entry.name} (#{entry.email})")
88
+ end
89
+ end
90
+ end
91
+
92
+ end
@@ -1,49 +1,41 @@
1
- module Eco
2
- module API
3
- class UseCases
4
- class DefaultCases
5
- class SetDefaultTagCase < DefaultCase
6
- # take the deepest tag (the one that is further down in the tree)
7
- # different options (several nodes at the same depth):
8
- # => take the common node between them (i.e. you have Hamilton and Auckland -> take New Zealand)
9
- # => if there's no common node between them, take the `first` (unless they are at top level of the tree)
1
+ class Eco::API::UseCases::DefaultCases::SetDefaultTagCase < Eco::API::Common::Loaders::UseCase
2
+ name "set-default-tag"
3
+ type :transform
10
4
 
11
- def process
12
- @cases.define("set-default-tag", type: :transform) do |people, session, options, usecase|
13
- if !session.tagtree
14
- msg = "There is no tagtree definition in the configuration files\n" +
15
- "For this usecase to work out you need to define it."
16
- session.logger.fatal(msg)
17
- raise msg
18
- end
5
+ # take the deepest tag (the one that is further down in the tree)
6
+ # different options (several nodes at the same depth):
7
+ # => take the common node between them (i.e. you have Hamilton and Auckland -> take New Zealand)
8
+ # => if there's no common node between them, take the `first` (unless they are at top level of the tree)
9
+ def main(people, session, options, usecase)
10
+ micro = session.micro
11
+ tagtree_present!(session)
12
+ users = users_present!(people, session)
13
+ update = session.new_job("main", "update", :update, usecase, :account)
19
14
 
20
- # IMPORTANT: this two lines ensure that only people to be updated is selected
21
- all_people = people
22
- people = people.account_present
23
-
24
- if people.length <= 0
25
- msg = "There are no people with account... aborting script"
26
- session.logger.info(msg)
27
- raise msg
28
- end
29
-
30
- update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :account)
15
+ users.each do |person|
16
+ micro.refresh_default_tag(nil, person, options)
17
+ update.add(person)
18
+ end
19
+ end
31
20
 
32
- people.each_with_index do |person, i|
33
- if session.tagtree
34
- person.account.default_tag = session.tagtree.default_tag(*person.filter_tags)
35
- else
36
- tags = person.filter_tags || []
37
- person.account.default_tag = tags.first unless tags.length > 1
38
- end
39
- update.add(person)
40
- end
21
+ private
41
22
 
42
- end
43
- end
23
+ def tagtree_present!(session)
24
+ if !session.tagtree
25
+ msg = "There is no tagtree definition in the configuration files\n" +
26
+ "For this usecase to work out you need to define it."
27
+ session.logger.fatal(msg)
28
+ raise msg
29
+ end
30
+ end
44
31
 
45
- end
32
+ def users_present!(people, session)
33
+ people.users.tap do |users|
34
+ unless users.length > 0
35
+ session.logger.info(msg = "There are no people with account... aborting script")
36
+ raise msg
46
37
  end
47
38
  end
48
39
  end
40
+
49
41
  end