eco-helpers 0.8.4 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/lib/eco/api/session/batch_jobs.rb +2 -2
  3. data/lib/eco/api/usecases/default_cases/change_email_case.rb +4 -4
  4. data/lib/eco/api/usecases/default_cases/create_case.rb +3 -3
  5. data/lib/eco/api/usecases/default_cases/create_details_case.rb +2 -2
  6. data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +3 -3
  7. data/lib/eco/api/usecases/default_cases/delete_case.rb +3 -3
  8. data/lib/eco/api/usecases/default_cases/email_as_id_case.rb +2 -2
  9. data/lib/eco/api/usecases/default_cases/hris_case.rb +4 -4
  10. data/lib/eco/api/usecases/default_cases/new_email_case.rb +2 -2
  11. data/lib/eco/api/usecases/default_cases/new_id_case.rb +2 -2
  12. data/lib/eco/api/usecases/default_cases/recover_db_case.rb +4 -4
  13. data/lib/eco/api/usecases/default_cases/refresh_presets_case.rb +4 -3
  14. data/lib/eco/api/usecases/default_cases/reinvite_case.rb +2 -2
  15. data/lib/eco/api/usecases/default_cases/remove_account_case.rb +2 -2
  16. data/lib/eco/api/usecases/default_cases/reset_landing_page_case.rb +2 -2
  17. data/lib/eco/api/usecases/default_cases/set_default_tag_case.rb +2 -2
  18. data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +2 -2
  19. data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +2 -2
  20. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +1 -1
  21. data/lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb +1 -1
  22. data/lib/eco/api/usecases/default_cases/update_case.rb +3 -3
  23. data/lib/eco/api/usecases/default_cases/update_details_case.rb +2 -2
  24. data/lib/eco/api/usecases/default_cases/upsert_case.rb +4 -4
  25. data/lib/eco/api/usecases/use_case_io.rb +1 -1
  26. data/lib/eco/version.rb +1 -1
  27. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05fa297f660326cad5045f7760c4352b961492c7be71a18eda2093cd7032b011
4
- data.tar.gz: 13690bdea42b4960af20e835c5171df3424cfc7213f25123f154c0a42205bc58
3
+ metadata.gz: c1c15ec5f243e3ddbf220b7177458666205cbd03aa2cd7b42ae49c75b7309c41
4
+ data.tar.gz: 3f46b25d6aff9988339d4e331356b9cf9e168a944ec7f7ae7ac171d660413499
5
5
  SHA512:
6
- metadata.gz: f795b7015969ddeaa59c76a1625d6d336ace2d35145651c15fdaecbbc0c32345c7023666febd94b1abb8e1de7ed1d3410aaf61bb19d5799edec6078bb0a02390
7
- data.tar.gz: 33e176df8b2209373683ef79eba539f8e05e61fb1bbee63ebf4c8823c0f2ffa215a2c1cc62aa1e55d6c6e75c799f6f57599d8f67f7fd924bc371657018617777
6
+ metadata.gz: 5fa870fa6491d12d458696895882b63895bf3dc5e2ca86ce58dd6ad476ec63e012b4a58809244f47ac09e674139dfcfe6e68fc32e052dbd248c145d0f9edb5c6
7
+ data.tar.gz: 692681ee1f899a6d6509289c99b291a379c20daa6b34155a6faa903e43badddca393644dc10dc07e00eaa4f96e0b6f83da0b31bc8764c70713b5c3f824a686fb
@@ -23,10 +23,10 @@ module Eco
23
23
  @jobs.key?(name)
24
24
  end
25
25
 
26
- def new(name, type:, sets:)
26
+ def new(name, type:, sets:, usecase: nil)
27
27
  fatal "Can't create job named '#{name}' because it already exists." if exists?(name)
28
28
 
29
- BatchJob.new(enviro, name: name, type: type, sets: sets).tap do |job|
29
+ BatchJob.new(enviro, name: name, type: type, sets: sets, usecase: usecase).tap do |job|
30
30
  @jobs[name] = job
