FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 6b9136c4 authored by Robin Goodall's avatar Robin Goodall :speech_balloon:
Browse files

add get_all_staff and get_staff_by_id ops

parent b928dabc
No related branches found
No related tags found
No related merge requests found
Pipeline #115215 passed with warnings
......@@ -171,6 +171,45 @@ def op_get_all_rooms():
_op_get_list('rooms', 'all_rooms')
def op_get_all_staff():
"""
Get list of all staff and put in `booker.all_staff`
"""
_op_get_list('staff', 'all_staff')
def op_get_staff_by_id():
"""
Get dict of all staff keyed on Booker.Id with filtered dict of data and
put in `booker.staff_by_id`
"""
all_staff = state.get('booker.all_staff', op_get_all_staff)
# Ignore staff without an Id (hopefully none) and filter which pieces of
# data to keep
filtered_keys = ['Id', 'OptimeIndex', 'email', 'forename', 'surname']
staff_by_id = {
_sanitised_staff_id(s['Id']): {k: v for k, v in s.items() if k in filtered_keys}
for s in all_staff if _valid_staff_id(s.get('Id'))
}
LOG.info(f'Booker staff by id: {len(staff_by_id)}')
state.set('booker.staff_by_id', staff_by_id)
def _valid_staff_id(id):
""" Smells like a crsid? """
if id is None:
return False
id = _sanitised_staff_id(id)
return re.fullmatch('[a-z][a-z0-9]{2,7}', id)
def _sanitised_staff_id(id):
""" Clean up Ids that have whitespace and are uppercase """
return id.strip().lower()
# List operations filtered by rooms with TermTime equipment
def op_get_rooms():
......@@ -529,7 +568,9 @@ def _get_booked_by_list():
if only a single value is present.
"""
booked_by = state.get('booker.booked_by', 'essm-sync')
# Unfortunately, user hasn't been created the same in each Booker instance
# so add both to the list
booked_by = state.get('booker.booked_by', ['essm-sync', 'devops+essm'])
if not isinstance(booked_by, list):
return [booked_by]
return booked_by
......
......@@ -51,6 +51,14 @@ Get list of all rooms and put them in the `booker.all_rooms` state key.
#### get_all_sites
Get list of all sites and put them in the `booker.all_sites` state key.
#### get_all_staff
Get list of all staff and put them in the `booker.all_staff` state key.
#### get_staff_by_id
Get all staff, filter to those with "crsid-looking" Ids, and create a dict keyed
on a sanitised Id with a dict for the value containing limited data. Put this in
the `booker.staff_by_id` state key.
#### get_buildings
Get a list of buildings related to the filtered rooms list (see get_rooms)
and put them in the `booker.buildings` state key.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment