Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/platform/security/sensitivity.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/platform/security/sensitivity.go |
| Original SHA-256 | b7b3ab312b3e64f75f3d34e382027cc7d678458713ea670a05c9ba7fb2b558ca |
| Git blob SHA | bbff06f57e9fba3791dbea98bc36d4b8140f1e1e |
| Reading-copy SHA-256 | b7b3ab312b3e64f75f3d34e382027cc7d678458713ea670a05c9ba7fb2b558ca |
Recovered source transcript
Download complete source text ↓126 lines · 5.9 KB
package security
// FIELD SENSITIVITY, the access question the capability matrix cannot answer.
//
// A capability answers "may this person open the candidates page". It cannot answer "may this person see the
// bill rate ON that page", because the answer differs per customer: a boutique firm where the owner recruits
// wants everyone to see pay data, and a hundred seat agency running competing desks absolutely does not. So
// the capability matrix stays fixed and correct, and this adds a second, per organization axis on top of it.
//
// THE TWO AXES BOTH HAVE TO PASS. A viewer with contact_visibility set to organization still cannot see a
// candidate they have no capability to read. Sensitivity NARROWS, it never widens: no setting here grants
// anything the capability matrix withheld, which is why an organization can safely be handed this control.
//
// THIS FILE IS PURE. No database, no context, no clock. Same inputs, same answer, every time, and it is unit
// tested without a server, which is what the engineering rules ask of the parts that decide who sees what.
// Sensitivity is how far a class of field travels inside an organization. The order is deliberate and the
// zero value is the most restrictive, so a field whose sensitivity was never configured is hidden rather than
// exposed. A missing setting must never read as permission.
type Sensitivity string
const (
// SensitivityOwner is the owner alone. Used by default for margin, which is the number that tells anyone
// holding it exactly what the agency makes on a placement.
SensitivityOwner Sensitivity = "owner"
// SensitivityManagers is the owner, admins and managers: the people accountable for a book of business.
// This is the industry default for pay data and the default for rates here.
SensitivityManagers Sensitivity = "managers"
// SensitivityTeam is everyone who does the work, which is managers plus recruiters. It excludes viewers
// and members, the two roles that exist to look at outcomes rather than to run a desk.
SensitivityTeam Sensitivity = "team"
// SensitivityOrganization is everyone with a login who can already read the record.
SensitivityOrganization Sensitivity = "organization"
)
// ValidSensitivity reports whether s is one of the four levels. Used at the settings boundary so an unknown
// string is refused on the way in rather than silently treated as restrictive on the way out.
func ValidSensitivity(s Sensitivity) bool {
switch s {
case SensitivityOwner, SensitivityManagers, SensitivityTeam, SensitivityOrganization:
return true
}
return false
}
// sensitivityFloor is the LOWEST role rank that satisfies each level, read against the same roleRank ladder
// the capability matrix uses. Expressing it as a floor on the existing ladder rather than as its own role
// list means a role added to this system later cannot silently fall outside field sensitivity: it lands at a
// rank, and the rank decides.
var sensitivityFloor = map[Sensitivity]int{
SensitivityOwner: roleRank[RoleOwner],
SensitivityManagers: roleRank[RoleManager],
SensitivityTeam: roleRank[RoleRecruiter],
SensitivityOrganization: roleRank[RoleViewer],
}
// CanSeeField reports whether role may see a field classified at level s.
//
// An UNRECOGNISED level denies. That is the whole design in one line: the failure mode of a typo, a partially
// applied migration, or a value from a newer version of this software is that a rate stops being visible, not
// that it starts being visible to everyone.
func CanSeeField(role Role, s Sensitivity) bool {
floor, ok := sensitivityFloor[s]
if !ok {
return false
}
rank, ok := roleRank[role]
if !ok {
return false
}
return rank >= floor
}
// WorkVisibility is how far one person's activity travels: whether a colleague can see that somebody is
// already working a candidate. It is the double work control, and it is separate from field sensitivity
// because it governs a different thing, a person's activity rather than a record's contents.
type WorkVisibility string
const (
// VisibilityPrivate means activity is visible only to its owner and to management. Chosen by firms whose
// recruiters compete on the same bench and who consider a desk's pipeline confidential.
VisibilityPrivate WorkVisibility = "private"
// VisibilityTeam means the people who run desks see each other's activity; viewers and members do not.
VisibilityTeam WorkVisibility = "team"
// VisibilityOrganization means anyone who can read the record can see who is on it. This is the DEFAULT,
// because preventing two recruiters from calling the same candidate on the same day is the entire reason
// the feature exists, and a default of private would ship the feature switched off.
VisibilityOrganization WorkVisibility = "organization"
)
// ValidWorkVisibility reports whether v is one of the three levels.
func ValidWorkVisibility(v WorkVisibility) bool {
switch v {
case VisibilityPrivate, VisibilityTeam, VisibilityOrganization:
return true
}
return false
}
// CanSeeOthersWork reports whether viewer, holding role, may see that another person is working a record.
//
// Management always sees it, at every level including private. That is not a loophole, it is the point of the
// setting: private means recruiters do not watch each other, never that a manager cannot see their own team's
// pipeline. A manager who cannot see who is working what cannot run a desk, and an agency that bought this to
// stop double work would have bought a control that hides the collision from the only person able to fix it.
func CanSeeOthersWork(role Role, v WorkVisibility) bool {
rank, ok := roleRank[role]
if !ok {
return false
}
if rank >= roleRank[RoleManager] {
return true
}
switch v {
case VisibilityOrganization:
return true
case VisibilityTeam:
return rank >= roleRank[RoleRecruiter]
case VisibilityPrivate:
return false
default:
// Same fail closed rule as CanSeeField. An unrecognised value hides activity rather than revealing it.
return false
}
}