Skip to content

feat(data): add the privileged people service for person changes - #28

Merged
sanadhamadd merged 6 commits into
mainfrom
feat/privileged-people-service
Nov 28, 2026
Merged

sanadhamadd merged 6 commits into
mainfrom
feat/privileged-people-service

Conversation

@sanadhamadd

Copy link
Copy Markdown
Owner

Summary

Adds the privileged people service: the only code that changes a person's record, with the organisation's rules
enforced on the server and every change audited.

  • updatePerson changes a person's name, job title, department, location, start date, employment status, leaving
    date and manager, each in one MongoDB transaction with an expected version, so a concurrent change fails with a
    conflict instead of being overwritten.
  • The acting user comes from the signed-in viewer, never from the input. They must be an active HR member with the
    people-management permission, and whose own record is not terminated.
  • Rules enforced:
    • HR members cannot change their own manager or department.
    • Department, location and manager must exist, and a manager must be a current person who is not the person
      themself.
    • A leaving date is allowed only with status terminated, and never before the start date.
    • Anonymised records cannot be edited.
  • Input is checked against an allow-list of the input's own fields, and ids must be exact strings, so operator
    objects such as { $ne: null } are refused.
  • Every change writes one audit event with the changed fields; names and work email are never recorded. Manager
    changes also update the reporting-lines guard document, so concurrent changes to reporting lines conflict.

Membership changes, the last-HR-member guard and the Supabase account flows follow in the next pull request;
reporting-line cycle checks follow with manager changes.

Verification

Tests against a real MongoDB replica set cover each rule in both directions:

  • refused actors, with nothing written and no audit event;
  • operator objects and inherited fields;
  • version conflicts, including two concurrent updates, where exactly one commits;
  • audit contents.

The full suite passes locally (953 tests); GitHub Actions runs the same checks on this pull request.

@sanadhamadd
sanadhamadd merged commit 29627d0 into main Nov 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant