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
@@ -1,12 +1,28 @@
1
1
  ASSETS.cli.config do |cnf|
2
2
  cnf.options_set do |options_set, options|
3
-
4
- options_set.add("-schema-id") do |options, session|
3
+ options_set.add("--help", "offers a help") do |options, sesssion|
4
+ conf = ASSETS.cli.config
5
+ puts conf.people_filters.help if hpf = SCR.get_arg("-filters")
6
+ puts conf.input_filters.help if hif = SCR.get_arg("-input-filters")
7
+ puts conf.options_set.help if ho = SCR.get_arg("-options")
8
+ puts conf.usecases.help if huc = SCR.get_arg("-usecases")
9
+ puts [
10
+ "Please specify one of the below:",
11
+ " -filters to display available filters on people",
12
+ " -input-filters to display available filters on input data",
13
+ " -options to dislpay available options",
14
+ " -usecases to display available usecases"
15
+ ].join("\n") unless hpf || hif || ho || huc
16
+ exit
17
+ end
18
+
19
+ desc = "fix the current session to work with this schema"
20
+ options_set.add("-schema-id", desc) do |options, session|
5
21
  sch_name = SCR.get_arg("-schema-id", with_param: true)
6
22
  sch_id = session.schemas.to_id(sch_name)
7
23
 
8
24
  unless sch_id
9
- msg = "You need to specify a schema id or name. '#{sch_id}' does not exist"
25
+ msg = "You need to specify a correct schema id or name. '#{sch_name}' does not exist"
10
26
  session.logger.error(msg)
11
27
  exit(1)
12
28
  end
@@ -17,84 +33,103 @@ ASSETS.cli.config do |cnf|
17
33
  session.schema = sch_id
18
34
  end
19
35
 
20
- options_set.add("-entries-from") do |options, session|
36
+ desc = "deprecated: used to be used to specify the input file when using -get-partial"
37
+ options_set.add("-entries-from", desc) do |options, session|
21
38
  options.deep_merge!(input: {entries_from: true})
22
39
  end
23
40
 
24
- options_set.add("-get-people") do |options, session|
41
+ desc = "locally cache all the people manager by retrieving from the server"
42
+ options_set.add("-get-people", desc) do |options, session|
25
43
  options.deep_merge!(people: {
26
44
  get: {from: :remote, type: :full}
27
45
  })
28
46
  end
29
47
 
30
- options_set.add(["-dry-run", "-simulate"]) do |options, session|
48
+ options_set.add(["-dry-run", "-simulate"], "runs in dry-run (no requests sent to server)") do |options, session|
31
49
  options[:dry_run] = true
32
50
  options[:simulate] = true
33
51
  session.config.dry_run!
34
52
  end
35
53
 
36
- options_set.add("-skip-batch-policy") do |options|
54
+ desc = "ignores threshold limitations on requests for this session (skip batch belt)"
55
+ options_set.add("-skip-batch-policy", desc) do |options|
37
56
  options.deep_merge!(skip: {batch_policy: true})
38
57
  end
39
58
 
40
- options_set.add("-skip-api-policies") do |options|
59
+ desc = "will not run the api policies defined for the enviro"
60
+ options_set.add("-skip-api-policies", desc) do |options|
41
61
  options.deep_merge!(skip: {api_policies: true})
42
62
  end
43
63
 
44
- options_set.add("-feed-only-stats") do |options|
64
+ options_set.add("-feed-only-stats", "shows only stats when giving feedback") do |options|
45
65
  options.deep_merge!(feedback: {only_stats: true})
46
66
  end
47
67
 
68
+ desc = "deprecated: used to be used to avoid reloading people after launch"
48
69
  options[:end_get] = true
49
- options_set.add("-no-get") do |options|
70
+ options_set.add("-no-get", desc) do |options|
50
71
  options[:end_get] = false
51
72
  end
52
73
 