31
31
  @callbacks[job] = Proc.new if block_given?
32
32
  end
@@ -5,10 +5,10 @@ module Eco
5
5
  class ChangeEMailCase < BaseCase
6
6
 
7
7
  def process
8
- @cases.define("change-email", type: :sync) do |entries, people, session, options|
9
- remove = session.job_group("main").new("remove account", type: :update, sets: :account)
10
- change = session.job_group("main").new("change email", type: :update, sets: :core)
11
- add_account = session.job_group("post").new("add account", type: :update, sets: :account)
8
+ @cases.define("change-email", type: :sync) do |entries, people, session, options, usecase|
9
+ remove = session.job_group("main").new("remove account", usecase: usecase, type: :update, sets: :account)
10
+ change = session.job_group("main").new("change email", usecase: usecase, type: :update, sets: :core)
11
+ add_account = session.job_group("post").new("add account", usecase: usecase, type: :update, sets: :account)
12
12
 
13
13
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
14
14
 
@@ -5,8 +5,8 @@ module Eco
5
5
  class CreateCase < UseCases::BaseCase
6
6
 
7
7
  def process
8
- @cases.define("create", type: :sync) do |entries, people, session, options|
9
- creation = session.job_group("main").new("create", type: :create, sets: [:core, :details, :account])
8
+ @cases.define("create", type: :sync) do |entries, people, session, options, usecase|
9
+ creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details, :account])
10
10
 
11
11
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
12
12
  pgs = session.policy_groups
@@ -32,7 +32,7 @@ module Eco
32
32
  final: person.account.policy_group_ids
33
33
  )
34
34
 
35
- person.account.permissions_custom = session.new_preset(person) unless options.dig(:exclude, :abilities)
35
+ person.account.permissions_custom = session.new_preset(person)
36
36
 
37
37
  if session.tagtree
38
38
  person.account.filter_tags = session.tagtree.user_tags(
@@ -5,8 +5,8 @@ module Eco
5
5
  class CreateDetailsCase < UseCases::BaseCase
6
6
 
7
7
  def process
8
- @cases.define("create-details", type: :sync) do |entries, people, session, options|
9
- creation = session.job_group("main").new("create", type: :create, sets: [:core, :details])
8
+ @cases.define("create-details", type: :sync) do |entries, people, session, options, usecase|
9
+ creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details])
10
10
 
11
11
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
12
12
 
@@ -6,9 +6,9 @@ module Eco
6
6
 
7
7
  def process
8
8
  # good candidate to do @cases.case("create-details").use.chain(@cases.case("set-supervisor").use)
9
- @cases.define("create-details-with-supervisor", type: :sync) do |entries, people, session, options|
10
- creation = session.job_group("main").new("create", type: :create, sets: [:core, :details])
11
- supers = session.job_group("post").new("supers", type: :update, sets: :core)
9
+ @cases.define("create-details-with-supervisor", type: :sync) do |entries, people, session, options, usecase|
10
+ creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details])
11
+ supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
12
12
 
13
13
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
14
14
 
@@ -5,15 +5,15 @@ module Eco
5
5
  class DeleteCase < BaseCase
6
6
 
7
7
  def process
8
- @cases.define("delete", type: :transform) do |people, session|
9
- delete = session.job_group("main").new("delete", type: :delete, sets: [:core, :details, :account])
8
+ @cases.define("delete", type: :transform) do |people, session, options, usecase|
9
+ delete = session.job_group("main").new("delete", usecase: usecase, type: :delete, sets: [:core, :details, :account])
10
10
  people.each_with_index do |person|
11
11
  delete.add(person)
12
12
  end
13
13
  end
14
14
 
15
15
  @cases.define("delete", type: :sync) do |entries, people, session|
