Class: PeopleGroup::Connectors::Hris

Inherits:
Object
  • Object
show all
Defined in:
lib/peoplegroup/connectors/hris.rb

Constant Summary collapse

EmployeeNotFoundError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initializeHris

Returns a new instance of Hris.



9
10
11
# File 'lib/peoplegroup/connectors/hris.rb', line 9

def initialize
  @workday = Workday::Client.new unless ENV.fetch('WORKDAY_SERVICE_URL', nil).nil?
end

Instance Method Details

#active_and_current_employeesArray<Hash> Also known as: active_and_current_team_members

List team members with the satus of ‘Active’ and a hireDate that is less than or equal to today.

Returns:

  • (Array<Hash>)

    team members with a status of ‘Active’ and a hireDate that is less than or equal to today.



35
36
37
38
39
40
# File 'lib/peoplegroup/connectors/hris.rb', line 35

def active_and_current_employees
  today = Date.current
  employees.select do |employee|
    employee['status'] == 'Active' && Date.parse(employee['hireDate']) <= today
  end
end

#active_employeesArray<Hash] team members with a status of 'Active'. Also known as: active_team_members

List team members with the satus of ‘Active’.

Returns:

  • (Array<Hash] team members with a status of 'Active'.)

    Array<Hash] team members with a status of ‘Active’.



28
29
30
# File 'lib/peoplegroup/connectors/hris.rb', line 28

def active_employees
  employees.select { |employee| employee['status'] == 'Active' }
end

#add_bonus(employee_number, comment) ⇒ Object



243
244
245
# File 'lib/peoplegroup/connectors/hris.rb', line 243

def add_bonus(employee_number, comment)
  @workday.add_bonus(employee_number, comment)
end

#departmentsArray<Hash>

List active departments from Workday.

Returns:

  • (Array<Hash>)

    list of departments from Workday.



249
250
251
# File 'lib/peoplegroup/connectors/hris.rb', line 249

def departments
  @workday.departments
end

#eligibility_status(eid, salary_min, salary_max) ⇒ Hash

Check team member eligibility status based on salary ranges.

Parameters:

  • eid (String|Integer)

    the team members employee number

  • salary_min (Integer)

    the minimum salary.

  • salary_max (Integer)

    the maximum salary.

Returns:

  • (Hash)

    details regarding their eligibility status.



258
259
260
# File 'lib/peoplegroup/connectors/hris.rb', line 258

def eligibility_status(eid, salary_min, salary_max)
  @workday.eligibility_status(eid, salary_min, salary_max)
end

#employeesArray<Hash> Also known as: team_members

List all team members from the WORKDAY_WORKERS_REPORT.

Returns:

  • (Array<Hash>)

    hris = PeopleGroup::Connectors::Hris.new hris.team_members #=> [{ “workEmail”=>“[email protected]” }, …]



18
19
20
21
22
23
# File 'lib/peoplegroup/connectors/hris.rb', line 18

def employees
  @employees ||= Workday::Report.call(
    url: ENV.fetch('WORKDAY_WORKERS_REPORT', nil),
    password: ENV.fetch('WORKDAY_ISU_PASSWORD', nil)
  )
end

#employment_statuses(employee_number) ⇒ Object

Raises:

  • (NotImplementedError)


221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/peoplegroup/connectors/hris.rb', line 221

def employment_statuses(employee_number)
  # Terminated/Active in one field already. Those are the statuses we need to care about
  # Look for a hire date that is after the start date (not original hire date) to account for rehires
  # Affected: joining.rb

  # Probation period, CXC contract ending, temporary contract ending won't be needed
  # We can ignore garden leave (terminate access to systems without pausing benefits/stock vesting)
  # Affected:
  # - anniversary.rb
  # - cxc_contract_renewal_email.rb
  # - extension_netherlands_contract_email.rb
  # - probation_email.rb
  # - probation_status.rb

  raise NotImplementedError
end

#fetch_manager(team_member) ⇒ Hash|nil

Find the manager of a team member.

Parameters:

  • team_member (Hash)

    the team member’s details.

Returns:

  • (Hash|nil)

    the manager’s details



179
180
181
# File 'lib/peoplegroup/connectors/hris.rb', line 179

def fetch_manager(team_member)
  active_team_members.find { |tm| tm['employeeNumber'] == team_member['supervisorId'] }
end

#fetch_manager!(team_member) ⇒ Object

Find the manager of a team member and raise error if not found.

Parameters:

  • team_member (Hash)

    the team member’s details.

Raises:

See Also:

  • PeopleGroup::Connectors::Hris.[PeopleGroup[PeopleGroup::Connectors[PeopleGroup::Connectors::Hris[PeopleGroup::Connectors::Hris#fetch_manager]


187
188
189
190
191
192
# File 'lib/peoplegroup/connectors/hris.rb', line 187

def fetch_manager!(team_member)
  manager = fetch_manager(team_member)
  raise EmployeeNotFoundError, "Manager not found for employee #{team_member['employeeNumber']}" if manager.nil?

  manager
end

#fetch_second_level_manager(team_member) ⇒ Hash|nil

Find the second level manager of a team member.

  1. Find the team member’s manager.

  2. Find the manager’s manager.

Parameters:

  • team_member (Hash)

    the team member’s details.

Returns:

  • (Hash|nil)

    the second level manager’s details or nil.



199
200
201
# File 'lib/peoplegroup/connectors/hris.rb', line 199

def fetch_second_level_manager(team_member)
  fetch_manager(fetch_manager(team_member))
end

#fetch_second_level_manager!(team_member) ⇒ Hash|nil

Find the second level manager of a team member, raise error if not found.

Parameters:

  • team_member (Hash)

    the team member’s details.

Returns:

  • (Hash|nil)

    the second level manager’s details or nil.

Raises:

See Also:

  • PeopleGroup::Connectors::Hris.[PeopleGroup[PeopleGroup::Connectors[PeopleGroup::Connectors::Hris[PeopleGroup::Connectors::Hris#fetch_second_level_manager]


208
209
210
211
212
213
# File 'lib/peoplegroup/connectors/hris.rb', line 208

def fetch_second_level_manager!(team_member)
  manager = fetch_second_level_manager(team_member)
  raise EmployeeNotFoundError, "No second level manager found for employee #{team_member['employeeNumber']}" if manager.nil?

  manager
end

#get_employee_details(employee_number) ⇒ Hash Also known as: get_team_member_details

Get the details of a team member from the WORKDAY_WORKERS_REPORT.

Examples:

hris = PeopleGroup::Connectors::Hris.new
hris.get_employee_details(12345)
#=> { "workEmail"=>"[email protected]", ... }

Parameters:

  • employee_number (String|Integer)

    the team member’s employee number.

Returns:

  • (Hash)

    the team member’s details.



50
51
52
# File 'lib/peoplegroup/connectors/hris.rb', line 50

def get_employee_details(employee_number)
  employees.find { |emp| emp['employeeNumber'] == employee_number.to_s }
end

#get_employee_details!(employee_number) ⇒ Object Also known as: get_team_member_details!

Get the details of a team member from the WORKDAY_WORKERS_REPORT.

Parameters:

  • employee_number (String|Integer)

Raises:

See Also:

  • PeopleGroup::Connectors::Hris.[PeopleGroup[PeopleGroup::Connectors[PeopleGroup::Connectors::Hris[PeopleGroup::Connectors::Hris#get_employee_details]


59
60
61
62
63
64
# File 'lib/peoplegroup/connectors/hris.rb', line 59

def get_employee_details!(employee_number)
  employee_details = get_employee_details(employee_number)
  raise EmployeeNotFoundError, "No team member found with employee number #{employee_number}" if employee_details.nil?

  employee_details
end

#job_details(employee_number) ⇒ Object



238
239
240
241
# File 'lib/peoplegroup/connectors/hris.rb', line 238

def job_details(employee_number)
  warn '[DEPRECATED] PeopleGroup::Connectors::Hris#job_details, use a custom workday report instead.'
  Workday::Report.call(url: ENV.fetch('WORKDAY_MANAGER_REPORT', nil))
end

#locationsArray<Hash>

List entities from Workday.

Returns:

  • (Array<Hash>)

    list of entities from Workday.



217
218
219
# File 'lib/peoplegroup/connectors/hris.rb', line 217

def locations
  @workday.locations
end

#search_employee(name) ⇒ Hash|nil Also known as: search_team_member

Search a team member by name.

Examples:

hris = PeopleGroup::Connectors::Hris.new
hris.search_employee('Jane Doe')

Parameters:

  • name (String)

    the team member’s name.

Returns:

  • (Hash|nil)

    the team member’s details if found or nil.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/peoplegroup/connectors/hris.rb', line 73

def search_employee(name)
  return if name.empty?

  employees.find do |emp|
    [
      emp['displayName']&.downcase,
      "#{emp['firstName']&.downcase} #{emp['lastName']&.downcase}",
      "#{emp['preferredName']&.downcase} #{emp['lastName']&.downcase}",
      "#{emp['firstName']&.downcase} #{emp['customPreferredLastName']&.downcase}",
      "#{emp['preferredName']&.downcase} #{emp['customPreferredLastName']&.downcase}",
      emp['fullName5']&.downcase # this is firstName middleName lastName
    ].include?(name.downcase)
  end
end

#search_employee!(name) ⇒ Object Also known as: search_team_member!

Search team member by name.

Parameters:

  • name (String)

    the team member’s name or display name.

Raises:

See Also:

  • PeopleGroup::Connectors::Hris.[PeopleGroup[PeopleGroup::Connectors[PeopleGroup::Connectors::Hris[PeopleGroup::Connectors::Hris#search_employee]


93
94
95
96
97
98
# File 'lib/peoplegroup/connectors/hris.rb', line 93

def search_employee!(name)
  employee = search_employee(name)
  raise EmployeeNotFoundError, "No employee found with name #{name}" if employee.nil?

  employee
end

#search_employee_by_field(field:, value:) ⇒ Hash|nil Also known as: search_team_member_by_field

Search a team meber by field.

Examples:

hris = PeopleGroup::Connectors::Hris.new
hris.search_employee_by_field('workEmail', '[email protected]')
 #=> { "workEmail"=>"[email protected]", ... }

Parameters:

  • field (String)

    the field to search on.

  • value (String|Integer)

    the value to search for.

Returns:

  • (Hash|nil)

    the team member’s details if found or nil.



109
110
111
# File 'lib/peoplegroup/connectors/hris.rb', line 109

def search_employee_by_field(field:, value:)
  employees.find { |employee| employee[field] == value.to_s }
end

#search_employee_by_field!(field:, value:) ⇒ Object Also known as: search_team_member_by_field!

Search a team member by field, and raise error if not found.

Parameters:

  • field (String)

    the field to search on.

  • value (String|Integer)

    the value to search for.

Raises:

See Also:

  • PeopleGroup::Connectors::Hris.[PeopleGroup[PeopleGroup::Connectors[PeopleGroup::Connectors::Hris[PeopleGroup::Connectors::Hris#search_employee_by_field]


119
120
121
122
123
124
# File 'lib/peoplegroup/connectors/hris.rb', line 119

def search_employee_by_field!(field:, value:)
  employee = search_employee_by_field(field: field, value: value)
  raise EmployeeNotFoundError, "No employee found with #{field}: #{value}" if employee.nil?

  employee
end

#search_team_member_by_email(email) ⇒ Hash|nil Also known as: slack_email_lookup_with_fallback

Find the associated team member without checking case on their e-mail fields.

  1. Look for a match on their workEmail field.

  2. Look for a match on their bestEmail field.

  3. Look for a match on their homeEmail field.

Parameters:

  • email (String)

    the team member’s e-mail address.

Returns:

  • (Hash|nil)

    the team member’s details if found or nil.



133
134
135
136
137
138
139
140
# File 'lib/peoplegroup/connectors/hris.rb', line 133

def search_team_member_by_email(email)
  return nil unless email

  team_members.find do |team_member|
    emails = [team_member['workEmail'], team_member['bestEmail'], team_member['homeEmail']]
    emails.compact.any? { |match| email.casecmp(match).zero? }
  end
end

#search_team_member_by_email!(email) ⇒ Object Also known as: slack_email_lookup_with_fallback!

Find the team member by email and raise error if not found.

Parameters:

  • email (String)

    the team members e-mail address.

Raises:

See Also:

  • PeopleGroup::Connectors::Hris.[PeopleGroup[PeopleGroup::Connectors[PeopleGroup::Connectors::Hris[PeopleGroup::Connectors::Hris#search_team_member_by_email]


146
147
148
149
150
151
152
# File 'lib/peoplegroup/connectors/hris.rb', line 146

def search_team_member_by_email!(email)
  team_member = search_team_member_by_email(email)

  return team_member if team_member

  raise EmployeeNotFoundError, "Could not find team member with the e-mail: #{email}"
end

#team_members_by_department(department) ⇒ Array<Hash>

Team members filtered by department

Examples:

hris = PeopleGroup::Connectors::Hris.new
hris.team_members_by_department('People Operations')
#=> [{ "workEmail"=>"[email protected]", ... }, ...]

Parameters:

  • department (String)

    the department name.

Returns:

  • (Array<Hash>)

    the team members that belong to that department



162
163
164
# File 'lib/peoplegroup/connectors/hris.rb', line 162

def team_members_by_department(department)
  active_and_current_team_members.select { |team_member| team_member['department'] == department }
end

#team_members_by_division(division) ⇒ Array<Hash>

Team members filtered by division

Examples:

hris = PeopleGroup::Connectors::Hris.new
hris.team_members_by_division('People Group')

Parameters:

  • division (String)

    the division name.

Returns:

  • (Array<Hash>)

    the team members that belong to that division



172
173
174
# File 'lib/peoplegroup/connectors/hris.rb', line 172

def team_members_by_division(division)
  active_and_current_team_members.select { |team_member| team_member['division'] == division }
end