53
- options_set.add("-search-strict") do |options|
74
+ desc = "force search mode to 'strict' when pairing input entries with existing people."
75
+ desc += " Besides id and external_id it will not try to find by email unless external_id is not specified"
76
+ options_set.add("-search-strict", desc) do |options|
54
77
  options.deep_merge!(search: {strict: true})
55
78
  end
56
- options_set.add("-search-soft") do |options|
57
- options.deep_merge!(search: {strict: false})
79
+
80
+ desc = "search mode that will try to find people using email when id and external_id have failed"
81
+ desc += " This option could identify existing people by their email addresses"
82
+ desc += " (it should not be used in orgs where multiple people usually have the same email address)"
83
+ options_set.add("-search-soft", desc) do |options|
84
+ options.deep_merge!(search: {soft: true, strict: false})
58
85
  end
59
86
 
60
- options_set.add(["-no-invites", "-exclude-invites"]) do |options|
87
+ desc = "silence notifications on account creation or invites"
88
+ options_set.add(["-no-invites", "-exclude-invites"], desc) do |options|
61
89
  options.merge!(send_invites: false)
62
90
  end
63
- options_set.add("-send-invites") do |options|
91
+ desc = "people with account will be reinvited if they haven't accepted the invitation"
92
+ options_set.add("-send-invites", desc) do |options|
64
93
  options.merge!(send_invites: true)
65
94
  end
66
95
 
67
- options_set.add("-exclude-core") do |options|
96
+ options_set.add("-exclude-core", "core input data is not used on the update") do |options|
68
97
  options.deep_merge!(exclude: {core: true})
69
98
  end
70
- options_set.add("-exclude-filter-tags") do |options|
99
+ options_set.add("-exclude-filter-tags", "filter_tags is not set with the input data") do |options|
71
100
  options.deep_merge!(exclude: {filter_tags: true})
72
101
  end
73
- options_set.add("-exclude-external-id") do |options|
102
+ options_set.add("-exclude-external-id", "external_id is not set with the input data") do |options|
74
103
  options.deep_merge!(exclude: {external_id: true})
75
104
  end
76
- options_set.add("-exclude-supervisor") do |options|
105
+ options_set.add("-exclude-supervisor", "supervisor_id is not set with the input data") do |options|
77
106
  options.deep_merge!(exclude: {supervisor: true})
78
107
  end
79
- options_set.add("-exclude-email") do |options|
108
+ options_set.add("-exclude-email", "email is not set with the input data") do |options|
80
109
  options.deep_merge!(exclude: {email: true})
81
110
  end
82
- options_set.add("-exclude-name") do |options|
111
+ options_set.add("-exclude-name", "name is not set with the input data") do |options|
83
112
  options.deep_merge!(exclude: {name: true})
84
113
  end
85
114
 
86
- options_set.add("-exclude-details") do |options|
115
+ options_set.add("-exclude-details", "details are not set with the input data") do |options|
87
116
  options.deep_merge!(exclude: {details: true})
88
117
  end
89
118
 
90
- options_set.add("-exclude-account") do |options|
119
+ options_set.add("-exclude-account", "account is not set with the input data") do |options|
91
120
  options.deep_merge!(exclude: {account: true})
92
121
  end
93
- options_set.add("-exclude-policy-groups") do |options|
122
+ options_set.add("-exclude-policy-groups", "policy_group_ids is not set with the input data") do |options|
94
123
  options.deep_merge!(exclude: {policy_groups: true})
95
124
  end
96
- options_set.add("-exclude-abilities") do |options|
125
+ options_set.add("-default-tag", "default_tag is not set with the input data") do |options|
126
+ options.deep_merge!(exclude: {default_tag: true})
127
+ end
128
+ options_set.add("-exclude-abilities", "permissions_custom is not set with the input data") do |options|
97
129
  options.deep_merge!(exclude: {abilities: true})
98
130
  end
131
+ options_set.add("-exclude-login-providers", "login_provider_ids is not set with the input data") do |options|
132
+ options.deep_merge!(exclude: {login_providers: true})
133
+ end
99
134
  end
100
135
  end
