0006. Every query scoped to the user’s homes¶
Status: accepted
Date: 2026-11-07
Context¶
One instance serves several homes and several people: a household, a tenant with read-only access, a craftsperson. A single forgotten filter would expose another home’s data. The filter must be in one place and used everywhere.
Decision¶
homes.Homeandhomes.Membership(rolesowner,member,read_only) exist from the first migration. Every business model inheritshomes.models.HomeOwnedModel(ahomeforeign key and anin_homes()query method).homes.services.homes_for(user, restrict_to=None)is the only function that decides which homes a user sees: active memberships of an active user, optionally narrowed to a token’s homes.homes.scoping.HomeScopedMixingives web and API viewsget_homes()andget_home()(from thehome_idURL parameter).WebHomeScopedMixinadds the sign-in requirement for web views. A home outside the user’s scope answers 404, never 403, so its existence does not leak.Write rights depend on the role (
ownerandmemberwrite,read_onlyreads), decided byhomes.services.can_write.
Consequences¶
New business views start from these mixins and query
Model.objects.in_homes(self.get_homes()).Tests for each new resource must include the “other user’s home” case, by the web and by the API, as
tests/test_homes.pydoes for homes.