Skip to content

Enrolling at an agency's clock

The rule

A staffing agency puts clocks at its clients’ sites. A new worker enrolls at the clock on their first day under their agency worker number. Their punches must go to the agency, under that number, at once; they should be able to punch at every clock of that site; and the agency should know which clock enrolled them.

How the recipe does it

Each clock is labelled with the agency’s tenant in Time and Attendance (agency = agency-a) and its site (site = north-dock). The enrolled hook writes to the person:

  • routes: a route to the agency’s tenant with the worker number as their id there. A route that names their id links them: their punches carry it, and they are sent to the group’s clocks as its placement says;
  • labels: site, so a placement rule selecting site = north-dock sends them to the other clocks at that site;
  • metadata: enrolled_at, the clock that enrolled them.

A clock with no agency label, or a PIN that is not a worker number (an administrator’s), links no one: the person stays unlinked on that clock, and person.enrolled tells whoever decides.

For a business enrolling under payroll numbers with no routes, see link-by-pin; for onboarding through HR first, onboard-first.

What the scenarios show

tests/01-enrolled.toml: enrolled at agency A’s clock at the north dock, routed, labelled and noted; at a clock with an agency and no site, routed without a label; at a clock no agency runs, or with a PIN that is no worker number, left unlinked.

Get the recipe

The recipe, its Lua and its scenarios are in the example packages repository: policy/enroll-for-the-agency. Test it, or your own copy of it, with hourctl pkg test, and push it to a tenant as any policy package.

The policy package

enroll-for-the-agency/package.toml
name = "enroll-for-the-agency"
version = "1.0.0"
kind = "policy"
description = "Workers enrolled at a staffing agency's clock are routed to the agency's tenant under their worker number, labelled with the clock's site, and noted with the clock that enrolled them."
host_api = 2
enroll-for-the-agency/main.lua
-- A staffing agency's clocks at its clients' sites. Each clock is
-- labelled with the agency's tenant in Time and Attendance
-- (agency = "agency-a") and the site it is at (site = "north-dock").
-- Workers enroll at the clock under their agency worker number. Enrolled,
-- they are given:
--
-- * a route to the agency's tenant, with the worker number as their id
-- there, so their punches go to the agency and to their record;
-- * the label site, so the sync group's placement can send them to the
-- other clocks at that site;
-- * metadata saying which clock enrolled them.
--
-- A route that names their id links them. A clock with no agency label,
-- or a PIN that is not a worker number, links no one: the person stays
-- unlinked, on that clock, for someone to look at.
return {
enrolled = function(person, device)
local labels = device.labels or {}
local agency = labels.agency
local number = person.user_id
if agency == nil or not string.match(number, "^%d+$") then
return nil
end
local fields = {
routes = { { system = "attendance", tenant = agency, person_id = number } },
metadata = { enrolled_at = device.endpoint .. "/" .. device.device },
}
if labels.site ~= nil then
fields.labels = { site = labels.site }
end
return { person = fields }
end,
}

Scenarios

Each scenario calls the package’s hooks with what Connect would hand them, and checks what they decide (the format).

Someone enrolled at an agency's clock is routed to the agency under their worker number and labelled with the site; elsewhere, or with a PIN that is no worker number, they stay unlinked
tests/01-enrolled.toml
description = "Someone enrolled at an agency's clock is routed to the agency under their worker number and labelled with the site; elsewhere, or with a PIN that is no worker number, they stay unlinked"
[[step]]
name = "enrolled at agency A's clock at the north dock"
hook = "enrolled"
person = { user_id = "50217", fields = { name = "Ana Ruiz" } }
device = { endpoint = "client-7", device = "N1", group = "client-7", labels = { agency = "agency-a", site = "north-dock" } }
[step.expect]
effects = { person = { routes = [{ system = "attendance", tenant = "agency-a", person_id = "50217" }], labels = { site = "north-dock" }, metadata = { enrolled_at = "client-7/N1" } } }
[[step]]
name = "a clock with an agency and no site: routed, no site label"
hook = "enrolled"
person = { user_id = "50218", fields = { name = "Bo Li" } }
device = { endpoint = "client-7", device = "M1", group = "client-7", labels = { agency = "agency-b" } }
[step.expect]
effects = { person = { routes = [{ system = "attendance", tenant = "agency-b", person_id = "50218" }], metadata = { enrolled_at = "client-7/M1" } } }
[[step]]
name = "a clock no agency runs: left unlinked"
hook = "enrolled"
person = { user_id = "50219", fields = { name = "Cy Do" } }
device = { endpoint = "client-7", device = "L1", group = "client-7", labels = { site = "lobby" } }
[step.expect]
effects = {}
[[step]]
name = "a PIN that is no worker number: left unlinked"
hook = "enrolled"
person = { user_id = "ADMIN", fields = { name = "Supervisor" } }
device = { endpoint = "client-7", device = "N1", group = "client-7", labels = { agency = "agency-a", site = "north-dock" } }
[step.expect]
effects = {}