@@ -5,7 +5,7 @@ ASSETS.cli.config do |cnf|
5
5
  options.deep_merge!(people: {
6
6
  get: {from: :remote, type: :full}
7
7
  })
8
- people = session.do.file_people
8
+ people = session.micro.people_cache
9
9
  elsif SCR.get_arg("-no-people")
10
10
  people = Eco::API::Organization::People.new([])
11
11
  elsif SCR.get_arg("-people-from-backup")
@@ -23,17 +23,17 @@ ASSETS.cli.config do |cnf|
23
23
  get: {from: :remote, type: :partial}
24
24
  })
25
25
 
26
- people = session.do.search(input, options: options)
26
+ people = session.micro.people_search(input, options: options)
27
27
  else
28
28
  options.deep_merge!(people: {
29
29
  get: {from: :local, type: :full}
30
30
  })
31
- people = session.do.load_people(modifier: [:newest, :save])
31
+ people = session.micro.people_load(modifier: [:newest, :save])
32
32
  if people.empty?
33
33
  options.deep_merge!(people: {
34
34
  get: {from: :remote, type: :full}
35
35
  })
36
- people = session.do.file_people if people.empty?
36
+ people = session.micro.people_cache if people.empty?
37
37
  end
38
38
  end
39
39
  people
@@ -0,0 +1,108 @@
1
+ ASSETS.cli.config do |cnf|
2
+ cnf.people_filters do |filters|
3
+
4
+ filters.add("-only-users", "only those with account") do |people, session, options|
5
+ options.deep_merge!(people: {filter: {account: true}})
6
+ people.users
7
+ end
8
+
9
+ filters.add("-no-account", "only those with no account") do |people, session, options|
10
+ options.deep_merge!(people: {filter: {account: false}})
11
+ people.account_present(false)
12
+ end
13
+
14
+ filters.add("-with-details", "only those with details") do |people, session, options|
15
+ options.deep_merge!(people: {filter: {details: true}})
16
+ people.details_present
17
+ end
18
+
19
+ filters.add("-no-id", "only those with no external_id") do |people, session, options|
20
+ options.deep_merge!(people: {filter: {external_id: nil}})
21
+ people.external_id_present(false)
22
+ end
23
+
24
+ filters.add("-supervisors", "only those that have subordinates") do |people, session, options|
25
+ options.deep_merge!(people: {filter: {subordinates: true}})
26
+ people.newFrom people.to_a.select {|person| person.subordinates > 0}
27
+ end
28
+
29
+ filters.add("-supervisor-id", "only those with certain supervisor") do |people, session, options|
30
+ id = SCR.get_arg("-supervisor-id", with_param: true)
31
+ options.deep_merge!(people: {filter: {supervisor_id: id}})
32
+ unless sup = session.micro.with_supervisor(id, people, strict: true)
33
+ status = session.batch.search([{"id" => id}])
34
+ sup = status.people.first
35
+ end
36
+ unless sup
37
+ session.logger.error("Supervisor with id '#{id}' does not exist")
38
+ exit(1)
39
+ end
40
+
41
+ people.supervisor_id(sup.id)
42
+ end
43
+
44
+ filters.add("-no-default-tag", "only those users with no default tag") do |people, session, options|
45
+ options.deep_merge!(people: {filter: {account: {default_tag: nil}}})
46
+ people.users.select do |person|
47
+ !person.account.default_tag
48
+ end.yield_self do |filtered|
49
+ people.newFrom filtered
50
+ end
51
+ end
52
+
53
+ desc = "only those that have ALL the specified tags separated by '|'"
54
+ filters.add("-filter-tags-all", desc) do |people, session, options|
55
+ tags = SCR.get_arg("-filter-tags-all", with_param: true).upcase.split("|")
56
+ options.deep_merge!(input: {filter: {filter_tags: {any: tags}}})
57
+ people.filter_tags_all(tags).tap do |filtered|
58
+ msg = "Filtered #{filtered.count} people (out of #{people.count}) with 'all' filter_tags #{tags}"
59
+ session.logger.info(msg)
60
+ end
61
+ end
62
+
63
+ desc = "only those that have ANY the specified tags separated by '|'"
64
+ filters.add("-filter-tags-any", desc) do |people, session, options|
65
+ tags = SCR.get_arg("-filter-tags-any", with_param: true).upcase.split("|")
66
+ options.deep_merge!(input: {filter: {filter_tags_any: tags}})
67
+ people.filter_tags_any(tags).tap do |filtered|
68
+ msg = "Filtered #{filtered.count} people (out of #{people.count}) with 'any' filter_tags #{tags}"
69
+ session.logger.info(msg)
70
+ end
71
+ end
72
+
73
+ desc = "only those that have ANY tag in the specified subtrees separated by '|'"
74
+ filters.add("-filter-tags-tree", desc) do |people, session, options|
75
+ top_tags = SCR.get_arg("-filter-tags-tree", with_param: true).upcase.split("|")
76
+ tags = top_tags.each_with_object([]) do |top, tags|
77
+ tags.concat(session.tagtree.node(top).tags)
78
+ end.uniq
79
+ options.deep_merge!(input: {filter: {filter_tags: {tree: top_tags, any: tags}}})
80
+ people.filter_tags_any(tags).tap do |filtered|
81
+ msg = "Filtered #{filtered.count} people (out of #{people.count}) with 'any' filter_tags in subtrees #{top_tags}"
82
+ session.logger.info(msg)
83
+ end
84
+ end
85
+
86
+ filters.add("-schema-id", "only those with the specified schema id or name") do |people, session, options|
87
+ sch_name = SCR.get_arg("-schema-id", with_param: true)
88
+ sch_id = session.schemas.to_id(sch_name)
89
+
90
+ unless sch_id
91
+ msg = "You need to specify a correct schema id or name. '#{sch_name}' does not exist"
92
+ session.logger.error(msg)
93
+ exit(1)
94
+ end
95
+
96
+ options.deep_merge!(people: {filter: {details: {schema_id: sch_id}}})
97
+ session.logger.info("Filtering people entries with schema #{session.schemas.to_name(sch_id)}")
98
+
99
+ people.select do |person|
100
+ person.details && (person.details.schema_id == sch_id)
101
+ end.yield_self do |filtered|
102
+ session.logger.info("Filtered #{filtered.count} people out of #{people.count} total")
103
+ people.newFrom filtered
104
+ end
105
+ end
106
+
107
+ end
108
+ end
@@ -1,7 +1,8 @@
1
1
  ASSETS.cli.config do |cnf|
