Object, Role, and Relationship Authorization
Use a doctor and patient example to connect a person, an action, and a current relationship to the actual data operation.
You’re reading a preview. Premium includes the full lesson and specialist practice. View the full curriculum.
Two doctors have the same role in a clinic app. One is assigned to a patient; the other is not. Should both be able to open that patient's record?
A role answers only part of the permission question. Authorization decides whether this person may perform this action on this particular object, under the current rules.
| Person and relationship | Read this patient's private record? |
|---|---|
| Assigned doctor with an active relationship | Yes, within the permitted fields |
| Unassigned doctor with the same role | No |
| Doctor whose assignment was revoked | No |
We'll turn that simple permission sentence into the checks around the actual read, then apply the same reasoning to writes, nested records, and batches.
Write the permission sentence first
Use a sentence with an actor, action, target, and condition: “An active assigned clinician may read this patient's clinical record.” This is more useful than “doctors have access.” It reveals which data the implementation must join or verify and which fixtures make good controls.
Role-based policy grants broad categories of actions. Attribute-based policy includes current properties such as tenant, record status, or assurance level. Relationship-based policy includes ownership, membership, assignment, and delegation. Real features often combine them. The review should describe the actual product rule rather than force every defect into a single acronym.
Follow the selector through identity and relationship to the repository.
Actor. The session identifies a doctor but does not choose their permitted patients.
const actor = requireSession(request);
requireRole(actor, "doctor");
Relation. The policy relates this actor to this target and action.
WHERE clinician_id = :actor
AND patient_id = :patient
AND status = 'active'
Read. Only the permitted projection is returned after the relationship is enforced.
return patients.findReadableByDoctor(actor, patientId);
Review question: The authorization sentence must survive all the way to the actual object operation.