16
- delete = session.job_group("main").new("delete", type: :delete, sets: [:core, :details, :account])
16
+ delete = session.job_group("main").new("delete", usecase: usecase, type: :delete, sets: [:core, :details, :account])
17
17
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
18
18
  entries.each_with_index do |entry|
19
19
  if person = people.find(entry, strict: strict_search)
@@ -5,8 +5,8 @@ module Eco
5
5
  class EmailAsIdCase < BaseCase
6
6
 
7
7
  def process
8
- @cases.define("email-as-id", type: :transform) do |people, session|
9
- job = session.job_group("main").new("update", type: :update, sets: :core)
8
+ @cases.define("email-as-id", type: :transform) do |people, session, options, usecase|
9
+ job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :core)
10
10
 
11
11
  people.each do |person|
12
12
  person.external_id = person.email
@@ -5,14 +5,14 @@ module Eco
5
5
  class HrisCase < BaseCase
6
6
 
7
7
  def process
8
- @cases.define("hris", type: :sync) do |entries, people, session, options|
8
+ @cases.define("hris", type: :sync) do |entries, people, session, options, usecase|
9
9
  # IMPORTANT: this two lines ensure that key users are preserved (only manually maintained)
10
10
  #people = people.exclude(session.discarded_entries)
11
11
  #entries = entries.exclude(session.discarded_entries)
12
12
 
13
- creation = session.job_group("main").new("create", type: :create, sets: [:core, :details, :account])
14
- update = session.job_group("main").new("update", type: :update, sets: [:core, :details, :account])
15
- supers = session.job_group("post").new("supers", type: :update, sets: :core)
13
+ creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details, :account])
14
+ update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account])
15
+ supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
16
16
  #remove = session.job_group("post").new("remove_account", type: :update, sets: :account)
17
17
 
18
18
  #people.users.each_with_index do |person, i|
@@ -5,8 +5,8 @@ module Eco
5
5
  class NewEmailCase < BaseCase
6
6
 
7
7
  def process
8
- @cases.define("new-email", type: :sync) do |entries, people, session, options|
9
- job = session.job_group("main").new("update", type: :update, sets: :core)
8
+ @cases.define("new-email", type: :sync) do |entries, people, session, options, usecase|
9
+ job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :core)
10
10
 
11
11
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
12
12
 
@@ -5,8 +5,8 @@ module Eco
5
5
  class NewIdCase < BaseCase
6
6
 
7
7
  def process
8
- @cases.define("new-id", type: :sync) do |entries, people, session, options|
9
- job = session.job_group("main").new("update", type: :update, sets: :core)
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
10
 
11
11
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
12
12
 
@@ -5,14 +5,14 @@ module Eco
5
5
  class RecoverDBCase < BaseCase
6
6
 
7
7
  def process
8
- @cases.define("recover-db", type: :sync) do |entries, people, session, options|
8
+ @cases.define("recover-db", type: :sync) do |entries, people, session, options, usecase|
9
9
  unless entries.is_a?(Eco::API::Organization::People)
10
10
  raise "Your input should be an 'Eco::API::Organization::People' object. Got: #{entries.class}"
11
11
  end
12
12
 
13
- creation = session.job_group("main").new("create", type: :create, sets: [:core, :details, :account])
14
- update = session.job_group("main").new("update", type: :update, sets: [:core, :details, :account])
15
- remove = session.job_group("main").new("remove", type: :delete, sets: [:core, :details, :account])
13
+ creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details, :account])
14
+ update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account])
15
+ remove = session.job_group("main").new("remove", usecase: usecase, type: :delete, sets: [:core, :details, :account])
16
16
 
17
17
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
18
18
  pgs = session.policy_groups
@@ -5,12 +5,13 @@ module Eco
5
5
  class RefreshPresets < BaseCase
6
6
 
7
7
  def process