2
2
  cnf.usecases do |cases|
3
3
 
4
- cases.add("-people-to-csv", :export) do |people, session, options|
4
+ desc = "It exports to a CSV the (filtered) people"
5
+ cases.add("-people-to-csv", :export, desc) do |people, session, options|
5
6
  file = SCR.get_file("-people-to-csv", required: true, should_exist: false)
6
7
  options.deep_merge!(export: {file: {name: file, format: :csv}})
7
8
  options.deep_merge!(export: {options: {nice_header: true}}) if SCR.get_arg("-nice-header")
@@ -10,7 +11,8 @@ ASSETS.cli.config do |cnf|
10
11
  session.usecases.case(case_name)
11
12
  end
12
13
 
13
- cases.add("-codes-to-tags-from", :other, case_name: "codes-to-tags-from") do |session, options|
14
+ desc = "Adds a column 'ecoPortalTag' to the input CSV with the tags that the location codes map to"
15
+ cases.add("-codes-to-tags-from", :other, desc, case_name: "codes-to-tags-from") do |session, options|
14
16
  file = SCR.get_file("-codes-to-tags-from", required: true, should_exist: true)
15
17
  options.deep_merge!(other: {file: {name: file, format: :csv}})
16
18
 
@@ -18,16 +20,24 @@ ASSETS.cli.config do |cnf|
18
20
  options.deep_merge!(other: {file: {codes_column: col_codes}})
