Skip to content

Onboarding through HR first

The rule

An employer onboards people in its HR system, which creates them in Time and Attendance and, through the API, in Connect. Someone enrolled at a clock directly has skipped onboarding, and must not stay on it. Supervisors may enroll people on the spot at their own clocks; those are kept until HR links them.

How the recipe does it

The enrolled hook returns delete = true, which deletes the person from the sync group, and so from the clock, unless the clock is labelled role = supervisor, where it returns nil and the person stays unlinked. person.enrolled tells HR who was enrolled where, either way.

What the scenarios show

tests/01-enrolled.toml: enrolled at the lobby clock, deleted; at a supervisor’s clock, kept.

Get the recipe

The recipe, its Lua and its scenarios are in the example packages repository: policy/onboard-first. 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

onboard-first/package.toml
name = "onboard-first"
version = "1.0.0"
kind = "policy"
description = "Onboarding goes through Time and Attendance first: a person enrolled at a clock is deleted from it, unless the clock is a supervisor's."
host_api = 2
onboard-first/main.lua
-- An employer onboards people in its HR system, which creates them in Time
-- and Attendance and, through the API, in Connect. Someone enrolled at a
-- clock directly has skipped onboarding: they are deleted from the group,
-- and so from the clock, and the person.enrolled event tells HR who. A
-- clock labelled role = "supervisor" is where supervisors enroll people on
-- the spot: those are kept, unlinked, until HR links them.
return {
enrolled = function(person, device)
if device.labels and device.labels.role == "supervisor" then
return nil
end
return { delete = true }
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 ordinary clock is deleted; at a supervisor's clock, kept unlinked
tests/01-enrolled.toml
description = "Someone enrolled at an ordinary clock is deleted; at a supervisor's clock, kept unlinked"
[[step]]
name = "enrolled at the lobby clock: deleted"
hook = "enrolled"
person = { user_id = "1001", fields = { name = "Ann Lee" } }
device = { endpoint = "office", device = "LOBBY", group = "hq", labels = { role = "lobby" } }
[step.expect]
effects = { delete = true }
[[step]]
name = "enrolled at a supervisor's clock: kept"
hook = "enrolled"
person = { user_id = "1002", fields = { name = "Bo Ng" } }
device = { endpoint = "office", device = "SUP1", group = "hq", labels = { role = "supervisor" } }
[step.expect]
effects = {}