lib/eco/api/microcases/set_supervisor.rb in eco-helpers-2.0.52 vs lib/eco/api/microcases/set_supervisor.rb in eco-helpers-2.0.53
- old
+ new
@@ -1,16 +1,19 @@
module Eco
module API
class MicroCases
# Unique access point to set the `supervisor_id` value on a person.
+ # @note
+ # - It prevents the basic cyclic supervisor case (supervisor to be supervisor of hemselves)
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
# @param sup_id [nil, String] the **supervisor id** we should set on the `person`.
# @param people [Eco::API::Organization::People] _People_ involved in the current update.
# @param options [Hash] the options.
# @yield [supervisor_id] callback when the supervisor_id is **unknown** (not `nil` nor any one's in `people`).
# @yieldparam supervisor_id [String] the **unknown** `supervisor_id`.
def set_supervisor(person, sup_id, people, options)
unless options.dig(:exclude, :core) || options.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