19
21
  end
20
22
 
21
- cases.add("-reset-landing-page", :transform, case_name: "reset-landing-page")
22
- cases.add("-email-as-id", :transform, case_name: "email-as-id")
23
- cases.add("-new-id-from", :sync, case_name: "new-id")
24
- # won't succeed if some other user with that email in all eP
25
- cases.add("-new-email-from", :sync, case_name: "new-email")
26
- # forces the change of email no matter what,
27
- # unless some other user with that email in the same organization
28
- cases.add("-change-email-from", :sync, case_name: "change-email")
29
- cases.add("-set-supervisor-from", :sync, case_name: "set-supervisor")
30
- cases.add("-switch-supervisor", :transform, case_name: "switch-supervisor") do |people, session, options|
23
+ desc = "Removes the landing page"
24
+ cases.add("-reset-landing-page", :transform, desc, case_name: "reset-landing-page")
25
+
26
+ desc = "Sets as external_id the email of the person"
27
+ cases.add("-email-as-id", :transform, desc, case_name: "email-as-id")
28
+
29
+ desc = "Sets the external_id to the one given in the input CSV"
30
+ cases.add("-new-id-from", :sync, desc, case_name: "new-id")
31
+
32
+ desc = "Sets the email of people. It won't succeed if email taken by any other user in eP"
33
+ cases.add("-new-email-from", :sync, desc, case_name: "new-email")
34
+ desc = "Forces a change of email in the same org. It won't succeed if email taken by an org member user"
35
+ cases.add("-change-email-from", :sync, desc, case_name: "change-email")
36
+
37
+ desc = "Sets the supervisor_id"
38
+ cases.add("-set-supervisor-from", :sync, desc, case_name: "set-supervisor")
39
+ desc = "Sets to -new-super the supervisor_id of the -old-super's subordinates"
40
+ cases.add("-switch-supervisor", :transform, desc, case_name: "switch-supervisor") do |people, session, options|
31
41
  unless old_id = SCR.get_arg("-old-super", with_param: true)
32
42
  msg = "You must specify an -old-super to target whose supervisor is changing"
33
43
  session.logger.error(msg)
@@ -45,15 +55,10 @@ ASSETS.cli.config do |cnf|
45
55
  options.deep_merge!(super: {new: new_id})
46
56
  end
47
57
 
48
- cases.add("-create-details-from", :sync, case_name: "create-details")
49
- cases.add("-update-details-from", :sync, case_name: "update-details")
50
- cases.add("-reinvite", :transform, case_name: "reinvite")
51
- cases.add("-reinvite-from", :sync, case_name: "reinvite")
52
- cases.add("-set-default-tag", :transform, case_name: "set-default-tag")
53
-
54
- cases.add("-recover-db-from", :sync, case_name: "recover-db") do |input, people, session, options|
58
+ desc = "Restores the people manager by using a backup.json file"
59
+ cases.add("-restore-db-from", :sync, desc, case_name: "restore-db") do |input, people, session, options|
55
60
  unless input && input.is_a?(Eco::API::Organization::People)
56
- file = SCR.get_file("-recover-db-from", required: true)
61
+ file = SCR.get_file("-restore-db-from", required: true)
57
62
  input = Eco::API::Organization::People.new(JSON.parse(File.read(file)))
58
63
  session.logger.info("Source DB: loaded #{input.length} entries.")
59
64
  end
@@ -62,17 +67,49 @@ ASSETS.cli.config do |cnf|
62
67
  options.deep_merge!(include: {create: true}) if SCR.get_arg("-include-create")
63
68
  end
64
69
 
