Class: Entitlements::Extras::Orgchart::Rules::Management

Inherits:
Data::Groups::Calculated::Rules::Base show all
Includes:
Contracts::Core
Defined in:
lib/entitlements/extras/orgchart/rules/management.rb

Constant Summary collapse

C =
::Contracts

Class Method Summary collapse

Methods included from Contracts::Core

common, extended, included

Class Method Details

.matches(value:, filename: nil, options: {}) ⇒ Object



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
# File 'lib/entitlements/extras/orgchart/rules/management.rb', line 24

def self.matches(value:, filename: nil, options: {})
  begin
    manager = Entitlements.cache[:people_obj].read(value)
  rescue Entitlements::Data::People::NoSuchPersonError
    # This is fatal. If this defines a team by a manager who is no longer in LDAP then the
    # entry needs to be corrected because those people have to report to someone...
    Entitlements.logger.fatal "Manager #{value} does not exist for file #{filename}!"
    raise "Manager #{value} does not exist!"
  end

  # Call all_reports which will return the set of all direct and indirect reports.
  # This is evaluated once per run of the program.
  Entitlements.cache[:management_obj] ||= begin
    Entitlements::Extras::Orgchart::Logic.new(people: Entitlements.cache.fetch(:people_obj).read)
  end

  # This is fatal. If this defines a manager who has nobody reporting to them, then they
  # aren't a manager at all. The entry should be changed to "username" or otherwise the
  # proper manager should be filled in.
  if Entitlements.cache[:management_obj].all_reports(manager).empty?
    Entitlements.logger.fatal "Manager #{value} has no reports for file #{filename}!"
    raise "Manager #{value} has no reports!"
  end

  # Most of the time, people will expect "management: xyz" to include xyz and anyone who
  # reports to them. Technically, xyz doesn't report to themself, but we'll hack it in here
  # because it's least surprise. If someone really wants "xyz's reports but not xyz" they
  # can use the "not" in conjunction.
  result = Set.new([manager])
  result.merge Entitlements.cache[:management_obj].all_reports(manager)
end