8
- @cases.define("refresh-presets", type: :transform) do |people, session|
9
- job = session.job_group("main").new("update", type: :update, sets: :account)
8
+ @cases.define("refresh-presets", type: :transform) do |people, session, options, usecase|
9
+ job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :account)
10
10
 
11
11
  users = people.users
12
- session.logger.warn("There are no people with account amoung your #{people.length} people")
12
+ session.logger.warn("There are no people with account amoung your #{people.length} people") unless users.length > 0
13
13
  users.each do |person|
14
+ print "."
14
15
  person.account.permissions_custom = session.new_preset(person)
15
16
  job.add(person)
16
17
  end
@@ -5,8 +5,8 @@ module Eco
5
5
  class ReinviteCase < BaseCase
6
6
 
7
7
  def process
8
- @cases.define("reinvite", type: :transform) do |people, session|
9
- invite = session.job_group("main").new("invite", type: :update, sets: :account)
8
+ @cases.define("reinvite", type: :transform) do |people, session, options, usecase|
9
+ invite = session.job_group("main").new("invite", usecase: usecase, type: :update, sets: :account)
10
10
  people.users.each do |person|
11
11
  person.account.send_invites = true
12
12
  invite.add(person)
@@ -6,8 +6,8 @@ module Eco
6
6
 
7
7
  def process
8
8
 
9
- @cases.define("remove-account", type: :transform) do |people, session|
10
- update = session.job_group("main").new("update", type: :update, sets: [:core, :account])
9
+ @cases.define("remove-account", type: :transform) do |people, session, options, usecase|
10
+ update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :account])
11
11
  people.users.map do |person|
12
12
  person.account = nil
13
13
  update.add(person)
@@ -5,8 +5,8 @@ module Eco
5
5
  class ResetLandingPageCase < UseCases::BaseCase
6
6
 
7
7
  def process
8
- @cases.define("reset-landing-page", type: :transform) do |people, session|
9
- job = session.job_group("main").new("update", type: :update, sets: :account)
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)
10
10
 
11
11
  people.users.each do |user|
12
12
  user.account.landing_page_id = nil
@@ -9,7 +9,7 @@ module Eco
9
9
  # => if there's no common node between them, take the `first` (unless they are at top level of the tree)
10
10
 
11
11
  def process
12
- @cases.define("set-default-tag", type: :transform) do |people, session, options|
12
+ @cases.define("set-default-tag", type: :transform) do |people, session, options, usecase|
13
13
  if !session.tagtree
14
14
  msg = "There is no tagtree definition in the configuration files\n" +
15
15
  "For this usecase to work out you need to define it."
@@ -26,7 +26,7 @@ module Eco
26
26
  exit
27
27
  end
28
28
 
29
- update = session.job_group("main").new("update", type: :update, sets: :account)
29
+ update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :account)
30
30
 
31
31
  people.each_with_index do |person, i|
32
32
  #next unless person.id == "5c527ba63f7690001243f5b2"
@@ -5,8 +5,8 @@ module Eco
5
5
  class SetSupervisorCase < BaseCase
6
6
 
7
7
  def process
8
- @cases.define("set-supervisor", type: :sync) do |entries, people, session, options|
9
- job = session.job_group("main").new("update", type: :update, sets: :core)
8
+ @cases.define("set-supervisor", type: :sync) do |entries, people, session, options, usecase|
9
+ job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :core)
10
10
 
11
11
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
12
12
 
@@ -5,7 +5,7 @@ module Eco
5
5
  class SwitchSupervisorCase < UseCases::BaseCase
6
6
 
7
7
  def process
8
- @cases.define("switch-supervisor", type: :transform) do |people, session, options|
8
+ @cases.define("switch-supervisor", type: :transform) do |people, session, options, usecase|
9
9
 
10
10
  unless old_id = options.dig(:super, :old)
11
11
  session.logger.error("You haven't specified the original supervisor. Aborting...")
@@ -39,7 +39,7 @@ module Eco
39
39
  session.logger.info("Going to change supervisor '#{old_sup.name}' (#{old_sup.external_id}) to '#{new_sup.name}' (#{new_sup.external_id})")