65
- cases.add("-create-from", :sync, case_name: "create")
66
- cases.add("-append-usergroups-from", :sync, case_name: "append-usergroups")
67
- cases.add("-update-from", :sync, case_name: "update")
68
- cases.add("-refresh", :transform, case_name: "refresh")
69
- cases.add("-refresh-presets", :transform, case_name: "refresh-presets")
70
- cases.add("-transfer-account-from", :sync, case_name: "transfer-account")
71
- cases.add("-remove-account", :transform, case_name: "remove-account")
72
- cases.add("-remove-account-from", :sync, case_name: "remove-account")
73
- cases.add("-delete", :transform, case_name: "delete")
74
- cases.add("-delete-from", :sync, case_name: "delete")
75
- cases.add("-upsert-from", :sync, case_name: "upsert")
76
- cases.add("-hris-from", :sync, case_name: "hris")
70
+ desc = "Re-sends invites to all filtered users that have not accepted the invite as yet"
71
+ cases.add("-reinvite", :transform, desc, case_name: "reinvite")
72
+ desc = "Re-sends invites to target users that have not accepted the invite as yet"
73
+ cases.add("-reinvite-from", :sync, desc, case_name: "reinvite")
74
+
75
+ desc = "Deletes everybody that has been filtered from the people manager"
76
+ cases.add("-delete", :transform, desc, case_name: "delete")
77
+ desc = "Deletes the people specified in the input data"
78
+ cases.add("-delete-from", :sync, desc, case_name: "delete")
79
+ desc = "Removes the account of everybody that has been filtered from the people manager"
80
+ cases.add("-remove-account", :transform, desc, case_name: "remove-account")
81
+ desc = "Removes the people specified in the input data"
82
+ cases.add("-remove-account-from", :sync, desc, case_name: "remove-account")
83
+
84
+ desc = "Re-freshes the default_tag of users"
85
+ cases.add("-set-default-tag", :transform, desc, case_name: "set-default-tag")
86
+
87
+ desc = "Creates people with with details and account"
88
+ cases.add("-create-from", :sync, desc, case_name: "create")
89
+ desc = "Creates people with only details"
90
+ cases.add("-create-details-from", :sync, desc, case_name: "create-details")
91
+
92
+ desc = "It just adds everybody to an update job without doing any change. If the org has policies, it will refresh"
93
+ cases.add("-refresh", :transform, desc, case_name: "refresh")
94
+ desc = "Remaps the abilities of every user based on their usergroups mappings thereof in the org api configuration"
95
+ cases.add("-refresh-abilities", :transform, desc, case_name: "refresh-abilities")
96
+
97
+ desc = "Updates details and core (including supervisor) to target people"
98
+ cases.add("-update-details-from", :sync, desc, case_name: "update-details")
99
+
100
+ desc = "Appends the policy_group_ids column to the people with account specified in the input data"
101
+ cases.add("-append-usergroups-from", :sync, desc, case_name: "append-usergroups")
102
+ desc = "Updates the people specified in the input data"
103
+ cases.add("-update-from", :sync, desc, case_name: "update")
104
+
105
+ desc = "Does an actual transfer of user from id|external_id account to 'destination-id' person"
106
+ cases.add("-transfer-account-from", :sync, desc, case_name: "transfer-account") do |input, people, session, options|
107
+ options.deep_merge!(include: {email: SCR.get_arg("-include-email")})
108
+ end
109
+
110
+ desc = "Tries to find the input entries and update them. It creates them if not found"
111
+ cases.add("-upsert-from", :sync, desc, case_name: "upsert")
112
+ desc = "It does like -upsert-from and additionally removes account and supervisor of those in people that are not in the entries (leavers)"
113
+ cases.add("-hris-from", :sync, desc, case_name: "hris")
77
114
  end
78
115
  end
@@ -4,7 +4,7 @@ ASSETS.cli.config do |config|
4
4
  io = nil
5
5
  # default rescue
6
6
  wf.rescue do |exception, io|
7
- io.session.logger.error(exception.patch_full_message)
7
+ io.session.logger.debug(exception.patch_full_message)
8
8
  wf.run(:close, io: io)
9
9
  io
10
10
  end
@@ -14,38 +14,42 @@ ASSETS.cli.config do |config|
14
14
  end
15
15
 
16
16
  wf.for(:load) do |wf_load|
