Class: Eco::API::MicroCases

Inherits:
Common::Session::BaseSession show all
Includes:
People
Defined in:
lib/eco/api/microcases.rb,
lib/eco/api/microcases/people.rb,
lib/eco/api/microcases/people/fetch.rb,
lib/eco/api/microcases/people/macro.rb,
lib/eco/api/microcases/people/manage.rb,
lib/eco/api/microcases/person_update.rb,
lib/eco/api/microcases/strict_search.rb,
lib/eco/api/microcases/people/preserve.rb,
lib/eco/api/microcases/people/integrity.rb,
lib/eco/api/microcases/s3upload_targets.rb,
lib/eco/api/microcases/append_usergroups.rb,
lib/eco/api/microcases/people/manage/load.rb,
lib/eco/api/microcases/people/manage/cache.rb,
lib/eco/api/microcases/people/apply_changes.rb,
lib/eco/api/microcases/people/manage/search.rb,
lib/eco/api/microcases/people/manage/refresh.rb,
lib/eco/api/microcases/people/fetch/with_each.rb,
lib/eco/api/microcases/people/manage/filename.rb,
lib/eco/api/microcases/people/macro/take_email.rb,
lib/eco/api/microcases/people/manage/load_cache.rb,
lib/eco/api/microcases/people/preserve/default_tag.rb,
lib/eco/api/microcases/people/preserve/filter_tags.rb,
lib/eco/api/microcases/people/fetch/with_supervisor.rb,
lib/eco/api/microcases/with_each_contractor_present.rb,
lib/eco/api/microcases/people/apply_changes/set_core.rb,
lib/eco/api/microcases/people/fetch/with_each_leaver.rb,
lib/eco/api/microcases/people/preserve/policy_groups.rb,
lib/eco/api/microcases/people/fetch/with_each_present.rb,
lib/eco/api/microcases/people/fetch/with_each_starter.rb,
lib/eco/api/microcases/people/apply_changes/set_account.rb,
lib/eco/api/microcases/people/integrity/fix_filter_tags.rb,
lib/eco/api/microcases/people/fetch/with_each_subordinate.rb,
lib/eco/api/microcases/people/integrity/fix_default_group.rb,
lib/eco/api/microcases/people/apply_changes/set_supervisor.rb,
lib/eco/api/microcases/people/integrity/refresh_default_tag.rb,
lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb,
lib/eco/api/microcases/people/apply_changes/set_core_with_supervisor.rb,
lib/eco/api/microcases/people/apply_changes/set_account/account_excluded.rb

Defined Under Namespace

Modules: People

Constant Summary

Constants included from People::ApplyChanges::SetCore::CoreExcluded

People::ApplyChanges::SetCore::CoreExcluded::CAN_EXCLUDE_CREATION, People::ApplyChanges::SetCore::CoreExcluded::CAN_EXCLUDE_UPDATE

Instance Attribute Summary

Attributes inherited from Common::Session::BaseSession

#config, #environment, #session

Attributes included from Language::AuxiliarLogger

#logger

Instance Method Summary collapse

Methods included from People::Macro::TakeEmail

#take_email_from_account

Methods included from People::Integrity::FixDefaultGroup

#fix_default_group

Methods included from People::Integrity::FixFilterTags

#fix_filter_tags

Methods included from People::Integrity::RefreshDefaultTag

#refresh_default_tag

Methods included from People::Preserve::PolicyGroups

#preserve_policy_groups

Methods included from People::Preserve::DefaultTag

#preserve_default_tag

Methods included from People::Preserve::FilterTags

#preserve_filter_tags

Methods included from People::ApplyChanges::SetAccount

#set_account

Methods included from People::ApplyChanges::SetAccount::AccountExcluded

#account_excluded

Methods included from People::ApplyChanges::SetCoreWithSupervisor

#set_core_with_supervisor

Methods included from People::ApplyChanges::SetSupervisor

#set_supervisor

Methods included from People::ApplyChanges::SetCore

#set_core

Methods included from People::ApplyChanges::SetCore::CoreExcluded

#core_excluded

Methods included from People::Fetch::WithEachSubordinate

#with_each_subordinate

Methods included from People::Fetch::WithEachLeaver

#with_each_leaver

Methods included from People::Fetch::WithEachStarter

#with_each_starter

Methods included from People::Fetch::WithEachPresent

#with_each_present

Methods included from People::Fetch::WithEach

#with_each

Methods included from People::Fetch::WithSupervisor

#with_supervisor

Methods included from People::Manage::Refresh

#people_refresh

Methods included from People::Manage::Search

#people_search

Methods included from People::Manage::Load

#people_load

Methods included from People::Manage::Cache

#people_cache

Methods inherited from Common::Session::BaseSession

#api, #api?, #fatal, #file_manager, #initialize, #logger, #mailer, #mailer?, #s3uploader, #s3uploader?, #sftp, #sftp?

Methods included from Language::AuxiliarLogger

#log

Constructor Details

This class inherits a constructor from Eco::API::Common::Session::BaseSession

Instance Method Details

#append_usergroups(entry, person, options) ⇒ Object

It preserves the usergroups of person and appends those defined in policy_group_ids of the entry

Parameters:

  • entry (PersonEntry)

    the input entry with the data we should set on person.

  • person (Ecoportal::API::V1::Person)

    the person we want to update, carrying the changes to be done.

  • options (Hash)

    the options.



8
9
10
11
12
13
# File 'lib/eco/api/microcases/append_usergroups.rb', line 8

def append_usergroups(entry, person, options)
  return if options.dig(:exclude, :account)
  return unless person.

  person..policy_group_ids |= entry.policy_group_ids
end

#microObject



7
8
9
# File 'lib/eco/api/microcases.rb', line 7

def micro
  self
end

#person_update!(person, context: 'Session', reason: '') ⇒ Boolean

Note:

if it succeeds the update, it calls person.consolidate!

It updates an idividual person.

Parameters:

  • person (Ecoportal::API::V1::Person)

    the person we want to update, carrying the changes to be done.

  • context (String) (defaults to: 'Session')

    main part of the message.

  • reason (String) (defaults to: '')

    why are we updating now.

Returns:

  • (Boolean)

    true if it succeded to update, and false otherwise



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

#s3upload_targetsArray<String>

Helper to upload target files to S3.

Returns:

  • (Array<String>)

    the paths in S3 of the uploaded files.



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

#strict_search?(options) ⇒ Boolean

Note:
  • strict searches ignore the email when the source entry has an external_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.

Parameters:

  • options (Hash)

    the options.

Returns:

  • (Boolean)

    true if the search should be strict only, and false otherwise.



10
11
12
13
14
15
# File 'lib/eco/api/microcases/strict_search.rb', line 10

def strict_search?(options)
  strict_config  = session.config.people.strict_search?
  strict_option  = options.dig(:search, :strict)
  soft_option    = options.dig(:search, :soft) && !strict_option
  (strict_config || strict_option) && !soft_option
end

#with_each_contractor_present(entries, contractors, options, log_new_record: false) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/eco/api/microcases/with_each_contractor_present.rb', line 19

def with_each_contractor_present(entries, contractors, options, log_new_record: false)
  found = []
  micro.with_each(entries, contractors, options) do |entry, contractor|
    if contractor.new?
      if log_new_record
        log(:error) {
          "This contractor does not exist: #{entry.to_s(:identify)}"
        }
      end

      next
    end

    found << contractor
    yield(entry, contractor) if block_given?
  end

  contractors.newFrom found
end