40
40
 
41
41
  # create batch queue
42
- supers = session.job_group("main").new("update", type: :update, sets: :core)
42
+ supers = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :core)
43
43
 
44
44
  people.each.with_index do |person, i|
45
45
  person.supervisor_id = new_sup.id
@@ -5,7 +5,7 @@ module Eco
5
5
  class ToCsvCase < BaseCase
6
6
 
7
7
  def process
8
- @cases.define("to-csv", type: :export) do |people, session, options|
8
+ @cases.define("to-csv", type: :export) do |people, session, options, usecase|
9
9
  unless people && !people.empty?
10
10
  session.logger.warn("No source people to create the file... aborting!")
11
11
  next false
@@ -5,7 +5,7 @@ module Eco
5
5
  class ToCsvDetailedCase < BaseCase
6
6
 
7
7
  def process
8
- @cases.define("to-csv-detailed", type: :export) do |people, session, options|
8
+ @cases.define("to-csv-detailed", type: :export) do |people, session, options, usecase|
9
9
  unless people && !people.empty?
10
10
  session.logger.warn("No source people to create the file... aborting!")
11
11
  next false
@@ -15,8 +15,8 @@ module Eco
15
15
  # p.suboption :exclude, :abilities, "Excludes the abilities from the update.", optional: true
16
16
  #end
17
17
 
18
- @cases.define("update", type: :sync) do |entries, people, session, options|
19
- update = session.job_group("main").new("update", type: :update, sets: [:core, :details, :account])
18
+ @cases.define("update", type: :sync) do |entries, people, session, options, usecase|
19
+ update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account])
20
20
 
21
21
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
22
22
  pgs = session.policy_groups
@@ -38,7 +38,7 @@ module Eco
38
38
  final: person.account.policy_group_ids
39
39
  )
40
40
 
41
- person.account.permissions_custom = session.new_preset(person) unless !create && options.dig(:exclude, :abilities)
41
+ person.account.permissions_custom = session.new_preset(person) unless options.dig(:exclude, :abilities)
42
42
 
43
43
  if session.tagtree
44
44
  person.account.filter_tags = session.tagtree.user_tags(
@@ -5,8 +5,8 @@ module Eco
5
5
  class UpdateDetailsCase < BaseCase
6
6
 
7
7
  def process
8
- @cases.define("update-details", type: :sync) do |entries, people, session, options|
9
- job = session.job_group("main").new("update", type: :update, sets: [:core, :details])
8
+ @cases.define("update-details", type: :sync) do |entries, people, session, options, usecase|
9
+ job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details])
10
10
 
11
11
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
12
12
 
@@ -5,10 +5,10 @@ module Eco
5
5
  class UpsertCase < BaseCase
6
6
 
7
7
  def process
8
- @cases.define("upsert", type: :sync) do |entries, people, session, options|
9
- creation = session.job_group("main").new("create", type: :create, sets: [:core, :details, :account])
10
- update = session.job_group("main").new("update", type: :update, sets: [:core, :details, :account])
11
- supers = session.job_group("post").new("supers", type: :update, sets: :core)
8
+ @cases.define("upsert", type: :sync) do |entries, people, session, options, usecase|
9
+ creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details, :account])
10
+ update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account])
11
+ supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
12
12
 
13
13
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
14
14
  pgs = session.policy_groups
@@ -56,7 +56,7 @@ module Eco
56
56
  kargs = {}
57
57
  kargs.merge!(input: input) if input_required?
58
58
  kargs.merge!(people: people) if people_required?
59
- kargs.merge!(session: session, options: opts)
59
+ kargs.merge!(session: session, options: opts, usecase: usecase)
60
60
  keyed ? kargs : kargs.values
61
61
  end
62
62
 
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "0.8.4"
2
+ VERSION = "0.9.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eco-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura