WIP: staff locking

STUD-1873
I've moved all this logic into a shared helper so it is much clearer to read and should be correct.