Class: Eco::API::MicroCases
- Inherits:
-
Common::Session::BaseSession
- Object
- Common::Session::BaseSession
- Eco::API::MicroCases
- Defined in:
- lib/eco/api/microcases.rb,
lib/eco/api/microcases/set_core.rb,
lib/eco/api/microcases/with_each.rb,
lib/eco/api/microcases/people_load.rb,
lib/eco/api/microcases/set_account.rb,
lib/eco/api/microcases/people_cache.rb,
lib/eco/api/microcases/core_excluded.rb,
lib/eco/api/microcases/people_search.rb,
lib/eco/api/microcases/person_update.rb,
lib/eco/api/microcases/strict_search.rb,
lib/eco/api/microcases/people_refresh.rb,
lib/eco/api/microcases/set_supervisor.rb,
lib/eco/api/microcases/fix_filter_tags.rb,
lib/eco/api/microcases/with_supervisor.rb,
lib/eco/api/microcases/account_excluded.rb,
lib/eco/api/microcases/s3upload_targets.rb,
lib/eco/api/microcases/with_each_leaver.rb,
lib/eco/api/microcases/append_usergroups.rb,
lib/eco/api/microcases/fix_default_group.rb,
lib/eco/api/microcases/with_each_present.rb,
lib/eco/api/microcases/with_each_starter.rb,
lib/eco/api/microcases/refresh_default_tag.rb,
lib/eco/api/microcases/preserve_default_tag.rb,
lib/eco/api/microcases/preserve_filter_tags.rb,
lib/eco/api/microcases/with_each_subordinate.rb,
lib/eco/api/microcases/preserve_policy_groups.rb,
lib/eco/api/microcases/take_email_from_account.rb,
lib/eco/api/microcases/set_core_with_supervisor.rb
Instance Attribute Summary
Attributes inherited from Common::Session::BaseSession
#config, #environment, #session
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
-
#account_excluded(person, options) ⇒ Array<String>
The account parameters that should not be included.
-
#append_usergroups(entry, person, options) ⇒ Object
It preserves the usergroups of
person
and appends those defined inpolicy_group_ids
of theentry
. -
#core_excluded(person, options) ⇒ Array<String>
The core parameters that should not be included.
-
#fix_default_group(entry, person, options) ⇒ Object
If defined, it sets the default usergroup, only when the
policy_group_ids
was not part of the input data. -
#fix_filter_tags(person, options) ⇒ Object
Helper that makes sure the custom
tags
are preserved. - #micro ⇒ Object
-
#people_cache(filename = enviro.config.people.cache) ⇒ Eco::API::Organization::People
Helper to locally cache the people manager.
-
#people_load(filename = enviro.config.people.cache, modifier: %i[newest api])) ⇒ Eco::API::Organization::People
Helper to load
People
that works in different phases: 1. -
#people_refresh(people:, include_created: true) ⇒ Eco::API::Organization::People
Helper to obtain all the elements of
people
anew from the People Manager. -
#people_search(data, options: {}, silent: true) ⇒ Eco::API::Organization::People
Helper to search/obtain people from
data
against the server (People Manager). -
#person_update!(person, context: "Session", reason: "") ⇒ Boolean
It updates an idividual person.
-
#preserve_default_tag(person, _options) ⇒ String
Helper to preserve the original
default_tag
. -
#preserve_filter_tags(person, _options, keep_new: false) ⇒ Array<String>
Helper to preserve the original filter tags.
-
#preserve_policy_groups(person, _options, keep_new: false) ⇒ String
Helper to preserve the original
policy_group_ids
. -
#refresh_default_tag(entry, person, options) ⇒ Object
When the input data, or
entry
, does not provide thedefault_tag
, it sets thedefault_tag
of the user following some criteria. -
#s3upload_targets ⇒ Array<String>
Helper to upload target files to
S3
. - #set_account(entry, person, options) ⇒ Object
-
#set_core(entry, person, options) ⇒ Object
Sets all the core details, but the supervisor.
-
#set_core_with_supervisor(entry, person, people, supers_job, options) ⇒ Object
Sets all the core details, but the supervisor.
-
#set_supervisor(person, sup_id, people, options) {|supervisor_id| ... } ⇒ Object
Unique access point to set the
supervisor_id
value on a person. -
#strict_search?(options) ⇒ Boolean
When trying to find an
person
with given a sourceentry
, it states if such a search should bestrict
orsoft
. -
#take_email_from_account(person, dest_email:, target_email: nil, options: {}, context: "Session") ⇒ Object
Frees up
target_email
from an account not present in this org. -
#with_each(entries, people, options, append_created: true) {|entry, person| ... } ⇒ Eco::API::Organization::People
Finds each entry of
entries
inpeople
and runs a block. -
#with_each_leaver(entries, people, options) {|person| ... } ⇒ Eco::API::Organization::People
Detects who has left the organization and
yield
s them one by one to the given block. -
#with_each_present(entries, people, options, log_starter: false) {|entry, person| ... } ⇒ Eco::API::Organization::People
Finds those in
entries
that already exist in the organization (people
) andyield
s them one by one to the given block. -
#with_each_starter(entries, people, options, log_present: false, append_created: true) {|entry, person| ... } ⇒ Eco::API::Organization::People
Detects who in the
entries
is new in the organization andyield
s them one by one to the given block. -
#with_each_subordinate(supervisor, people) {|subordinate| ... } ⇒ Eco::API::Organization::People
Finds all the subordinates of
supervisor
. -
#with_supervisor(value, people, strict: false) {|supervisor| ... } ⇒ nil, Ecoportal::API::V1::Person
Finds the supervisor among
people
by using thesupervisor_id
ofvalue
.
Methods inherited from Common::Session::BaseSession
#api, #api?, #fatal, #file_manager, #initialize, #logger, #mailer, #mailer?, #s3uploader, #s3uploader?, #sftp, #sftp?
Methods included from Language::AuxiliarLogger
Constructor Details
This class inherits a constructor from Eco::API::Common::Session::BaseSession
Instance Method Details
#account_excluded(person, options) ⇒ Array<String>
Returns the account parameters that should not be included.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/eco/api/microcases/account_excluded.rb', line 7 def account_excluded(person, ) [].tap do |account_excluded| unless person.new? if .dig(:exclude, :policy_groups) account_excluded.push("policy_group_ids") end if .dig(:exclude, :default_tag) account_excluded.push("default_tag") end if .dig(:exclude, :login_providers) account_excluded.push("login_provider_ids") end end end end |
#append_usergroups(entry, person, options) ⇒ Object
It preserves the usergroups of person
and appends those defined in policy_group_ids
of the entry
8 9 10 11 12 13 |
# File 'lib/eco/api/microcases/append_usergroups.rb', line 8 def append_usergroups(entry, person, ) return if .dig(:exclude, :account) return unless person.account person.account.policy_group_ids |= entry.policy_group_ids end |
#core_excluded(person, options) ⇒ Array<String>
by default supervisor_id
is always excluded.
Returns the core parameters that should not be included.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/eco/api/microcases/core_excluded.rb', line 8 def core_excluded(person, ) ["supervisor_id"].tap do |core_excluded| can_exclude = person.new?? ["filter_tags"] : %w[name external_id email filter_tags] exclusions = can_exclude.select do |attr| .dig(:exclude, attr.to_sym) end core_excluded.concat(exclusions) end end |
#fix_default_group(entry, person, options) ⇒ Object
If defined, it sets the default usergroup, only when the policy_group_ids
was not part of the input data.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/eco/api/microcases/fix_default_group.rb', line 8 def fix_default_group(entry, person, ) return if .dig(:exclude, :account) return if .dig(:exclude, :policy_groups) && !person.new? end_pg_ids = person.account.policy_group_ids if person.account_added? && __def_usergroup_id && !entry.policy_group_ids? # on account creation, if missing policy_group_ids column in the input # use default_usergroup, if it's defined end_pg_ids = [__def_usergroup_id] end person.account.policy_group_ids = end_pg_ids end |
#fix_filter_tags(person, options) ⇒ Object
- this feature is essential to preserve custom
tags
in users that have register tags. - for this to work out, it requires a
tagtree
to be defined.
Helper that makes sure the custom tags
are preserved.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/eco/api/microcases/fix_filter_tags.rb', line 13 def (person, ) return unless session.tagtree = .dig(:exclude, :core) || .dig(:exclude, :filter_tags) return if !person.new? && person. = session.tagtree.( initial: person.original_doc["filter_tags"] || [], final: person., preserve_custom: (), add_custom: () ) end |
#micro ⇒ Object
4 5 6 |
# File 'lib/eco/api/microcases.rb', line 4 def micro self end |
#people_cache(filename = enviro.config.people.cache) ⇒ Eco::API::Organization::People
Helper to locally cache the people manager.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/eco/api/microcases/people_cache.rb', line 7 def people_cache(filename = enviro.config.people.cache) log(:info) { "Going to get all the people via API" } start = Time.now people = session.batch.get_people secs = (Time.now - start).round(3) cnt = people.count per_sec = (cnt.to_f / secs).round(2) log(:info) { "Loaded #{cnt} people in #{secs} seconds (#{per_sec} people/sec)" } file = file_manager.save_json(people, filename, :timestamp) log(:info) { "#{people.length} people loaded and saved locally to #{file}." } Eco::API::Organization::People.new(people) end |
#people_load(filename = enviro.config.people.cache, modifier: %i[newest api])) ⇒ Eco::API::Organization::People
filename
will be relative to the working directory (the one of the sessionenviro
set by the user).
Helper to load People
that works in different phases:
- first tries to get the newest cached file that follows
filename
pattern- if not the newest, it tries to find the specific filename
- if it succeeds to identify a cached file, it loads it
- if it fails, it tries to get people from the server
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/eco/api/microcases/people_load.rb', line 18 def people_load(filename = enviro.config.people.cache, modifier: %i[newest api]) # rubocop:disable Metrics/AbcSize modifier = [modifier].flatten load_file = %i[file newest].any? {|flag| modifier.include?(flag)} case when filename && load_file file = people_load_filename(filename, newest: modifier.include?(:newest)) if file file_manager.load_json(file).tap do |people| next unless people.is_a?(Array) log(:info) { "#{people&.length} people loaded from file #{file}" } end else log(:error) { "could not find the file #{file_manager.dir.file(filename)}" } exit unless modifier.include?(:api) people_load(modifier: modifier - %i[newest file]) end when modifier.include?(:api) log(:info) { "Going to get all the people via API (load)" } start = Time.now session.batch.get_people.tap do |people| secs = (Time.now - start).round(3) cnt = people.count per_sec = (cnt.to_f / secs).round(2) log(:info) { "Loaded #{cnt} people in #{secs} seconds (#{per_sec} people/sec)" } if modifier.include?(:save) && people && people.length.positive? file = file_manager.save_json(people, filename, :timestamp) log(:info) { "#{people.length} people saved to file #{file}." } end end end.then do |people| Eco::API::Organization::People.new(people) end end |
#people_refresh(people:, include_created: true) ⇒ Eco::API::Organization::People
- This helper is normally used to run consecutive usecases, where data needs refresh.
- It only includes new people if they are not dirty (they do not have pending updates)
- This contingency wouldn't be necessary if the server worked perfectly.
Helper to obtain all the elements of people
anew from the People Manager.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/eco/api/microcases/people_refresh.rb', line 12 def people_refresh(people:, include_created: true) # rubocop:disable Metrics/AbcSize people = people.newFrom people.select do |person| !person.new? || !person.dirty? end ini = people.length if include_created session.job_groups.find_jobs(type: :create).map do |job| to_add = job.people.reject(&:dirty?) people = people.merge(to_add) end end created = people.length - ini msg = "Going to refresh #{people.length} people with server data" msg += " (including #{created} that were created)" if created.positive? log(:info) { msg } start = Time.now entries = session.batch.get_people(people, silent: true) secs = (Time.now - start).round(3) cnt = entries.count per_sec = (cnt.to_f / secs).round(2) log(:info) { "Re-loaded #{cnt} people (out of #{people.length}) in #{secs} seconds (#{per_sec} people/sec)" } missing = people.length - entries.length if missing.positive? log(:error) { "Missed to obtain #{missing} people during the refresh" } end Eco::API::Organization::People.new(entries) end |
#people_search(data, options: {}, silent: true) ⇒ Eco::API::Organization::People
- this helper is normally used to get partial part of the people manager.
- therefore, normally used with delta input files (files with only the differences).
Helper to search/obtain people from data
against the server (People Manager).
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/eco/api/microcases/people_search.rb', line 13 def people_search(data, options: {}, silent: true) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength log(:info) { "Going to api get #{data.length} entries..." } silent &&= data.count <= 500 start = Time.now people = session.batch.search(data, silent: silent).then do |status| secs = (Time.now - start).round(3) Eco::API::Organization::People.new(status.people).tap do |people| # rubocop:disable Lint/ShadowingOuterLocalVariable cnt = people.count per_sec = (cnt.to_f / secs).round(2) msg = "... could get #{cnt} people " msg << "(out of #{data.length} entries) in #{secs} seconds (#{per_sec} people/sec)" log(:info) { msg } end end # get the supervisors of found people (current supervisors) supers = people_search_prepare_supers_request(people) if supers.length.positive? log(:info) { " Going to api get #{supers.length} current supervisors..." } start = Time.now people = session.batch.search(supers, silent: silent).then do |status| secs = (Time.now - start).round(3) found = status.people cnt = found.count per_sec = (cnt.to_f / secs).round(2) msg = "... could find #{cnt} current supers " msg << "(out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)" log(:info) { msg } people.merge(found, strict: micro.strict_search?()) end end # get the supervisors referred in the input data (future supervisors) supers = people_search_prepare_supers_request(data, people) if supers.length.positive? log(:info) { " Going to api get #{supers.length} supervisors as per input entries..." } start = Time.now people = session.batch.search(supers, silent: silent).then do |status| secs = (Time.now - start).round(3) found = status.people cnt = found.count per_sec = (cnt.to_f / secs).round(2) msg = "... could find #{cnt} input supers " msg << "(out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)" log(:info) { msg } people.merge(found, strict: micro.strict_search?()) end end log(:info) { "Finally got #{people.length} people (out of #{data.length} entries)" } people end |
#person_update!(person, context: "Session", reason: "") ⇒ Boolean
if it succeeds the update, it calls person.consolidate!
It updates an idividual person.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/eco/api/microcases/person_update.rb', line 10 def person_update!(person, context: "Session", reason: "") log(:debug) { "#{context}, going to \"#{reason}\".\nPerson: #{person_ref(person)}" } if (response = api.people.update(person)) if response.success? person.consolidate! true else msg = "#{context} Error #{response.status}: #{response.body}\n" msg += " -- Failed to \"#{reason}\".\n" msg += " • Person: #{person_ref(person)}" log(:error) { msg } false end else msg = "#{context} Error (connection error)\n" msg += " -- Failed to \"#{reason}\".\n" msg += " • Person: #{person_ref(person)}" log(:error) { msg } false end end |
#preserve_default_tag(person, _options) ⇒ String
- It only works if the original value of
default_tag
was not empty
Helper to preserve the original default_tag
.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/eco/api/microcases/preserve_default_tag.rb', line 10 def preserve_default_tag(person, ) return unless (account = person.account) account.default_tag.tap do next unless account.as_update.key?("default_tag") next unless (original = person.original_doc.dig("account", "default_tag")) person.account.default_tag = original return original end end |
#preserve_filter_tags(person, _options, keep_new: false) ⇒ Array<String>
- It only works if the original value of
filter_tags
was not empty
Helper to preserve the original filter tags.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/eco/api/microcases/preserve_filter_tags.rb', line 11 def (person, , keep_new: false) person..tap do next unless person.as_update.key?('filter_tags') next unless (original = person.original_doc['filter_tags']) next if original.empty? if keep_new person. += original else person. = original end return person. end end |
#preserve_policy_groups(person, _options, keep_new: false) ⇒ String
- It only works if the original value of
policy_group_ids
was not empty
Helper to preserve the original policy_group_ids
.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/eco/api/microcases/preserve_policy_groups.rb', line 11 def preserve_policy_groups(person, , keep_new: false) return unless (account = person.account) account.policy_group_ids.tap do next unless account.as_update.key?("policy_group_ids") next unless (original = person.original_doc.dig("account", "policy_group_ids")) next if original.empty? if keep_new person.account.policy_group_ids += original else person.account.policy_group_ids = original end return account.policy_group_ids end end |
#refresh_default_tag(entry, person, options) ⇒ Object
it assumes default_tag
has been already set to person.account
When the input data, or entry
, does not provide the default_tag
,
it sets the default_tag
of the user following some criteria
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/eco/api/microcases/refresh_default_tag.rb', line 10 def refresh_default_tag(entry, person, ) return unless person.account return if .dig(:exclude, :account) return if .dig(:exclude, :filter_tags) return if .dig(:exclude, :default_tag) return if entry&.default_tag? if session.tagtree person.account.default_tag = session.tagtree.default_tag(*person.) else = person. || [] person.account.default_tag = .first unless .length > 1 end end |
#s3upload_targets ⇒ Array<String>
Helper to upload target files to S3
.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/eco/api/microcases/s3upload_targets.rb', line 6 def s3upload_targets # rubocop:disable Metrics/AbcSize [].tap do |paths| session.config.s3storage.target_files.each_with_object(paths) do |file, arr| arr.push(session.s3upload(file: file)) end session.config.s3storage.target_directories.each_with_object(paths) do |folder, arr| arr.concat(session.s3upload(directory: folder)) end session.config.s3storage.target_file_patterns.each_with_object(paths) do |pattern, arr| filenames = [] case pattern when Regexp Dir.entries(".").sort.each do |file| next unless File.file?(file) # Skip directories filenames.push(file) if file =~ pattern end when String Dir.glob(pattern).sort.each do |file| next unless File.file?(file) # Skip directories filenames.push(file) end else # missconfiguration end filenames.each do |file| arr.push(session.s3upload(file: file)) end end end end |
#set_account(entry, person, options) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/eco/api/microcases/set_account.rb', line 7 def set_account(entry, person, ) return if .dig(:exclude, :account) entry.set_account(person, exclude: micro.account_excluded(person, )) person.account.send_invites = [:send_invites] if .key?(:send_invites) micro.refresh_default_tag(entry, person, ) micro.fix_default_group(entry, person, ) end |
#set_core(entry, person, options) ⇒ Object
supervisor_id
requires a special treatment, and therefore is always excluded.
Sets all the core details, but the supervisor.
9 10 11 12 13 14 |
# File 'lib/eco/api/microcases/set_core.rb', line 9 def set_core(entry, person, ) return if .dig(:exclude, :core) && !person.new? entry.set_core(person, exclude: micro.core_excluded(person, )) micro.(person, ) end |
#set_core_with_supervisor(entry, person, people, supers_job, options) ⇒ Object
supervisor_id
requires a special treatment, and therefore is always excluded.
Sets all the core details, but the supervisor.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/eco/api/microcases/set_core_with_supervisor.rb', line 11 def set_core_with_supervisor(entry, person, people, supers_job, ) return if .dig(:exclude, :core) && !person.new? micro.set_core(entry, person, ) return unless entry.supervisor_id? micro.set_supervisor( person, entry.supervisor_id, people, ) do |unknown_id| # delay setting supervisor if does not exit supers_job.add(person) do |pers| micro.set_supervisor(pers, unknown_id, people, ) end end end |
#set_supervisor(person, sup_id, people, options) {|supervisor_id| ... } ⇒ Object
- It prevents the basic cyclic supervisor case (supervisor to be supervisor of themselves)
Unique access point to set the supervisor_id
value on a person.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/eco/api/microcases/set_supervisor.rb', line 13 def set_supervisor(person, sup_id, people, ) return false if .dig(:exclude, :core) || .dig(:exclude, :supervisor) return false if sup_id && ((person.id == sup_id) || (person.external_id == sup_id)) cur_id = person.supervisor_id cur_super = cur_id && with_supervisor(cur_id, people) micro.with_supervisor(sup_id, people) do |new_super| if !sup_id person.supervisor_id = nil descrease_subordinates(cur_super) elsif new_super && (id = new_super.id) set_supervisor(new_super, nil, people, ) if new_super_direct_cyclic?(person, new_super) person.supervisor_id = id descrease_subordinates(cur_super) increase_subordinates(new_super) elsif !block_given? descrease_subordinates(cur_super) person.supervisor_id = sup_id elsif block_given? yield(sup_id) end end end |
#strict_search?(options) ⇒ Boolean
strict
searches ignore the email when the sourceentry
has anexternal_id
specified.- see related command line options
-search-strict
and-search-soft
When trying to find an person
with given a source entry
, it states if such a search should be strict
or soft
.
10 11 12 13 14 15 |
# File 'lib/eco/api/microcases/strict_search.rb', line 10 def strict_search?() strict_config = session.config.people.strict_search? strict_option = .dig(:search, :strict) soft_option = .dig(:search, :soft) && !strict_option (strict_config || strict_option) && !soft_option end |
#take_email_from_account(person, dest_email:, target_email: nil, options: {}, context: "Session") ⇒ Object
- It does not do the final update to the server to the
target_email
. You will need to do this part yourself. - You would call this function only when you got an error of
email already taken
. - If the
target_email
is associated to a user in the same org, this will fail.
Frees up target_email
from an account not present in this org.
Allows to force target_email
on the current user's account.
- If the person does not have account, this case will not do anything.
- If
original_doc["account"]
isnil
(no account on server side), this case will not do anything. - If the
target_email
and thecurrent_email
are the same or empty, this case will not do anything.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/eco/api/microcases/take_email_from_account.rb', line 26 def take_email_from_account(person, dest_email:, target_email: nil, options: {}, context: "Session") return false if .dig(:exclude, :account) return false unless (account = person.account) return false unless (had_account = person.original_doc["account"]) # rubocop:disable Lint/UselessAssignment target_email ||= person.email account_email = person.original_doc["email"] return false unless target_email != account_email return false if account_email.to_s.strip.empty? return false if target_email.to_s.strip.empty? if dest_email.is_a?(String) return false unless target_email != dest_email return false unless dest_email != account_email return false if dest_email.to_s.strip.empty? end account_json = _take_email_account_json(account) person.email = account_email if (success = _take_email_remove_account!(person, context: context)) if (success = _take_email_acquire_account!(person, target_email, account: {}, context: context)) if (success = _take_email_email_free_up!(person, dest_email: dest_email, context: context)) if (success = _take_email_remove_account!(person, context: context)) # Bring back the original account if (success = _take_email_acquire_account!(person, account_email, account: account_json, context: context)) # rubocop:disable Style/SoleNestedConditional success = true person.email = target_email end end else # free up target email # restore reverted = false if reverted ||= _take_email_remove_account!(person, context: context) reverted ||= _take_email_acquire_account!(person, account_email, account: account_json, context: context) end unless reverted msg = "Could not revert back to the original account #{person.identify}" log(:debug) { msg } puts msg end success = false end else # aquire other account # restore unless _take_email_acquire_account!(person, account_email, account: account_json, context: context) msg = "Could not bring back the original account that " msg << "we want to update the email to '#{target_email}' #{person.identify}" log(:debug) { msg } puts msg end success = false end end success end |
#with_each(entries, people, options, append_created: true) {|entry, person| ... } ⇒ Eco::API::Organization::People
- it also links to
person.entry
the input data entry.
Finds each entry of entries
in people
and runs a block.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/eco/api/microcases/with_each.rb', line 15 def with_each(entries, people, , append_created: true) @_skip_all_multiple_results = false people_copy = people.newFrom(people.to_a) entries.each_with_object([]) do |entry, scoped| begin person = people_copy.find(entry, strict: micro.strict_search?()) person ||= session.new_person.tap do |pers| people << pers if append_created end rescue Eco::API::Organization::People::MultipleSearchResults => e unless @_skip_all_multiple_results msg = "\n * When searching this Entry: #{entry.to_s(:identify)}" person = _with_each_prompt_to_select_user(e.(msg), entry: entry) end end next unless person person.entry = entry yield(entry, person) if block_given? scoped << person end.then do |all_people| people.newFrom all_people.uniq end end |
#with_each_leaver(entries, people, options) {|person| ... } ⇒ Eco::API::Organization::People
- To be used only when the input file is the full DB
- The
Entries#find
method. If the people manager entry does not haveexternal_id
, but has a matchingemail
wiht some input entry (row), it won't be identified as a leaver.
Detects who has left the organization and yield
s them one by one to the given block
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/eco/api/microcases/with_each_leaver.rb', line 15 def with_each_leaver(entries, people, ) leavers = people.map do |person| unless entries.find(person, strict: micro.strict_search?()) yield(person) if block_given? person end end.compact people.newFrom leavers end |
#with_each_present(entries, people, options, log_starter: false) {|entry, person| ... } ⇒ Eco::API::Organization::People
- it also links to
person.entry
the input dataentry
.
Finds those in entries
that already exist in the organization (people
) and yield
s them one by one to the given block.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/eco/api/microcases/with_each_present.rb', line 15 def with_each_present(entries, people, , log_starter: false) found = [] micro.with_each(entries, people, ) do |entry, person| if person.new? if log_starter log(:error) { "This person does not exist: #{entry.to_s(:identify)}" } end next end found << person yield(entry, person) if block_given? end people.newFrom found end |
#with_each_starter(entries, people, options, log_present: false, append_created: true) {|entry, person| ... } ⇒ Eco::API::Organization::People
- it also links to
person.entry
the input dataentry
.
Detects who in the entries
is new in the organization and yield
s them one by one to the given block.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/eco/api/microcases/with_each_starter.rb', line 16 def with_each_starter(entries, people, , log_present: false, append_created: true) starters = [] micro.with_each(entries, people, , append_created: append_created) do |entry, person| unless person.new? if log_present log(:error) { "This person (id: '#{person.id}') already exists: #{entry.to_s(:identify)}" } end next end starters << person yield(entry, person) if block_given? end people.newFrom starters end |
#with_each_subordinate(supervisor, people) {|subordinate| ... } ⇒ Eco::API::Organization::People
if supervisor
is nil
, it will return all people with no supervisor.
Finds all the subordinates of supervisor
.
11 12 13 14 15 16 17 |
# File 'lib/eco/api/microcases/with_each_subordinate.rb', line 11 def with_each_subordinate(supervisor, people) people.supervisor_id(_person_id(supervisor, people)).tap do |subordinates| subordinates.each do |subordinate| yield(subordinate) if block_given? end end end |
#with_supervisor(value, people, strict: false) {|supervisor| ... } ⇒ nil, Ecoportal::API::V1::Person
Finds the supervisor among people
by using the supervisor_id
of value
.
12 13 14 15 16 17 18 |
# File 'lib/eco/api/microcases/with_supervisor.rb', line 12 def with_supervisor(value, people, strict: false) if sup_id = with_supervisor_supervisor_id(value) people.person(id: sup_id, external_id: sup_id, email: sup_id, strict: strict) end.tap do |supervisor| yield(supervisor) if block_given? end end |