Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Check soft-delete/disabled flags before serving a cached entity
A truthy lookup result can still be a deactivated entity — check its active/deleted flag before returning it publicly.
Bad example
| 1 | const user = await UserRepository.byId(req.params.id); |
| 2 | if (!user) throw new Http404(); |
| 3 |
|
| 4 | return res.json(user.publicProfile()); |
Explanation (EN)
A truthy object can still represent an entity no longer publicly visible.
Objašnjenje (HR)
Objekt koji je truthy i dalje može predstavljati entitet koji više nije javno dostupan.
Good example
| 1 | const user = await UserRepository.byId(req.params.id); |
| 2 | if (!user || user.isDeleted || user.disabled) throw new Http404(); |
| 3 |
|
| 4 | return res.json(user.publicProfile()); |
Explanation (EN)
The entity's own active/deleted state is checked explicitly, so a deactivated record is treated the same as a missing one from the caller's perspective.
Objašnjenje (HR)
Eksplicitno se provjerava vlastito stanje entiteta (aktivan/obrisan), pa se deaktiviran zapis za pozivatelja tretira jednako kao da ne postoji.
Notes (EN)
Before serving a protected entity, enforce its current active/deleted visibility contract and the cache invalidation or version policy that keeps that state trustworthy.
Exceptions / Tradeoffs (EN)
Checking a stale cached active flag alone cannot enforce a newly revoked entity. Administrative access may intentionally include deleted records under separate authorization.