17
- active_cases = nil
18
-
19
- wf_load.on(:input) do |wf_input, io|
20
- active_cases = config.usecases.active(io: io)
17
+ wf_load.for(:input) do |wf_input|
18
+ wf_input.on(:get) do |wf_input_get, io|
19
+ cases_with_input = config.usecases.active(io: io).select do |usecase, data|
20
+ io.class.input_required?(usecase.type)
21
+ end
22
+ next io unless (!io.input || io.input.empty?) && !cases_with_input.empty?
21
23
 
22
- cases_with_input = active_cases.select do |usecase, data|
23
- io.class.input_required?(usecase.type)
24
+ if io.options.dig(:input, :entries_from)
25
+ io = io.new(input: config.input.get(io: io))
26
+ else
27
+ opt_case = cases_with_input.values.first[:option]
28
+ io = io.new(input: config.input.get(io: io, option: opt_case))
29
+ end
30
+ io
24
31
  end
25
32
 
26
- next io unless (!io.input || io.input.empty?) && !cases_with_input.empty?
27
-
28
- if io.options.dig(:input, :entries_from)
29
- io = io.new(input: config.input.get(io: io))
30
- else
31
- opt_case = cases_with_input.values.first[:option]
32
- io = io.new(input: config.input.get(io: io, option: opt_case))
33
+ wf_input.on(:filter) do |wf_input_filter, io|
34
+ next io unless io.input && !io.input.empty?
35
+ io = io.new(input: config.input_filters.process(io: io))
33
36
  end
34
- io
35
37
  end
36
38
 
37
- wf_load.on(:people) do |wf_people, io|
38
- cases_with_people = active_cases.select do |usecase, data|
39
- io.class.people_required?(usecase.type)
39
+ wf_load.for(:people) do |wf_people|
40
+ wf_people.on(:get) do |wf_people_get, io|
41
+ cases_with_people = config.usecases.active(io: io).select do |usecase, data|
42
+ io.class.people_required?(usecase.type)
43
+ end
44
+ get_people = io.options.dig(:people, :get, :from) == :remote
45
+ next io unless !cases_with_people.empty? || get_people
46
+ io = io.new(people: config.people(io: io))
40
47
  end
41
- get_people = io.options.dig(:people, :get, :from) == :remote
42
- next io unless !cases_with_people.empty? || get_people
43
- io = io.new(people: config.people(io: io))
44
- end
45
48
 
46
- wf_load.on(:filter) do |wf_filter, io|
47
- next io unless io.people && !io.people.empty?
48
- io = io.new(people: config.people_filters.process(io: io))
49
+ wf_people.on(:filter) do |wf_people_filter, io|
50
+ next io unless io.people && !io.people.empty?
51
+ io = io.new(people: config.people_filters.process(io: io))
52
+ end
49
53
  end
50
54
  end
51
55
 
@@ -85,7 +89,7 @@ ASSETS.cli.config do |config|
85
89
  partial_update = io.options.dig(:people, :get, :type) == :partial
86
90
  if !io.options[:dry_run] && partial_update
87
91
  # get target people afresh
88
- people = io.session.do.people_refresh(people: io.people, include_created: true)
92
+ people = io.session.micro.people_refresh(people: io.people, include_created: true)
89
93
  io = io.new(people: people)
90
94
  else
91
95
  wf_post.skip!
@@ -116,10 +120,16 @@ ASSETS.cli.config do |config|
116
120
  end
117
121
  end
118
122
 
123
+ wf.on(:report) do |wf_report, io|
124
+ #config.reports.active(io: io)
125
+ #io.session.reports
126
+ io
127
+ end
128
+
119
129
  wf.on(:end) do |wf_end, io|
120
130
  partial_update = io.options.dig(:people, :get, :type) == :partial
121
131
  unless !io.options[:end_get] || io.options[:dry_run] || partial_update
122
- people = io.session.do.file_people
132
+ people = io.session.micro.people_cache
123
133
  io = io.new(people: people)
124
134
  end
125
135
  io